-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchecker.sh
More file actions
113 lines (96 loc) · 2.34 KB
/
checker.sh
File metadata and controls
113 lines (96 loc) · 2.34 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
#!/usr/bin/bash
POINTS=(
5
5
2 2 3 3
2 3 3
3 3
3 3
2 2 2 3
2 2 2 3
2 2 3
2 2 3
2 2 3
2 2 2 2 2 2 2 2
)
TESTS=${#POINTS[@]}
TOTAL=100
TOTALTESTS=0
VALGRINDPOINTS=0
GREEN=$(tput setaf 2)
RED=$(tput setaf 1)
RESET=$(tput sgr0)
function readme() {
if test -f "README" || test -f "README.md"
then
echo "README: 5/5"
let TOTALTESTS+=5
else
echo "README: 0/5"
fi
}
function checkExe() {
if test -f "tema1"
then
main
else
echo "The executable file needs to be named 'tema1'"
fi
}
function valgrindTest() {
local file_name="$1"
valgrind --leak-check=full --track-origins=yes -q --log-file=rezultat_valgrind.txt ./tema1 < tema1.in > /dev/null
if [ ! -s rezultat_valgrind.txt ]; then
echo " Valgrind ${GREEN}PASSED${RESET}"
VALGRIND_PER_TEST=$(echo "scale=4; 20.0 / $TESTS" | bc)
VALGRINDPOINTS=$(echo "$VALGRINDPOINTS + $VALGRIND_PER_TEST" | bc)
else
echo " Valgrind ${RED}FAILED${RESET}"
fi
}
function testInput() {
local file="$1"
local test_index="$2"
local file_name
file_name=$(basename "$file")
local ref_file="tests/ref/${file_name%.in}.ref"
cat "$file" > tema1.in
dos2unix -q tema1.in
timeout 10s ./tema1 < tema1.in > tema1.out
if [ "$?" -eq 139 ]; then
echo "$file_name: segmentation fault"
return
fi
if ! diff -B -Z --strip-trailing-cr "$ref_file" tema1.out > /dev/null 2>&1; then
echo "$file_name: 0/${POINTS[$test_index-1]}"
else
echo "$file_name: ${POINTS[$test_index-1]}/${POINTS[$test_index-1]}"
let TOTALTESTS+=${POINTS[$test_index-1]}
valgrindTest "$file_name"
fi
}
function makeCommand() {
make 1> /dev/null
if [ "$?" -ne 0 ]
then
exit 1
fi
}
function main() {
echo " -= BROWSER SIMULATION =-"
echo
touch tema1.in
touch tema1.out
readme
local test_index=1
for file in $(ls tests/input/*.in | sort); do
testInput "$file" "$test_index"
((test_index++))
done
echo
echo "Total: $TOTALTESTS/$TOTAL"
VALGRINDPOINTS_ROUNDED=$(printf "%.0f" "$VALGRINDPOINTS")
echo "Valgrind: $VALGRINDPOINTS_ROUNDED/20"
}
makeCommand
checkExe