[DTrace-devel] [PATCH 2/4] test: -xcpu for just one CPU, loop over all CPUs in stress test (cpc)

eugene.loh at oracle.com eugene.loh at oracle.com
Tue Jan 23 00:57:11 UTC 2024


From: Eugene Loh <eugene.loh at oracle.com>

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 test/stress/options/tst.cpu-cpc.sh   | 27 ++++++++++++++++++++++++++
 test/unittest/options/tst.cpu-cpc.sh | 29 ++++++++++++++++------------
 2 files changed, 44 insertions(+), 12 deletions(-)
 create mode 100755 test/stress/options/tst.cpu-cpc.sh

diff --git a/test/stress/options/tst.cpu-cpc.sh b/test/stress/options/tst.cpu-cpc.sh
new file mode 100755
index 00000000..99e1c5dd
--- /dev/null
+++ b/test/stress/options/tst.cpu-cpc.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 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
+
+nerr=0
+
+# Loop over CPUs.
+for cpu0 in `awk '/^processor[ 	]*: [0-9]*$/ {print $3}' /proc/cpuinfo`; do
+	# Observe where DTrace runs.
+	cpu=`$dtrace $dt_flags -xcpu=$cpu0 -qn 'cpc:::cpu_clock-all-100000000 { trace(cpu); exit(0); }'`
+
+	# Check result.
+	echo expected cpu $cpu0 got cpu $cpu
+	if [ `echo $cpu | wc -w` -ne 1 ]; then
+		nerr=$(($nerr + 1))
+	elif [ $(($cpu + 0)) != $cpu0 ]; then
+		nerr=$(($nerr + 1))
+	fi
+done
+
+exit $nerr
diff --git a/test/unittest/options/tst.cpu-cpc.sh b/test/unittest/options/tst.cpu-cpc.sh
index 37dc5f98..c5778a66 100755
--- a/test/unittest/options/tst.cpu-cpc.sh
+++ b/test/unittest/options/tst.cpu-cpc.sh
@@ -1,22 +1,27 @@
 #!/bin/bash
 #
 # Oracle Linux DTrace.
-# Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 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
 
-nerr=0
-for cpu0 in `awk '/^processor[ 	]*: [0-9]*$/ {print $3}' /proc/cpuinfo`; do
-	cpu=`$dtrace $dt_flags -xcpu=$cpu0 -qn 'cpc:::cpu_clock-all-100000000 { trace(cpu); exit(0); }'`
-	echo expected cpu $cpu0 got cpu $cpu
-	if [ `echo $cpu | wc -w` -ne 1 ]; then
-		nerr=$(($nerr + 1))
-	elif [ $(($cpu + 0)) != $cpu0 ]; then
-		nerr=$(($nerr + 1))
-	fi
-done
+# Pick a CPU at random.
+cpulist=( `awk '/^processor[ 	]*: [0-9]*$/ {print $3}' /proc/cpuinfo` )
+ncpus=${#cpulist[@]}
+cpu0=${cpulist[$((RANDOM % $ncpus))]}
 
-exit $nerr
+# Observe where DTrace runs.
+cpu=`$dtrace $dt_flags -xcpu=$cpu0 -qn 'cpc:::cpu_clock-all-100000000 { trace(cpu); exit(0); }'`
+
+# Check result.
+echo expected cpu $cpu0 got cpu $cpu
+if [ `echo $cpu | wc -w` -ne 1 ]; then
+	exit 1
+elif [ $(($cpu + 0)) != $cpu0 ]; then
+	exit 1
+fi
+
+exit 0
-- 
2.18.4




More information about the DTrace-devel mailing list