[PATCH 5/6] test,funcs: add uresolve() tests
Alan Maguire <[email protected]> Fri, 5 Jun 2026 23:12:16 +0100
| Newsgroups | dev.linux.lists.dtrace |
|---|---|
| Message-ID | <[email protected]> |
Add test for uresolve() symbol lookup failure with/without fallback. Also add positive test which does per-target and systemwide context uresolve() lookups, ensuring expected value is found. Signed-off-by: Alan Maguire <[email protected]> Assisted-by: OpenAI Codex (GPT-5) <[email protected]> --- test/unittest/funcs/uresolve/err.nofallback.d | 21 +++ test/unittest/funcs/uresolve/err.nofallback.r | 2 + test/unittest/funcs/uresolve/tst.fallback.d | 25 +++ test/unittest/funcs/uresolve/tst.fallback.r | 2 + test/unittest/funcs/uresolve/tst.positive.sh | 144 ++++++++++++++++++ 5 files changed, 194 insertions(+) create mode 100644 test/unittest/funcs/uresolve/err.nofallback.d create mode 100644 test/unittest/funcs/uresolve/err.nofallback.r create mode 100644 test/unittest/funcs/uresolve/tst.fallback.d create mode 100644 test/unittest/funcs/uresolve/tst.fallback.r create mode 100755 test/unittest/funcs/uresolve/tst.positive.sh diff --git a/test/unittest/funcs/uresolve/err.nofallback.d b/test/unittest/funcs/uresolve/err.nofallback.d new file mode 100644 index 00000000..5d6a1e87 --- /dev/null +++ b/test/unittest/funcs/uresolve/err.nofallback.d @@ -0,0 +1,21 @@ +/* + * 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. + */ + +/* @@trigger: longsleep */ + +/* + * ASSERTION: uresolve() withot fallback for unknown symbol fails. + * + * SECTION: Functions and Variables/uresolve() + */ + +#pragma D option quiet + +BEGIN +{ + x = uresolve("a.out`__dtrace_no_such_symbol__"); +} diff --git a/test/unittest/funcs/uresolve/err.nofallback.r b/test/unittest/funcs/uresolve/err.nofallback.r new file mode 100644 index 00000000..b93f9f78 --- /dev/null +++ b/test/unittest/funcs/uresolve/err.nofallback.r @@ -0,0 +1,2 @@ +-- @@stderr -- +dtrace: failed to compile script test/unittest/funcs/uresolve/err.nofallback.d: line 20: failed to resolve target user symbol a.out`__dtrace_no_such_symbol__ diff --git a/test/unittest/funcs/uresolve/tst.fallback.d b/test/unittest/funcs/uresolve/tst.fallback.d new file mode 100644 index 00000000..a2d5e203 --- /dev/null +++ b/test/unittest/funcs/uresolve/tst.fallback.d @@ -0,0 +1,25 @@ +/* + * 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. + */ + +/* @@trigger: longsleep */ + +/* + * ASSERTION: uresolve() returns its optional fallback value when a target + * user symbol cannot be resolved. + * + * SECTION: Functions and Variables/uresolve() + */ + +#pragma D option quiet + +BEGIN +{ + x = uresolve("a.out`__dtrace_no_such_symbol__", 0); + y = uresolve("a.out`__dtrace_no_such_symbol2__", 0xdeadbeef); + printf("%lu %lx\n", (unsigned long)x, (unsigned long)y); + exit(0); +} diff --git a/test/unittest/funcs/uresolve/tst.fallback.r b/test/unittest/funcs/uresolve/tst.fallback.r new file mode 100644 index 00000000..a224d874 --- /dev/null +++ b/test/unittest/funcs/uresolve/tst.fallback.r @@ -0,0 +1,2 @@ +0 deadbeef + diff --git a/test/unittest/funcs/uresolve/tst.positive.sh b/test/unittest/funcs/uresolve/tst.positive.sh new file mode 100755 index 00000000..a552695b --- /dev/null +++ b/test/unittest/funcs/uresolve/tst.positive.sh @@ -0,0 +1,144 @@ +#!/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. + +# @@timeout: 80 + +if [ $# != 1 ]; then + echo expected one argument: '<'dtrace-path'>' + exit 2 +fi + +dtrace=$1 +DIRNAME="$tmpdir/uresolve.$$.$RANDOM" +holdpid= +firepid= + +cleanup() +{ + if [ -n "$holdpid" ]; then + kill "$holdpid" >/dev/null 2>&1 + wait "$holdpid" >/dev/null 2>&1 + holdpid= + fi + if [ -n "$firepid" ]; then + kill "$firepid" >/dev/null 2>&1 + wait "$firepid" >/dev/null 2>&1 + firepid= + fi +} + +trap cleanup EXIT + +fail() +{ + echo "ERROR: $1" + if [ -f D.out ]; then + echo "==== DTrace output" + cat D.out + fi + cleanup + exit 1 +} + +mkdir -p "$DIRNAME" || exit 1 +cd "$DIRNAME" || exit 1 + +cat > prov.d <<EOF +provider uresolve_tst { + probe go(); +}; +EOF + +cat > main.c <<EOF +#include <signal.h> +#include <string.h> +#include <unistd.h> +#include "prov.h" + +volatile int uresolve_tst_value = 0x12345678; + +__attribute__((noinline)) void +uresolve_tst_fire(void) +{ + URESOLVE_TST_GO(); +} + +int +main(int argc, char **argv) +{ + int i; + + if (argc > 1 && strcmp(argv[1], "hold") == 0) { + for (;;) + pause(); + } + + if (argc > 1 && strcmp(argv[1], "wait") == 0) { + for (i = 0; i < 400 && !URESOLVE_TST_GO_ENABLED(); i++) + usleep(50000); + if (!URESOLVE_TST_GO_ENABLED()) + return 2; + sleep(2); + } + + uresolve_tst_fire(); + return 0; +} +EOF + +$dtrace $dt_flags -h -s prov.d || fail "failed to generate USDT header" +$CC $test_cppflags -O0 -fPIE -fno-inline -c main.c || + fail "failed to compile test object" +$dtrace $dt_flags -G -s prov.d main.o || fail "failed to generate USDT DOF" +$CC $test_ldflags -fPIE -pie -Wl,--export-dynamic -o main main.o prov.o || + fail "failed to link test program" + +$dtrace $dt_flags -q -c ./main -n ' +pid$target:a.out:uresolve_tst_fire:entry +{ + this->val = (int *)copyin(uresolve("a.out`uresolve_tst_value"), + sizeof(int)); + exit(*this->val == 0x12345678 ? 0 : 1); +}' > D.out 2>&1 || fail "pid target uresolve failed" + +$dtrace $dt_flags -q -c "./main wait" -n ' +uresolve_tst$target:::go +{ + this->val = (int *)copyin(uresolve("uresolve_tst_value"), + sizeof(int)); + exit(*this->val == 0x12345678 ? 0 : 1); +}' > D.out 2>&1 || fail "target USDT uresolve failed" + +./main hold & +holdpid=$! +sleep 1 + +$dtrace $dt_flags -Zq -p "$holdpid" -n ' +uresolve_tst*:::go +/pid != $target/ +{ + this->val = (int *)copyin(uresolve("a.out`uresolve_tst_value"), + sizeof(int)); + exit(*this->val == 0x12345678 ? 0 : 1); +} + +tick-1s +/i++ > 30/ +{ + exit(1); +}' > D.out 2>&1 & +dtpid=$! + +sleep 1 +./main wait & +firepid=$! +wait "$dtpid" || fail "system-wide USDT uresolve with target failed" +wait "$firepid" >/dev/null 2>&1 +firepid= + +cleanup +exit 0 -- 2.43.5