-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsemantic-test.sh
executable file
·190 lines (144 loc) · 4.51 KB
/
semantic-test.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
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
#!/bin/bash
EXECUTABLE="Main"
declare -a DATASETS
DATASETS=("./examples" "./examples/extra")
declare -a LABELS
LABELS=("positive" "negative")
EDITOR="$(command -v code)"
function log
{
if [[ "$1" == *"[SUCCESS]"* ]]
then
color=118
elif [[ "$1" == *"[FAILURE]"* ]]
then
color=166
elif [[ "$1" == *"[MESSAGE]"* ]]
then
color=6
elif [[ "$1" == *"[WARNING]"* ]]
then
color=170
else
color=196
fi
echo -e "$(tput setaf "$color")$1$(tput sgr0): $2"
}
./compile.sh --clean
if [[ "$*" == *"--clean"* ]]
then
log "[MESSAGE]" "Purging..."
find . -maxdepth 5 -name "*.ll" -delete -print
for dataset in "${DATASETS[@]}"
do
for label in "${LABELS[@]}"
do
rm -rfv "$dataset"/"$label"/out "$dataset"/"$label"/error
done
done
exit 0
fi
if ! ./compile.sh > /dev/null 2>&1
then
log "[ERROR]:" "Compilation failed [./log/compile.log]"
exit 1
fi
if [[ "$*" == *"-all"* ]]
then
set -- "--success" "--failure" "--problem"
fi
for i in "${!DATASETS[@]}"
do
dataset="${DATASETS[$i]}"
if [ ! -d "$dataset" ]
then
continue;
fi
brief=""; problematic=0
log "[MESSAGE]" "Processing dataset '$dataset'"
for j in "${!LABELS[@]}"
do
label="${LABELS[$j]}"
log "[MESSAGE]" "Processing files labeled '$label'\n"
total=0; faulty=0;
dir_out="$dataset"/"$label"/out
dir_off="$dataset"/offset
dir_err="$dataset"/"$label"/error
mkdir -p "$dir_out" "$dir_err"
for file in $(ls "$dataset"/"$label"/*.java)
do
counterpart=""
result="[SUCCESS]"; ((total++))
name="$(basename "$file")"
name="${name%.*}"
file_out="$dir_out"/"$name".out
file_off="$dir_off"/"$name".off
file_err="$dir_err"/"$name".error
if ! java "$EXECUTABLE" "$file" 2> "$file_err" 1> "$file_out"
then
((faulty++))
if [ "$label" == "negative" ]
then
result="[FAILURE]";
counterpart="$dataset/positive/$(basename "${file%-error.java}").java"
else
result="[PROBLEM]"; details="File labeled as 'positive' failed"
fi
else
if [ "$label" == "negative" ]
then
result="[PROBLEM]"; details="File labeled as 'negative' succeeded"
else
differences="$(diff <( tr -d "[:space:]" <"$file_out" ) <( tr -d "[:space:]" <"$file_off"))";
if [ -n "$differences" ]
then
result="[PROBLEM]"; details="Different program structures"
fi
fi
fi
if [ "$result" == "[PROBLEM]" ]
then
((problematic++))
log "$result" "$file ($details)"
else
log "$result" "$file"
fi
if [ -n "$EDITOR" ]
then
if [[ "$*" == *"--success"* ]] && [ "$result" == "[SUCCESS]" ]
then
"$EDITOR" -r -d "$file_out" "$file_off"; "$EDITOR" -r -w "$file"
fi
if [[ "$*" == *"--failure"* ]] && [ "$result" == "[FAILURE]" ]
then
if [ -r "$counterpart" ]
then
"$EDITOR" -r -d "$file" "$counterpart"
"$EDITOR" -r -w "$file_err"
else
"$EDITOR" -r -w "$file" "$file_err"
fi
fi
if [[ "$*" == *"--problem"* ]] && [ "$result" == "[PROBLEM]" ]
then
if [ -r "$file_out" ] && [ -r "$file_off" ]
then
"$EDITOR" -r -d "$file_out" "$file_off"
fi
"$EDITOR" -r -w "$file" "$file_err"
fi
fi
done
brief="$brief\n$(printf "%02d" $faulty) out of $(printf "%02d" $total) files labeled as '$label' exhibited problems"
if [ "$i" -lt "${#DATASETS[@]}" ]
then
echo -en '\n'
fi
done
echo -e "$brief\n"
if [ "$problematic" -gt 0 ]
then
echo -e "$(tput setaf 196)$(printf "%02d" "$problematic") out of $(printf "%02d" "$total") files were problematic$(tput sgr0)\n"
fi
done
exit 0