diff options
| -rw-r--r-- | src/config.py | 9 | ||||
| -rwxr-xr-x | src/main.py | 21 | ||||
| -rw-r--r-- | src/test/test.py | 52 |
3 files changed, 63 insertions, 19 deletions
diff --git a/src/config.py b/src/config.py index 1235307..f718296 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/27 18:00:53 by charles ### ########.fr # +# Updated: 2020/09/28 12:06:05 by cacharle ### ########.fr # # # # ############################################################################ # @@ -44,3 +44,10 @@ PHILO_EXEC_PATHS = [ os.path.join(PHILO_PATHS[1], "philo_two"), os.path.join(PHILO_PATHS[2], "philo_three") ] + +INT_MIN = -2147483648 +INT_MAX = 2147483647 +UINT_MAX = 4294967295 +LONG_MIN = -9223372036854775808 +LONG_MAX = 9223372036854775807 +ULONG_MAX = 18446744073709551615 diff --git a/src/main.py b/src/main.py index 473fc9a..13b2d41 100755 --- a/src/main.py +++ b/src/main.py @@ -1,4 +1,4 @@ -#!/bin/python3 +#!/usr/bin/env python3 # ############################################################################ # # # @@ -50,10 +50,27 @@ def main(): if args.philo != 1: sys.exit(1) - Test(10, 100, 100, 10) + Test.new_error([]) + Test.new_error(["10"]) + Test.new_error(["10", "10"]) + Test.new_error(["10", "10", "10"]) + Test.new_error(["10", "10", "10", "10", "10", "10"]) + Test.new_error(["-1", "10", "10", "10"]) + Test.new_error(["10", "-1", "10", "10"]) + Test.new_error(["10", "10", "-1", "10"]) + Test.new_error(["10", "10", "10", "-1"]) + Test.new_error(["10", "10", "10", "10", "-1"]) + + # Test(error_cmd=[str(config.UINT_MAX + 1), "10", "10", "10"], error=True) + + + # Test(10, 100, 100, 10) Test.run_all(config.PHILO_EXEC_PATHS[0]) # print("yo") if __name__ == "__main__": main() + + + diff --git a/src/test/test.py b/src/test/test.py index 83e2718..92bf20a 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/27 18:40:33 by charles ### ########.fr # +# Updated: 2020/09/28 12:23:40 by cacharle ### ########.fr # # # # ############################################################################ # @@ -26,38 +26,50 @@ class Test: for t in cls._tests: t.run() + @staticmethod + def new_error(error_cmd: [str]): + Test(error_cmd=error_cmd) + def __init__( self, - philo_num: int, - timeout_die: int, - timeout_eat: int, - timeout_sleep: int, + philo_num: int = None, + timeout_die: int = None, + timeout_eat: int = None, + timeout_sleep: int = None, meal_num: int = None, - should_fail: bool = False + should_fail: bool = False, + error_cmd: [str] = None ): self._philo_num = philo_num self._timeout_die = timeout_die self._timeout_eat = timeout_eat self._timeout_sleep = timeout_sleep self._meal_num = meal_num + self._error_cmd = error_cmd Test._tests.append(self) def run(self): - argv = [ - Test._exec_path, - str(self._philo_num), - str(self._timeout_die), - str(self._timeout_eat), - str(self._timeout_sleep) - ] - if self._meal_num is not None: - argv.append(str(self._meal_num)) + if self._error_cmd is not None: + argv = [Test._exec_path, *self._error_cmd] + else: + argv = [ + Test._exec_path, + str(self._philo_num), + str(self._timeout_die), + str(self._timeout_eat), + str(self._timeout_sleep) + ] + if self._meal_num is not None: + argv.append(str(self._meal_num)) process = subprocess.Popen( argv, stdout=subprocess.PIPE, stderr=subprocess.STDOUT ) - self._check_output(process.stdout) + if self._error_cmd is not None: + self._check_error(process) + else: + self._check_output(process.stdout) process.wait(timeout=config.TIMEOUT) def _check_output(self, stream): @@ -66,3 +78,11 @@ class Test: line = line.decode()[:-1] table.add_log(philo.Log(line, self._philo_num)) table.check() + + def _check_error(self, process): + line_num = len([None for _ in process.stdout]) + if line_num != 1: + raise ValueError("you should have an error message") + if process.returncode == 0: + raise ValueError("you should have a non zero status code") + |
