diff options
| author | yctct <yctct@yctct.com> | 2026-09-13 19:15:41 +0200 |
|---|---|---|
| committer | yctct <yctct@yctct.com> | 2026-09-13 19:15:41 +0200 |
| commit | b9a960822aa9b341a79eb59bfc2128e1c4f5ecd2 (patch) | |
| tree | ca7b720c750e107e2a880e9de0aca7261e336961 | |
| parent | 3b5882a15239c0ddeb99f84b22c78b21094d1e12 (diff) | |
Add tests
| -rwxr-xr-x | test.sh | 158 |
1 files changed, 158 insertions, 0 deletions
@@ -0,0 +1,158 @@ +# dining philosopher tests Copyright (C) 2026 yctct +# +#This program is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. +# +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. +# +#You should have received a copy of the GNU General Public License +#along with this program. If not, see <https://www.gnu.org/licenses/>. + +#!/usr/bin/bash + +printf "Checks that a single philosopher should starve at timestamp 800\n" +./philo 1 800 200 200 200 10 0 fifo + +printf "\nChecks that philosophers should each eat 10 times, total of 50, no starve\n" +for run in {1..3}; do + ./philo 5 2000 200 200 200 10 0 fifo > output && + grep 'is eating' output | + wc -l +done + +printf "\nChecks that philosophers should each eat 7 times, total of 35, no starve\n" +for run in {1..3}; do + ./philo 5 2000 200 200 200 7 0 edf > output && + grep 'is eating' output | + wc -l +done + +printf "\nChecks that a philosopher should starve at timestamp timestamp 500\n" +./philo 5 500 200 200 200 10 0 fifo > output && +grep 'starved' output + +printf "\nChecks that 'is eating' is preceded by 2 'has taken a fork'\n" +./philo 5 2000 200 200 200 7 0 edf > output && +grep 'is eating' -B 2 output +read -p "Press enter to continue" + +printf "\nChecks that philosophers wait 400 ms before taking a fork\n" +printf "and no philosophers starving --- fifo\n" +./philo 5 3000 200 200 200 10 400 fifo > output && +grep 'has taken a fork' output && +tail -n 1 output +read -p "Press enter to continue" + +printf "\nChecks that philosophers wait 400 ms before taking a fork\n" +printf "and no philosophers starve --- edf\n" +./philo 5 3000 200 200 200 10 400 edf > output && +grep 'has taken a fork' output && +tail -n 1 output +read -p "Press enter to continue" + +printf "\nCompares fifo vs edf order\n" +./philo 5 3000 200 200 200 10 800 fifo +read -p "Press enter to continue" +./philo 5 3000 200 200 200 10 800 edf +read -p "Press enter to continue" + +printf "\nRuns the following with valgrind, drd and helgrind\n" +printf "valgrind ./philo 1 800 200 200 200 10 0 fifo\n" +valgrind ./philo 1 800 200 200 200 10 0 fifo + +printf "valgrind --tool=helgrind ./philo 1 800 200 200 200 10 0 fifo\n" +read -p "Press enter to continue" +valgrind --tool=helgrind ./philo 1 800 200 200 200 10 0 fifo + +printf "valgrind --tool=drd ./philo 1 800 200 200 200 10 0 fifo\n" +read -p "Press enter to continue" +valgrind --tool=drd ./philo 1 800 200 200 200 10 0 fifo + +read -p "Press enter to continue" +printf "valgrind ./philo 5 2000 200 200 200 10 0 fifo\n" +valgrind ./philo 5 2000 200 200 200 10 0 fifo + +printf "valgrind --tool=helgrind ./philo 5 2000 200 200 200 10 0 fifo\n" +read -p "Press enter to continue" +valgrind --tool=helgrind ./philo 5 2000 200 200 200 10 0 fifo + +printf "valgrind --tool=drd ./philo 5 2000 200 200 200 10 0 fifo\n" +read -p "Press enter to continue" +valgrind --tool=drd ./philo 5 2000 200 200 200 10 0 fifo + +printf "valgrind ./philo 5 2000 200 200 200 7 0 edf\n" +read -p "Press enter to continue" +valgrind ./philo 5 2000 200 200 200 7 0 edf + +printf "valgrind --tool=helgrind ./philo 5 2000 200 200 200 7 0 edf\n" +read -p "Press enter to continue" +valgrind --tool=helgrind ./philo 5 2000 200 200 200 7 0 edf + +printf "valgrind --tool=drd ./philo 5 2000 200 200 200 7 0 edf\n" +read -p "Press enter to continue" +valgrind --tool=drd ./philo 5 2000 200 200 200 7 0 edf + +printf "valgrind ./philo 5 500 200 200 200 10 0 fifo\n" +read -p "Press enter to continue" +valgrind ./philo 5 500 200 200 200 10 0 fifo + +printf "valgrind --tool=helgrind ./philo 5 500 200 200 200 10 0 fifo\n" +read -p "Press enter to continue" +valgrind --tool=helgrind ./philo 5 500 200 200 200 10 0 fifo + +printf "valgrind --tool=drd ./philo 5 500 200 200 200 10 0 fifo\n" +read -p "Press enter to continue" +valgrind --tool=drd ./philo 5 500 200 200 200 10 0 fifo + +printf "valgrind ./philo 5 2000 200 200 200 7 0 edf\n" +read -p "Press enter to continue" +valgrind ./philo 5 2000 200 200 200 7 0 edf + +printf "valgrind --tool=helgrind ./philo 5 2000 200 200 200 7 0 edf\n" +read -p "Press enter to continue" +valgrind --tool=helgrind ./philo 5 2000 200 200 200 7 0 edf + +printf "valgrind --tool=drd ./philo 5 2000 200 200 200 7 0 edf\n" +read -p "Press enter to continue" +valgrind --tool=drd ./philo 5 2000 200 200 200 7 0 edf + +printf "valgrind ./philo 5 3000 200 200 200 10 400 fifo\n" +read -p "Press enter to continue" +valgrind ./philo 5 3000 200 200 200 10 400 fifo + +printf "valgrind --tool=helgrind ./philo 5 3000 200 200 200 10 400 fifo\n" +read -p "Press --tool=helgrind enter to continue" +valgrind --tool=helgrind ./philo 5 3000 200 200 200 10 400 fifo + +printf "valgrind --tool=drd ./philo 5 3000 200 200 200 10 400 fifo\n" +read -p "Press --tool=helgrind enter to continue" +valgrind --tool=drd ./philo 5 3000 200 200 200 10 400 fifo + +printf "valgrind ./philo 5 3000 200 200 200 10 800 fifo\n" +read -p "Press --tool=helgrind enter to continue" +valgrind ./philo 5 3000 200 200 200 10 800 fifo + +printf "valgrind --tool=helgrind ./philo 5 3000 200 200 200 10 800 fifo\n" +read -p "Press enter to continue" +valgrind --tool=helgrind ./philo 5 3000 200 200 200 10 800 fifo + +printf "valgrind --tool=drd ./philo 5 3000 200 200 200 10 800 fifo\n" +read -p "Press enter to continue" +valgrind --tool=drd ./philo 5 3000 200 200 200 10 800 fifo + +printf "valgrind ./philo 5 3000 200 200 200 10 800 edf\n" +read -p "--tool=helgrind Press enter to continue" +valgrind ./philo 5 3000 200 200 200 10 800 edf + +printf "valgrind --tool=helgrind ./philo 5 3000 200 200 200 10 800 edf\n" +read -p "Press enter to continue" +valgrind --tool=helgrind ./philo 5 3000 200 200 200 10 800 edf + +printf "valgrind --tool=drd ./philo 5 3000 200 200 200 10 800 edf\n" +read -p "Press enter to continue" +valgrind --tool=drd ./philo 5 3000 200 200 200 10 800 edf |
