From: Zorro Lang <zlang@kernel.org>
To: fstests@vger.kernel.org
Cc: Andrey Albershteyn <aalbersh@redhat.com>,
cem@kernel.org, Dave Chinner <david@fromorbit.com>,
linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org,
linux-ext4@vger.kernel.org
Subject: [PATCH 6/6] doc: document the test hooks
Date: Thu, 26 Nov 2026 05:28:23 +0800 [thread overview]
Message-ID: <20261125212823.3389430-7-zlang@kernel.org> (raw)
In-Reply-To: <20261125212823.3389430-1-zlang@kernel.org>
Add README.hooks describing the hook events, modes, the context hooks
receive and the limitations, with examples for both modes.
Signed-off-by: Zorro Lang <zlang@kernel.org>
---
README.hooks | 156 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 156 insertions(+)
create mode 100644 README.hooks
diff --git a/README.hooks b/README.hooks
new file mode 100644
index 00000000..66cd4ddd
--- /dev/null
+++ b/README.hooks
@@ -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
--
2.56.0
prev parent reply other threads:[~2026-11-25 21:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 21:28 [PATCH 0/6] Add test hook infrastructure Zorro Lang
2026-11-25 21:28 ` [PATCH 1/6] common: add builtin " Zorro Lang
2026-11-25 21:28 ` [PATCH 2/6] common: add out-of-process hook mode Zorro Lang
2026-11-25 21:28 ` [PATCH 3/6] check: introduce pre-test hook and CLI option Zorro Lang
2026-11-25 21:28 ` [PATCH 4/6] check: introduce post-test " Zorro Lang
2026-11-25 21:28 ` [PATCH 5/6] check: introduce post-result " Zorro Lang
2026-11-25 21:28 ` Zorro Lang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125212823.3389430-7-zlang@kernel.org \
--to=zlang@kernel.org \
--cc=aalbersh@redhat.com \
--cc=cem@kernel.org \
--cc=david@fromorbit.com \
--cc=fstests@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox