Skip to content

Commit dbcf763

Browse files
broonieshuahkh
authored andcommitted
selftests/ftrace: Improve integration with kselftest runner
The ftrace selftests do not currently produce KTAP output, they produce a custom format much nicer for human consumption. This means that when run in automated test systems we just get a single result for the suite as a whole rather than recording results for individual test cases, making it harder to look at the test data and masking things like inappropriate skips. Address this by adding support for KTAP output to the ftracetest script and providing a trivial wrapper which will be invoked by the kselftest runner to generate output in this format by default, users using ftracetest directly will continue to get the existing output. This is not the most elegant solution but it is simple and effective. I did consider implementing this by post processing the existing output format but that felt more complex and likely to result in all output being lost if something goes seriously wrong during the run which would not be helpful. I did also consider just writing a separate runner script but there's enough going on with things like the signal handling for that to seem like it would be duplicating too much. Acked-by: Steven Rostedt (Google) <[email protected]> Acked-by: Masami Hiramatsu (Google) <[email protected]> Tested-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Mark Brown <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 4b79f76 commit dbcf763

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed

tools/testing/selftests/ftrace/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# SPDX-License-Identifier: GPL-2.0
22
all:
33

4-
TEST_PROGS := ftracetest
4+
TEST_PROGS_EXTENDED := ftracetest
5+
TEST_PROGS := ftracetest-ktap
56
TEST_FILES := test.d settings
67
EXTRA_CLEAN := $(OUTPUT)/logs/*
78

tools/testing/selftests/ftrace/ftracetest

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ echo "Usage: ftracetest [options] [testcase(s)] [testcase-directory(s)]"
1313
echo " Options:"
1414
echo " -h|--help Show help message"
1515
echo " -k|--keep Keep passed test logs"
16+
echo " -K|--ktap Output in KTAP format"
1617
echo " -v|--verbose Increase verbosity of test messages"
1718
echo " -vv Alias of -v -v (Show all results in stdout)"
1819
echo " -vvv Alias of -v -v -v (Show all commands immediately)"
@@ -85,6 +86,10 @@ parse_opts() { # opts
8586
KEEP_LOG=1
8687
shift 1
8788
;;
89+
--ktap|-K)
90+
KTAP=1
91+
shift 1
92+
;;
8893
--verbose|-v|-vv|-vvv)
8994
if [ $VERBOSE -eq -1 ]; then
9095
usage "--console can not use with --verbose"
@@ -178,6 +183,7 @@ TEST_DIR=$TOP_DIR/test.d
178183
TEST_CASES=`find_testcases $TEST_DIR`
179184
LOG_DIR=$TOP_DIR/logs/`date +%Y%m%d-%H%M%S`/
180185
KEEP_LOG=0
186+
KTAP=0
181187
DEBUG=0
182188
VERBOSE=0
183189
UNSUPPORTED_RESULT=0
@@ -229,7 +235,7 @@ prlog() { # messages
229235
newline=
230236
shift
231237
fi
232-
printf "$*$newline"
238+
[ "$KTAP" != "1" ] && printf "$*$newline"
233239
[ "$LOG_FILE" ] && printf "$*$newline" | strip_esc >> $LOG_FILE
234240
}
235241
catlog() { #file
@@ -260,11 +266,11 @@ TOTAL_RESULT=0
260266

261267
INSTANCE=
262268
CASENO=0
269+
CASENAME=
263270

264271
testcase() { # testfile
265272
CASENO=$((CASENO+1))
266-
desc=`grep "^#[ \t]*description:" $1 | cut -f2- -d:`
267-
prlog -n "[$CASENO]$INSTANCE$desc"
273+
CASENAME=`grep "^#[ \t]*description:" $1 | cut -f2- -d:`
268274
}
269275

270276
checkreq() { # testfile
@@ -277,40 +283,68 @@ test_on_instance() { # testfile
277283
grep -q "^#[ \t]*flags:.*instance" $1
278284
}
279285

286+
ktaptest() { # result comment
287+
if [ "$KTAP" != "1" ]; then
288+
return
289+
fi
290+
291+
local result=
292+
if [ "$1" = "1" ]; then
293+
result="ok"
294+
else
295+
result="not ok"
296+
fi
297+
shift
298+
299+
local comment=$*
300+
if [ "$comment" != "" ]; then
301+
comment="# $comment"
302+
fi
303+
304+
echo $CASENO $result $INSTANCE$CASENAME $comment
305+
}
306+
280307
eval_result() { # sigval
281308
case $1 in
282309
$PASS)
283310
prlog " [${color_green}PASS${color_reset}]"
311+
ktaptest 1
284312
PASSED_CASES="$PASSED_CASES $CASENO"
285313
return 0
286314
;;
287315
$FAIL)
288316
prlog " [${color_red}FAIL${color_reset}]"
317+
ktaptest 0
289318
FAILED_CASES="$FAILED_CASES $CASENO"
290319
return 1 # this is a bug.
291320
;;
292321
$UNRESOLVED)
293322
prlog " [${color_blue}UNRESOLVED${color_reset}]"
323+
ktaptest 0 UNRESOLVED
294324
UNRESOLVED_CASES="$UNRESOLVED_CASES $CASENO"
295325
return $UNRESOLVED_RESULT # depends on use case
296326
;;
297327
$UNTESTED)
298328
prlog " [${color_blue}UNTESTED${color_reset}]"
329+
ktaptest 1 SKIP
299330
UNTESTED_CASES="$UNTESTED_CASES $CASENO"
300331
return 0
301332
;;
302333
$UNSUPPORTED)
303334
prlog " [${color_blue}UNSUPPORTED${color_reset}]"
335+
ktaptest 1 SKIP
304336
UNSUPPORTED_CASES="$UNSUPPORTED_CASES $CASENO"
305337
return $UNSUPPORTED_RESULT # depends on use case
306338
;;
307339
$XFAIL)
308340
prlog " [${color_green}XFAIL${color_reset}]"
341+
ktaptest 1 XFAIL
309342
XFAILED_CASES="$XFAILED_CASES $CASENO"
310343
return 0
311344
;;
312345
*)
313346
prlog " [${color_blue}UNDEFINED${color_reset}]"
347+
ktaptest 0 error
314348
UNDEFINED_CASES="$UNDEFINED_CASES $CASENO"
315349
return 1 # this must be a test bug
316350
;;
@@ -371,6 +405,7 @@ __run_test() { # testfile
371405
run_test() { # testfile
372406
local testname=`basename $1`
373407
testcase $1
408+
prlog -n "[$CASENO]$INSTANCE$CASENAME"
374409
if [ ! -z "$LOG_FILE" ] ; then
375410
local testlog=`mktemp $LOG_DIR/${CASENO}-${testname}-log.XXXXXX`
376411
else
@@ -405,6 +440,17 @@ run_test() { # testfile
405440
# load in the helper functions
406441
. $TEST_DIR/functions
407442

443+
if [ "$KTAP" = "1" ]; then
444+
echo "TAP version 13"
445+
446+
casecount=`echo $TEST_CASES | wc -w`
447+
for t in $TEST_CASES; do
448+
test_on_instance $t || continue
449+
casecount=$((casecount+1))
450+
done
451+
echo "1..${casecount}"
452+
fi
453+
408454
# Main loop
409455
for t in $TEST_CASES; do
410456
run_test $t
@@ -439,6 +485,17 @@ prlog "# of unsupported: " `echo $UNSUPPORTED_CASES | wc -w`
439485
prlog "# of xfailed: " `echo $XFAILED_CASES | wc -w`
440486
prlog "# of undefined(test bug): " `echo $UNDEFINED_CASES | wc -w`
441487

488+
if [ "$KTAP" = "1" ]; then
489+
echo -n "# Totals:"
490+
echo -n " pass:"`echo $PASSED_CASES | wc -w`
491+
echo -n " faii:"`echo $FAILED_CASES | wc -w`
492+
echo -n " xfail:"`echo $XFAILED_CASES | wc -w`
493+
echo -n " xpass:0"
494+
echo -n " skip:"`echo $UNTESTED_CASES $UNSUPPORTED_CASES | wc -w`
495+
echo -n " error:"`echo $UNRESOLVED_CASES $UNDEFINED_CASES | wc -w`
496+
echo
497+
fi
498+
442499
cleanup
443500

444501
# if no error, return 0
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh -e
2+
# SPDX-License-Identifier: GPL-2.0-only
3+
#
4+
# ftracetest-ktap: Wrapper to integrate ftracetest with the kselftest runner
5+
#
6+
# Copyright (C) Arm Ltd., 2023
7+
8+
./ftracetest -K

0 commit comments

Comments
 (0)