[DTrace-devel] [PATCH 7/7] Add a test of disassembly modes
Kris Van Hees
kris.van.hees at oracle.com
Wed Feb 9 04:47:23 UTC 2022
Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>
... but with changes:
- do not use disasm mode 0 (patch adding that is not accepted)
- do not have disasm mode id in the header (patch adding that was not accepted)
- do not flag differing BOOTTM values as a significant difference
- move the test to unittest/dtrace-util
... I will add it to 'dev'
On Thu, Jun 24, 2021 at 09:42:47PM -0400, eugene.loh at oracle.com wrote:
> 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
>
>
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel
More information about the DTrace-devel
mailing list