aboutsummaryrefslogtreecommitdiff
path: root/gcc/cil/tests/run-tests.sh
blob: fa1ddffad1ada2dc41e0b9802a93b44e1b58608a (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/bash

if [ $# -eq 0 ] ; then
    TESTS="args.c  array.c  attribute.c  bitfield.c bitfield-r1.c bitfield-r2.c bitfield-r3.c bitfieldxc.c bsort.c cvolatile.c deref_struct.c div.c empty.c  enum.c  enum_op.c float_call.c getbitsx.c icall.c initialization.c longlong.c lscope_struct.c pinvoke.c printf.c  qsort.c qsort-r.c radial33.c s0.c  s1.c  s2.c  s3.c  scalar.c string.c struct_op.c  struct_op-r.c struct_op-t.c struct_union.c switch.c switch2.c switch-r.c vec.c"
else
    TESTS="$@"
fi
TESTSDIR="$(dirname $0)"


CIL32GCC="/opt/gcc4NET/bin/cil32-gcc"
GCCCIL_PREFIX="/home/ricardo/mine/install"
GCCCIL="${GCCCIL_PREFIX}/bin/gcil"
#GCCCIL_OPTIONS=" -fuse-mono-runtime"
GCCCIL_OPTIONS=""
VM='mono'
DIS='monodis'

EXTRACIL1O3="-mtune=generic"

function e ()
{
    LOG="$1"
    shift
    echo $@ >> $LOG
    $@ >> $LOG 2>&1
} 

function eo ()
{
    LOG="$1"
    shift
    OUT="$1"
    shift
    echo $@ \> $OUT >> $LOG
    $@ > $OUT 2>> $LOG
} 

function eoe ()
{
    LOG="$1"
    shift
    OUT="$1"
    shift
    echo $@ \&\> $OUT >> $LOG
    $@ &> $OUT
} 

for i in $TESTS ; do
    f=${TESTSDIR}/$i
    ib="$(echo $(basename $f) | rev | cut -d. -f2- | rev)"
    echo -n "${ib} "
    echo "$ib"  > "$ib".log

    e "$ib".log ${CIL32GCC} "$f" -S -o "${ib}.il"
    if [ $? -ne 0 ] ; then echo "FAILED compiling C to IL" ; continue ; fi

    e "$ib".log ${CIL32GCC} "$f" -o "${ib}.exe"
    if [ $? -ne 0 ] ; then echo "FAILED compiling C to EXE" ; continue ; fi

    eo "$ib".log ${ib}.exe.dis ${DIS} ${ib}.exe 
    if [ $? -ne 0 ] ; then echo "FAILED disassembling EXE" ; continue ; fi

    e "$ib".log ${GCCCIL} -S "${ib}.exe" ${GCCCIL_OPTIONS} -o "${ib}.exe.s"
    if [ $? -ne 0 ] ; then echo "FAILED compiling EXE to assembler" ; continue ; fi


    e "$ib".log ${GCCCIL} -v "${ib}.exe" ${GCCCIL_OPTIONS} -lm -o "${ib}"
    if [ $? -ne 0 ] ; then echo "FAILED compiling EXE to executable" ; continue ; fi

    eoe "$ib".log "${ib}.vmout" ${VM} "${ib}.exe"
    VM_EXITCODE=$?
    echo "Vm output: <<EOF"  >> "$ib".log 2>&1
    cat "${ib}.vmout"  >> "$ib".log 2>&1
    echo "EOF"  >> "$ib".log 2>&1
    echo "Vm exitcode: ${VM_EXITCODE}" >> "$ib".log 2>&1

    eoe "$ib".log "${ib}.out" "./${ib}"
    EXECUTABLE_EXITCODE=$?
    echo "Executable output: <<EOF"  >> "$ib".log 2>&1
    cat "${ib}.out"  >> "$ib".log 2>&1
    echo "EOF"  >> "$ib".log 2>&1
    echo "Exitcode: ${EXECUTABLE_EXITCODE}" >> "$ib".log 2>&1

    if [ $VM_EXITCODE -eq $EXECUTABLE_EXITCODE ]  ; then
	echo "Same exit code" >> "$ib".log 2>&1
    else
	echo "FAILED due to different exit code"
	continue
    fi

    if cmp "${ib}.out" "${ib}.vmout" >> "$ib".log 2>&1 ; then
	echo "Output matches exactly" >> "$ib".log 2>&1
    else
	echo "FAILED due to different output"
	continue
    fi

    e "$ib".log ${GCCCIL} -O3 -S ${GCCCIL_OPTIONS} $EXTRACIL1O3 "${ib}.exe" -o "${ib}.exe.O3.s"
    if [ $? -ne 0 ] ; then echo "FAILED compiling EXE to assembler with -O3" ; continue ; fi

    e "$ib".log ${GCCCIL} -O3 -v ${GCCCIL_OPTIONS} "${ib}.exe" -lm -o "${ib}.O3"
    if [ $? -ne 0 ] ; then echo "FAILED compiling EXE to executable with -O3" ; continue ; fi

    eoe "$ib".log "${ib}.O3.out" "./${ib}.O3"
    EXECUTABLE_O3_EXITCODE=$?
    echo "Executable with O3 output: <<EOF"  >> "$ib".log 2>&1
    cat "${ib}.O3.out"  >> "$ib".log 2>&1
    echo "EOF"  >> "$ib".log 2>&1
    echo "Exitcode: ${EXECUTABLE_O3_EXITCODE}" >> "$ib".log 2>&1

    if [ $VM_EXITCODE -eq $EXECUTABLE_O3_EXITCODE ]  ; then
	echo "Same exit code" >> "$ib".log 2>&1
    else
	echo "FAILED due to different exit code with -O3"
	continue
    fi

    if cmp "${ib}.out" "${ib}.O3.out" >> "$ib".log 2>&1 ; then
	echo "Output with -O3 matches exactly" >> "$ib".log 2>&1
    else
	echo "FAILED due to different output with -O3"
	continue
    fi

    e "$ib".log ${CIL32GCC} "$f" -O3 -S -o "${ib}.fO3.il"
    if [ $? -ne 0 ] ; then echo "FAILED compiling C to IL with -O3" ; continue ; fi

    e "$ib".log ${CIL32GCC} "$f" -O3 -o "${ib}.fO3.exe"
    if [ $? -ne 0 ] ; then echo "FAILED compiling C to EXE with -O3" ; continue ; fi

    eo "$ib".log "${ib}.fO3.exe.dis" ${DIS} "${ib}.fO3.exe" 
    if [ $? -ne 0 ] ; then echo "FAILED disassembling EXE from O3" ; continue ; fi



    e "$ib".log ${GCCCIL} -S "${ib}.fO3.exe" ${GCCCIL_OPTIONS} -o "${ib}.fO3.exe.s"
    if [ $? -ne 0 ] ; then echo "FAILED compiling -O3 EXE to assembler" ; continue ; fi

    e "$ib".log ${GCCCIL} -v ${GCCCIL_OPTIONS} "${ib}.fO3.exe" -lm -o "${ib}.fO3"
    if [ $? -ne 0 ] ; then echo "FAILED compiling -O3 EXE to executable" ; continue ; fi

    eoe "$ib".log "${ib}.fO3.out" "./${ib}.fO3"
    EXECUTABLE_FO3_EXITCODE=$?
    echo "Executable from O3 output: <<EOF"  >> "$ib".log 2>&1
    cat "${ib}.fO3.out"  >> "$ib".log 2>&1
    echo "EOF"  >> "$ib".log 2>&1
    echo "Exitcode: ${EXECUTABLE_FO3_EXITCODE}" >> "$ib".log 2>&1

    if [ $VM_EXITCODE -eq $EXECUTABLE_FO3_EXITCODE ]  ; then
	echo "Same exit code" >> "$ib".log 2>&1
    else
	echo "FAILED due to different exit code from -O3"
	continue
    fi

    if cmp "${ib}.fO3.out" "${ib}.O3.out" >> "$ib".log 2>&1 ; then
	echo "Output form -O3 matches exactly" >> "$ib".log 2>&1
    else
	echo "FAILED due to different from -O3 output"
	continue
    fi



    e "$ib".log ${GCCCIL} -O3 -S ${GCCCIL_OPTIONS} $EXTRACIL1O3 "${ib}.fO3.exe" -o "${ib}.fO3.exe.O3.s"
    if [ $? -ne 0 ] ; then echo "FAILED compiling -O3 EXE to assembler with -O3" ; continue ; fi

    e "$ib".log ${GCCCIL} -O3 -v ${GCCCIL_OPTIONS} "${ib}.fO3.exe" -lm -o "${ib}.fO3.O3"
    if [ $? -ne 0 ] ; then echo "FAILED compiling -O3 EXE to executable with -O3" ; continue ; fi

    eoe "$ib".log "${ib}.fO3.O3.out" "./${ib}.fO3.O3"
    EXECUTABLE_FO3_O3_EXITCODE=$?
    echo "Executable from O3 output with O3: <<EOF"  >> "$ib".log 2>&1
    cat "${ib}.fO3.O3.out"  >> "$ib".log 2>&1
    echo "EOF"  >> "$ib".log 2>&1
    echo "Exitcode: ${EXECUTABLE_FO3_O3_EXITCODE}" >> "$ib".log 2>&1

    if [ $VM_EXITCODE -eq $EXECUTABLE_FO3_O3_EXITCODE ]  ; then
	echo "Same exit code" >> "$ib".log 2>&1
    else
	echo "FAILED due to different exit code from -O3 with -O3"
	continue
    fi

    if cmp "${ib}.fO3.O3.out" "${ib}.O3.out" >> "$ib".log 2>&1 ; then
	echo "Output form -O3 with -O3 matches exactly" >> "$ib".log 2>&1
    else
	echo "FAILED due to different from -O3 output with -O3"
	continue
    fi

    echo "OK"
done