├── requirements.txt ├── docker ├── build.sh ├── Dockerfile ├── cleanup.sh └── run.sh ├── philo.pdf ├── img ├── start.png └── example.png ├── visualizer.sh ├── Makefile ├── visualizer.py ├── README.md └── test.sh /requirements.txt: -------------------------------------------------------------------------------- 1 | selenium==4.7.2 -------------------------------------------------------------------------------- /docker/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker build -t memory-test:0.1 . -------------------------------------------------------------------------------- /philo.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dantonik/42-philosophers-tester/HEAD/philo.pdf -------------------------------------------------------------------------------- /img/start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dantonik/42-philosophers-tester/HEAD/img/start.png -------------------------------------------------------------------------------- /img/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dantonik/42-philosophers-tester/HEAD/img/example.png -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:16.04 2 | 3 | RUN apt-get update 4 | RUN apt-get upgrade -y 5 | RUN apt-get install build-essential valgrind git-all -y -------------------------------------------------------------------------------- /visualizer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if command -v python3 >/dev/null 2>&1; then 4 | pip3 install -r requirements.txt >/dev/null 2>&1 5 | python3 visualizer.py 6 | else 7 | echo "Python is not installed. Please install python to run the script." 8 | fi -------------------------------------------------------------------------------- /docker/cleanup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # WARNING! This will remove: 4 | # - all stopped containers 5 | # - all networks not used by at least one container 6 | # - all volumes not used by at least one container 7 | # - all dangling images 8 | # - all dangling build cache 9 | docker system prune --volumes 10 | clear -------------------------------------------------------------------------------- /docker/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | WARN_COLOR="\033[0;33m" 4 | RESET="\033[0m" 5 | 6 | docker run --rm -ti -v $PWD/../..:/test memory-test:0.1 bash -c "cd /test/; make re && clear && printf '\n${WARN_COLOR}Command example:${RESET} valgrind --tool=helgrind ./philo \n\n' && bash" 7 | 8 | clear 9 | printf "\n${WARN_COLOR}Do you want to clean up (prune) Docker?${RESET}\n\n" 10 | bash cleanup.sh -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: dantonik +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/25 07:04:54 by dantonik #+# #+# # 9 | # Updated: 2022/12/25 07:29:32 by dantonik ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | CC = gcc 14 | CFLAGS = -Wall -Wextra -Werror 15 | 16 | re: 17 | @make fclean -C ../ 18 | @make -C ../ 19 | 20 | clean: 21 | @rm -rf fails 22 | @rm test 23 | 24 | .PHONY: re clean -------------------------------------------------------------------------------- /visualizer.py: -------------------------------------------------------------------------------- 1 | import os 2 | from selenium import webdriver 3 | from selenium.webdriver.common.by import By 4 | from selenium.webdriver.chrome.options import Options 5 | from selenium.webdriver.support.ui import WebDriverWait 6 | from selenium.webdriver.support import expected_conditions as EC 7 | 8 | url = "https://nafuka11.github.io/philosophers-visualizer/" 9 | 10 | try: 11 | chrome_options = Options() 12 | chrome_options.add_experimental_option("detach", True) 13 | driver = webdriver.Chrome(options=chrome_options) 14 | driver.get(url) 15 | except Exception: 16 | print("Error opening the website in Chrome") 17 | print("Trying to open in Firefox . . .") 18 | try: 19 | driver = webdriver.Firefox() 20 | driver.get(url) 21 | except Exception: 22 | print("Error opening the website in Firefox") 23 | 24 | 25 | i = 0 26 | for file in os.listdir('fails'): 27 | filename = 'fails/' + os.fsdecode(file) 28 | with open(filename) as f: 29 | if i != 0: 30 | driver.execute_script(f"window.open('about:blank', '{i}');") 31 | driver.switch_to.window(f"{i}") 32 | driver.get(url) 33 | lines = f.readlines() 34 | textarea = driver.find_element(By.CSS_SELECTOR, "textarea") 35 | textarea.clear() 36 | textarea.send_keys(lines) 37 | i += 1 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 42 Philosophers Tester 2 | 3 | #### Tester for the Dininig Philosophers Problem project at 42 Schools 4 | 5 | ## Installation 6 | Clone the repo into your philosophers folder. 7 | ```bash 8 | git clone https://github.com/dantonik/42-philosophers-tester.git 9 | ``` 10 | 11 | You must have the following file structure: 12 | ``` 13 | ├─ philo/ 14 | │ ├─ *.* 15 | │ ├─ 42-philosophers-tester/ 16 | │ │ ├─test.sh 17 | ``` 18 | 19 | ## Usage 20 | Run ./test.sh when inside the repo's directory. 21 | ```bash 22 | cd 42-philosophers-tester 23 | ./test.sh 24 | ``` 25 | ### Usage optional 26 | You can add the path to your philo executable as an argument if your folder structure looks differently. 27 | ```bash 28 | ./test.sh /path/to/philo 29 | ``` 30 | [-i iterations] 31 | ```bash 32 | ./test.sh -i 10 33 | ``` 34 | [-t times_to_eat] 35 | ```bash 36 | ./test.sh -t 10 37 | ``` 38 | 39 | ### Failed tests 40 | The output of your failed test(s) get saved in the 'fails' folder for further inspection. 41 | 42 | ### Screenshots 43 | 44 | ![Start](img/start.png?raw=true "Start") 45 | 46 | ![Example](img/example.png?raw=true "Example") 47 | 48 | ### Valgrind 49 | A simple docker Valgrind setup. 50 | ```bash 51 | cd docker 52 | ./build.sh 53 | ./run.sh 54 | ``` 55 | 56 | ### Visualizer 57 | Experimental integration with a [Philosophers Visualizer](https://nafuka11.github.io/philosophers-visualizer/). 58 | 59 | ### Why 60 | Because the [Lazy Philosophers Tester](https://github.com/MichelleJiam/LazyPhilosophersTester) is a bit tedious and only semiautomatic. 61 | 62 | ### Ressources 63 | [Introduction to Parallel Computing](https://web.archive.org/web/20201109032323/https://computing.llnl.gov/tutorials/parallel_comp/?) 64 | 65 | [POSIX Threads Programming](https://web.archive.org/web/20210306083711/https://computing.llnl.gov/tutorials/pthreads/) 66 | 67 | ### Future ideas 68 | - Leak checking 69 | - Visualizer 70 | - Data race checking 71 | - Death lock checking 72 | - Wiki How-To Philo -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | percent=0 4 | count_correct_all=0 5 | count_false_all=0 6 | iterations=10 7 | times_to_eat=10 8 | folder=fails/ 9 | tempfile=tempfile 10 | 11 | function cleanup() 12 | { 13 | rm -f $tempfile 14 | if [ -z "$(ls -A fails)" ]; then 15 | rm -rf fails 16 | fi 17 | } 18 | trap cleanup EXIT 19 | 20 | while getopts gi:t: OPTION; do 21 | case "$OPTION" in 22 | i) 23 | iterations="$OPTARG" 24 | ;; 25 | t) 26 | times_to_eat="$OPTARG" 27 | ;; 28 | g) 29 | printf "GitHub repo testing to be implemented.\n" 30 | ;; 31 | ?) 32 | printf "script usage: $0 [-i iterations] [-t times_to_eat] [path]\n" >&2 33 | exit 1 34 | ;; 35 | esac 36 | done 37 | shift "$(($OPTIND -1))" 38 | 39 | COM_COLOR="\033[0;34m" 40 | OBJ_COLOR="\033[0;36m" 41 | OK_COLOR="\033[0;32m" 42 | ERROR_COLOR="\033[0;31m" 43 | WARN_COLOR="\033[0;33m" 44 | PURPLE="\033[0;35m" 45 | RESET="\033[0m" 46 | BOLD="\033[1m" 47 | PURPLE_BOLD="\033[1;35m" 48 | OK_COLOR_BOLD="\033[0;32m" 49 | ERROR_COLOR_BOLD="\033[0;31m" 50 | WARN_COLOR_BOLD="\033[0;33m" 51 | BH_OK_COLOR="\e[1;92m" 52 | 53 | DEFCL="\033[0m" 54 | DEL_R="\033[A\r" 55 | DEL_K="\033[K\r" 56 | 57 | if [ "$#" -gt 1 ]; then 58 | printf "Invalid input!\n" 59 | exit 60 | elif [ "$#" -lt 1 ]; then 61 | philo=../philo 62 | else 63 | philo=$1 64 | fi 65 | 66 | if [ -d "${folder}" ]; then 67 | rm -rf ${folder}; 68 | fi 69 | 70 | mkdir ${folder} 71 | 72 | if [ ! -x "${philo}" ]; then 73 | make re 74 | fi 75 | 76 | if ! command ${philo} 5 200 100 100 &> /dev/null; then 77 | printf "\e[1;1H\e[2J" 78 | printf "Couldn't execute \"${philo}\"!\n" 79 | exit 1 80 | fi 81 | 82 | print_loading_bar () { 83 | printf "LOADING\t" 84 | for (( x=10; x <= $1; x+=10)) ; do 85 | { 86 | if (( $1 % 10 == 0 )) ; then 87 | printf "${BH_OK_COLOR}#${RESET}" 88 | fi 89 | } 90 | done 91 | } 92 | 93 | visualizer () { 94 | printf "\n\n${COM_COLOR}Visualize failed tests\t[0]${RESET}\n\n" 95 | printf "${BOLD}Keep failed tests\t\t\t\t[1]${RESET}\n\n" 96 | printf "${BOLD}Delete failed tests\t\t\t\t[2]${RESET}\n\n" 97 | read -r -n 1 -p $'Please choose:' test 98 | printf "\n" 99 | case $test in 100 | 0) 101 | $(bash visualizer.sh) 102 | ;; 103 | 1) 104 | exit 0 105 | ;; 106 | 2) 107 | rm -rf fails 108 | ;; 109 | $'\e') 110 | printf "\e[1;1H\e[2J" 111 | exit 0 112 | ;; 113 | q) 114 | printf "\e[1;1H\e[2J" 115 | exit 0 116 | ;; 117 | *) 118 | printf "\e[1;1H\e[2J" 119 | printf "${WARN_COLOR}Invalid input!\n${RESET}" 120 | visualizer 121 | ;; 122 | esac 123 | } 124 | 125 | normal_hardcore () { 126 | printf "\e[1;1H\e[2J" 127 | printf "\n${COM_COLOR}42 Philosophers Tester${RESET}\t$(date +%Y/%m/%d)\nIterations: ${iterations}\n\n" 128 | printf "${PURPLE_BOLD}Mandatory tests (eval sheet)\t\t[0]${RESET}\n\n" 129 | printf "Normal tests\t\t\t\t[1]\n" 130 | printf "Hardcore tests (a lot)\t\t\t[2]\n\n" 131 | printf "Exit Tester\t\t\t\t[ESC]\n\n" 132 | read -r -n 1 -p $'\n\nPlease choose:' test 133 | printf "\n" 134 | case $test in 135 | 0) 136 | printf "\e[1;1H\e[2J" 137 | mandatory_tests 138 | ;; 139 | 1) 140 | printf "\e[1;1H\e[2J" 141 | normal_tests 142 | ;; 143 | 2) 144 | printf "\e[1;1H\e[2J" 145 | hardcore_tests 146 | ;; 147 | $'\e') 148 | printf "\e[1;1H\e[2J" 149 | exit 0 150 | ;; 151 | q) 152 | printf "\e[1;1H\e[2J" 153 | exit 0 154 | ;; 155 | *) 156 | printf "\e[1;1H\e[2J" 157 | printf "${WARN_COLOR}Invalid input!\n${RESET}" 158 | normal_hardcore 159 | ;; 160 | esac 161 | } 162 | 163 | normal_tests () { 164 | text 165 | read -r -n 1 -p $'\n\nPlease choose:' test 166 | printf "\n" 167 | case $test in 168 | 0) 169 | printf "\e[1;1H\e[2J" 170 | uneven_live 171 | even_live 172 | uneven_die 173 | even_die 174 | ;; 175 | 1) 176 | printf "\e[1;1H\e[2J" 177 | uneven_live 178 | ;; 179 | 2) 180 | printf "\e[1;1H\e[2J" 181 | even_live 182 | ;; 183 | 3) 184 | printf "\e[1;1H\e[2J" 185 | uneven_live 186 | even_live 187 | ;; 188 | 4) 189 | printf "\e[1;1H\e[2J" 190 | uneven_die 191 | ;; 192 | 5) 193 | printf "\e[1;1H\e[2J" 194 | even_die 195 | ;; 196 | 6) 197 | printf "\e[1;1H\e[2J" 198 | uneven_die 199 | even_die 200 | ;; 201 | 7) 202 | printf "\e[1;1H\e[2J" 203 | own_test 204 | exit 0 205 | ;; 206 | $'\e') 207 | printf "\e[1;1H\e[2J" 208 | exit 0 209 | ;; 210 | q) 211 | printf "\e[1;1H\e[2J" 212 | exit 0 213 | ;; 214 | *) 215 | printf "\e[1;1H\e[2J" 216 | printf "${WARN_COLOR}Invalid input!\n${RESET}" 217 | normal_tests 218 | ;; 219 | esac 220 | } 221 | 222 | hardcore_tests () { 223 | text 224 | read -r -n 1 -p $'\n\nPlease choose:' test 225 | printf "\n" 226 | case $test in 227 | 0) 228 | printf "\e[1;1H\e[2J" 229 | uneven_live 230 | uneven_live_extended 231 | even_live 232 | even_live_extended 233 | uneven_die 234 | uneven_die_extended 235 | even_die 236 | even_die_extended 237 | ;; 238 | 1) 239 | printf "\e[1;1H\e[2J" 240 | uneven_live 241 | uneven_live_extended 242 | ;; 243 | 2) 244 | printf "\e[1;1H\e[2J" 245 | even_live 246 | even_live_extended 247 | ;; 248 | 3) 249 | printf "\e[1;1H\e[2J" 250 | uneven_live 251 | uneven_live_extended 252 | even_live 253 | even_live_extended 254 | ;; 255 | 4) 256 | printf "\e[1;1H\e[2J" 257 | uneven_die 258 | uneven_die_extended 259 | ;; 260 | 5) 261 | printf "\e[1;1H\e[2J" 262 | even_die 263 | even_die_extended 264 | ;; 265 | 6) 266 | printf "\e[1;1H\e[2J" 267 | uneven_die 268 | uneven_die_extended 269 | even_die 270 | even_die_extended 271 | ;; 272 | 7) 273 | printf "\e[1;1H\e[2J" 274 | own_test 275 | exit 0 276 | ;; 277 | $'\e') 278 | printf "\e[1;1H\e[2J" 279 | exit 0 280 | ;; 281 | q) 282 | printf "\e[1;1H\e[2J" 283 | exit 0 284 | ;; 285 | *) 286 | printf "\e[1;1H\e[2J" 287 | printf "${WARN_COLOR}Invalid input!\n${RESET}" 288 | hardcore_tests 289 | ;; 290 | esac 291 | } 292 | 293 | die () { 294 | count_false=0 295 | count_correct=0 296 | loading_bar_count=0 297 | printf "\t${WARN_COLOR}$1 $2 $3 $4 $5${RESET}\n" 298 | for (( i=1; i <= $iterations; i++)) ; do 299 | print_loading_bar $(awk -v count="$loading_bar_count" -v tests="$iterations" 'BEGIN {print 100 / tests * count}') 300 | lines=$($philo $1 $2 $3 $4 $5 > ${tempfile}) 301 | end_line=$(tail -n 1 ${tempfile}) 302 | if [ $(tail -n 1 ${tempfile} | grep -c died) -ne 0 ]; then 303 | printf "\e[2K \r$i\t${OK_COLOR}Pass${RESET}\t" 304 | printf "${OK_COLOR}[✓]${RESET}\t" 305 | printf "$(tail -n 1 ${tempfile})\n" 306 | (( count_correct++ )) 307 | (( count_correct_all++ )) 308 | else 309 | printf "\e[2K \r$i\t${ERROR_COLOR}Fail${RESET}\t" 310 | printf "${ERROR_COLOR}[x]${RESET}\t" 311 | printf "$(tail -n 1 ${tempfile})\n" 312 | cat ${tempfile} > ${folder}$1-$2-$3-$4-$5_$i 313 | (( count_false++ )) 314 | (( count_false_all++ )) 315 | fi 316 | (( loading_bar_count++ )) 317 | done 318 | print_percent `awk -v count="$count_correct" -v tests="$iterations" 'BEGIN {print 100 / tests * count}'` 319 | } 320 | 321 | live () { 322 | count_false=0 323 | count_correct=0 324 | loading_bar_count=0 325 | printf "\t${WARN_COLOR}$1 $2 $3 $4 $5${RESET}\n" 326 | for (( i=1; i <= $iterations; i++)) ; do 327 | print_loading_bar $(awk -v count="$loading_bar_count" -v tests="$iterations" 'BEGIN {print 100 / tests * count}') 328 | lines=$($philo $1 $2 $3 $4 $5 > ${tempfile}) 329 | end_line=$(tail -n 1 ${tempfile}) 330 | if [ $(tail -n 1 ${tempfile} | grep -c died) -ne 0 ]; then 331 | printf "\e[2K \r$i\t${ERROR_COLOR}Fail${RESET}\t" 332 | printf "${ERROR_COLOR}[x]${RESET}\t" 333 | printf "$(tail -n 1 ${tempfile})\n" 334 | cat ${tempfile} > ${folder}$1-$2-$3-$4-$5_$i 335 | (( count_false++ )) 336 | (( count_false_all++ )) 337 | else 338 | printf "\e[2K \r$i\t${OK_COLOR}Pass${RESET}\t" 339 | printf "${OK_COLOR}[✓]${RESET}\t" 340 | printf "$(tail -n 1 ${tempfile})\n" 341 | (( count_correct++ )) 342 | (( count_correct_all++ )) 343 | fi 344 | (( loading_bar_count++ )) 345 | done 346 | print_percent `awk -v count="$count_correct" -v tests="$iterations" 'BEGIN {print 100 / tests * count}'` 347 | } 348 | 349 | print_percent () { 350 | if [ $1 -gt 89 ]; then 351 | printf "\t${OK_COLOR_BOLD}$1 %% correct${RESET}\n" 352 | elif [ $1 -gt 69 ]; then 353 | printf "\t${WARN_COLOR_BOLD}$1 %% correct${RESET}\n" 354 | else 355 | printf "\t${ERROR_COLOR_BOLD}$1 %% correct${RESET}\n" 356 | fi 357 | printf "____________________________________________\n" 358 | } 359 | 360 | mandatory_tests () { 361 | printf "${OBJ_COLOR}Mandatory tests${RESET}\n\n" 362 | die 1 800 200 200 $times_to_eat 363 | live 5 800 200 200 7 364 | live 4 410 200 200 $times_to_eat 365 | die 4 310 200 100 $times_to_eat 366 | } 367 | 368 | uneven_live () { 369 | printf "${OBJ_COLOR}Testing uneven numbers - they shouldn't die${RESET}\n\n" 370 | live 5 800 200 200 $times_to_eat 371 | live 5 610 200 200 $times_to_eat 372 | live 199 610 200 200 $times_to_eat 373 | } 374 | 375 | uneven_live_extended () { 376 | printf "${OBJ_COLOR}Testing uneven numbers (overkill) - they shouldn't die${RESET}\n\n" 377 | live 5 610 200 100 $times_to_eat 378 | live 5 601 200 200 $times_to_eat 379 | live 31 610 200 100 $times_to_eat 380 | live 31 610 200 200 $times_to_eat 381 | live 31 605 200 200 $times_to_eat 382 | live 31 601 200 200 $times_to_eat 383 | live 131 610 200 100 $times_to_eat 384 | live 131 610 200 200 $times_to_eat 385 | live 131 605 200 200 $times_to_eat 386 | live 131 601 200 200 $times_to_eat 387 | live 199 610 200 100 $times_to_eat 388 | live 199 610 200 200 $times_to_eat 389 | live 199 605 200 200 $times_to_eat 390 | live 199 601 200 200 $times_to_eat 391 | } 392 | 393 | even_live () { 394 | printf "${OBJ_COLOR}Testing even numbers - they shouldn't die${RESET}\n" 395 | live 4 410 200 100 $times_to_eat 396 | live 4 410 200 200 $times_to_eat 397 | live 198 610 200 200 $times_to_eat 398 | live 198 800 200 200 $times_to_eat 399 | } 400 | 401 | even_live_extended () { 402 | printf "${OBJ_COLOR}Testing even numbers (overkill) - they shouldn't die${RESET}\n" 403 | live 50 410 200 100 $times_to_eat 404 | live 50 410 200 200 $times_to_eat 405 | live 50 405 200 200 $times_to_eat 406 | live 50 401 200 200 $times_to_eat 407 | live 130 410 200 100 $times_to_eat 408 | live 130 410 200 200 $times_to_eat 409 | live 130 405 200 200 $times_to_eat 410 | live 130 401 200 200 $times_to_eat 411 | live 198 410 200 100 $times_to_eat 412 | live 198 410 200 200 $times_to_eat 413 | live 198 405 200 200 $times_to_eat 414 | live 198 401 200 200 $times_to_eat 415 | } 416 | 417 | even_die () { 418 | printf "${OBJ_COLOR}Testing even numbers - one should die${RESET}\n" 419 | die 3 599 200 200 $times_to_eat 420 | die 31 599 200 200 $times_to_eat 421 | die 131 596 200 200 $times_to_eat 422 | } 423 | 424 | even_die_extended () { 425 | printf "${OBJ_COLOR}Testing even numbers - one should die${RESET}\n" 426 | die 4 310 200 100 $times_to_eat 427 | die 50 396 200 200 $times_to_eat 428 | die 50 399 200 200 $times_to_eat 429 | die 50 400 200 200 $times_to_eat 430 | die 130 396 200 200 $times_to_eat 431 | die 130 399 200 200 $times_to_eat 432 | die 130 400 200 200 $times_to_eat 433 | die 198 396 200 200 $times_to_eat 434 | die 198 399 200 200 $times_to_eat 435 | die 198 400 200 200 $times_to_eat 436 | } 437 | 438 | uneven_die () { 439 | printf "${OBJ_COLOR}Testing uneven numbers - one should die${RESET}\n" 440 | die 4 310 200 100 $times_to_eat 441 | die 1 800 200 100 $times_to_eat 442 | } 443 | 444 | uneven_die_extended () { 445 | printf "${OBJ_COLOR}Testing uneven numbers - one should die${RESET}\n" 446 | die 3 596 200 200 $times_to_eat 447 | die 3 599 200 200 $times_to_eat 448 | die 3 600 200 200 $times_to_eat 449 | die 31 596 200 200 $times_to_eat 450 | die 31 599 200 200 $times_to_eat 451 | die 31 600 200 200 $times_to_eat 452 | die 131 596 200 200 $times_to_eat 453 | die 131 599 200 200 $times_to_eat 454 | die 131 600 200 200 $times_to_eat 455 | die 199 596 200 200 $times_to_eat 456 | die 199 599 200 200 $times_to_eat 457 | die 199 600 200 200 $times_to_eat 458 | } 459 | 460 | own_test () { 461 | read -r -p $'\n\nNumber_of_philosophers:' n_philos 462 | printf "\n$n_philos" 463 | read -r -p $'\n\nTime_to_die:' time_to_die 464 | printf "\n$n_philos $time_to_die" 465 | read -r -p $'\n\nTime_to_eat:' time_to_eat 466 | printf "\n$n_philos $time_to_die $time_to_eat" 467 | read -r -p $'\n\nTime_to_sleep:' time_to_sleep 468 | printf "\n$n_philos $time_to_die $time_to_eat $time_to_sleep" 469 | read -r -p $'\n\nNumber_of_times_each_philosopher_must_eat:' number_of_times_each_philosopher_must_eat 470 | printf "\n$n_philos $time_to_die $time_to_eat $time_to_sleep $number_of_times_each_philosopher_must_eat" 471 | read -r -n 1 -p $'\n\nShould die?\t[0]\nShouldn\'t die?\t[1]\n' should_die 472 | if [ $should_die -eq 0 ]; then 473 | die $n_philos $time_to_die $time_to_eat $time_to_sleep $number_of_times_each_philosopher_must_eat 474 | else 475 | live $n_philos $time_to_die $time_to_eat $time_to_sleep $number_of_times_each_philosopher_must_eat 476 | fi 477 | } 478 | 479 | text () { 480 | printf "\e[1;1H\e[2J" 481 | printf "\n${COM_COLOR}42 Philosophers Tester${RESET}\t$(date +%Y/%m/%d)\nIterations: ${iterations}\n\n" 482 | printf "${PURPLE_BOLD}All tests\t\t\t\t[0]${RESET}\n\n" 483 | printf "Uneven numbers that shouldn't die\t[1]\n" 484 | printf "Even numbers that shouldn't die\t\t[2]\n" 485 | printf "${PURPLE_BOLD}All numbers that shouldn't die\t\t[3]${RESET}\n\n" 486 | printf "Uneven numbers that should die\t\t[4]\n" 487 | printf "Even numbers that should die\t\t[5]\n" 488 | printf "${PURPLE_BOLD}All numbers that should die\t\t[6]${RESET}\n\n" 489 | printf "${PURPLE}Own tests\t\t\t\t[7]${RESET}\n" 490 | printf "Exit Tester\t\t\t\t[ESC]\n\n" 491 | } 492 | 493 | normal_hardcore 494 | rm -f test 495 | printf "\n${BOLD}RESULT: passed: ${count_correct_all}\tfailed: ${count_false_all}${RESET}\n" 496 | print_percent `awk -v count="$count_correct_all" -v tests_fail="$count_false_all" 'BEGIN {print 100 / (count + tests_fail) * count}'` 497 | 498 | if [ -z "$(ls -A fails)" ]; then 499 | rm -rf fails 500 | fi 501 | 502 | # if [ -d "fails" ]; then 503 | # visualizer 504 | # fi 505 | --------------------------------------------------------------------------------