forked from MIMUW-Inf-2002/IPP_testy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_forward_1.sh
executable file
·132 lines (105 loc) · 3.24 KB
/
test_forward_1.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
#!/bin/bash
CC="gcc"
CFLAGS="-std=c17 -Wall -Wextra -Wno-implicit-fallthrough -g"
VALGRIND_FLAGS="--leak-check=full --show-leak-kinds=all
--errors-for-leak-kinds=all --quiet"
TEST_DIR="testy_forward_1"
BOLD=$(tput bold)
NORMAL=$(tput sgr0)
C_RED="\033[0;31m"
C_DEFAULT="\033[0m"
SKIP_REV_FLAG=""
SKIP_CMAKE_FLAG=""
RUN_VALGRIND_FLAG=0
# Function definitions
print_usage() {
header="Usage: $0 [options] <path/to/src>"
options="Options:
-h show this help message
-c remove test files
-s skip tests for phfwdReverse()
-m skip cmake and doc tests
-v run tests with valgrind"
printf "%s\n%s\n" "$header" "$options"
}
clean() {
printf "Removing test files...\n"
FILES=$(find testy_forward_1/ -type f -name "*.o")
rm -f $FILES
}
test_cmake() {
# Test CMake Release
mkdir tmp_cmake_$1_forward_test
cd tmp_cmake_$1_forward_test || exit
cmake -D CMAKE_BUILD_TYPE=$1 ../$SRC_DIR/.. > /dev/null
make > /dev/null
printf "[OK] TEST CMAKE $1\n"
./phone_forward >temp_message
make clean > temp_message
rm temp_message
cd ..
rm -r -f tmp_cmake_$1_forward_test
}
test_doc() {
# Test CMake Release
mkdir tmp_doc_forward_test
cd tmp_doc_forward_test || exit
cmake ../$SRC_DIR/.. > /dev/null
make > /dev/null
make doc 2> temp_message 1> /dev/null
if [ -s temp_message ]; then
printf "[ERROR] Documentation has warnings\n"
else
printf "[OK] Documentation has no warnings\n"
fi
make clean > temp_message
rm temp_message
cd ..
rm -r -f tmp_doc_forward_test
}
# Check flags
while getopts 'chsvm' FLAG; do
case "${FLAG}" in
c) clean; exit 0;;
h) print_usage; exit 0;;
s) SKIP_REV_FLAG="s";;
m) SKIP_CMAKE_FLAG="m";;
v) RUN_VALGRIND_FLAG=1;;
*) print_usage; exit 1;;
esac
done
# Check number of arguments
[[ $# < 1 ]] && print_usage && exit 1
SRC_DIR=${@:$#}
# Notify user if skipping tests
[ "$SKIP_CMAKE_FLAG" == "m" ] && printf "Skipping tests for cmake and doc\n"
[ "$SKIP_REV_FLAG" == "s" ] && printf "Skipping tests for phfwdReverse()\n"
[ $RUN_VALGRIND_FLAG == 1 ] && printf "Running tests with valgrind\n"
# Check if SRC_DIR exists
[ ! -d "$SRC_DIR" ] && printf "Directory %s does not exist!\n" "$SRC_DIR" && exit 1
##############################################################################
# cmake/doc tests #
##############################################################################
[ "$SKIP_CMAKE_FLAG" == "m" ] || test_cmake ''
[ "$SKIP_CMAKE_FLAG" == "m" ] || test_cmake 'Release'
[ "$SKIP_CMAKE_FLAG" == "m" ] || test_cmake 'Test'
[ "$SKIP_CMAKE_FLAG" == "m" ] || test_doc
# Compile and run tests
SRC_FILES=()
for SRC_FILE in $SRC_DIR/*.c; do
SRC_FILE_NAME=$(basename -- "$SRC_FILE")
[ "$SRC_FILE_NAME" == "phone_forward_example.c" ] || SRC_FILES+="${SRC_FILE} "
done
TEST_FILES=$(find testy_forward_1/ -type f -name "*.c")
for TEST in $TEST_FILES
do
echo -e "\n${BOLD}========= Running test ${TEST} =========${NORMAL}\n"
$CC $CFLAGS -o ${TEST%.c}.o $TEST $SRC_FILES >/dev/null
[ "$?" -ne 0 ] && printf "${C_RED}Compilation error${C_DEFAULT}\n" && exit 1
if [[ $RUN_VALGRIND_FLAG == 1 ]]
then
valgrind $VALGRIND_FLAGS ./${TEST%.c}.o $SKIP_REV_FLAG
else
time ./${TEST%.c}.o $SKIP_REV_FLAG
fi
done