-
Notifications
You must be signed in to change notification settings - Fork 0
/
c_translator_formative.sh
53 lines (41 loc) · 1.39 KB
/
c_translator_formative.sh
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
#!/bin/bash
if [[ "$1" != "" ]] ; then
compiler="$1"
else
compiler="bin/c_compiler"
fi
have_compiler=0
if [[ ! -f bin/c_compiler ]] ; then
>&2 echo "Warning : cannot find compiler at path ${compiler}. Only checking C reference against python reference."
have_compiler=1
fi
input_dir="translator_tests/tests"
working="tmp/formative"
mkdir -p ${working}
for i in ${input_dir}/*.c ; do
base=$(echo $i | sed -E -e "s|${input_dir}/([^.]+)[.]c|\1|g");
# Compile the reference C version
gcc $i -o $working/$base
# Run the reference C version
$working/$base
REF_C_OUT=$?
# Run the reference python version
#python3 ${input_dir}/$base.py
#REF_P_OUT=$?
if [[ ${have_compiler} -eq 0 ]] ; then
# Create the DUT python version by invoking the compiler with translation flags
$compiler --translate $i -o ${working}/$base-got.py
# Run the DUT python version
python3 ${working}/$base-got.py
GOT_P_OUT=$?
fi
#if [[ $REF_C_OUT -ne $REF_P_OUT ]] ; then
# echo "$base, REF_FAIL, Expected ${REF_C_OUT}, got ${REF_P_OUT}"
if [[ ${have_compiler} -ne 0 ]] ; then
echo "$base, Fail, No C compiler/translator"
elif [[ $REF_C_OUT -ne $GOT_P_OUT ]] ; then
echo "$base, Fail, Expected ${REF_C_OUT}, got ${GOT_P_OUT}"
else
echo "$base, Pass"
fi
done