-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbmp_run.sh
253 lines (194 loc) · 5.33 KB
/
bmp_run.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#!/bin/bash
EXEC="bmp"
# Define ANSI color codes
RESET="\e[0m"
RED="\e[31m"
GREEN="\e[32m"
ORANGE="\e[33m"
BLUE="\e[34m"
CYAN="\e[36m"
function init {
valgrind_err=0
pad=$(printf '%.1s' "."{1..70})
padlength=71
make
if [ $? -ne 0 ]; then
echo -e "${RED}Makefile failed!${RESET}"
exit 1
fi
mkdir -p output
mkdir -p output/basic_commands
mkdir -p output/insert_image
mkdir -p output/draw_commands
mkdir -p output/fill_color
mkdir -p output/mix_commands
}
function print_result {
test_name="$1"
result="$2"
if [ "$result" == "passed" ]; then
color="$GREEN"
elif [ "$result" == "failed" ]; then
color="$RED"
else
color="$RESET"
fi
printf "${ORANGE}%s${BLUE}" "Test $test_name"
printf "%*.*s" 0 $((padlength - 9 - ${#test_name} - ${#result} )) "$pad"
printf "${color}%s${RESET}\n" "$result"
}
function check_task {
start_test_id=0
end_test_id=0
printf "${CYAN}%s............................Basic Commands.........................\n"
for test_id in $(seq $start_test_id $end_test_id); do
test_file="./input/basic_commands/input${test_id}.txt"
ref_file="./ref/basic_commands/output${test_id}.bmp"
output_file="./output/basic_commands/output${test_id}.bmp"
./$EXEC < "$test_file"
diff "$output_file" "$ref_file" &> /dev/null
ret=$?
if [ $ret == 0 ]; then
print_result "$test_id" "passed"
else
print_result "$test_id" "failed"
fi
if [ $ret == 0 ]; then
valgrind --tool=memcheck --leak-check=full --error-exitcode=1 "./$EXEC < $input_file" &>/dev/null
if [ $? == 1 ]; then
print_result "valgrind" "failed"
valgrind_err=1
else
print_result "valgrind" "passed"
fi
else
print_result "valgrind" "failed"
valgrind_err=1
fi
rm -f "$output_file"
done
echo " "
start_test_id=0
end_test_id=4
printf "${CYAN}%s............................Insert Image...........................\n"
for test_id in $(seq $start_test_id $end_test_id); do
test_file="./input/insert_image/input${test_id}.txt"
ref_file="./ref/insert_image/output${test_id}.bmp"
output_file="./output/insert_image/output${test_id}.bmp"
./$EXEC < "$test_file"
diff "$output_file" "$ref_file" &> /dev/null
ret=$?
if [ $ret == 0 ]; then
print_result "$test_id" "passed"
else
print_result "$test_id" "failed"
fi
if [ $ret == 0 ]; then
valgrind --tool=memcheck --leak-check=full --error-exitcode=1 "./$EXEC < $input_file" &>/dev/null
if [ $? == 1 ]; then
print_result "valgrind" "failed"
valgrind_err=1
else
print_result "valgrind" "passed"
fi
else
print_result "valgrind" "failed"
valgrind_err=1
fi
rm -f "$output_file"
done
echo " "
start_test_id=0
end_test_id=3
printf "${CYAN}%s............................Draw Commands..........................\n"
for test_id in $(seq $start_test_id $end_test_id); do
test_file="./input/draw_commands/input${test_id}.txt"
ref_file="./ref/draw_commands/output${test_id}.bmp"
output_file="./output/draw_commands/output${test_id}.bmp"
./$EXEC < "$test_file"
diff "$output_file" "$ref_file" &> /dev/null
ret=$?
if [ $ret == 0 ]; then
print_result "$test_id" "passed"
else
print_result "$test_id" "failed"
fi
if [ $ret == 0 ]; then
valgrind --tool=memcheck --leak-check=full --error-exitcode=1 "./$EXEC < $input_file" &>/dev/null
if [ $? == 1 ]; then
print_result "valgrind" "failed"
valgrind_err=1
else
print_result "valgrind" "passed"
fi
else
print_result "valgrind" "failed"
valgrind_err=1
fi
rm -f "$output_file"
done
echo " "
start_test_id=0
end_test_id=2
printf "${CYAN}%s............................Fill Color.............................\n"
for test_id in $(seq $start_test_id $end_test_id); do
test_file="./input/fill_color/input${test_id}.txt"
ref_file="./ref/fill_color/output${test_id}.bmp"
output_file="./output/fill_color/output${test_id}.bmp"
./$EXEC < "$test_file"
diff "$output_file" "$ref_file" &> /dev/null
ret=$?
if [ $ret == 0 ]; then
print_result "$test_id" "passed"
else
print_result "$test_id" "failed"
fi
if [ $ret == 0 ]; then
valgrind --tool=memcheck --leak-check=full --error-exitcode=1 "./$EXEC < $input_file" &>/dev/null
if [ $? == 1 ]; then
print_result "valgrind" "failed"
valgrind_err=1
else
print_result "valgrind" "passed"
fi
else
print_result "valgrind" "failed"
valgrind_err=1
fi
rm -f "$output_file"
done
echo " "
start_test_id=0
end_test_id=4
printf "${CYAN}%s............................Mix Commands...........................\n"
for test_id in $(seq $start_test_id $end_test_id); do
test_file="./input/mix_commands/input${test_id}.txt"
ref_file="./ref/mix_commands/output${test_id}.bmp"
output_file="./output/mix_commands/output${test_id}.bmp"
./$EXEC < "$test_file"
diff "$output_file" "$ref_file" &> /dev/null
ret=$?
if [ $ret == 0 ]; then
print_result "$test_id" "passed"
else
print_result "$test_id" "failed"
fi
if [ $ret == 0 ]; then
valgrind --tool=memcheck --leak-check=full --error-exitcode=1 "./$EXEC < $input_file" &>/dev/null
if [ $? == 1 ]; then
print_result "valgrind" "failed"
valgrind_err=1
else
print_result "valgrind" "passed"
fi
else
print_result "valgrind" "failed"
valgrind_err=1
fi
rm -f "$output_file"
done
echo -e " "
}
init
check_task
make clean &> /dev/null