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

eugene.loh at oracle.com eugene.loh at oracle.com
Tue Jan 23 00:57:10 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-BEGIN.sh   | 27 ++++++++++++++++++++++++++
 test/stress/options/tst.cpu-END.sh     | 27 ++++++++++++++++++++++++++
 test/unittest/options/tst.cpu-BEGIN.sh | 27 +++++++++++++++-----------
 test/unittest/options/tst.cpu-END.sh   | 27 +++++++++++++++-----------
 4 files changed, 86 insertions(+), 22 deletions(-)
 create mode 100755 test/stress/options/tst.cpu-BEGIN.sh
 create mode 100755 test/stress/options/tst.cpu-END.sh

diff --git a/test/stress/options/tst.cpu-BEGIN.sh b/test/stress/options/tst.cpu-BEGIN.sh
new file mode 100755
index 00000000..24d60767
--- /dev/null
+++ b/test/stress/options/tst.cpu-BEGIN.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 'BEGIN { 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/stress/options/tst.cpu-END.sh b/test/stress/options/tst.cpu-END.sh
new file mode 100755
index 00000000..0568d6db
--- /dev/null
+++ b/test/stress/options/tst.cpu-END.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 'BEGIN { exit(0) } END { trace(cpu); }'`
+
+	# 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-BEGIN.sh b/test/unittest/options/tst.cpu-BEGIN.sh
index 793ece8f..b62fdc23 100755
--- a/test/unittest/options/tst.cpu-BEGIN.sh
+++ b/test/unittest/options/tst.cpu-BEGIN.sh
@@ -8,15 +8,20 @@
 
 dtrace=$1
 
-nerr=0
-for cpu0 in `awk '/^processor[ 	]*: [0-9]*$/ {print $3}' /proc/cpuinfo`; do
-	cpu=`$dtrace $dt_flags -xcpu=$cpu0 -qn 'BEGIN { 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 'BEGIN { 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
diff --git a/test/unittest/options/tst.cpu-END.sh b/test/unittest/options/tst.cpu-END.sh
index b77cbf3c..4e19c54b 100755
--- a/test/unittest/options/tst.cpu-END.sh
+++ b/test/unittest/options/tst.cpu-END.sh
@@ -8,15 +8,20 @@
 
 dtrace=$1
 
-nerr=0
-for cpu0 in `awk '/^processor[ 	]*: [0-9]*$/ {print $3}' /proc/cpuinfo`; do
-	cpu=`$dtrace $dt_flags -xcpu=$cpu0 -qn 'BEGIN { exit(0) } END { trace(cpu); }'`
-	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 'BEGIN { exit(0) } END { trace(cpu); }'`
+
+# 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