Merge pull request #2910 from cptjazz/compiler_warnings
[mono.git] / mono / mini / test_op_il_seq_point.sh
1 #!/bin/bash
2
3 TEST_FILE=$1
4 USE_AOT=$2
5
6 TMP_FILE_PREFIX=$(basename $0).tmp
7 BASEDIR=$(dirname $0)
8
9 case "$(uname -s)" in
10         CYGWIN*) PLATFORM_PATH_SEPARATOR=';';;
11         *) PLATFORM_PATH_SEPARATOR=':';;
12 esac
13
14 MONO_PATH=$BASEDIR/../../mcs/class/lib/net_4_x$PLATFORM_PATH_SEPARATOR$BASEDIR
15 RUNTIME=$BASEDIR/../../runtime/mono-wrapper
16
17 trap "rm -rf ${TMP_FILE_PREFIX}*" EXIT
18
19 tmp_file () {
20         mktemp ./${TMP_FILE_PREFIX}XXXX
21 }
22
23 clean_aot () {
24         rm -rf *.exe.so *.exe.dylib *.exe.dylib.dSYM *.exe.dll
25 }
26
27 # The test compares the generated native code size between a compilation with and without seq points.
28 # In some architectures ie:amd64 when possible 32bit instructions and registers are used instead of 64bit ones.
29 # Using MONO_DEBUG=single-imm-size avoids 32bit optimizations thus mantaining the native code size between compilations.
30
31 get_methods () {
32         if [ -z $4 ]; then
33                 MONO_PATH=$1 $2 -v --compile-all=1 $3 | grep '^Method .*code length' | sed 's/emitted[^()]*//' | sort
34         else
35                 clean_aot
36                 MONO_PATH=$1 $2 -v --aot $3 | grep '^Method .*code length' | sed 's/emitted[^()]*//' | sort
37         fi
38 }
39
40 get_method () {
41         if [ -z $5 ]; then
42                 MONO_VERBOSE_METHOD="$4" MONO_PATH=$1 $2 --compile-all=1 $3 | sed 's/0x[0-9a-fA-F]*/0x0/g'
43         else
44                 clean_aot
45                 MONO_VERBOSE_METHOD="$4" MONO_PATH=$1 $2 --aot $3 | sed 's/0x[0-9a-fA-F]*/0x0/g'
46         fi
47 }
48
49 diff_methods () {
50         TMP_FILE1=$(tmp_file)
51         TMP_FILE2=$(tmp_file)
52         echo "$(MONO_DEBUG=single-imm-size get_methods $1 $2 $3 $4)" >$TMP_FILE1
53         echo "$(MONO_DEBUG=gen-compact-seq-points,single-imm-size get_methods $1 $2 $3 $4)" >$TMP_FILE2
54         diff $TMP_FILE1 $TMP_FILE2
55 }
56
57 diff_method () {
58         TMP_FILE1=$(tmp_file)
59         TMP_FILE2=$(tmp_file)
60         echo "$(MONO_DEBUG=single-imm-size get_method $1 $2 $3 $4 $5)" >$TMP_FILE1
61         echo "$(MONO_DEBUG=gen-compact-seq-points,single-imm-size get_method $1 $2 $3 $4 $5 | grep -Ev il_seq_point)" >$TMP_FILE2
62         sdiff -w 150 $TMP_FILE1 $TMP_FILE2
63 }
64
65 get_method_name () {
66         echo $1 | sed -E 's/.*Method (\([^)]*\) )?([^ ]*).*/\2/g'
67 }
68
69 get_method_length () {
70         echo $1 | sed 's/.*code length \([0-9]*\).*/\1/'
71 }
72
73 if [ -z $USE_AOT ]; then
74         echo "Checking unintended native code changes in $TEST_FILE without AOT"
75 else
76         echo "Checking unintended native code changes in $TEST_FILE with AOT"
77 fi
78
79 TMP_FILE=$(tmp_file)
80
81 echo "$(diff_methods $MONO_PATH $RUNTIME $TEST_FILE $USE_AOT)" > $TMP_FILE
82
83 CHANGES=0
84 METHOD=""
85 MIN_SIZE=10000
86
87 while read line; do
88         if [ "$line" != "" ]; then
89                 echo $line
90                 if [[ ${line:0:1} == "<" ]]; then
91                         CHANGES=$((CHANGES+1))
92                         SIZE=$(get_method_length "$line")
93                         if [[ SIZE -lt MIN_SIZE ]]; then
94                                 MIN_SIZE=$SIZE
95                                 METHOD="$line"
96                         fi
97                 fi
98         fi
99 done < $TMP_FILE
100
101 TESTRESULT_FILE=TestResult-op_il_seq_point.tmp
102
103 echo -n "              <test-case name=\"MonoTests.op_il_seq_point.${TEST_FILE}${USE_AOT}\" executed=\"True\" time=\"0\" asserts=\"0\" success=\"" >> $TESTRESULT_FILE
104
105 if [ $CHANGES != 0 ]
106 then
107         METHOD_NAME=$(get_method_name "$METHOD")
108
109         echo "False\">" >> $TESTRESULT_FILE
110         echo "                <failure>" >> $TESTRESULT_FILE
111         echo -n "                  <message><![CDATA[" >> $TESTRESULT_FILE
112         echo "Detected OP_IL_SEQ_POINT incompatibility on $TEST_FILE" >> $TESTRESULT_FILE
113         echo "  $CHANGES methods differ when sequence points are enabled." >> $TESTRESULT_FILE
114         echo '  This is probably caused by a runtime optimization that is not handling OP_IL_SEQ_POINT' >> $TESTRESULT_FILE
115         echo '' >> $TESTRESULT_FILE
116         echo "Diff $METHOD_NAME" >> $TESTRESULT_FILE
117         echo "Without IL_OP_SEQ_POINT                                                         With IL_OP_SEQ_POINT" >> $TESTRESULT_FILE
118         echo -n "$(diff_method $MONO_PATH $RUNTIME $TEST_FILE $METHOD_NAME $USE_AOT)" >> $TESTRESULT_FILE
119         echo "]]></message>" >> $TESTRESULT_FILE
120         echo "                  <stack-trace>" >> $TESTRESULT_FILE
121         echo "                  </stack-trace>" >> $TESTRESULT_FILE
122         echo "                </failure>" >> $TESTRESULT_FILE
123         echo "              </test-case>" >> $TESTRESULT_FILE
124
125         echo ''
126         echo "Detected OP_IL_SEQ_POINT incompatibility on $TEST_FILE"
127         echo "  $CHANGES methods differ when sequence points are enabled."
128         echo '  This is probably caused by a runtime optimization that is not handling OP_IL_SEQ_POINT'
129
130         echo ''
131         echo "Diff $METHOD_NAME"
132         echo "Without IL_OP_SEQ_POINT                                                         With IL_OP_SEQ_POINT"
133         echo "$(diff_method $MONO_PATH $RUNTIME $TEST_FILE $METHOD_NAME $USE_AOT)"
134         exit 1
135 else
136         echo "True\" />" >> $TESTRESULT_FILE
137 fi