Skip to content

Commit ee5f8cc

Browse files
mwajdeczshuahkh
authored andcommitted
kunit: Reset test status on each param iteration
If we skip one parametrized test case then test status remains SKIP for all subsequent test params leading to wrong reports: $ ./tools/testing/kunit/kunit.py run \ --kunitconfig ./lib/kunit/.kunitconfig *.example_params* --raw_output \ [ ] Starting KUnit Kernel (1/1)... KTAP version 1 1..1 # example: initializing suite KTAP version 1 # Subtest: example # module: kunit_example_test 1..1 KTAP version 1 # Subtest: example_params_test # example_params_test: initializing # example_params_test: cleaning up ok 1 example value 3 # SKIP unsupported param value 3 # example_params_test: initializing # example_params_test: cleaning up ok 2 example value 2 # SKIP unsupported param value 3 # example_params_test: initializing # example_params_test: cleaning up ok 3 example value 1 # SKIP unsupported param value 3 # example_params_test: initializing # example_params_test: cleaning up ok 4 example value 0 # SKIP unsupported param value 0 # example_params_test: pass:0 fail:0 skip:4 total:4 ok 1 example_params_test # SKIP unsupported param value 0 # example: exiting suite ok 1 example # SKIP Reset test status and status comment after each param iteration to avoid using stale results. Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com> Cc: David Gow <davidgow@google.com> Cc: Rae Moar <rmoar@google.com> Reviewed-by: David Gow <davidgow@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 53568b7 commit ee5f8cc

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/kunit/kunit-example-test.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ static void example_static_stub_test(struct kunit *test)
190190
static const struct example_param {
191191
int value;
192192
} example_params_array[] = {
193+
{ .value = 3, },
193194
{ .value = 2, },
194195
{ .value = 1, },
195196
{ .value = 0, },
@@ -213,8 +214,8 @@ static void example_params_test(struct kunit *test)
213214
KUNIT_ASSERT_NOT_NULL(test, param);
214215

215216
/* Test can be skipped on unsupported param values */
216-
if (!param->value)
217-
kunit_skip(test, "unsupported param value");
217+
if (!is_power_of_2(param->value))
218+
kunit_skip(test, "unsupported param value %d", param->value);
218219

219220
/* You can use param values for parameterized testing */
220221
KUNIT_EXPECT_EQ(test, param->value % param->value, 0);

lib/kunit/test.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,12 +614,14 @@ int kunit_run_tests(struct kunit_suite *suite)
614614
param_desc,
615615
test.status_comment);
616616

617+
kunit_update_stats(&param_stats, test.status);
618+
617619
/* Get next param. */
618620
param_desc[0] = '\0';
619621
test.param_value = test_case->generate_params(test.param_value, param_desc);
620622
test.param_index++;
621-
622-
kunit_update_stats(&param_stats, test.status);
623+
test.status = KUNIT_SUCCESS;
624+
test.status_comment[0] = '\0';
623625
}
624626
}
625627

0 commit comments

Comments
 (0)