summaryrefslogtreecommitdiff
path: root/test.sh
blob: 4071d40892b6e7413d60a2f952ada25be2c6fbc6 (plain)
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
# 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