This repository has been archived by the owner on Nov 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrader.sh
executable file
·270 lines (239 loc) · 10.1 KB
/
grader.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/bin/bash
#################################
# CSCI3150 Multi-threading grader
# Usage:
# ./grader.sh help
#
#################################
INPUT_DIR=./testcases
OUTPUT_DIR=./res
BD="\033[1m" # bold
BDED="\033[21m"
RED="\033[31m" #red
GREEN="\033[92m" #green
YELLOW="\e[33m" #yellow
ED="\e[0m"
DIFF_FLAG="-Z -b -B"
#################################
# main
function main {
# clean the output directory
# rm -rf ${OUTPUT_DIR}/*
arg1=$1
if [ "$arg1" == "help" ]
then
helpmessage
elif [ "$arg1" == "PartA" ]
then
EXCUTABLE=$2
TESTCASE=$3
parta $EXCUTABLE $TESTCASE
elif [ "$arg1" == "PartB" ]
then
EXCUTABLE=$2
partb $EXCUTABLE $3 $4
else
helpmessage
fi
}
function helpmessage {
echo -e "${BD}${GREEN}Usage:${ED}"
echo -e "${BD}${GREEN} ./grader.sh help${ED} -- print out this help message"
echo -e "${BD}${GREEN} ./grader.sh PartA [executable] [testcase]${ED} -- run [testcase] using [executable] with 4 threads, output is in ${GREEN}./res${ED}"
echo " eg. : ./grader.sh PartA asg3-pthread C0"
echo " eg. : ./grader.sh PartA asg3-openmp C1"
echo -e "${BD}${GREEN} ./grader.sh PartA [executable]${ED} -- show you the mark you get for [executable] after test all testcases"
echo " eg. : ./grader.sh PartA asg3-pthread"
echo " eg. : ./grader.sh PartA asg3-openmp"
echo -e "${BD}${GREEN} ./grader.sh PartB [executable] scaleout${ED} -- tell you whether your [executable] can scale-out"
echo -e "${BD}${GREEN} ./grader.sh PartB [executable] [testcase] [ThreadNum]${ED} -- run testcase using [executable], tell you the running time"
echo " eg. : ./grader.sh PartB asg3-pthread S1 2"
echo " eg. : ./grader.sh PartB asg3-openmp S2 4"
}
function parta {
EXCUTABLE=$1
# check EXCUTABLE
if [ ! -f ${EXCUTABLE} ]
then
echo -e "${BD}${RED}Cannot find ${EXCUTABLE} !${ED}"
exit -1
fi
if [ -n "$2" ]
then
TESTCASE=$2
if [ ! -d ${INPUT_DIR}/${TESTCASE} ]; then
echo -e "${BD}${RED}Testcase ${INPUT_DIR}/${TESTCASE} not exist!${ED}"
exit -1
fi
echo ""
echo -e "${BD}${YELLOW}Checking $EXCUTABLE Correctness of Testcase $TESTCASE ${ED}"
echo ""
# cat ${INPUT_DIR}/${TESTCASE}/README
# echo ""
# excute
./$EXCUTABLE ${INPUT_DIR}/${TESTCASE}/input1.txt ${INPUT_DIR}/${TESTCASE}/input2.txt ${OUTPUT_DIR}/output${TESTCASE}.txt 4
# diff
if diff ${OUTPUT_DIR}/output${TESTCASE}.txt ${INPUT_DIR}/${TESTCASE}/expected.txt >/dev/null 2>&1
then
echo -e "${BD}${GREEN}Testcase $TESTCASE Passed!${ED}"
else
echo -e "${BD}${RED}""Failed Testcase $TESTCASE! ${ED}"
echo -e "${RED}unmatched: yours vs expected${ED}"
echo -e "${RED} ${OUTPUT_DIR}/output${TESTCASE}.txt ${INPUT_DIR}/${TESTCASE}/expected.txt${ED}"
# echo -e "${RED}right res:${INPUT_DIR}/${TESTCASE}/output.txt${ED}"
# echo -e "${RED}your res:./res/output${TESTCASE}.txt${ED}"
# diff -y ${diff_flags} ${OUTPUT_DIR}/output.txt ${INPUT_DIR}/${TESTCASE}/output.txt;
fi
else
total=12
pass=0
for i in $(seq 1 12)
do
# rm -rf ${OUTPUT_DIR}/*
TESTCASE=C${i}
./$EXCUTABLE ${INPUT_DIR}/${TESTCASE}/input1.txt ${INPUT_DIR}/${TESTCASE}/input2.txt ${OUTPUT_DIR}/output${TESTCASE}.txt 4
if diff ${OUTPUT_DIR}/output${TESTCASE}.txt ${INPUT_DIR}/${TESTCASE}/expected.txt >/dev/null 2>&1
then
pass=`expr ${pass} + 1`
else
echo -e "${BD}${RED}Failed Testcase $TESTCASE! ${ED}"
# echo -e "${RED}right res:${INPUT_DIR}/${TESTCASE}/output.txt${ED}"
# echo -e "${RED}your res:./res/output${TESTCASE}.txt${ED}"
# echo ""
fi
done
echo ""
MARK=`expr 2 \* ${pass}`
echo -e "${BD}${GREEN}[Result] $EXCUTABLE ${pass}/${total} test cases passed${ED}"
echo -e "${BD}${GREEN}[Mark] $EXCUTABLE: ${MARK} ${ED}"
echo ""
fi
}
function partb {
EXCUTABLE=$1
# check EXCUTABLE
if [ ! -f ${EXCUTABLE} ]
then
echo -e "${BD}${RED}Cannot find ${EXCUTABLE} !${ED}"
exit -1
fi
if [ "$2" == "scaleout" ]
then
echo ""
echo -e "${BD}${YELLOW}Checking scale-out${ED}"
echo ""
TESTCASE="S0"
# check read data time
{ time ./read ${INPUT_DIR}/${TESTCASE}/input1.txt ${INPUT_DIR}/${TESTCASE}/input2.txt ${OUTPUT_DIR}/outputread.txt 1;} 2>${OUTPUT_DIR}/tempperfread;
perf=`cat ${OUTPUT_DIR}/tempperfread | grep "real"`
perf=`echo "$perf" | cut -f2`
midx=`echo "${perf}" | grep -aob 'm' | grep -oE '[0-9]+'`
min=${perf:0:${midx}}
sidx=`echo "${perf}" | grep -aob 's' | grep -oE '[0-9]+'`
midx=`expr ${midx} + 1`
sec=${perf:${midx}:`expr ${sidx} - ${midx}`}
readcalc=$(echo ${min} ${sec} | awk '{ printf "%.3f", $1 * 60 + $2 }')
# execute number of thread = 4
{ time ./$EXCUTABLE ${INPUT_DIR}/${TESTCASE}/input1.txt ${INPUT_DIR}/${TESTCASE}/input2.txt ${OUTPUT_DIR}/output${TESTCASE}.txt 4;} 2>${OUTPUT_DIR}/tempperf4;
if diff ${OUTPUT_DIR}/output${TESTCASE}.txt ${INPUT_DIR}/${TESTCASE}/expected.txt >/dev/null 2>&1
then
echo
else
echo -e "${RED}unmatched: yours vs expected${ED}"
echo -e "${RED} ${OUTPUT_DIR}/output${TESTCASE}.txt ${INPUT_DIR}/${TESTCASE}/expected.txt${ED}"
exit -1
fi
{ time ./$EXCUTABLE ${INPUT_DIR}/${TESTCASE}/input1.txt ${INPUT_DIR}/${TESTCASE}/input2.txt ${OUTPUT_DIR}/output${TESTCASE}.txt 3;} 2>${OUTPUT_DIR}/tempperf3;
{ time ./$EXCUTABLE ${INPUT_DIR}/${TESTCASE}/input1.txt ${INPUT_DIR}/${TESTCASE}/input2.txt ${OUTPUT_DIR}/output${TESTCASE}.txt 2;} 2>${OUTPUT_DIR}/tempperf2;
{ time ./$EXCUTABLE ${INPUT_DIR}/${TESTCASE}/input1.txt ${INPUT_DIR}/${TESTCASE}/input2.txt ${OUTPUT_DIR}/output${TESTCASE}.txt 1;} 2>${OUTPUT_DIR}/tempperf1;
before=0
for i in 4 3 2 1
do
perf=`cat ${OUTPUT_DIR}/tempperf${i} | grep "real"`
perf=`echo "$perf" | cut -f2`
midx=`echo "${perf}" | grep -aob 'm' | grep -oE '[0-9]+'`
# echo $midx
min=${perf:0:${midx}}
# echo $min
sidx=`echo "${perf}" | grep -aob 's' | grep -oE '[0-9]+'`
# echo $sidx
midx=`expr ${midx} + 1`
sec=${perf:${midx}:`expr ${sidx} - ${midx}`}
# echo $sec
calc=$(echo ${min} ${sec} | awk '{ printf "%.3f", $1 * 60 + $2 }')
duration=$(echo ${calc} ${readcalc} | awk '{ printf "%3f", $1 - $2 }')
zero=0
tmp=`echo $duration'>'$zero | bc -l`
if [ $tmp -eq 0 ]
then
echo $i thread using 0 seconds
else
echo $i thread using $calc - $readcalc = ${duration} seconds
fi
comp=`echo $before'<'$calc | bc -l`
if [ "$comp" == "1" ]
then
before=$calc
else
echo -e "${BD}${RED}Cannot scale out!${ED}"
exit -1
fi
done
echo -e "${BD}${GREEN}Scale out!${ED}"
else
TESTCASE=$2
if [ ! -d ${INPUT_DIR}/${TESTCASE} ]; then
echo -e "${BD}${RED}Testcase ${INPUT_DIR}/${TESTCASE} not exist!${ED}"
exit -1
fi
echo ""
echo -e "${BD}${YELLOW}Checking $EXCUTABLE Performance of Testcase $TESTCASE ${ED}"
echo ""
# cat ${INPUT_DIR}/${TESTCASE}/README
# echo ""
# check read data time
{ time ./read ${INPUT_DIR}/${TESTCASE}/input1.txt ${INPUT_DIR}/${TESTCASE}/input2.txt ${OUTPUT_DIR}/outputread.txt 1;} 2>${OUTPUT_DIR}/tempperfread;
perf=`cat ${OUTPUT_DIR}/tempperfread | grep "real"`
perf=`echo "$perf" | cut -f2`
midx=`echo "${perf}" | grep -aob 'm' | grep -oE '[0-9]+'`
min=${perf:0:${midx}}
sidx=`echo "${perf}" | grep -aob 's' | grep -oE '[0-9]+'`
midx=`expr ${midx} + 1`
sec=${perf:${midx}:`expr ${sidx} - ${midx}`}
readcalc=$(echo ${min} ${sec} | awk '{ printf "%.3f", $1 * 60 + $2 }')
{ time ./$EXCUTABLE ${INPUT_DIR}/${TESTCASE}/input1.txt ${INPUT_DIR}/${TESTCASE}/input2.txt ${OUTPUT_DIR}/output${TESTCASE}.txt $3;} 2>${OUTPUT_DIR}/tempperf;
if diff ${OUTPUT_DIR}/output${TESTCASE}.txt ${INPUT_DIR}/${TESTCASE}/expected.txt >/dev/null 2>&1
then
perf=`cat ${OUTPUT_DIR}/tempperf | grep "real"`
perf=`echo "$perf" | cut -f2`
midx=`echo "${perf}" | grep -aob 'm' | grep -oE '[0-9]+'`
# echo $midx
min=${perf:0:${midx}}
# echo $min
sidx=`echo "${perf}" | grep -aob 's' | grep -oE '[0-9]+'`
# echo $sidx
midx=`expr ${midx} + 1`
sec=${perf:${midx}:`expr ${sidx} - ${midx}`}
# echo $sec
calc=$(echo ${min} ${sec} | awk '{ printf "%.3f", $1 * 60 + $2 }')
duration=$(echo ${calc} ${readcalc} | awk '{ printf "%3f", $1 - $2 }')
zero=0
tmp=`echo $duration'>'$zero | bc -l`
if [ $tmp -eq 0 ]
then
echo testcase ${TESTCASE} using 0 seconds
else
echo testcase ${TESTCASE} using $calc - $readcalc = ${duration} seconds
fi
# rm ${OUTPUT_DIR}/tempperf
else
echo -e "${BD}${RED}""Failed Testcase $TESTCASE! ${ED}"
echo -e "${RED}unmatched: yours vs expected${ED}"
echo -e "${RED} ${OUTPUT_DIR}/output${TESTCASE}.txt ${INPUT_DIR}/${TESTCASE}/expected.txt${ED}"
# echo -e "${RED}right res:${INPUT_DIR}/${TESTCASE}/output.txt${ED}"
# echo -e "${RED}your res:./res/output${TESTCASE}.txt${ED}"
fi
fi
}
#################################
main $1 $2 $3 $4