Skip to contentSkip to conversation

selftests: harness: avoid false negatives if test has no ASSERTs

PATCH In review Jakub Kicinski 2 participants 2 messages Nov 24, 2021 – Dec 3, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: harness: avoid false negatives if test has no ASSERTs

Test can fail either immediately when ASSERT() failed or at the end if one or more EXPECT() was not met. The exact return code is decided based on the number of successful ASSERT()s.

If test has no ASSERT()s, however, the return code will be 0, as if the test did not fail. Start counting ASSERT()s from 1.

Fixes 369130b63178 ("selftests: Enhance kselftest_harness.h to print which assert failed")
---
 tools/testing/selftests/kselftest_harness.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kselftest_harness.h +1 -1
index ae0f0f33b2a6..79a182cfa43a 100644
@@ -969,7 +969,7 @@ void __run_test(struct __fixture_metadata *f,
 	t->passed = 1;
 	t->skip = 0;
 	t->trigger = 0;
-	t->step = 0;
+	t->step = 1;
 	t->no_print = 0;
 	memset(t->results->reason, 0, sizeof(t->results->reason));
 
Signature · 1 line
2.31.1
maintainer
#1 lore raw
Quoted 19 lines · Jakub Kicinski

Test can fail either immediately when ASSERT() failed or at the end if one or more EXPECT() was not met. The exact return code is decided based on the number of successful ASSERT()s.

If test has no ASSERT()s, however, the return code will be 0, as if the test did not fail. Start counting ASSERT()s from 1.

Fixes 369130b63178 ("selftests: Enhance kselftest_harness.h to print which assert failed")
---
  tools/testing/selftests/kselftest_harness.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kselftest_harness.h +0 -0
index ae0f0f33b2a6..79a182cfa43a 100644

tools/testing/selftests/kselftest_harness.h void __run_test(struct __fixture_metadata *f, · line 975

Quoted 8 lines
tools/testing/selftests/kselftest_harness.h +1 -1
@@ -969,7 +969,7 @@ void __run_test(struct __fixture_metadata *f,
  	t->passed = 1;
  	t->skip = 0;
  	t->trigger = 0;
-	t->step = 0;
+	t->step = 1;
  	t->no_print = 0;
  	memset(t->results->reason, 0, sizeof(t->results->reason));
 

Thank you for the fix. Will apply for the next pull request.

thanks,
-- Shuah