[DTrace-devel] [PATCH 1/2] Test curcpu->cpu_id
eugene.loh at oracle.com
eugene.loh at oracle.com
Tue Aug 25 14:55:26 PDT 2020
From: Eugene Loh <eugene.loh at oracle.com>
The built-in variable curcpu is exercised only very mildly in
the test suite. In test/unittest/variables/bvar/tst.curcpu.d,
we check only if 'curcpu' can be accessed and is not -1. In
test/unittest/sched/tst.var-curcpu.d, curcpu->cpu_id is
printed but the value is not checked.
Add test/unittest/variables/bvar/tst.curcpu_cpu_id.sh to check
the curcpu->cpu_id value.
Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
.../variables/bvar/tst.curcpu_cpu_id.sh | 61 +++++++++++++++++++
1 file changed, 61 insertions(+)
create mode 100755 test/unittest/variables/bvar/tst.curcpu_cpu_id.sh
diff --git a/test/unittest/variables/bvar/tst.curcpu_cpu_id.sh b/test/unittest/variables/bvar/tst.curcpu_cpu_id.sh
new file mode 100755
index 00000000..d5992d29
--- /dev/null
+++ b/test/unittest/variables/bvar/tst.curcpu_cpu_id.sh
@@ -0,0 +1,61 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2020, 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.
+#
+
+##
+#
+# ASSERTION:
+# The cpucpu->cpu_id field matches the CPU.
+#
+# SECTION: Variables/Built-in Variables/curcpu
+#
+##
+
+dtrace=$1
+
+# Testing turns off default CPU ID output for more reproducible results.
+# For this test, however, we want that CPU ID output.
+unset _DTRACE_TESTING
+
+# Feed DTrace output into awk script to process results.
+$dtrace $dt_flags -n '
+profile-3 {
+ trace(curcpu->cpu_id);
+}
+
+profile-2 {
+ exit(0);
+}
+' | awk '
+BEGIN {
+ nevents = 0;
+ nerrors = 0;
+ ID = -1;
+}
+
+{ print }
+
+$3 == ":profile-3" {
+ nevents++;
+ if (NF != 4) { nerrors++; print; print "ERROR: not 4 fields" };
+ if ($1 != $4) { nerrors++; print; print "ERROR: CPU ID and cpu_id differ" };
+ if (used[$1] != 0) { nerrors++; print; print "ERROR: CPU ID repeated" };
+ used[$1] += 1;
+ if (ID == -1) { ID = $2 };
+ if (ID != $2) { nerrors++; print; print "ERROR: probe ID changed" };
+}
+
+END {
+ if (nevents == 0) { print "NO EVENTS"; exit(1) };
+ if (nerrors != 0) { print "FOUND ERRORS"; exit(1) };
+ print "success";
+ exit(0);
+}
+'
+
+exit $?
+
--
2.18.4
More information about the DTrace-devel
mailing list