Add test hook infrastructure
cover Add test hook infrastructure
Hi all,
This series adds test hook support to fstests, allowing users to customize a test run (e.g., collecting traces, capturing extra debug data, or reporting results to an external framework) without modifying fstests itself. It is inspired by Dave Chinner's earlier hook infrastructure RFC [1] and also addresses the use cases from a recent fstests mailing list discussion [2], supporting both in-process and out-of-process hooks as well as a post-result event.
Hooks are registered on the command line via --hook-pre-test, --hook-post-test, and --hook-post-result:
--hook-<event> path=/path/to/hook[,mode=in|out][,match=<glob>]...
Options can be repeated and hooks run in the order given. Optional match=<glob> patterns restrict a hook to matching test names; without them, the hook runs for every test.
Two execution modes are supported:
- mode=in (default): a bash script defining hook_execute(), sourced in a subshell with full access to the test environment and fstests helpers.
- mode=out: a standalone executable written in any language, invoked via env(1) with the test variables in HOOK_ENV_LIST and the hook context.
All hook output is appended to $seqres.hooks, and hook failures are logged there without affecting the test result.
Series overview:
- Patch 1 adds the core hook infrastructure (mode=in) in common/hooks.
- Patch 2 adds out-of-process hook support (mode=out).
- Patches 3-5 wire up the pre-test, post-test, and post-result events and CLI options in check.
- Patch 6 adds README.hooks documenting usage and examples.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/fstests/[email protected]/
Feedback and reviews are welcome.
Thanks,
Zorro
Dave Chinner (1):
common: add builtin test hook infrastructure
Zorro Lang (5):
common: add out-of-process hook mode
check: introduce pre-test hook and CLI option
check: introduce post-test hook and CLI option
check: introduce post-result hook and CLI option
doc: document the test hooks
README.hooks | 156 ++++++++++++++++++++++++++++++++++ check | 30 ++++++- common/hooks | 230 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 414 insertions(+), 2 deletions(-) create mode 100644 README.hooks create mode 100644 common/hooks
Signature · 1 line
2.56.0
PATCH 1/6 common: add builtin test hook infrastructure
From: Dave Chinner <[email protected]>
Add support for user-defined test hooks so users can customize a test run without modifying fstests. Each hook is a bash script that defines hook_execute(). 'check' sources it in a subshell at specific points during a test, giving it full access to the test environment (devices, mount points, options, and fstests helpers).
Hooks are registered as:
--hook-pre-test path=/path/to/script[,match=<glob>]...
--hook-post-test and --hook-post-result take the same format. These options can be repeated; hooks run in the order given. Without a match pattern, a hook runs for every test; otherwise, it runs only when the test name (<type>/<seq>, e.g. generic/482) matches at least one of the glob patterns.
hook_execute() is passed the test name, along with the exit code (post-test) or final result (post-result). Hook output is saved to $seqres.hooks, and hook failures are logged without affecting the test result.
Based on Dave Chinner's hook infrastructure RFC:
https://lore.kernel.org/all/[email protected]/
--- common/hooks | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 common/hooks
common/hooks new file +175 -0
@@ -0,0 +1,175 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Test hooks let you customize a test run without modifying fstests. +# Each hook is a bash script that 'check' sources in a subshell at +# specific points during a test, with full access to the test +# environment (devices, mount points, options, and fstests helpers). +# +# Register hooks on the command line: +# +# --hook-pre-test path=/path/to/script[,match=<glob>]... +# +# --hook-post-test and --hook-post-result take the same format. These +# options can be repeated; hooks run in the order given. Without a +# match pattern, a hook runs for every test; otherwise, it runs only +# when the test name (<type>/<seq>, e.g. generic/482) matches at least +# one of the glob patterns. +# +# Relative paths are resolved from $here (the fstests root directory). +# Tilde (~) expansion is not supported; use $HOME or an absolute path. +# Match patterns cannot contain whitespace or commas. +# +# Each hook script should define a hook_execute() function, which is +# invoked with: +# +# $1 test name (e.g. generic/482) +# $2 status: test exit code (post-test), final result +# such as pass/fail/notrun/expunge (post-result), +# or unset (pre-test) +# HOOK_EVENT the event name (pre-test, post-test, post-result) +# runtime test runtime in seconds (if applicable) +# cwd $here +# stdout/stderr appended to $seqres.hooks +# +# Scripts that don't define hook_execute() are silently skipped. Hook +# failures are logged to $seqres.hooks and never affect the test result. + +_hook_pre_test_paths=() +_hook_pre_test_matches=() +_hook_post_test_paths=() +_hook_post_test_matches=() +_hook_post_result_paths=() +_hook_post_result_matches=() + +# Parse a single --hook-<event> option and record it in the per-event +# arrays. Repeated options are preserved in the order given. +_hook_parse_args() +{ + local event="$1" args="$2" + local opts pair key value + local path="" matches=() + + case "$event" in + pre-test|post-test|post-result) + ;; + *) + _fatal "hook $event: unknown event" + ;; + esac + + IFS=, read -ra opts <<< "$args" + for pair in "${opts[@]}"; do + key="${pair%%=*}" + value="${pair#*=}" + if [ "$key" = "$pair" ]; then + _fatal "hook $event: expected key=value, got '$pair'" + fi + case "$key" in + path) + [ -z "$path" ] || _fatal "hook $event: duplicate 'path'" + path="$value" + ;; + match) + matches+=("$value") + ;; + *) + _fatal "hook $event: unknown option '$key'" + ;; + esac + done + + [ -n "$path" ] || _fatal "hook $event: missing 'path'" + case "$path" in + /*) ;; + *) path="$here/$path" ;; + esac + [ -r "$path" ] || _fatal "hook $event: hook script not readable: $path" + + case "$event" in + pre-test) + _hook_pre_test_paths+=("$path") + _hook_pre_test_matches+=("${matches[*]}") + ;; + post-test) + _hook_post_test_paths+=("$path") + _hook_post_test_matches+=("${matches[*]}") + ;; + post-result) + _hook_post_result_paths+=("$path") + _hook_post_result_matches+=("${matches[*]}") + ;; + esac +} + +# Return 0 if $test_seqnum matches any of the space-separated patterns, +# or if no patterns are specified. +_hook_matches() +{ + local test_seqnum="$1" patterns="$2" + local p + + [ -z "$patterns" ] && return 0 + for p in $patterns; do + [[ "$test_seqnum" == $p ]] && return 0 + done + return 1 +} + +# Run a single hook in a subshell if its patterns match $test_seqnum. +# Output and errors go to $seqres.hooks; failures never fail the test. +_hook_run_one() +{ + local event="$1" test_seqnum="$2" status="$3" runtime="$4" + local path="$5" patterns="$6" + local rc log="$seqres.hooks" + + _hook_matches "$test_seqnum" "$patterns" || return 0 + + ( + export HOOK_EVENT="$event" + export runtime="$runtime" + . "$path" + declare -F hook_execute > /dev/null || return 0 + hook_execute "$test_seqnum" ${status:+"$status"} + ) >> "$log" 2>&1 + rc=$? + if [ $rc -ne 0 ]; then + echo "hook $event: $path failed (exit code $rc)" >> "$log" + fi +} + +# Run all hooks registered for $event that match $test_seqnum, in the +# order they were given. $status and $runtime are optional and depend +# on the event. +_hook_run_event() +{ + local event="$1" test_seqnum="$2" status="$3" runtime="$4" + local i + + case "$event" in + pre-test) + for ((i = 0; i < ${#_hook_pre_test_paths[@]}; i++)); do + _hook_run_one "$event" "$test_seqnum" \ + "$status" "$runtime" \ + "${_hook_pre_test_paths[$i]}" \ + "${_hook_pre_test_matches[$i]}" + done + ;; + post-test) + for ((i = 0; i < ${#_hook_post_test_paths[@]}; i++)); do + _hook_run_one "$event" "$test_seqnum" \ + "$status" "$runtime" \ + "${_hook_post_test_paths[$i]}" \ + "${_hook_post_test_matches[$i]}" + done + ;; + post-result) + for ((i = 0; i < ${#_hook_post_result_paths[@]}; i++)); do + _hook_run_one "$event" "$test_seqnum" \ + "$status" "$runtime" \ + "${_hook_post_result_paths[$i]}" \ + "${_hook_post_result_matches[$i]}" + done + ;; + esac +}
Signature · 1 line
2.56.0
PATCH 2/6 common: add out-of-process hook mode
In reply to Zorro LangAdd mode=out to the --hook-* options to run hooks as standalone executables rather than sourcing them in-process. This allows hooks to be written in any language. In-process sourcing remains the default (mode=in).
Both modes expose the same context to hooks:
- Test name and result as $1 and $2
- HOOK_EVENT and runtime variables
- Variables from 'check' listed in HOOK_ENV_LIST
Hooks always receive the full set of variables, with any irrelevant or missing values left empty. Since out-of-process hooks do not share the test shell environment, check explicitly passes this context to them, whereas in-process hooks inherit it directly.
--- common/hooks | 107 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 81 insertions(+), 26 deletions(-)
common/hooks +81 -26
@@ -1,13 +1,12 @@ # SPDX-License-Identifier: GPL-2.0 # # Test hooks let you customize a test run without modifying fstests. -# Each hook is a bash script that 'check' sources in a subshell at -# specific points during a test, with full access to the test -# environment (devices, mount points, options, and fstests helpers). +# Each hook is a script or executable that 'check' runs at specific +# points during a test. # # Register hooks on the command line: # -# --hook-pre-test path=/path/to/script[,match=<glob>]... +# --hook-pre-test path=/path/to/script[,mode=in|out][,match=<glob>]... # # --hook-post-test and --hook-post-result take the same format. These # options can be repeated; hooks run in the order given. Without a
@@ -19,27 +18,51 @@ # Tilde (~) expansion is not supported; use $HOME or an absolute path. # Match patterns cannot contain whitespace or commas. # -# Each hook script should define a hook_execute() function, which is -# invoked with: +# The default mode is "in": the script is sourced in a subshell and +# has full access to the test environment (devices, mount points, +# options, and fstests helpers). It should define hook_execute(); +# scripts without it are silently skipped. +# +# With mode=out, the hook runs as a standalone executable (written in +# any language). It has no access to the test shell environment and +# receives the hook context described below instead. +# +# Both modes receive the same context: # # $1 test name (e.g. generic/482) # $2 status: test exit code (post-test), final result # such as pass/fail/notrun/expunge (post-result), -# or unset (pre-test) +# or invalid (pre-test) # HOOK_EVENT the event name (pre-test, post-test, post-result) -# runtime test runtime in seconds (if applicable) +# runtime test runtime in seconds (post-result only; invalid +# for pre-test and post-test) +# <HOOK_ENV_LIST> test variables exposed by 'check' (see below) # cwd $here +# stdin /dev/null # stdout/stderr appended to $seqres.hooks # -# Scripts that don't define hook_execute() are silently skipped. Hook -# failures are logged to $seqres.hooks and never affect the test result. +# Hook failures are logged to $seqres.hooks and never affect the test +# result. mode=out requires env(1). + +# Variables exported to mode=out hooks (mode=in hooks already inherit +# them from the test environment). Unconfigured variables may be empty. +# Add to this list if hooks need more context from 'check'. +HOOK_ENV_LIST=( + FSTYP section iters + TEST_DEV TEST_DIR SCRATCH_DEV SCRATCH_MNT + MKFS_OPTIONS MOUNT_OPTIONS + RESULT_BASE REPORT_DIR seqres seqnum +) _hook_pre_test_paths=() _hook_pre_test_matches=() +_hook_pre_test_modes=() _hook_post_test_paths=() _hook_post_test_matches=() +_hook_post_test_modes=() _hook_post_result_paths=() _hook_post_result_matches=() +_hook_post_result_modes=() # Parse a single --hook-<event> option and record it in the per-event # arrays. Repeated options are preserved in the order given.
@@ -47,7 +70,7 @@ _hook_parse_args() { local event="$1" args="$2" local opts pair key value - local path="" matches=() + local path="" matches=() mode="in" case "$event" in pre-test|post-test|post-result)
@@ -72,6 +95,11 @@ _hook_parse_args() match) matches+=("$value") ;; + mode) + [ "$value" = "in" -o "$value" = "out" ] || \ + _fatal "hook $event: invalid mode '$value'" + mode="$value" + ;; *) _fatal "hook $event: unknown option '$key'" ;;
@@ -83,20 +111,32 @@ _hook_parse_args() /*) ;; *) path="$here/$path" ;; esac - [ -r "$path" ] || _fatal "hook $event: hook script not readable: $path" + case "$mode" in + in) + [ -r "$path" ] || \ + _fatal "hook $event: hook script not readable: $path" + ;; + out) + [ -x "$path" ] || \ + _fatal "hook $event: program not executable: $path" + ;; + esac case "$event" in pre-test) _hook_pre_test_paths+=("$path") _hook_pre_test_matches+=("${matches[*]}") + _hook_pre_test_modes+=("$mode") ;; post-test) _hook_post_test_paths+=("$path") _hook_post_test_matches+=("${matches[*]}") + _hook_post_test_modes+=("$mode") ;; post-result) _hook_post_result_paths+=("$path") _hook_post_result_matches+=("${matches[*]}") + _hook_post_result_modes+=("$mode") ;; esac }
@@ -115,23 +155,35 @@ _hook_matches() return 1 } -# Run a single hook in a subshell if its patterns match $test_seqnum. -# Output and errors go to $seqres.hooks; failures never fail the test. +# Run a single hook if its patterns match $test_seqnum. Output and +# errors go to $seqres.hooks; failures never fail the test. _hook_run_one() { local event="$1" test_seqnum="$2" status="$3" runtime="$4" - local path="$5" patterns="$6" - local rc log="$seqres.hooks" + local path="$5" patterns="$6" mode="$7" + local rc log="$seqres.hooks" hook_env=() v _hook_matches "$test_seqnum" "$patterns" || return 0 - ( - export HOOK_EVENT="$event" - export runtime="$runtime" - . "$path" - declare -F hook_execute > /dev/null || return 0 - hook_execute "$test_seqnum" ${status:+"$status"} - ) >> "$log" 2>&1 + case "$mode" in + in) + ( + export HOOK_EVENT="$event" + export runtime="$runtime" + . "$path" + declare -F hook_execute > /dev/null || return 0 + hook_execute "$test_seqnum" "$status" + ) < /dev/null >> "$log" 2>&1 + ;; + out) + for v in "${HOOK_ENV_LIST[@]}"; do + hook_env+=("$v=${!v}") + done + hook_env+=(HOOK_EVENT="$event" runtime="$runtime") + env "${hook_env[@]}" "$path" "$test_seqnum" "$status" \ + < /dev/null >> "$log" 2>&1 + ;; + esac rc=$? if [ $rc -ne 0 ]; then echo "hook $event: $path failed (exit code $rc)" >> "$log"
@@ -152,7 +204,8 @@ _hook_run_event() _hook_run_one "$event" "$test_seqnum" \ "$status" "$runtime" \ "${_hook_pre_test_paths[$i]}" \ - "${_hook_pre_test_matches[$i]}" + "${_hook_pre_test_matches[$i]}" \ + "${_hook_pre_test_modes[$i]}" done ;; post-test)
@@ -160,7 +213,8 @@ _hook_run_event() _hook_run_one "$event" "$test_seqnum" \ "$status" "$runtime" \ "${_hook_post_test_paths[$i]}" \ - "${_hook_post_test_matches[$i]}" + "${_hook_post_test_matches[$i]}" \ + "${_hook_post_test_modes[$i]}" done ;; post-result)
@@ -168,7 +222,8 @@ _hook_run_event() _hook_run_one "$event" "$test_seqnum" \ "$status" "$runtime" \ "${_hook_post_result_paths[$i]}" \ - "${_hook_post_result_matches[$i]}" + "${_hook_post_result_matches[$i]}" \ + "${_hook_post_result_modes[$i]}" done ;; esac
Signature · 1 line
2.56.0
PATCH 3/6 check: introduce pre-test hook and CLI option
In reply to Zorro LangAdd the --hook-pre-test option and run matching hooks right before each test is executed. Hooks are validated during option parsing, before any tests run.
--- check | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
check +11 -2
@@ -48,6 +48,7 @@ export DIFF_LENGTH=${DIFF_LENGTH:=10} timestamp=${TIMESTAMP:=false} . common/exit . common/test_names +. common/hooks rm -f $tmp.list $tmp.tmp $tmp.grep $here/$iam.out $tmp.report.* $tmp.arglist
@@ -75,6 +76,9 @@ General options: -T output timestamps -R fmt[,fmt] generate report in formats specified. Supported formats: xunit, xunit-quiet + --hook-pre-test path=script[,mode=in|out][,match=glob]... + run a hook before each matching test; may be + given multiple times --exact-order run tests in the exact order specified --extra-space <size> require minimum free space on scratch device --fs <type> test the given FSTYP; valid types include:
@@ -388,7 +392,7 @@ process_remain_tests() parse_check_args() { local short_opts="g:x:X:e:E:s:S:lnri:I:TdbR:L:h" - local long_opts="fs:,exact-order,large-fs,extra-space:,udiff,help" + local long_opts="fs:,exact-order,large-fs,extra-space:,udiff,help,hook-pre-test:" compat_old_option "$@"
@@ -489,6 +493,10 @@ parse_check_args() do_report=true shift ;; + --hook-pre-test) + _hook_parse_args pre-test "$2" + shift + ;; --large-fs) export LARGE_SCRATCH_DEV=yes ;;
@@ -1054,7 +1062,7 @@ function run_section() mkdir -p $RESULT_DIR rm -f ${RESULT_DIR}/require_scratch* rm -f ${RESULT_DIR}/require_test* - rm -f $seqres.out.bad $seqres.hints $seqres.out.good + rm -f $seqres.out.bad $seqres.hints $seqres.out.good $seqres.hooks # check if we really should run it if _expunge_test $seqnum; then
@@ -1092,6 +1100,7 @@ function run_section() (echo 1 > $DEBUGFS_MNT/clear_warn_once) > /dev/null 2>&1 test_start_time="$(date +"%F %T")" + _hook_run_event pre-test "$seqnum" if [ "$DUMP_OUTPUT" = true ]; then _run_seq 2>&1 | tee $tmp.out # Because $? would get tee's return code
Signature · 1 line
2.56.0
PATCH 4/6 check: introduce post-test hook and CLI option
In reply to Zorro LangAdd the --hook-post-test option to run matching hooks right after each test finishes (before golden output comparison), passing the test's exit code.
--- check | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
check +9 -1
@@ -79,6 +79,9 @@ General options: --hook-pre-test path=script[,mode=in|out][,match=glob]... run a hook before each matching test; may be given multiple times + --hook-post-test path=script[,mode=in|out][,match=glob]... + run a hook after each matching test; may be + given multiple times --exact-order run tests in the exact order specified --extra-space <size> require minimum free space on scratch device --fs <type> test the given FSTYP; valid types include:
@@ -392,7 +395,7 @@ process_remain_tests() parse_check_args() { local short_opts="g:x:X:e:E:s:S:lnri:I:TdbR:L:h" - local long_opts="fs:,exact-order,large-fs,extra-space:,udiff,help,hook-pre-test:" + local long_opts="fs:,exact-order,large-fs,extra-space:,udiff,help,hook-pre-test:,hook-post-test:" compat_old_option "$@"
@@ -497,6 +500,10 @@ parse_check_args() _hook_parse_args pre-test "$2" shift ;; + --hook-post-test) + _hook_parse_args post-test "$2" + shift + ;; --large-fs) export LARGE_SCRATCH_DEV=yes ;;
@@ -1109,6 +1116,7 @@ function run_section() _run_seq >$tmp.out 2>&1 sts=$? fi + _hook_run_event post-test "$seqnum" "$sts" # If someone sets kernel.core_pattern or kernel.core_uses_pid, # coredumps generated by fstests might have a longer name than
Signature · 1 line
2.56.0
PATCH 5/6 check: introduce post-result hook and CLI option
In reply to Zorro LangAdd the --hook-post-result option to run matching hooks once each test's final result (pass/fail/notrun/expunge) is determined, passing the result and runtime. Hooks run even when no report format (-R) is requested.
--- check | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
check +10 -1
@@ -82,6 +82,9 @@ General options: --hook-post-test path=script[,mode=in|out][,match=glob]... run a hook after each matching test; may be given multiple times + --hook-post-result path=script[,mode=in|out][,match=glob]... + run a hook with the result of each matching test; + may be given multiple times --exact-order run tests in the exact order specified --extra-space <size> require minimum free space on scratch device --fs <type> test the given FSTYP; valid types include:
@@ -395,7 +398,7 @@ process_remain_tests() parse_check_args() { local short_opts="g:x:X:e:E:s:S:lnri:I:TdbR:L:h" - local long_opts="fs:,exact-order,large-fs,extra-space:,udiff,help,hook-pre-test:,hook-post-test:" + local long_opts="fs:,exact-order,large-fs,extra-space:,udiff,help,hook-pre-test:,hook-post-test:,hook-post-result:" compat_old_option "$@"
@@ -504,6 +507,10 @@ parse_check_args() _hook_parse_args post-test "$2" shift ;; + --hook-post-result) + _hook_parse_args post-result "$2" + shift + ;; --large-fs) export LARGE_SCRATCH_DEV=yes ;;
@@ -783,6 +790,8 @@ _stash_test_status() { _make_testcase_report "$section" "$test_seq" \ "$test_status" "$((stop - start))" fi + _hook_run_event post-result "$test_seq" "$test_status" \ + "$((stop - start))" if ((${#loop_status[*]} > 0)); then # continuing or completing rerun-on-failure loop
Signature · 1 line
2.56.0
PATCH 6/6 doc: document the test hooks
In reply to Zorro LangAdd README.hooks describing the hook events, modes, the context hooks receive and the limitations, with examples for both modes.
--- README.hooks | 156 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 README.hooks
README.hooks new file +156 -0
@@ -0,0 +1,156 @@ +Hooks +===== + +Test hooks let you customize a test run without modifying fstests. Each +hook is a script or executable that 'check' runs at specific points during +a test. Register hooks with the --hook-pre-test, --hook-post-test, and +--hook-post-result options: + + --hook-pre-test path=/path/to/script[,mode=in|out][,match=<glob>]... + +Each option can be repeated; hooks run in the order given. Without a +match pattern, a hook runs for every test; otherwise, it runs only when +the test name (e.g. generic/482) matches at least one of the glob patterns. +Match patterns cannot contain whitespace or commas. + +Note: Relative paths are resolved from the fstests root directory ($here). + Tilde (~) expansion is not supported; use $HOME or an absolute path. + + +Events +------ + +pre-test + Runs right before each test starts (once per iteration when using + -i or -L). + +post-test + Runs right after each test finishes, before golden output + comparison, passing the test's exit code. + +post-result + Runs once each test's final result (pass/fail/notrun/expunge) is + determined, passing the result and runtime. It runs even when no + report format (-R) is requested. + + +Modes +----- + +mode=in (default) + The script is sourced in a subshell and has full access to the + test environment (devices, mount points, options, and fstests + helpers). It should define hook_execute(); scripts without it + are silently skipped. + +mode=out + The hook runs as a standalone executable (written in any + language). It has no access to the test shell environment or + fstests helpers; instead, 'check' passes the hook context via + arguments and environment variables. Requires env(1), and the + hook file must be executable. + + +Hook context +------------ + +Both modes run hooks with the same basic context: + + $1 test name (e.g. generic/482) + $2 status: test exit code (post-test), final result + such as pass/fail/notrun/expunge (post-result), + or invalid (pre-test) + HOOK_EVENT the event name (pre-test, post-test, post-result) + runtime test runtime in seconds (post-result only; invalid + for pre-test and post-test) + cwd $here (the fstests root directory) + stdin /dev/null + stdout/stderr appended to $seqres.hooks + +In addition, mode=out hooks receive the following 'check' variables in +their environment (mode=in hooks already inherit them). Unconfigured +variables may be empty: + + FSTYP section iters + TEST_DEV TEST_DIR SCRATCH_DEV SCRATCH_MNT + MKFS_OPTIONS MOUNT_OPTIONS + RESULT_BASE REPORT_DIR seqres seqnum + +Hook failures are logged to $seqres.hooks and never affect the test result. + + +Examples +-------- + +Trace a single test across multiple iterations with trace-cmd (mode=in): + + $ mkdir -p $HOME/wrapper + $ cat > $HOME/wrapper/trace-start <<'EOF' + hook_execute() + { + trace-cmd start -b 8192 -e xfs\* -e xlog\* + } + EOF + + $ cd /path/to/xfstests/ + $ mkdir -p hooks + $ cat > hooks/trace-stop <<'EOF' + hook_execute() + { + trace-cmd extract -o $seqres.trace.dat + trace-cmd reset + trace-cmd report -i $seqres.trace.dat > $seqres.trace + } + EOF + + $ ./check --hook-pre-test path=$HOME/wrapper/trace-start,match=generic/482 \ + --hook-post-test path=hooks/trace-stop,match=generic/482 \ + -i 100 generic/482 + +Report each test result to an external framework (mode=out): + + $ mkdir -p /opt/fstests-hooks + $ cat > /opt/fstests-hooks/report.sh <<'EOF' + #!/bin/bash + case "$2" in + pass) outcome=pass ;; + fail) outcome=fail ;; + notrun) outcome=skip ;; + *) outcome=error ;; + esac + my-reporter --name "/$section/$1" --result "$outcome" --runtime "$runtime" + EOF + $ chmod +x /opt/fstests-hooks/report.sh + $ ./check --hook-post-result path=/opt/fstests-hooks/report.sh,mode=out \ + -g quick + +Keep a hook inside the fstests tree and use a relative path (resolved +from the fstests root directory): + + $ cd /path/to/xfstests/ + $ mkdir -p hooks + $ cat > myhooks/pre-greet.sh <<'EOF' + hook_execute() + { + echo "running $1" + } + EOF + $ chmod +x hooks/pre-greet.sh + $ ./check --hook-pre-test path=hooks/pre-greet.sh generic/001 + +Run a pair of out-of-process hooks on every xfs test with a glob match, +repeating the same option (hooks run in the order given): + + $ cd /path/to/xfstests/ + $ cat > hooks1/notify.sh <<'EOF' + #!/bin/bash + echo "$1 finished with status $2" | logger -t fstests + EOF + $ cat > hooks2/save-log.sh <<'EOF' + #!/bin/bash + cp "$seqres.full" /var/log/fstests/"$seqnum".full + EOF + $ chmod +x hooks1/notify.sh hooks2/save-log.sh + $ ./check --hook-post-test path=hooks1/notify.sh,mode=out,match=xfs/0* \ + --hook-post-test path=hooks2/save-log.sh,mode=out \ + -g auto
Signature · 1 line
2.56.0