[System] UriKind.RelativeOrAbsolute workaround.
[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 MONO_PATH=$BASEDIR/../../mcs/class/lib/net_4_5:$BASEDIR
10 RUNTIME=$BASEDIR/../../runtime/mono-wrapper
11
12 trap "rm -rf ${TMP_FILE_PREFIX}*" EXIT
13
14 tmp_file () {
15         mktemp ./${TMP_FILE_PREFIX}XXXX
16 }
17
18 clean_aot () {
19         rm -rf *.exe..so *.exe.dylib *.exe.dylib.dSYM
20 }
21
22 get_methods () {
23         if [ -z $4 ]; then
24                 MONO_PATH=$1 $2 -v --compile-all=1 $3 | grep '^Method .*code length' | sed 's/emitted[^()]*//' | sort
25         else
26                 clean_aot
27                 MONO_PATH=$1 $2 -v --aot $3 | grep '^Method .*code length' | sed 's/emitted[^()]*//' | sort
28         fi
29 }
30
31 get_method () {
32         if [ -z $5 ]; then
33                 MONO_VERBOSE_METHOD="$4" MONO_PATH=$1 $2 --compile-all=1 $3 | sed 's/0x[0-9a-fA-F]*/0x0/g'
34         else
35                 clean_aot
36                 MONO_VERBOSE_METHOD="$4" MONO_PATH=$1 $2 --aot $3 | sed 's/0x[0-9a-fA-F]*/0x0/g'
37         fi
38 }
39
40 diff_methods () {
41         TMP_FILE=$(tmp_file)
42         echo "$(get_methods $1 $2 $3 $4)" >$TMP_FILE
43         diff <(cat $TMP_FILE) <(echo "$(MONO_DEBUG=gen-compact-seq-points get_methods $1 $2 $3 $4)")
44 }
45
46 diff_method () {
47         TMP_FILE=$(tmp_file)
48         echo "$(get_method $1 $2 $3 $4 $5)" >$TMP_FILE
49         sdiff -w 150 <(cat $TMP_FILE) <(echo "$(MONO_DEBUG=gen-compact-seq-points get_method $1 $2 $3 $4 $5 | grep -Ev il_seq_point)")
50 }
51
52 get_method_name () {
53         echo $1 | sed -E 's/.*Method (\([^)]*\) )?([^ ]*).*/\2/g'
54 }
55
56 get_method_length () {
57         echo $1 | sed 's/.*code length \([0-9]*\).*/\1/'
58 }
59
60 if [ -z $USE_AOT ]; then
61         echo "Checking unintended native code changes in $TEST_FILE without AOT"
62 else
63         echo "Checking unintended native code changes in $TEST_FILE with AOT"
64 fi
65
66 TMP_FILE=$(tmp_file)
67
68 echo "$(diff_methods $MONO_PATH $RUNTIME $TEST_FILE $USE_AOT)" > $TMP_FILE
69
70 CHANGES=0
71 METHOD=""
72 MIN_SIZE=10000
73
74 while read line; do
75         if [ "$line" != "" ]; then
76                 echo $line
77                 if [[ ${line:0:1} == "<" ]]; then
78                         CHANGES=$((CHANGES+1))
79                         SIZE=$(get_method_length "$line")
80                         if [[ SIZE -lt MIN_SIZE ]]; then
81                                 MIN_SIZE=$SIZE
82                                 METHOD="$line"
83                         fi
84                 fi
85         fi
86 done < $TMP_FILE
87
88 echo -n "              <test-case name=\"MonoTests.op_il_seq_point.${TEST_FILE}${USE_AOT}\" executed=\"True\" time=\"0\" asserts=\"0\" success=\"" >> TestResults_op_il_seq_point.xml
89
90 if [ $CHANGES != 0 ]
91 then
92         METHOD_NAME=$(get_method_name "$METHOD")
93
94         echo "False\">" >> TestResults_op_il_seq_point.xml
95         echo "                <failure>" >> TestResults_op_il_seq_point.xml
96         echo -n "                  <message><![CDATA[" >> TestResults_op_il_seq_point.xml
97         echo "Detected OP_IL_SEQ_POINT incompatibility on $TEST_FILE" >> TestResults_op_il_seq_point.xml
98         echo "  $CHANGES methods differ when sequence points are enabled." >> TestResults_op_il_seq_point.xml
99         echo '  This is probably caused by a runtime optimization that is not handling OP_IL_SEQ_POINT' >> TestResults_op_il_seq_point.xml
100         echo '' >> TestResults_op_il_seq_point.xml
101         echo "Diff $METHOD_NAME" >> TestResults_op_il_seq_point.xml
102         echo "Without IL_OP_SEQ_POINT                                                         With IL_OP_SEQ_POINT" >> TestResults_op_il_seq_point.xml
103         echo -n "$(diff_method $MONO_PATH $RUNTIME $TEST_FILE $METHOD_NAME $USE_AOT)" >> TestResults_op_il_seq_point.xml
104         echo "]]></message>" >> TestResults_op_il_seq_point.xml
105         echo "                  <stack-trace>" >> TestResults_op_il_seq_point.xml
106         echo "                  </stack-trace>" >> TestResults_op_il_seq_point.xml
107         echo "                </failure>" >> TestResults_op_il_seq_point.xml
108         echo "              </test-case>" >> TestResults_op_il_seq_point.xml
109
110         echo ''
111         echo "Detected OP_IL_SEQ_POINT incompatibility on $TEST_FILE"
112         echo "  $CHANGES methods differ when sequence points are enabled."
113         echo '  This is probably caused by a runtime optimization that is not handling OP_IL_SEQ_POINT'
114
115         echo ''
116         echo "Diff $METHOD_NAME"
117         echo "Without IL_OP_SEQ_POINT                                                         With IL_OP_SEQ_POINT"
118         echo "$(diff_method $MONO_PATH $RUNTIME $TEST_FILE $METHOD_NAME $USE_AOT)"
119         exit 1
120 else
121         echo "True\" />" >> TestResults_op_il_seq_point.xml
122 fi