Skip to content

Commit e2d890a

Browse files
committed
Merge branch 'selftests-xfail'
Jakub Kicinski says: ==================== selftests: kselftest_harness: support using xfail When running selftests for our subsystem in our CI we'd like all tests to pass. Currently some tests use SKIP for cases they expect to fail, because the kselftest_harness limits the return codes to pass/fail/skip. XFAIL which would be a great match here cannot be used. Remove the no_print handling and use vfork() to run the test in a different process than the setup. This way we don't need to pass "failing step" via the exit code. Further clean up the exit codes so that we can use all KSFT_* values. Rewrite the result printing to make handling XFAIL/XPASS easier. Support tests declaring combinations of fixture + variant they expect to fail. Merge plan is to put it on top of -rc6 and merge into net-next. That way others should be able to pull the patches without any networking changes. v4: - rebase on top of Mickael's vfork() changes v3: https://lore.kernel.org/all/[email protected]/ - combine multiple series - change to "list of expected failures" rather than SKIP()-like handling v2: https://lore.kernel.org/all/[email protected]/ - fix alignment follow up RFC: https://lore.kernel.org/all/[email protected]/ v1: https://lore.kernel.org/all/[email protected]/ ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 7779f26 + c05bf0e commit e2d890a

File tree

10 files changed

+178
-141
lines changed

10 files changed

+178
-141
lines changed

tools/testing/selftests/kselftest.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* ksft_test_result_skip(fmt, ...);
2626
* ksft_test_result_xfail(fmt, ...);
2727
* ksft_test_result_error(fmt, ...);
28+
* ksft_test_result_code(exit_code, test_name, fmt, ...);
2829
*
2930
* When all tests are finished, clean up and exit the program with one of:
3031
*
@@ -254,6 +255,50 @@ static inline __printf(1, 2) void ksft_test_result_error(const char *msg, ...)
254255
va_end(args);
255256
}
256257

258+
static inline __printf(3, 4)
259+
void ksft_test_result_code(int exit_code, const char *test_name,
260+
const char *msg, ...)
261+
{
262+
const char *tap_code = "ok";
263+
const char *directive = "";
264+
int saved_errno = errno;
265+
va_list args;
266+
267+
switch (exit_code) {
268+
case KSFT_PASS:
269+
ksft_cnt.ksft_pass++;
270+
break;
271+
case KSFT_XFAIL:
272+
directive = " # XFAIL ";
273+
ksft_cnt.ksft_xfail++;
274+
break;
275+
case KSFT_XPASS:
276+
directive = " # XPASS ";
277+
ksft_cnt.ksft_xpass++;
278+
break;
279+
case KSFT_SKIP:
280+
directive = " # SKIP ";
281+
ksft_cnt.ksft_xskip++;
282+
break;
283+
case KSFT_FAIL:
284+
default:
285+
tap_code = "not ok";
286+
ksft_cnt.ksft_fail++;
287+
break;
288+
}
289+
290+
/* Docs seem to call for double space if directive is absent */
291+
if (!directive[0] && msg[0])
292+
directive = " # ";
293+
294+
va_start(args, msg);
295+
printf("%s %u %s%s", tap_code, ksft_test_num(), test_name, directive);
296+
errno = saved_errno;
297+
vprintf(msg, args);
298+
printf("\n");
299+
va_end(args);
300+
}
301+
257302
static inline int ksft_exit_pass(void)
258303
{
259304
ksft_print_cnts();

0 commit comments

Comments
 (0)