Commit 646a6fef authored by Daniel Vetter's avatar Daniel Vetter

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

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's avatarDaniel Vetter <>
parent c67ebf41
......@@ -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);
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)
if (in_subtest)
else if (test_with_subtests)
skip_subtests_henceforth = true;
......@@ -771,7 +774,7 @@ void igt_success(void)
succeeded_one = true;
if (in_subtest)
void igt_fail(int exitcode)
......@@ -784,13 +787,22 @@ void igt_fail(int exitcode)
failed_one = true;
if (in_subtest)
else {
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);
void igt_exit(void)
if (igt_only_list_subtests())
......@@ -836,7 +848,7 @@ void igt_skip_on_simulation(void)
if (igt_run_in_simulation())
/* other helpers */
......@@ -106,7 +106,11 @@ bool igt_only_list_subtests(void);
void igt_skip(void);
void igt_success(void);
void igt_fail(int exitcode) __attribute__((noreturn));
void __igt_fail_assert(int exitcode, const char *file,
const int line, const char *func, const char *assertion)
void igt_exit(void);
#define igt_assert(expr) do { if (!(expr)) __igt_fail_assert(99, __FILE__, __LINE__, __func__, #expr ); } while (0)
/* check functions which auto-skip tests by calling igt_skip() */
void gem_check_caching(int fd);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment