Re: [PATCH v4 8/8] selftests/verification: add tlob selftests
Gabriele Monaco <[email protected]>
| Newsgroups | org.kernel.vger.linux-trace-kernel,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
On Wed, 2026-07-08 at 23:38 +0800, [email protected] wrote: > From: Wen Yang <[email protected]> > > Add seven ftrace-style test scripts for the tlob RV monitor under > tools/testing/selftests/verification/test.d/tlob/. The tests cover > uprobe binding management, budget violation detection, and per-state > time accounting. > > Helper binaries tlob_target and tlob_sym are included in the same > directory so the suite is self-contained. tlob_sym resolves ELF > symbol offsets for uprobe registration; tlob_target provides busy-spin, > sleep, and preempt workloads. > > ftracetest is updated to walk up the directory tree when searching for > test.d/functions, so monitor subdirectories can be passed as the test > directory without placing a dummy functions shim in each new directory. > > Signed-off-by: Wen Yang <[email protected]> > --- ... > +"$UPROBE_TARGET" 30000 & # busy mode: tlob_busy_work fires every 200 ms > +busy_pid=$! > +"$UPROBE_TARGET" 30000 sleep & # sleep mode: tlob_sleep_work fires every 200 > ms > +sleep_pid=$! > +sleep 0.05 > + > +echo 1 > /sys/kernel/tracing/events/rv/error_env_tlob/enable > +echo 1 > /sys/kernel/tracing/events/rv/detail_env_tlob/enable > +echo 1 > /sys/kernel/tracing/tracing_on > +echo 1 > monitors/tlob/enable > +echo > /sys/kernel/tracing/trace > + > +# Binding A: 5 s budget on the busy probe - must not fire in 200 ms loops. > +echo "p ${UPROBE_TARGET}:${busy_offset} ${busy_stop} threshold=5000000000" > > "$TLOB_MONITOR" > +# Binding B: 10 us budget on the sleep probe - fires on first invocation. > +echo "p ${UPROBE_TARGET}:${sleep_offset} ${sleep_stop} threshold=10000" > > "$TLOB_MONITOR" > + > +# Wait up to 2 s for error_env_tlob from binding B. > +found=0; i=0 > +while [ "$i" -lt 20 ]; do > + sleep 0.1 > + grep -q "error_env_tlob" /sys/kernel/tracing/trace && { found=1; > break; } > + i=$((i+1)) > +done Be careful when starting tasks and making assertions (e.g. grep) before killing them, in case those assertions fail, set -e would exit immediately and we'll skip stopping the tasks. I'd say whenever you start tlob_target (or anything else) you can do: teardown() { kill "$sleep_pid" 2>/dev/null || true; wait "$sleep_pid" 2>/dev/null || true kill "$busy_pid" 2>/dev/null || true; wait "$busy_pid" 2>/dev/null || true } trap teardown EXIT just to be safe. This will kill and wait again if you need teardown before the end of the test, but that isn't an issue. > + > +echo "-${UPROBE_TARGET}:${busy_offset}" > "$TLOB_MONITOR" 2>/dev/null > +echo "-${UPROBE_TARGET}:${sleep_offset}" > "$TLOB_MONITOR" 2>/dev/null > +kill "$sleep_pid" 2>/dev/null || true; wait "$sleep_pid" 2>/dev/null || true > +kill "$busy_pid" 2>/dev/null || true; wait "$busy_pid" 2>/dev/null || true > + > +echo 0 > monitors/tlob/enable > +echo 0 > /sys/kernel/tracing/events/rv/error_env_tlob/enable > +echo 0 > /sys/kernel/tracing/events/rv/detail_env_tlob/enable > + > +[ "$found" = "1" ] > +# error_env_tlob payload: clock variable must be present. > +# The event field can be "budget_exceeded" (hrtimer path) or the DA event > +# name ("sleep", "preempt") depending on which fires first; don't constrain > it. > +grep "error_env_tlob" /sys/kernel/tracing/trace | head -n 1 | grep -q > "clk_elapsed=" > +# detail_env_tlob must appear alongside the error. > +grep -q "detail_env_tlob" /sys/kernel/tracing/trace > + > +echo > /sys/kernel/tracing/trace > diff --git > a/tools/testing/selftests/verification/test.d/tlob/uprobe_no_event.tc > b/tools/testing/selftests/verification/test.d/tlob/uprobe_no_event.tc > new file mode 100644 > index 000000000000..bb2eeef17019 > --- /dev/null > +++ b/tools/testing/selftests/verification/test.d/tlob/uprobe_no_event.tc > @@ -0,0 +1,19 @@ > +#!/bin/sh > +# SPDX-License-Identifier: GPL-2.0-or-later > +# description: Test tlob monitor no spurious events without active uprobe > binding > +# requires: tlob:monitor > + > +TLOB_MONITOR=monitors/tlob/monitor This appears unused here. Thanks, Gabriele