-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-p5.sh
More file actions
219 lines (184 loc) · 5.06 KB
/
Copy pathtest-p5.sh
File metadata and controls
219 lines (184 loc) · 5.06 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
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
#!/bin/bash
TEST_DIR=/p/course/cs537-yuvraj/tests/p5
INPUT_DIR=${TEST_DIR}/inputs
OUTPUT_DIR=${TEST_DIR}/outputs
#flags
continue_flag=1
test_select=0
#results
test_cnt=0
test_passed=0
bonus_passed=0
check_output=1
score=0
function check_p5_files {
if [ ! -f Makefile ]; then
echo "Makefile not found!"
exit 1
fi
}
#imgscan_run disk_image num_jpgs deleted_jpgs longdesc
function imgscan_run {
test_cnt=$((test_cnt+1))
# args
img=${1}
n_jpgs=${2}
n_del_jpgs=${3}
long_desc="Find ${n_jpgs} jpg(s), ${n_del_jpgs} deleted jpg(s) -- ${4}"
outdir="output_t${test_cnt}"
executable="runscan"
echo "[Test${test_cnt} - ${long_desc}]"
if [ ${test_select} -gt 0 ]; then
if [ ${test_select} -ne ${test_cnt} ]; then
echo "[Skip Test${test_cnt}]"
echo
return 0
fi
fi
echo " Running \$./${executable} ${img} ${outdir}"
# Build command string
run_cmd="./${executable} ${img} ${outdir}"
run_cmd="timeout 30 ${run_cmd}"
# Run program
if ! eval ${run_cmd}; then
echo "[Test${test_cnt} failed]"
echo " Error occured while running ./${executable} ${img} ${outdir}"
echo
if [ ${continue_flag} -eq 1 ]; then
return 1
fi
exit 1
fi
# compare expected output files to actual ones
for file in "${OUTPUT_DIR}/${outdir}/"*
do
if [[ ${file##*/} == file* ]]; then
if ! test -f ${outdir}/"${file##*/}"; then
echo "[Test${test_cnt}A failed]"
echo " The output file ${file##*/} does not exist."
if [ ${continue_flag} -eq 1 ]; then
return 1
fi
exit 1
fi
if ! cmp --silent "${file}" ${outdir}/"${file##*/}"; then
echo "[Test${test_cnt}A failed]"
echo " The output is different from the expected output."
echo " - expected output path: ${OUTPUT_DIR}/${outdir}/${out_filename}"
echo " - actual output path: ${outdir}/${out_filename}"
echo
if [ ${continue_flag} -eq 1 ]; then
return 1
fi
exit 1
fi
fi
done
# make sure there are no extra output files in user outdir
for file in "${outdir}/"*
do
if ! test -f "${OUTPUT_DIR}/${outdir}/${file##*/}"; then
echo "[Test${test_cnt}A failed]"
echo " You created some extra file ${file##*/}"
if [ ${continue_flag} -eq 1 ]; then
return 1
fi
exit 1
fi
done
echo "[Test${test_cnt}A Success]"
echo ""
test_passed=$((test_passed+1))
score=$((score+10))
# compare expected output files to actual ones
for file in "${OUTPUT_DIR}/${outdir}/"*
do
if ! test -f ${outdir}/"${file##*/}"; then
echo "[Test${test_cnt}B failed]"
echo " The output file ${file##*/} does not exist."
if [ ${continue_flag} -eq 1 ]; then
return 1
fi
exit 1
fi
if ! cmp --silent "${file}" ${outdir}/"${file##*/}"; then
echo "[Test${test_cnt}B failed]"
echo " The output is different from the expected output."
echo " - expected output path: ${OUTPUT_DIR}/${outdir}/${out_filename}"
echo " - actual output path: ${outdir}/${out_filename}"
echo
if [ ${continue_flag} -eq 1 ]; then
return 1
fi
exit 1
fi
done
# make sure there are no extra output files in user outdir
for file in "${outdir}/"*
do
if ! test -f "${OUTPUT_DIR}/${outdir}/${file##*/}"; then
echo "[Test${test_cnt}B failed]"
echo " You created some extra file ${file##*/}"
if [ ${continue_flag} -eq 1 ]; then
return 1
fi
exit 1
fi
done
echo "[Test${test_cnt}B Success]"
echo ""
bonus_passed=$((bonus_passed+1))
score=$((score+5))
}
# ******************************************************************************
# Main Testing
# ******************************************************************************
# mode select
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-t)
test_select=$2
shift
shift
;;
-c)
continue_flag=1
shift
;;
esac
done
executable="runscan"
# check Makefile exists
if [ ! -f Makefile ]; then
echo "Makefile not found!"
exit 1
fi
echo "Deleting old output directories..."
rm -rf output_*
# make project
rm -f ${executable}
make
# check executable exists
if [ ! -f $executable ]; then
echo "*** ERROR: ${executable} not built by make command"
exit
fi
#imgscan_run disk_image num_jpgs deleted_jpgs longdesc
imgscan_run "${INPUT_DIR}/img1.in" 1 0 "one jpg in root dir"
imgscan_run "${INPUT_DIR}/img2.in" 0 1 "one deleted jpg in root dir"
imgscan_run "${INPUT_DIR}/img3.in" 4 0 "multiple jpgs in root dir"
imgscan_run "${INPUT_DIR}/img4.in" 1 4 "multiple jpgs in root dir, mixed"
imgscan_run "${INPUT_DIR}/img5.in" 2 0 "jpgs in subdir"
imgscan_run "${INPUT_DIR}/img6.in" 4 0 "jpgs of mixed size"
imgscan_run "${INPUT_DIR}/img7.in" 4 0 "standard jpgs with variable length names in many directories"
imgscan_run "${INPUT_DIR}/img8.in" 0 4 "deleted jpgs with variable length names"
imgscan_run "${INPUT_DIR}/img9.in" 1 0 "huge jpg"
imgscan_run "${INPUT_DIR}/img10.in" 100 0 "jpg and txt files"
# *** RESULTS ***
echo ""
echo "Mandatory Tests Passed [${test_passed}/${test_cnt}]"
echo "Bonus Tests Passed [${bonus_passed}/${test_cnt}]"
echo "Score: [${score}/100]"
exit 0