summaryrefslogtreecommitdiff
path: root/test.sh
diff options
context:
space:
mode:
authoryctct <yctct@yctct.com>2026-09-13 19:15:41 +0200
committeryctct <yctct@yctct.com>2026-09-13 19:15:41 +0200
commitb9a960822aa9b341a79eb59bfc2128e1c4f5ecd2 (patch)
treeca7b720c750e107e2a880e9de0aca7261e336961 /test.sh
parent3b5882a15239c0ddeb99f84b22c78b21094d1e12 (diff)
Add tests
Diffstat (limited to 'test.sh')
-rwxr-xr-xtest.sh158
1 files changed, 158 insertions, 0 deletions
diff --git a/test.sh b/test.sh
new file mode 100755
index 0000000..4071d40
--- /dev/null
+++ b/test.sh
@@ -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