[Piglit] [PATCH] util: Add piglit_result_to_string() helper v2
Tom Stellard
tom at stellard.net
Fri Dec 14 06:57:21 PST 2012
From: Tom Stellard <thomas.stellard at amd.com>
v2:
- Simplify piglit_report_result()
---
tests/util/piglit-util.c | 36 ++++++++++++++++++++++--------------
tests/util/piglit-util.h | 1 +
2 files changed, 23 insertions(+), 14 deletions(-)
diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index c061def..1fe734f 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -158,26 +158,34 @@ 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)
{
+ const char *result_str = piglit_result_to_string(result);
+
fflush(stderr);
- if (result == PIGLIT_PASS) {
- printf("PIGLIT: {'result': 'pass' }\n");
- fflush(stdout);
- exit(0);
- } else if (result == PIGLIT_SKIP) {
- printf("PIGLIT: {'result': 'skip' }\n");
- fflush(stdout);
- exit(0);
- } else if (result == PIGLIT_WARN) {
- printf("PIGLIT: {'result': 'warn' }\n");
- fflush(stdout);
+ printf("PIGLIT: {'result': '%s' }\n", result_str);
+ fflush(stdout);
+
+ switch(result) {
+ case PIGLIT_PASS:
+ case PIGLIT_SKIP:
+ case PIGLIT_WARN:
exit(0);
- } else {
- printf("PIGLIT: {'result': 'fail' }\n");
- fflush(stdout);
+ default:
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