generated from q4x3/CS1958-Lab3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grade.sh
78 lines (71 loc) · 1.94 KB
/
grade.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
#!/bin/bash
mkdir build
cp ./vector.hpp ./build
cp ./exceptions.hpp ./build
cp ./utility.hpp ./build
cp ./data/class-bint.hpp ./build
cp ./data/class-integer.hpp ./build
cp ./data/class-matrix.hpp ./build
test_answer() {
DIR=$1
echo "Testing for" $1"... May take long..."
cp ./data/${DIR}/code.cpp ./build
cp ./data/${DIR}/answer.txt ./build
cd build
g++ code.cpp -o code
./code > tmp.txt
diff ./answer.txt ./tmp.txt
if [ $? -ne 0 ];
then
echo "Fail test" $1"!"
else
echo "Success test" $1"!"
fi;
rm ./code.cpp ./answer.txt ./code ./tmp.txt
cd ..
}
test_memory() {
DIR=$1
echo "Memory testing for" $1"... May take long..."
cp ./data/${DIR}.memcheck/code.cpp ./build
cp ./data/${DIR}.memcheck/answer.txt ./build
cd build
g++ code.cpp -o code
./code > tmp.txt
diff ./answer.txt ./tmp.txt
if [ $? -ne 0 ];
then
echo "Fail test" $1"!"
else
valgrind --tool=memcheck --leak-check=full --log-file=log.txt ./code > tmp.txt
flagA=0
flagB=0
cat log.txt|while read line
do
strA="All heap blocks were freed -- no leaks are possible"
strB="ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)"
resultA=$(echo $line | grep "${strA}")
resultB=$(echo $line | grep "${strB}")
if [[ "$resultA" != "" ]]
then
echo "0 leaks"
fi;
if [[ "$resultB" != "" ]]
then
echo "0 errors"
fi;
done
fi;
rm ./code.cpp ./answer.txt ./code ./tmp.txt
cd ..
}
echo "-------------------------Test One--------------------------"
test_answer one
test_memory one
echo "-------------------------Test Two--------------------------"
test_answer two
test_memory two
echo "------------------------Test Three-------------------------"
test_answer three
test_memory three
rm -rf build