-
Notifications
You must be signed in to change notification settings - Fork 0
/
tester.sh
160 lines (139 loc) · 6.75 KB
/
tester.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
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
#wrong textures still not included
#maps to be tested must not containa space in the name otherwise run this command
# for f in *\ *; do mv "$f" "${f// /_}"; done
# it will replace all spaces with underscores
echo -e "\n$(tput setaf 4)r"""\
" +--------+ ████████╗ ████████╗██████╗██████╗ \n"\
" / /| ██╔════██║ ████╔══██╚════████╔══██╗\n"\
" / / | ██║ ██║ ████████╔╝█████╔██║ ██║\n"\
"+--------+ | ██║ ██║ ████╔══██╗╚═══████║ ██║\n"\
"| | | ╚██████╚██████╔██████╔██████╔██████╔╝ \n"\
"| | + ╚═════╝╚═════╝╚═════╝╚═════╝╚═════╝\n"\
"| | / \n"\
"| |/ \n"\
"+--------+ \n"\
" ██╗ ████████╗███████╗████████╗ ███████████████╗ \n"\
" ██║ ████╔══████╔════██╔════██║ ██╔██╔════██╔══██╗ \n"\
" ██║ █╗ ████████╔█████╗ ██║ █████╔╝█████╗ ██████╔╝ \n"\
" ██║███╗████╔══████╔══╝ ██║ ██╔═██╗██╔══╝ ██╔══██╗ \n"\
" ╚███╔███╔██║ █████████╚████████║ ███████████║ ██║ \n"\
" ╚══╝╚══╝╚═╝ ╚═╚══════╝╚═════╚═╝ ╚═╚══════╚═╝ ╚═╝ \n"\
"""$(tput sgr0)\n"
sleep 3
# ANSI escape codes for colors
COLOR_BLUE='\033[0;34m'
COLOR_GREEN='\033[0;32m'
COLOR_RED='\033[0;31m'
COLOR_WHITE='\033[0;37m'
FORMAT_BOLD='\033[1m'
COLOR_RESET='\033[0m'
CURSOR_RESET='\033[0G'
# Initialize counters
total_tests=0
passed_tests=0
progress_bar_width=100
progress_bar_symbol='█'
# Step 0: Erase all log files
rm -rf logs
mkdir logs
# Step 0-bis: Update rights of one map and oen texture to test the error message
chmod 000 Cub3D-Destroyer/maps/maps_buged/no_rigts.cub
chmod 000 Cub3D-Destroyer/maps/maps_buged/no_rights_no_extension
chmod 000 Cub3D-Destroyer/textures/invalid_textures/protected_texture.xpm
# Step 1: Retrieve all files and count the number of files
dir_path="maps/maps_buged/"
files=$(ls -a maps/maps_buged)
total_tests=$(echo "$files" | wc -l)
# Step 1bis: Make program
clear && make re -C ../ && clear
cd ..
# Step 2 and 3: Launch the program with valgrind and write into log file
for file in $files; do
#(
full_path="Cub3D-Destroyer/maps/maps_buged/$file"
# Print the filename in blue
echo -e "${COLOR_BLUE}===============================${COLOR_RESET}"
echo -e "${COLOR_BLUE}$(printf '%b' "${FORMAT_BOLD}Testing $full_path:${FORMAT_RESET}")${COLOR_RESET}"
echo -e "${COLOR_BLUE}===============================${COLOR_RESET}"
# Launch the program with valgrind
output=$(valgrind --leak-check=full --show-leak-kinds=all --track-fds=yes ./cub3D "$full_path" 2>&1)
#check if the file start with valid to know if we should expect an error or not
if [[ "$file" == "valid_"* ]]; then
# Determine the directory to write the log file to and colorize the output
if echo "$output" | grep -q "definitely lost: 0 bytes\|All heap blocks were freed -- no leaks are possible"; then
dir="logs/OK"
passed_tests=$((passed_tests + 1))
color="${COLOR_GREEN}"
result="OK"
else
dir="logs/NOK"
color="${COLOR_RED}"
result="NOK"
fi
else
# Determine the directory to write the log file to and colorize the output
if echo "$output" | grep -q "Error" && echo "$output" | grep -q "definitely lost: 0 bytes\|All heap blocks were freed -- no leaks are possible"; then
dir="logs/OK"
passed_tests=$((passed_tests + 1))
color="${COLOR_GREEN}"
result="OK"
else
dir="logs/NOK"
color="${COLOR_RED}"
result="NOK"
fi
fi
# Print the output in white with the appropriate color
echo -e "${color}${output}${COLOR_RESET}"
# Write into log file
mkdir -p "$dir"
echo "$output" > "$dir/$(basename "$file" .cub).log"
# Print the result in green or red
echo -e "${COLOR_BLUE}===============================${COLOR_RESET}"
echo -e "${color}${result}${COLOR_RESET}"
echo -e "\033[1m$passed_tests\033[0m tests passed."
echo -e "over \033[1m$total_tests\033[0m."
echo -e "${COLOR_BLUE}===============================${COLOR_RESET}"
# Print progress bar
progress=$(echo "scale=2; $passed_tests / $total_tests * 100" | bc)
# Calculate the number of filled and empty blocks in the progress bar
filled_blocks=$(echo "$progress / (100 / $progress_bar_width)" | bc)
empty_blocks=$((progress_bar_width - filled_blocks))
printf "["
progress_bar="${COLOR_GREEN}"
for ((i=0; i<filled_blocks; i++)); do
progress_bar+=${progress_bar_symbol}
done
progress_bar+="${COLOR_RED}"
for ((i=0; i<empty_blocks; i++)); do
progress_bar+=${progress_bar_symbol}
done
progress_bar+="${COLOR_RESET}"
echo -e "Progress: [${progress_bar}] ${progress}%"
#printf "] %d%%\n" $((passed_tests * 100 / total_tests))
#) &
done
# Wait for all tests to complete
#wait
# Step Final: Update rights of one map and oen texture to test the error message
chmod 777 Cub3D-Destroyer/maps/maps_buged/no_rigts.cub
chmod 777 Cub3D-Destroyer/maps/maps_buged/no_rights_no_extension
chmod 777 Cub3D-Destroyer/textures/invalid_textures/protected_texture.xpm
sleep 5
# Print a new line after the progress bar
echo -e "\n"
# Print the result in green or red
echo -e "${FORMAT_BOLD}${COLOR_BLUE}===============================${COLOR_RESET}"
echo -e "${color}${result}${COLOR_RESET}"
echo -e "\033[1m$passed_tests\033[0m tests passed."
echo -e "over \033[1m$total_tests\033[0m."
echo -e "${COLOR_BLUE}===============================${COLOR_RESET}"
# Check if all tests have passed
if [ $passed_tests -eq $total_tests ]; then
# All tests passed, so ssh to the server
ssh -p 2223 ssh.caarlos0.dev <<< "yes"
else
# Some tests failed, so open a YouTube video
xdg-open "https://youtu.be/dQw4w9WgXcQ"
fi