[Piglit] [PATCH 1/4] util: Add piglit_result_to_string() helper

Tom Stellard tom at stellard.net
Thu Dec 6 14:14:47 PST 2012


From: Tom Stellard <thomas.stellard at amd.com>

---
 tests/util/piglit-util.c | 21 +++++++++++++++++----
 tests/util/piglit-util.h |  1 +
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index c061def..98e0800 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -158,25 +158,38 @@ int piglit_find_line(const char *program, int position)
 	return line;
 }
 
+const char *
+piglit_result_to_string(enum piglit_result result)
+{
+        switch (result) {
+        case PIGLIT_FAIL: return "fail";
+        case PIGLIT_SKIP: return "skip";
+        case PIGLIT_WARN: return "warn";
+        case PIGLIT_PASS: return "pass";
+        }
+        return "Unknown result";
+}
+
 void
 piglit_report_result(enum piglit_result result)
 {
 	fflush(stderr);
 
+	const char *result_str = piglit_result_to_string(result);
 	if (result == PIGLIT_PASS) {
-		printf("PIGLIT: {'result': 'pass' }\n");
+		printf("PIGLIT: {'result': '%s' }\n", result_str);
 		fflush(stdout);
 		exit(0);
 	} else if (result == PIGLIT_SKIP) {
-		printf("PIGLIT: {'result': 'skip' }\n");
+		printf("PIGLIT: {'result': '%s' }\n", result_str);
 		fflush(stdout);
 		exit(0);
 	} else if (result == PIGLIT_WARN) {
-		printf("PIGLIT: {'result': 'warn' }\n");
+		printf("PIGLIT: {'result': '%s' }\n", result_str);
 		fflush(stdout);
 		exit(0);
 	} else {
-		printf("PIGLIT: {'result': 'fail' }\n");
+		printf("PIGLIT: {'result': '%s' }\n", result_str);
 		fflush(stdout);
 		exit(1);
 	}
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index e22246a..2bbc767 100644
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -133,6 +133,7 @@ bool piglit_is_extension_in_array(const char **haystack, const char *needle);
 
 int piglit_find_line(const char *program, int position);
 void piglit_merge_result(enum piglit_result *all, enum piglit_result subtest);
+const char * piglit_result_to_string(enum piglit_result result);
 void piglit_report_result(enum piglit_result result);
 
 #ifndef HAVE_STRCHRNUL
-- 
1.7.11.4



More information about the Piglit mailing list