Skip to content

Commit

Permalink
kunit: Fix result propagation for parameterised tests
Browse files Browse the repository at this point in the history
[ Upstream commit 384426b ]

When one parameter of a parameterised test failed, its failure would be
propagated to the overall test, but not to the suite result (unless it
was the last parameter).

This is because test_case->success was being reset to the test->success
result after each parameter was used, so a failing test's result would
be overwritten by a non-failing result. The overall test result was
handled in a third variable, test_result, but this was discarded after
the status line was printed.

Instead, just propagate the result after each parameter run.

Signed-off-by: David Gow <davidgow@google.com>
Fixes: fadb08e ("kunit: Support for Parameterized Testing")
Reviewed-by: Marco Elver <elver@google.com>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
sulix authored and gregkh committed Jul 14, 2021
1 parent 55cb127 commit 8c2254d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/kunit/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ static void kunit_run_case_catch_errors(struct kunit_suite *suite,
context.test_case = test_case;
kunit_try_catch_run(try_catch, &context);

test_case->success = test->success;
test_case->success &= test->success;
}

int kunit_run_tests(struct kunit_suite *suite)
Expand All @@ -355,7 +355,7 @@ int kunit_run_tests(struct kunit_suite *suite)

kunit_suite_for_each_test_case(suite, test_case) {
struct kunit test = { .param_value = NULL, .param_index = 0 };
bool test_success = true;
test_case->success = true;

if (test_case->generate_params) {
/* Get initial param. */
Expand All @@ -365,7 +365,6 @@ int kunit_run_tests(struct kunit_suite *suite)

do {
kunit_run_case_catch_errors(suite, test_case, &test);
test_success &= test_case->success;

if (test_case->generate_params) {
if (param_desc[0] == '\0') {
Expand All @@ -387,7 +386,7 @@ int kunit_run_tests(struct kunit_suite *suite)
}
} while (test.param_value);

kunit_print_ok_not_ok(&test, true, test_success,
kunit_print_ok_not_ok(&test, true, test_case->success,
kunit_test_case_num(suite, test_case),
test_case->name);
}
Expand Down

0 comments on commit 8c2254d

Please sign in to comment.