[DTrace-devel] [PATCH] test: Account for large stack-limit kernel parameter
eugene.loh at oracle.com
eugene.loh at oracle.com
Thu Oct 9 21:09:14 UTC 2025
From: Eugene Loh <eugene.loh at oracle.com>
In commit d0fdeec50 ("test: Fix some ustackdepth tests"), the test was
tweaked to check that the full stack would be recovered if the kernel
stack-limit parameter were increased from a default 127 to greater than
about 190 frames. But this does not work if the system already has
reset the kernel parameter to a high value.
Change the test to deliberately try a "too small" and a "big enough"
value -- again, ultimately restoring the original value.
Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
.../variables/bvar/tst.ustackdepth_big.sh | 103 +++++++++++-------
1 file changed, 65 insertions(+), 38 deletions(-)
diff --git a/test/unittest/variables/bvar/tst.ustackdepth_big.sh b/test/unittest/variables/bvar/tst.ustackdepth_big.sh
index 4ce53d929..0ab59fadf 100755
--- a/test/unittest/variables/bvar/tst.ustackdepth_big.sh
+++ b/test/unittest/variables/bvar/tst.ustackdepth_big.sh
@@ -23,52 +23,79 @@ cd $DIRNAME
orig_maxstack=`sysctl -n kernel.perf_event_max_stack`
echo kernel.perf_event_max_stack was $orig_maxstack
-trap "sysctl kernel.perf_event_max_stack=$orig_maxstack" QUIT EXIT
-sysctl kernel.perf_event_max_stack=200
+trap "sleep 2; sysctl kernel.perf_event_max_stack=$orig_maxstack" QUIT EXIT
-$dtrace $dt_flags -c $TRIGGER -qn '
-profile-1
-/pid == $target/
-{
- printf("DEPTH %d\n", ustackdepth);
- printf("TRACE BEGIN\n");
- ustack(200);
- printf("TRACE END\n");
- exit(0);
-}
-ERROR
-{
- exit(1);
-}
-' > D.out
-if [ $? -ne 0 ]; then
- echo DTrace failure
- exit 1
-fi
+# set bounds on the full stack depth (which is ambiguous)
+lo=188
+hi=192
-sleep 2
-sysctl kernel.perf_event_max_stack=$orig_maxstack
+function do_dtrace() {
+ # set the kernel parameter
+ sysctl kernel.perf_event_max_stack=$stack_limit
-$POSTPROC D.out > awk.out
-if [ $? -ne 0 ]; then
- echo post processing failure
- exit 1
-fi
+ # run dtrace
+ $dtrace $dt_flags -c $TRIGGER -qn '
+ profile-1
+ /pid == $target/
+ {
+ printf("DEPTH %d\n", ustackdepth);
+ printf("TRACE BEGIN\n");
+ ustack(200);
+ printf("TRACE END\n");
+ exit(0);
+ }
+ ERROR
+ {
+ exit(1);
+ }
+ ' > D.out.$stack_limit
+ if [ $? -ne 0 ]; then
+ echo ERROR: DTrace failure with $stack_limit
+ exit 1
+ fi
-if echo "Stack depth OK" | diff -q - awk.out; then
- mydepth=`gawk '/DEPTH/ { print $2 }' D.out`
- if [ $mydepth -gt $orig_maxstack ]; then
- echo success depth $mydepth exceeded original limit $orig_maxstack
- exit 0
- else
- echo ERROR: $mydepth does not exceed original limit $orig_maxstack
+ # check stackdepth consistency
+ $POSTPROC D.out.$stack_limit > awk.out.$stack_limit
+ if [ $? -ne 0 ]; then
+ echo ERROR: post processing failure
+ exit 1
+ fi
+ if ! grep -q "Stack depth OK" awk.out.$stack_limit; then
+ echo ERROR: stack depth does not match stack
cat D.out
exit 1
fi
-else
- echo "ERROR: stack depth does not match stack"
- cat D.out
+
+ # get actual stack depth
+ mydepth=`gawk '/DEPTH/ { print $2 }' D.out.$stack_limit`
+ echo with limit $stack_limit got stack depth $mydepth
+}
+
+# try a stack limit that is too small
+stack_limit=$(($lo / 2))
+do_dtrace
+echo " " stack limit $stack_limit is too small for the entire stack
+if [ $mydepth -ne $stack_limit ]; then
+ echo ERROR: $mydepth does not match $stack_limit
+ exit 1
+fi
+echo " " success: actual depth matches limit
+
+# try a stack limit that is large enough
+stack_limit=$(($hi + 20))
+do_dtrace
+echo " " stack limit $stack_limit is large enough
+if [ $mydepth -lt $lo ]; then
+ echo ERROR: $mydepth is lower than low bound $lo
+ exit 1
+fi
+if [ $mydepth -gt $hi ]; then
+ echo ERROR: $mydepth is greater than high bound $hi
exit 1
fi
+echo " " success: actual depth captures full stack
+
+# restore the kernel parameter
+sysctl kernel.perf_event_max_stack=$orig_maxstack
exit 0
--
2.47.3
More information about the DTrace-devel
mailing list