Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftest/ftrace: Generalise ftracetest to use with RV

The ftracetest script is a fairly complete test framework for tracefs-like
subsystem, but it can only be used for ftrace selftests.

If OPT_TEST_DIR is provided and includes a function file, use that as
test directory going forward rather than just grabbing tests from it.

Generalise function names like initialize_ftrace to initialize_system.

Add the --rv argument to set up the test for rv, basically changing the
trace directory to $TRACING_DIR/rv and displaying an error if that
cannot be found.

This prepares for rv selftests inclusion.

Link: https://lore.kernel.org/r/20251017115203.140080-2-gmonaco@redhat.com
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>

+28 -14
+24 -10
tools/testing/selftests/ftrace/ftracetest
··· 22 22 echo " -d|--debug Debug mode (trace all shell commands)" 23 23 echo " -l|--logdir <dir> Save logs on the <dir>" 24 24 echo " If <dir> is -, all logs output in console only" 25 + echo " --rv Run RV selftests instead of ftrace ones" 25 26 exit $1 26 27 } 27 28 ··· 134 133 LINK_PTR= 135 134 shift 2 136 135 ;; 136 + --rv) 137 + RV_TEST=1 138 + shift 1 139 + ;; 137 140 *.tc) 138 141 if [ -f "$1" ]; then 139 142 OPT_TEST_CASES="$OPT_TEST_CASES `abspath $1`" ··· 157 152 ;; 158 153 esac 159 154 done 160 - if [ ! -z "$OPT_TEST_CASES" ]; then 155 + if [ -n "$OPT_TEST_CASES" ]; then 161 156 TEST_CASES=$OPT_TEST_CASES 157 + fi 158 + if [ -n "$OPT_TEST_DIR" -a -f "$OPT_TEST_DIR"/test.d/functions ]; then 159 + TOP_DIR=$OPT_TEST_DIR 160 + TEST_DIR=$TOP_DIR/test.d 162 161 fi 163 162 } 164 163 ··· 199 190 TOP_DIR=`absdir $0` 200 191 TEST_DIR=$TOP_DIR/test.d 201 192 TEST_CASES=`find_testcases $TEST_DIR` 202 - LOG_TOP_DIR=$TOP_DIR/logs 203 - LOG_DATE=`date +%Y%m%d-%H%M%S` 204 - LOG_DIR=$LOG_TOP_DIR/$LOG_DATE/ 205 - LINK_PTR=$LOG_TOP_DIR/latest 206 193 KEEP_LOG=0 207 194 KTAP=0 208 195 DEBUG=0 ··· 206 201 UNSUPPORTED_RESULT=0 207 202 UNRESOLVED_RESULT=0 208 203 STOP_FAILURE=0 204 + RV_TEST=0 209 205 # Parse command-line options 210 206 parse_opts $* 211 207 208 + LOG_TOP_DIR=$TOP_DIR/logs 209 + LOG_DATE=`date +%Y%m%d-%H%M%S` 210 + LOG_DIR=$LOG_TOP_DIR/$LOG_DATE/ 211 + LINK_PTR=$LOG_TOP_DIR/latest 212 + 212 213 [ $DEBUG -ne 0 ] && set -x 213 214 214 - # Verify parameters 215 - if [ -z "$TRACING_DIR" -o ! -d "$TRACING_DIR" ]; then 216 - errexit "No ftrace directory found" 215 + if [ $RV_TEST -ne 0 ]; then 216 + TRACING_DIR=$TRACING_DIR/rv 217 + if [ ! -d "$TRACING_DIR" ]; then 218 + err_ret=$err_skip 219 + errexit "rv is not configured in this kernel" 220 + fi 217 221 fi 218 222 219 223 # Preparing logs ··· 433 419 __run_test() { # testfile 434 420 # setup PID and PPID, $$ is not updated. 435 421 (cd $TRACING_DIR; read PID _ < /proc/self/stat; set -e; set -x; 436 - checkreq $1; initialize_ftrace; . $1) 422 + checkreq $1; initialize_system; . $1) 437 423 [ $? -ne 0 ] && kill -s $SIG_FAIL $SIG_PID 438 424 } 439 425 ··· 510 496 exit 1 511 497 fi 512 498 done 513 - (cd $TRACING_DIR; finish_ftrace) # for cleanup 499 + (cd $TRACING_DIR; finish_system) # for cleanup 514 500 515 501 prlog "" 516 502 prlog "# of passed: " `echo $PASSED_CASES | wc -w`
+1 -1
tools/testing/selftests/ftrace/test.d/00basic/mount_options.tc
··· 28 28 local mount_point="$1" 29 29 30 30 # Need to make sure the mount isn't busy so that we can umount it 31 - (cd $mount_point; finish_ftrace;) 31 + (cd $mount_point; finish_system;) 32 32 33 33 cleanup 34 34 }
+3 -3
tools/testing/selftests/ftrace/test.d/functions
··· 104 104 done 105 105 } 106 106 107 - initialize_ftrace() { # Reset ftrace to initial-state 107 + initialize_system() { # Reset ftrace to initial-state 108 108 # As the initial state, ftrace will be set to nop tracer, 109 109 # no events, no triggers, no filters, no function filters, 110 110 # no probes, and tracing on. ··· 134 134 enable_tracing 135 135 } 136 136 137 - finish_ftrace() { 138 - initialize_ftrace 137 + finish_system() { 138 + initialize_system 139 139 # And recover it to default. 140 140 [ -f options/pause-on-trace ] && echo 0 > options/pause-on-trace 141 141 }