aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.py4
-rwxr-xr-xsrc/main.py3
-rw-r--r--src/test/test.py25
3 files changed, 20 insertions, 12 deletions
diff --git a/src/config.py b/src/config.py
index ebe7a94..bbc9d25 100644
--- a/src/config.py
+++ b/src/config.py
@@ -6,7 +6,7 @@
# By: charles <me@cacharle.xyz> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/09/27 11:05:38 by charles #+# #+# #
-# Updated: 2020/09/28 14:54:02 by cacharle ### ########.fr #
+# Updated: 2020/09/28 16:07:03 by cacharle ### ########.fr #
# #
# ############################################################################ #
@@ -30,7 +30,7 @@ TIMEOUT = 1
TIMEOUT_ERROR = 0.2
# Timeout for infinite test
-INFINITE_TIMEOUT = 1
+INFINITE_WAIT_TIME = 0.2
################################################################################
# Do not edit
diff --git a/src/main.py b/src/main.py
index 17d1bf8..dcee90e 100755
--- a/src/main.py
+++ b/src/main.py
@@ -78,8 +78,9 @@ def main():
Test.new_error(["0", "100", "100", "100"])
Test.new_error(["1", "100", "100", "100"])
+ Test(10, 100, 100, 10)
+ Test(10, 200, 10, 10, infinite=True)
- # Test(10, 100, 100, 10)
Test.run_all(config.PHILO_EXEC_PATHS[0])
# print("yo")
diff --git a/src/test/test.py b/src/test/test.py
index e8c5ab4..91fbbca 100644
--- a/src/test/test.py
+++ b/src/test/test.py
@@ -6,7 +6,7 @@
# By: charles <me@cacharle.xyz> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/09/27 11:36:32 by charles #+# #+# #
-# Updated: 2020/09/28 14:53:40 by cacharle ### ########.fr #
+# Updated: 2020/09/28 16:08:51 by cacharle ### ########.fr #
# #
# ############################################################################ #
@@ -37,13 +37,13 @@ class Test:
def __init__(
self,
- philo_num: int = None,
- timeout_die: int = None,
- timeout_eat: int = None,
- timeout_sleep: int = None,
- meal_num: int = None,
- should_fail: bool = False,
- error_cmd: [str] = None
+ philo_num: int = None,
+ timeout_die: int = None,
+ timeout_eat: int = None,
+ timeout_sleep: int = None,
+ meal_num: int = None,
+ error_cmd: [str] = None,
+ infinite: bool = False
):
self._philo_num = philo_num
self._timeout_die = timeout_die
@@ -51,6 +51,7 @@ class Test:
self._timeout_sleep = timeout_sleep
self._meal_num = meal_num
self._error_cmd = error_cmd
+ self._infinite = infinite
Test._tests.append(self)
def run(self):
@@ -74,16 +75,22 @@ class Test:
)
if self._error_cmd is not None:
self._check_error(process)
+ elif self._infinite:
+ self._check_output(process.stdout, died=False)
+ time.sleep(config.INFINITE_WAIT_TIME)
+ process.kill()
else:
self._check_output(process.stdout)
process.wait(timeout=config.TIMEOUT)
- def _check_output(self, stream):
+ def _check_output(self, stream, died: bool = True):
table = philo.Table(self._philo_num, self._timeout_eat)
for line in stream:
line = line.decode()[:-1]
table.add_log(philo.Log(line, self._philo_num))
table.check()
+ if died and not table.dead:
+ raise philo.LogError("one philosopher should have died")
def _check_error(self, process):
try: