[PATCH v5 8/9] stapsdt: add systemwide test for is-enabled probes
Alan Maguire <[email protected]> Wed, 4 Mar 2026 08:01:24 +0000
| Newsgroups | dev.linux.lists.dtrace |
|---|---|
| Message-ID | <[email protected]> |
Add is-enabled probes to library and ensure they fire with expected arguments when enabled. Same approach is taken as is used for system-wide libs, but semaphores must be placed in .probes section to ensure they work correctly for both existing and new processes (the semaphore counts are managed by the kernel). Signed-off-by: Alan Maguire <[email protected]> --- .../tst.stapsdt-notes-systemwide-isenabled.r | 13 + .../tst.stapsdt-notes-systemwide-isenabled.sh | 266 ++++++++++++++++++ 2 files changed, 279 insertions(+) create mode 100644 test/unittest/usdt/tst.stapsdt-notes-systemwide-isenabled.r create mode 100755 test/unittest/usdt/tst.stapsdt-notes-systemwide-isenabled.sh diff --git a/test/unittest/usdt/tst.stapsdt-notes-systemwide-isenabled.r b/test/unittest/usdt/tst.stapsdt-notes-systemwide-isenabled.r new file mode 100644 index 00000000..d7824fb5 --- /dev/null +++ b/test/unittest/usdt/tst.stapsdt-notes-systemwide-isenabled.r @@ -0,0 +1,13 @@ +libstapsdttest.so:zero +libstapsdttest.so:one:1 +libstapsdttest.so:two:2:3 +libstapsdttest.so:three:4:5:7 +libstapsdttest.so:four:7:8:9:10 +libstapsdttest.so:five:11:12:13:14:15 +libstapsdttest.so:six:16:17:18:19:20:21 +libstapsdttest.so:seven:22:23:24:25:26:27:28 +libstapsdttest.so:eight:29:30:31:32:33:34:35:36 +libstapsdttest.so:nine:37:38:39:40:41:42:43:44:45 +libstapsdttest.so:eleven:56:57:58:59:60:61:62:63:64:65 +libstapsdttest.so:twelve:67:68:69:70:71:72:73:74:75:76 + diff --git a/test/unittest/usdt/tst.stapsdt-notes-systemwide-isenabled.sh b/test/unittest/usdt/tst.stapsdt-notes-systemwide-isenabled.sh new file mode 100755 index 00000000..80c7c83c --- /dev/null +++ b/test/unittest/usdt/tst.stapsdt-notes-systemwide-isenabled.sh @@ -0,0 +1,266 @@ +#!/bin/bash +# +# Oracle Linux DTrace. +# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at +# http://oss.oracle.com/licenses/upl. + +# This test covers all stapsdt probes fired by the STAP_PROBEn macros. +# Arguments values are checked only for first 10 arguments because +# there is support for arg0 ... arg9 only at this moment. + +if [ $# != 1 ]; then + echo expected one argument: '<'dtrace-path'>' + exit 2 +fi + +dtrace=$1 +CC=/usr/bin/gcc +CFLAGS="-I${PWD}/test/unittest/usdt" + +DIRNAME="$tmpdir/usdt-notes.$$.$RANDOM" +mkdir -p $DIRNAME +cd $DIRNAME + +cat > libstapsdttest.c <<EOF +#include <stdio.h> +#define _SDT_HAS_SEMAPHORES 1 +#include <sdt_notes.h> + +#define SEC(name) __attribute__((section(name), used)) + +#define SEMA_DEFINE(name) \ + __extension__ unsigned short test_prov_##name##_semaphore \ + __attribute__((unused)) SEC(".probes") + +#define SEMA_ENABLED(name) \ + __builtin_expect (test_prov_##name##_semaphore, 0) + +SEMA_DEFINE(zero); +SEMA_DEFINE(one); +SEMA_DEFINE(two); +SEMA_DEFINE(three); +SEMA_DEFINE(four); +SEMA_DEFINE(five); +SEMA_DEFINE(six); +SEMA_DEFINE(seven); +SEMA_DEFINE(eight); +SEMA_DEFINE(nine); +SEMA_DEFINE(ten); +SEMA_DEFINE(eleven); +SEMA_DEFINE(twelve); + +void +libfn(int argc, char **argv) +{ + if (argc == 0 && argv == 0) + return; + if (SEMA_ENABLED(zero)) + STAP_PROBE(test_prov, zero); + if (SEMA_ENABLED(one)) + STAP_PROBE1(test_prov, one, argc); + if (SEMA_ENABLED(two)) + STAP_PROBE2(test_prov, two, 2, 3); + if (SEMA_ENABLED(three)) + STAP_PROBE3(test_prov, three, 4, 5, 7); + if (SEMA_ENABLED(four)) + STAP_PROBE4(test_prov, four, 7, 8, 9, 10); + if (SEMA_ENABLED(five)) + STAP_PROBE5(test_prov, five, 11, 12, 13, 14, 15); + if (SEMA_ENABLED(six)) + STAP_PROBE6(test_prov, six, 16, 17, 18, 19, 20, 21); + if (SEMA_ENABLED(seven)) + STAP_PROBE7(test_prov, seven, 22, 23, 24, 25, 26, 27, 28); + if (SEMA_ENABLED(eight)) + STAP_PROBE8(test_prov, eight, 29, 30, 31, 32, 33, 34, 35, 36); + if (SEMA_ENABLED(nine)) + STAP_PROBE9(test_prov, nine, 37, 38, 39, 40, 41, 42, 43, 44, 45); + if (SEMA_ENABLED(ten)) { + printf("should not see this since ten probe is not enabled!\n"); + STAP_PROBE10(test_prov, ten, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55); + fflush(stdout); + } + if (SEMA_ENABLED(eleven)) + STAP_PROBE11(test_prov, eleven, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66); + if (SEMA_ENABLED(twelve)) + STAP_PROBE12(test_prov, twelve, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78); +} +EOF + +cat > test.c <<EOF + +#include <unistd.h> + +extern void libfn(int argc, char **argv); + +int +main(int argc, char **argv) +{ + int i; + + for (i = 0; i < 20; i++) { + libfn(argc, argv); + sleep(1); + } + return 0; +} +EOF + +${CC} ${CFLAGS} -c -fpic libstapsdttest.c +${CC} -shared -o libstapsdttest.so libstapsdttest.o +${CC} -L. ${CFLAGS} -o test test.c -lstapsdttest +if [ $? -ne 0 ]; then + echo "failed to compile test.c" >& 2 + exit 1 +fi + +export LD_LIBRARY_PATH=.:${LD_LIBRARY_PATH} + +# Launch one program before DTrace starts + +./test & + +sleep 1 + +# Launch another with dtrace -c +$dtrace -w -c './test' -qs /dev/stdin <<EOF + +BEGIN +{ + donecount = 0; + afters = 0; +} + +/* And launch two more with system() */ +profile:::tick-1s +/ afters < 2 / +{ + system("./test &"); + afters++; +} + +test_prov*:libstapsdttest.so::zero, +test_prov*:libstapsdttest.so::one, +test_prov*:libstapsdttest.so::two, +test_prov*:libstapsdttest.so::three, +test_prov*:libstapsdttest.so::four, +test_prov*:libstapsdttest.so::five, +test_prov*:libstapsdttest.so::six, +test_prov*:libstapsdttest.so::seven, +test_prov*:libstapsdttest.so::eight, +test_prov*:libstapsdttest.so::nine, +test_prov*:libstapsdttest.so::eleven, +test_prov*:libstapsdttest.so::twelve +/ !done[probename, pid] && fired[probename] < 4 / +{ + fired[probename]++; + done[probename, pid] = 1; +} + +test_prov*:libstapsdttest.so::zero +/ fired[probename] == 4 / +{ + printf("%s:%s\n", probemod, probename); + fired[probename]++; + donecount++; +} + +test_prov*:libstapsdttest.so::one +/ fired[probename] == 4 / +{ + printf("%s:%s:%li\n", probemod, probename, arg0); + fired[probename]++; + donecount++; +} + +test_prov*:libstapsdttest.so::two +/ fired[probename] == 4 / +{ + printf("%s:%s:%li:%li\n", probemod, probename, arg0, arg1); + fired[probename]++; + donecount++; +} + +test_prov*:libstapsdttest.so::three +/ fired[probename] == 4 / +{ + printf("%s:%s:%li:%li:%li\n", probemod, probename, arg0, arg1, + arg2); + fired[probename]++; + donecount++; +} + +test_prov*:libstapsdttest.so::four +/ fired[probename] == 4 / +{ + printf("%s:%s:%li:%li:%li:%li\n", probemod, probename, arg0, arg1, + arg2, arg3); + fired[probename]++; + donecount++; +} + +test_prov*:libstapsdttest.so::five +/ fired[probename] == 4 / +{ + printf("%s:%s:%li:%li:%li:%li:%li\n", probemod, probename, + arg0, arg1, arg2, arg3, arg4); + fired[probename]++; + donecount++; +} + +test_prov*:libstapsdttest.so::six +/ fired[probename] == 4 / +{ + printf("%s:%s:%li:%li:%li:%li:%li:%li\n", probemod, probename, + arg0, arg1, arg2, arg3, arg4, arg5); + fired[probename]++; + donecount++; +} + +test_prov*:libstapsdttest.so::seven +/ fired[probename] == 4 / +{ + printf("%s:%s:%li:%li:%li:%li:%li:%li:%li\n", probemod, probename, + arg0, arg1, arg2, arg3, arg4, arg5, arg6); + fired[probename]++; + donecount++; +} + +test_prov*:libstapsdttest.so::eight +/ fired[probename] == 4 / +{ + printf("%s:%s:%li:%li:%li:%li:%li:%li:%li:%li\n", probemod, probename, + arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + fired[probename]++; + donecount++; +} + +test_prov*:libstapsdttest.so::nine +/ fired[probename] == 4 / +{ + printf("%s:%s:%li:%li:%li:%li:%li:%li:%li:%li:%li\n", probemod, probename, + arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + fired[probename]++; + donecount++; +} + +test_prov*:libstapsdttest.so::eleven, +test_prov*:libstapsdttest.so::twelve +/ fired[probename] == 4 / +{ + printf("%s:%s:%li:%li:%li:%li:%li:%li:%li:%li:%li:%li\n", probemod, probename, + arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); + fired[probename]++; + donecount++; +} + +profile:::tick-1s +/ donecount == 12 && afters == 2 / +{ + exit(0); +} + +EOF +status=$? + +exit $status -- 2.43.5