-
Notifications
You must be signed in to change notification settings - Fork 0
/
checker.sh
149 lines (122 loc) · 2.79 KB
/
checker.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
#!/bin/bash
#
# Tema3 Test Suite
#
# 2021, SD
#
# ----------------- General declarations and util functions ------------------ #
INPUT_DIR=_test/input/
REF_DIR=_test/ref/
OUT_DIR=_test/output/
EXEC_NAME=./tema3
VALGRIND="valgrind --leak-check=full --error-exitcode=1"
max_points=135
max_bonus=20
result_points=0
bonus_points=0.0
print_header()
{
header="${1}"
header_len=${#header}
printf "\n"
if [ $header_len -lt 71 ]; then
padding=$(((71 - $header_len) / 2))
for ((i = 0; i < $padding; i++)); do
printf " "
done
fi
printf "= %s =\n\n" "${header}"
}
test_do_fail()
{
if test ${1} -eq 1; then
printf "example\n"
else
printf "failed [ 0/%02d]\n" "$max_points"
if test "x$EXIT_IF_FAIL" = "x1"; then
exit 1
fi
fi
}
test_do_pass()
{
if test ${2} -eq 1; then
printf "example\n"
else
printf "passed [%02d/%02d]\n" "${1}" "$max_points"
((result_points+=${1}))
fi
}
valgrind_passed()
{
if test ${2} -eq 1; then
printf "example\n"
else
printf "passed [%02.1f/%02d]\n" "${1}" "$max_bonus"
bonus_points=`echo $bonus_points + ${1} | bc`
fi
}
valgrind_failed()
{
if test ${1} -eq 1; then
printf "example\n"
else
printf "failed [ 0/%02d]\n" "$max_bonus"
fi
}
test_function()
{
input_file="$INPUT_DIR${1}"
output_file="$OUT_DIR${2}"
ref_file="$REF_DIR${3}"
points_per_test="${4}"
points_per_test_vg="${5}"
is_example=${6:-0}
$EXEC_NAME $input_file $output_file
diff $output_file $ref_file > /dev/null
if test $? -eq 0; then
printf "[%s] ........................................... " ${2}
test_do_pass $points_per_test $is_example
#valgrind test
$VALGRIND $EXEC_NAME $input_file $output_file &> /dev/null
if [ $? -eq 0 ]; then
printf "[%s - VALGRIND: PASSED] ........................ " ${2}
valgrind_passed $points_per_test_vg $is_example
else
printf "[%s - VALGRIND: FAILED] ........................ " ${2}
valgrind_failed $is_example
fi
else
printf "[%s] ........................................... " ${2}
test_do_fail $is_example
fi
}
init_function()
{
make build
mkdir -p $OUT_DIR &> /dev/null
}
clean_out_function()
{
rm _test/output/*.*
rmdir _test/output
}
init_function
print_header "Tema 3 SD Biblioteca online"
#Testing
declare tests_values=5
declare valgrind_tests_values=(0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 1 1 1 1 1 1 1 1 1 1 1 1 1) # 14 * 0.5 + 13 * 1
# Run the example:
test_function "example.txt" "output_example.txt" "ref_example.txt" "0" "0" 1
echo ""
# Run tests
for i in {1..27}
do
test_function "input$i.txt" "output$i.txt" "ref$i.txt" "${tests_values}" "${valgrind_tests_values[$i-1]}"
echo ""
done
#end Testing
printf "%65s [%02d/$max_points]\n" "Total:" $result_points;
printf "%65s [%02.1f/%02.1f]\n" "Bonus:" $bonus_points $max_bonus;
# clean_out_function
echo