Skip to content

Commit a0aa283

Browse files
committed
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>
1 parent e9a6fb0 commit a0aa283

3 files changed

Lines changed: 28 additions & 14 deletions

File tree

tools/testing/selftests/ftrace/ftracetest

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ echo " --fail-unresolved Treat UNRESOLVED as a failure"
2222
echo " -d|--debug Debug mode (trace all shell commands)"
2323
echo " -l|--logdir <dir> Save logs on the <dir>"
2424
echo " If <dir> is -, all logs output in console only"
25+
echo " --rv Run RV selftests instead of ftrace ones"
2526
exit $1
2627
}
2728

@@ -133,6 +134,10 @@ parse_opts() { # opts
133134
LINK_PTR=
134135
shift 2
135136
;;
137+
--rv)
138+
RV_TEST=1
139+
shift 1
140+
;;
136141
*.tc)
137142
if [ -f "$1" ]; then
138143
OPT_TEST_CASES="$OPT_TEST_CASES `abspath $1`"
@@ -152,9 +157,13 @@ parse_opts() { # opts
152157
;;
153158
esac
154159
done
155-
if [ ! -z "$OPT_TEST_CASES" ]; then
160+
if [ -n "$OPT_TEST_CASES" ]; then
156161
TEST_CASES=$OPT_TEST_CASES
157162
fi
163+
if [ -n "$OPT_TEST_DIR" -a -f "$OPT_TEST_DIR"/test.d/functions ]; then
164+
TOP_DIR=$OPT_TEST_DIR
165+
TEST_DIR=$TOP_DIR/test.d
166+
fi
158167
}
159168

160169
# Parameters
@@ -190,25 +199,30 @@ fi
190199
TOP_DIR=`absdir $0`
191200
TEST_DIR=$TOP_DIR/test.d
192201
TEST_CASES=`find_testcases $TEST_DIR`
193-
LOG_TOP_DIR=$TOP_DIR/logs
194-
LOG_DATE=`date +%Y%m%d-%H%M%S`
195-
LOG_DIR=$LOG_TOP_DIR/$LOG_DATE/
196-
LINK_PTR=$LOG_TOP_DIR/latest
197202
KEEP_LOG=0
198203
KTAP=0
199204
DEBUG=0
200205
VERBOSE=0
201206
UNSUPPORTED_RESULT=0
202207
UNRESOLVED_RESULT=0
203208
STOP_FAILURE=0
209+
RV_TEST=0
204210
# Parse command-line options
205211
parse_opts $*
206212

213+
LOG_TOP_DIR=$TOP_DIR/logs
214+
LOG_DATE=`date +%Y%m%d-%H%M%S`
215+
LOG_DIR=$LOG_TOP_DIR/$LOG_DATE/
216+
LINK_PTR=$LOG_TOP_DIR/latest
217+
207218
[ $DEBUG -ne 0 ] && set -x
208219

209-
# Verify parameters
210-
if [ -z "$TRACING_DIR" -o ! -d "$TRACING_DIR" ]; then
211-
errexit "No ftrace directory found"
220+
if [ $RV_TEST -ne 0 ]; then
221+
TRACING_DIR=$TRACING_DIR/rv
222+
if [ ! -d "$TRACING_DIR" ]; then
223+
err_ret=$err_skip
224+
errexit "rv is not configured in this kernel"
225+
fi
212226
fi
213227

214228
# Preparing logs
@@ -419,7 +433,7 @@ trap 'SIG_RESULT=$XFAIL' $SIG_XFAIL
419433
__run_test() { # testfile
420434
# setup PID and PPID, $$ is not updated.
421435
(cd $TRACING_DIR; read PID _ < /proc/self/stat; set -e; set -x;
422-
checkreq $1; initialize_ftrace; . $1)
436+
checkreq $1; initialize_system; . $1)
423437
[ $? -ne 0 ] && kill -s $SIG_FAIL $SIG_PID
424438
}
425439

@@ -496,7 +510,7 @@ for t in $TEST_CASES; do
496510
exit 1
497511
fi
498512
done
499-
(cd $TRACING_DIR; finish_ftrace) # for cleanup
513+
(cd $TRACING_DIR; finish_system) # for cleanup
500514

501515
prlog ""
502516
prlog "# of passed: " `echo $PASSED_CASES | wc -w`

tools/testing/selftests/ftrace/test.d/00basic/mount_options.tc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ unmount_tracefs() {
2828
local mount_point="$1"
2929

3030
# 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;)
3232

3333
cleanup
3434
}

tools/testing/selftests/ftrace/test.d/functions

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ clear_dynamic_events() { # reset all current dynamic events
104104
done
105105
}
106106

107-
initialize_ftrace() { # Reset ftrace to initial-state
107+
initialize_system() { # Reset ftrace to initial-state
108108
# As the initial state, ftrace will be set to nop tracer,
109109
# no events, no triggers, no filters, no function filters,
110110
# no probes, and tracing on.
@@ -134,8 +134,8 @@ initialize_ftrace() { # Reset ftrace to initial-state
134134
enable_tracing
135135
}
136136

137-
finish_ftrace() {
138-
initialize_ftrace
137+
finish_system() {
138+
initialize_system
139139
# And recover it to default.
140140
[ -f options/pause-on-trace ] && echo 0 > options/pause-on-trace
141141
}

0 commit comments

Comments
 (0)