summaryrefslogtreecommitdiff
path: root/test/mono/run_tests.sh
blob: 08926aaacf3742e5d59cc1658271ed3ade5083c6 (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
#!/usr/bin/env bash
set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SAILDIR="$DIR/../.."
TESTSDIR="$DIR"
OUTPUTDIR="$DIR/test-output"

RED='\033[0;91m'
GREEN='\033[0;92m'
YELLOW='\033[0;93m'
NC='\033[0m'

rm -f $DIR/tests.xml

pass=0
fail=0

XML=""

function green {
    (( pass += 1 ))
    printf "$1: ${GREEN}$2${NC}\n"
    XML+="    <testcase name=\"$1\"/>\n"
}

function yellow {
    (( fail += 1 ))
    printf "$1: ${YELLOW}$2${NC}\n"
    XML+="    <testcase name=\"$1\">\n      <error message=\"$2\">$2</error>\n    </testcase>\n"
}

function red {
    (( fail += 1 ))
    printf "$1: ${RED}$2${NC}\n"
    XML+="    <testcase name=\"$1\">\n      <error message=\"$2\">$2</error>\n    </testcase>\n"
}

function finish_suite {
    printf "$1: Passed ${pass} out of $(( pass + fail ))\n\n"
    XML="  <testsuite name=\"$1\" tests=\"$(( pass + fail ))\" failures=\"${fail}\" timestamp=\"$(date)\">\n$XML  </testsuite>\n"
    printf "$XML" >> "$DIR/tests.xml"
    XML=""
    pass=0
    fail=0
}

printf "<testsuites>\n" >> "$DIR/tests.xml"

cd "$DIR"
mkdir -p "$OUTPUTDIR"

echo > log

if [ -z "$1" ]
then
    TESTS=`find $TESTSDIR/pass -type f | sort`
else
    TESTS="$@"
fi

for i_full in $TESTS;
do
    cd "$DIR"
    i=`basename "$i_full"`
    echo "Running test $i" >> log
    if "$SAILDIR/sail" -lem -lem_mwords -lem_lib Test_extra -o out $(< "$i_full") &>>log;
    then
        mv out.lem out_types.lem "$OUTPUTDIR"
	if lem -ocaml -lib "$SAILDIR/src/lem_interp" \
               -outdir "$OUTPUTDIR" \
               "$SAILDIR/src/gen_lib/sail2_values.lem" \
               "$SAILDIR/src/gen_lib/sail2_operators.lem" \
               "$SAILDIR/src/gen_lib/sail2_operators_mwords.lem" \
               "$SAILDIR/src/lem_interp/sail2_instr_kinds.lem" \
               "$SAILDIR/src/gen_lib/sail2_prompt.lem" \
               "$SAILDIR/src/gen_lib/sail2_state_monad.lem" \
               "$SAILDIR/src/gen_lib/sail2_state.lem" \
               "$SAILDIR/src/gen_lib/sail2_prompt_monad.lem" \
               "$SAILDIR/src/gen_lib/sail2_string.lem" \
               "$DIR/test_extra.lem" \
               "$OUTPUTDIR/out_types.lem" "$OUTPUTDIR/out.lem" &>>log;
	then
            cd "$OUTPUTDIR"
            if ocamlfind ocamlc -linkpkg -package zarith -package lem \
                         sail2_values.ml sail2_operators.ml \
                         sail2_instr_kinds.ml sail2_prompt_monad.ml sail2_prompt.ml \
                         sail2_operators_mwords.ml sail2_state_monad.ml sail2_state.ml \
                         sail2_string.ml \
                         test_extra.ml out_types.ml out.ml ../test.ml \
                         -o test &>>"$DIR/log"
            then
                if ./test &>>"$DIR/log"
                then
	            green "tested $i expecting pass" "pass"
                else
	            red "tested $i expecting pass" "running generated test failed"
                fi
            else
	        red "tested $i expecting pass" "compiling generated OCaml failed"
            fi
	else
	    red "tested $i expecting pass" "failed to generate OCaml from Lem"
	fi
    else
	red "tested $i expecting pass" "failed to generate Lem"
    fi
    echo >> "$DIR/log"
done

finish_suite "monomorphisation tests"

printf "</testsuites>\n" >> $DIR/tests.xml