summaryrefslogtreecommitdiff
path: root/lib/drmtest.c
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2013-08-13 11:52:01 +0200
committerDaniel Vetter <daniel.vetter@ffwll.ch>2013-08-13 15:07:01 +0200
commit646a6fefbc2f11df9d25811c317d1f05aa21da45 (patch)
tree3bf36ec427c803a710d3ae7fc30d5f5615f4a086 /lib/drmtest.c
parentc67ebf413a45dd225049b14562fd76d2bbc444e2 (diff)
lib/drmtest: add igt_assert as a replacement for assert
The aim is that we keep on running subtests even when a not-too-lethal assert failed in a subtest. To make that useful also print per-subtest test results from igt_skip|fail|success functions. If required we can always go googletest-nuts with different types of asserts later on, but I think for now we're good with what we have here. v2: Also print out proper SKIP message when skipping all subsequent tests since a global (i.e. outside of a subtest) init step failed and resulted in an igt_skip call. Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'lib/drmtest.c')
-rw-r--r--lib/drmtest.c38
1 files changed, 25 insertions, 13 deletions
diff --git a/lib/drmtest.c b/lib/drmtest.c
index 486ef67c..edcb7844 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -676,7 +676,7 @@ void igt_stop_signal_helper(void)
/* subtests helpers */
static bool list_subtests = false;
static char *run_single_subtest = NULL;
-static bool in_subtest = false;
+static const char *in_subtest = NULL;
static bool test_with_subtests = false;
static bool skip_subtests_henceforth = false;
@@ -719,21 +719,23 @@ out:
*/
bool __igt_run_subtest(const char *subtest_name)
{
- assert(in_subtest == false);
+ assert(!in_subtest);
if (list_subtests) {
printf("%s\n", subtest_name);
return false;
}
- if (skip_subtests_henceforth)
+ if (skip_subtests_henceforth) {
+ printf("Subtest %s: SKIP\n", in_subtest);
return false;
+ }
if (!run_single_subtest) {
- return in_subtest = true;
+ return (in_subtest = subtest_name);
} else {
if (strcmp(subtest_name, run_single_subtest) == 0)
- return in_subtest = true;
+ return (in_subtest = subtest_name);
return false;
}
@@ -749,18 +751,19 @@ static bool succeeded_one = false;
static bool failed_one = false;
static int igt_exitcode;
-static void exit_subtest(void) __attribute__((noreturn));
-static void exit_subtest(void)
+static void exit_subtest(const char *) __attribute__((noreturn));
+static void exit_subtest(const char *result)
{
- in_subtest = false;
+ printf("Subtest %s: %s\n", in_subtest, result);
+ in_subtest = NULL;
longjmp(igt_subtest_jmpbuf, 1);
}
void igt_skip(void)
{
skipped_one = true;
- if (in_subtest)
- exit_subtest();
+ if (in_subtest)
+ exit_subtest("SKIP");
else if (test_with_subtests)
skip_subtests_henceforth = true;
else
@@ -771,7 +774,7 @@ void igt_success(void)
{
succeeded_one = true;
if (in_subtest)
- exit_subtest();
+ exit_subtest("SUCCESS");
}
void igt_fail(int exitcode)
@@ -784,13 +787,22 @@ void igt_fail(int exitcode)
failed_one = true;
if (in_subtest)
- exit_subtest();
+ exit_subtest("FAIL");
else {
assert(!test_with_subtests);
exit(exitcode);
}
}
+void __igt_fail_assert(int exitcode, const char *file,
+ const int line, const char *func, const char *assertion)
+{
+ printf("Test assertion failure function %s, file %s:%i:\n"
+ "Failed assertion: %s\n",
+ func, file, line, assertion);
+ igt_fail(exitcode);
+}
+
void igt_exit(void)
{
if (igt_only_list_subtests())
@@ -836,7 +848,7 @@ void igt_skip_on_simulation(void)
return;
if (igt_run_in_simulation())
- exit(77);
+ igt_skip();
}
/* other helpers */