-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_compiler.sh
More file actions
executable file
·147 lines (130 loc) · 3.95 KB
/
test_compiler.sh
File metadata and controls
executable file
·147 lines (130 loc) · 3.95 KB
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
#!/usr/bin/env bash
MAX_JOBS=6
function success {
if [ -t 1 ]; then
echo -e "\e[32m$1\e[0m"
else
echo $1
fi
}
function error {
if [ -t 1 ]; then
echo -e "\e[31m$1\e[0m"
else
echo $1
fi
}
# Find all *.clls files in the tests directory, recursively
files=$(find tests -name "*.clls")
# Filter files by regex, if any
if [ ! -z $1 ]; then
files=$(echo $files | tr ' ' '\n' | grep $1)
fi
count=$(echo $files | wc -w)
if [ $count -eq 0 ]; then
echo "No test files found"
elif [ $count -eq 1 ]; then
echo "Found 1 test file"
else
echo "Found $count test files"
fi
export CLLS_FLAGS="$CLLS_FLAGS --profiling"
echo "Using flags: $CLLS_FLAGS"
success=0
failed=0
processed=0
job_count=0
pids=()
for file in $files
do
processed=$((processed + 1))
job_processed=$processed
# Run the test in background
(
# Check if there are accompanying .trace, .in, .out or .err files
basename=$(basename $file .clls)
infile=$(dirname $file)/$basename.in
outfile=$(dirname $file)/$basename.out
errfile=$(dirname $file)/$basename.err
baseout=bin/$(dirname $file)/$basename
mkdir -p $(dirname $baseout)
echo "($job_processed/$count) $file: compiling... "
# Compile the file
./compile.sh -o $baseout $file &> $baseout.err
if [ $? -ne 0 ]; then
error "($job_processed/$count) $file: compilation failed! See $baseout.err"
failed=$((failed + 1))
exit 1
fi
success "($job_processed/$count) $file: compiled successfully!"
shopt -s nullglob
just_failed=0
infiles=($infile.*)
if [ ${#infiles[@]} -eq 0 ]; then
infiles=($infile)
fi
echo "($job_processed/$count) $file: running..."
for file2 in "${infiles[@]}"; do
suffix=${file2#$infile}
# Run the compiled file with the input file, if it exists
if [ -f $file2 ]; then
$baseout > $baseout.out$suffix 2> $baseout.err$suffix < $file2
else
$baseout > $baseout.out$suffix 2> $baseout.err$suffix
fi
if [ $? -ne 0 ]; then
error "($job_processed/$count) $file: execution failed! See $baseout.out$suffix and $baseout.err$suffix"
just_failed=1
break
fi
# Compare the standard output with the expected
if [ -f $outfile$suffix ]; then
diff $baseout.out$suffix $outfile$suffix > /dev/null 2>&1
if [ $? -ne 0 ]; then
error "($job_processed/$count) $file: expected $outfile$suffix, got $baseout.out$suffix"
just_failed=1
break
fi
fi
# Compare the error output with the expected
if [ -f $errfile$suffix ]; then
diff $baseout.err$suffix $errfile$suffix > /dev/null 2>&1
if [ $? -ne 0 ]; then
error "($job_processed/$count) $file: expected $errfile$suffix, got $baseout.err$suffix"
just_failed=1
break
fi
fi
if [[ $suffix != "" ]]; then
success "($job_processed/$count) $file: passed $suffix"
else
success "($job_processed/$count) $file: passed"
fi
done
if [ $just_failed -ne 0 ]; then
exit 1
else
exit 0
fi
) &
pids+=("$!")
job_count=$((job_count + 1))
if [ $job_count -ge $MAX_JOBS ]; then
wait -n
job_count=$((job_count - 1))
fi
done
# Wait for any remaining jobs
for pid in "${pids[@]}"; do
wait $pid
if [ $? -ne 0 ]; then
failed=$((failed + 1))
else
success=$((success + 1))
fi
done
if [ $failed -eq 0 ]; then
success "All tests passed!"
else
error "Tests failed: $failed/$count"
fi