[DTrace-devel] [PATCH 7/7] Add a test of disassembly modes
eugene.loh at oracle.com
eugene.loh at oracle.com
Thu Jun 24 18:42:47 PDT 2021
From: Eugene Loh <eugene.loh at oracle.com>
Check that:
x disassembly of all modes in one run is the same
as what the various modes report individually
x the default mode is correct
Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
test/unittest/dif/tst.DisOption.sh | 126 +++++++++++++++++++++++++++++
1 file changed, 126 insertions(+)
create mode 100755 test/unittest/dif/tst.DisOption.sh
diff --git a/test/unittest/dif/tst.DisOption.sh b/test/unittest/dif/tst.DisOption.sh
new file mode 100755
index 00000000..ebbf332d
--- /dev/null
+++ b/test/unittest/dif/tst.DisOption.sh
@@ -0,0 +1,126 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2021, 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: That the dtrace -xdisasm option can control the listings.
+
+dtrace=$1
+
+DIRNAME="$tmpdir/DisOption.$$.$RANDOM"
+mkdir -p $DIRNAME
+cd $DIRNAME
+
+# create sample D scripts and expected D output
+
+cat << EOF > D1.d
+int x;
+BEGIN {
+ x = 1234;
+ y = x;
+}
+EOF
+cat << EOF > D2.d
+BEGIN {
+ trace(y);
+ exit(0);
+}
+EOF
+cat << EOF > D.out
+1234
+EOF
+
+# run dtrace for various xdisasm settings
+
+function run_dtrace() {
+ $dtrace $dt_flags $2 -Sq -s D1.d -s D2.d > $1.out 2> $1.err
+ if [ $? -ne 0 ]; then
+ echo DTrace failed $2
+ cat $1.out $1.err
+ exit 1
+ fi
+}
+
+run_dtrace def # default
+run_dtrace 0 -xdisasm=1 # listing mode 0
+run_dtrace 1 -xdisasm=2 # listing mode 1
+run_dtrace 2 -xdisasm=4 # listing mode 2
+run_dtrace 3 -xdisasm=8 # listing mode 3
+run_dtrace 4 -xdisasm=16 # listing mode 4
+run_dtrace all -xdisasm=31 # all
+
+# check individual D stdout and stderr files
+
+for x in def 0 1 2 3 4 all; do
+ if [ `cat $x.err | wc -l` -lt 10 ]; then
+ echo $x.err is suspiciously small
+ cat $x.err
+ exit 1
+ fi
+ if ! diff -q $x.out D.out > /dev/null; then
+ echo $x.out is not as expected
+ cat $x.out
+ exit 1
+ fi
+done
+
+# check default setting
+
+if ! diff -q 1.err def.err > /dev/null; then
+ echo it appears that -xdisasm=2 is not the default
+ cat 1.err def.err
+ exit 1
+fi
+
+# split all.err into *.chk files
+
+for x in 0 1 2 3 4; do
+ rm -f $x.chk
+ touch $x.chk
+done
+
+awk '
+BEGIN { f = "/dev/null"; lastlineblank = 0; }
+lastlineblank == 1 {
+ # if previous line was blank, see if we should change output file
+ if (index($0, "Disassembly (#0) code generation") == 1) { f = "0.chk" } else
+ if (index($0, "Disassembly (#1) clause " ) == 1) { f = "1.chk" } else
+ if (index($0, "Disassembly (#2) program " ) == 1) { f = "2.chk" } else
+ if (index($0, "Disassembly (#3) linked program ") == 1) { f = "3.chk" } else
+ if (index($0, "Disassembly (#4) final program " ) == 1) { f = "4.chk" }
+
+ # in any case, print that previous (blank) line
+ print "" >> f;
+}
+
+# if this line is blank, do not print it yet; wait to see the next line
+NF == 0 {
+ lastlineblank = 1;
+}
+NF != 0 {
+ print $0 >> f;
+ lastlineblank = 0;
+}
+' all.err
+
+echo >> 4.chk # need an extra blank line at the end
+
+# check against *.chk files
+
+for x in 0 1 2 3 4; do
+ if ! diff -q $x.chk $x.err > /dev/null; then
+ echo $x.chk does not match $x.err
+ diff $x.chk $x.err
+ echo $x.chk
+ cat $x.chk
+ echo $x.err
+ cat $x.err
+ exit 1
+ fi
+done
+
+echo success
+exit 0
--
2.18.4
More information about the DTrace-devel
mailing list