[DTrace-devel] [PATCH v2 2/2] tests, actions: fix tst.symmod.sh

Nick Alcock nick.alcock at oracle.com
Mon Feb 12 16:21:31 UTC 2024


This test needed adjusting for /proc/kallsyms support, which means we can't
handle built-in modules any more: so gain a bit of function to make up for
it by picking a random modular symbol instead of always using ksys_write.

This exposed another bug: when a modular symbol is picked, it doesn't strip
off the []s from the module name, causing a spurious test failure.

(This is the first time I have ever had reason to use shuf(1).)

Signed-off-by: Nick Alcock <nick.alcock at oracle.com>
---
 test/unittest/actions/symmod/tst.symmod.sh | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/test/unittest/actions/symmod/tst.symmod.sh b/test/unittest/actions/symmod/tst.symmod.sh
index 340baf53e7bb..0625ae01f366 100755
--- a/test/unittest/actions/symmod/tst.symmod.sh
+++ b/test/unittest/actions/symmod/tst.symmod.sh
@@ -1,20 +1,26 @@
 #!/bin/bash
 #
 # Oracle Linux DTrace.
-# Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2021, 2024, 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.
 #
 
 dtrace=$1
 
-# pick a test symbol from /proc/kallmodsyms
-read ADD NAM MOD <<< `awk '/ksys_write/ {print $1, $4, $5}' /proc/kallmodsyms`
+# Skip on a non-modular kernel, rather than inflooping.
 
-# a blank module means the module is vmlinux
-if [ x$MOD == x ]; then
-	MOD=vmlinux
-fi
+[[ ! -e /proc/modules ]] && exit 67
+
+# pick a test symbol from /proc/kallsyms: if we get no module, keep trying,
+# because a blank module might be vmlinux or might be built-in.  (We cannot
+# validate these given only /proc/kallsyms: the test would need to scan
+# vmlinux.ranges as well.)
+MOD=
+while [[ -z $MOD ]]; do
+    read ADD NAM MOD <<< `shuf /proc/kallsyms | head -1 | awk '{print $1, $3, gensub(/[[\]]/,"","g", $4)}'`
+    [[ -z $MOD ]] && continue;
+done
 
 # add the module to the name
 NAM=$MOD'`'$NAM
-- 
2.43.0.272.gce700b77fd




More information about the DTrace-devel mailing list