-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautograde.sh
More file actions
96 lines (76 loc) · 1.61 KB
/
autograde.sh
File metadata and controls
96 lines (76 loc) · 1.61 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
#!/bin/bash
### Build your executable
make
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NOCOLOR='\033[0m'
SCORE=0
### Autograder for counter
EXEC="./counter"
THREADS="2"
chmod u+x $EXEC
TESTDIR=""
if [ $# -eq 1 ]
then
TESTDIR=$1
else
TESTDIR="./autograde_tests"
fi
for prim in "--lock=tas" "--lock=ttas" "--lock=ticket" "--lock=pthread" "--bar=sense"; do
for file in $TESTDIR/*; do
if [ "${file: -4}" == ".cnt" ]
then
IN=$file
CASE=${IN%.*}
MY=$CASE.my
read -r ITERS < $IN
ANS=$((ITERS*THREADS))
$EXEC -o $MY -t $THREADS -i $ITERS $prim
read -r MYANS < $MY
if [ $MYANS -eq $ANS ]
then
SCORE=$(($SCORE+2))
echo -e $ITERS $prim "..... ${GREEN}Pass${NOCOLOR}"
else
echo -e $ITERS $prim "..... ${RED}FAIL${NOCOLOR}"
fi
fi
done
done
#### Autograder for sort
### Generate a test file
### (of unspecified range and size)
# shuf -i0-2147483643 -n382 > case1.txt
### Sort it using sort
# sort -n case1.txt > soln1.txt
EXEC="./mysort"
THREADS="2"
chmod u+x $EXEC
for prim in "--lock=tas" "--lock=ttas" "--lock=ticket" "--lock=pthread" "--bar=sense"; do
for file in $TESTDIR/*; do
if [ "${file: -4}" == ".txt" ]
then
IN=$file
CASE=${IN%.*}
MY=$CASE.my
ANS=$CASE.ans
$EXEC $IN -o $MY -t $THREADS $prim
if cmp --silent $MY $ANS;
then
SCORE=$(($SCORE+8))
echo -e $CASE $prim "..... ${GREEN}Pass${NOCOLOR}"
else
echo -e $CASE $prim "..... ${RED}FAIL${NOCOLOR}"
fi
fi
done
done
SCORE=$(echo "scale=1; $SCORE/2" | bc -l)
echo -e "${YELLOW}Score:" $SCORE "${NOCOLOR}"
RET=1
if [ $SCORE == "25.0" ]
then
RET=0
fi
exit $RET