summaryrefslogtreecommitdiff
path: root/qemu-wrapper.sh
blob: ea162c7ae95d6db312e8c2e0b022957ca98070d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash

# Modern versions of sanitizer enable LSAN. LSan sets atexit handler
# that calls internal_clone function that's not supported in QEMU, so
# disable it.
if [ "x$ASAN_OPTIONS" = x ]; then
    ASAN_OPTIONS=detect_leaks=0
    export ASAN_OPTIONS
else
    ASAN_OPTIONS=${ASAN_OPTIONS}:detect_leaks=0
fi

TIMEOUT="ptimeout -s KILL 300"
#The messages from /usr/bin/time cause some tests to fail when scanning the output, so don't use it
#TIME="/usr/bin/time --verbose"
TIME=
case QEMU_BIN in
    *umeq*)
	$TIMEOUT $TIME setarch x86_64 -R PROOT -q "QEMU_BIN " -R WHICHSYSROOT -b BUILDROOT "$@" #UMEQ
	exit $? #UMEQ
	;;
esac
$TIMEOUT $TIME setarch x86_64 -R PROOT -q "QEMU_BIN -cpu QEMU_CPU -R 0" -R WHICHSYSROOT -b BUILDROOT "$@"
ret1=$?

# nlocate tests are effective-target tests that fail under proot, but
# we don't want to try to make them pass without proot, because
# eventually the real testcases fail, and I don't understand why. Is
# it because qemu alone partly uses the host's locale data files?
# Just keep locale tests unsupported
case "$@" in
    *nlocale*.x)
	exit $ret1
	;;
    */lookup.*)
	STRACE="strace -f -tt"
	#QEMU_TRACE="-d in_asm,cpu"
	QEMU_TRACE="-strace"
	;;
esac

# If execution failed with proot, try without
if [ $ret1 -ne 0 ]; then
    echo "Retrying execution without proot (previous return code: $ret1)"
    $TIMEOUT $STRACE QEMU_BIN -cpu QEMU_CPU -R 0 ${QEMU_TRACE} -L WHICHSYSROOT -E LD_LIBRARY_PATH=WHICHSYSROOT/lib "$@"
    ret1=$?
    echo "Return code without proot: $ret1"
fi

case "$@" in
    # Ignore random return-code from gfortran's execute_command_line_3 when ran under proot
    *execute_command_line_3*)
	[ $ret1 -eq 127 ] && ret1=0
esac

# Some return codes can be 'safely' accepted:
# 0 OK
# 1 is a normal return code (when testing effective-targets, or in tests that verify assertions (they print an error message before exiting))
# 125 is expected by gcc/testsuite/gfortran.dg/error_stop_1.f08
# 127 is used by guality_check and read_dir
# 2 seems to be an expected error code from fortran tests
# 255 is used by arm*hw effective targets and fenv_exceptions
# 66 is used by tsan
# So, we'll ignore: 0, 1, 125, 127, 2, 66, and 255 for arm*_hw* and
# fenv_exceptions. Always report the return code, though, to help
# debug this script.

case $ret1 in
    0) exit 0 ;;
    1|125|2|66) ignore=true ;;
    127)
	case $@ in
	    *tree_map_rand*|*tree_set_rand*|*priority_queue_rand*) ignore=false ;;
	    *) ignore=true ;;
	esac
	;;
    255)
	case $@ in
	    arm*_hw*|fenv_exceptions*) ignore=true ;;
	    *) ignore=false ;;
	esac
	;;
    *) ignore=false ;;
esac

if $ignore; then
    echo "Execution returned $ret1"
    exit $ret1
fi

# Copy the executable for later debug
#if [ $ret1 -ne 0 ]; then
#    dst=/prj/compwork2/lyon/gcc-fsf-error-$ret1
#    mkdir -p $dst
#    cp $1 $dst
#fi

# If execution failed, restart it with debug traces
[ "x$TMPDIR" = "x" ] && TMPDIR=$PWD
QEMU_TRACE="-d in_asm,int,exec,cpu,unimp,guest_errors,nochain -singlestep -D $TMPDIR/qemu.log.$$"
QEMU_TRACE="-d in_asm,cpu,unimp,guest_errors -singlestep -D $TMPDIR/qemu.log.$$"

trap "rm $TMPDIR/qemu.log.$$" EXIT
#setarch x86_64 -R PROOT -q "QEMU_BIN -cpu QEMU_CPU -R 0 -d in_asm,cpu -D $TMPDIR/qemu.log.$$" -R WHICHSYSROOT -b BUILDROOT "$@"
$TIMEOUT QEMU_BIN -cpu QEMU_CPU -R 0 $QEMU_TRACE -L WHICHSYSROOT -E LD_LIBRARY_PATH=WHICHSYSROOT/lib "$@"
ret2=$?
echo "Execution failed (returned $ret1), debug execution returned $ret2"
#echo setarch x86_64 -R PROOT -q "QEMU_BIN -cpu QEMU_CPU -R 0 -d in_asm,cpu -D $TMPDIR/qemu.log.$$" -R WHICHSYSROOT -b BUILDROOT "$@"
echo QEMU_BIN -cpu QEMU_CPU -R 0 $QEMU_TRACE -L WHICHSYSROOT -E LD_LIBRARY_PATH=WHICHSYSROOT/lib "$@"
echo "START QEMU TRACE:"
tail -n 300  $TMPDIR/qemu.log.$$
echo "END QEMU TRACE:"

if [ $ret1 -ne $ret2 ]; then
    echo "DEBUGRANDOM: $@ had 2 different results: $ret1 and $ret2"
fi

# Use $ret2 in case the 1st execution failed because of "interrupted
# system call" and the 2nd one succeeded, this will avoid noise in the
# results.
exit $ret2