diff options
Diffstat (limited to 'src/main.py')
| -rwxr-xr-x | src/main.py | 91 |
1 files changed, 19 insertions, 72 deletions
diff --git a/src/main.py b/src/main.py index 6aee6c9..1bb0286 100755 --- a/src/main.py +++ b/src/main.py @@ -24,92 +24,40 @@ import sys import subprocess -import argparse import config from test import Test +from args import parse_args +from suite import suite +from helper import blue def main(): - parser = argparse.ArgumentParser(description="Philosophers test") - parser.add_argument( - "-p", "--philo", - help="Id of the philosophers to test ", - required=True, - type=int, - choices=[1, 2, 3] - ) - parser.add_argument( - "-b", "--build", - help="Build and exit", - action="store_true" - ) - parser.add_argument( - "-g", "--pager", - help="Open {} in a pager after the test".format(config.RESULT_FILE), - action="store_true" - ) - args = parser.parse_args() + args = parse_args() if config.BUILD_BEFORE or args.build: try: - print("=====================================BUILD======================================") - subprocess.run(config.BUILD_CMD.format(path=config.PHILO_PATHS[0]).split(' '), check=True) - print("================================================================================") + print(blue("=====================================BUILD======================================")) + subprocess.run( + config.BUILD_CMD.format(path=config.PHILO_PATHS[0]).split(' '), + check=True + ) + print(blue("================================================================================")) except subprocess.CalledProcessError: sys.exit(1) if args.build: sys.exit(0) - if args.philo != 1: - sys.exit(1) + config.TIMEOUT = args.timeout - Test.new_error([]) - Test.new_error(["a", "a", "a", "a"]) - Test.new_error(["aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "a", "a", "a"]) - 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.new_error([str(config.UINT_MAX + 1), "10", "10", "10"]) - Test.new_error(["10", str(config.UINT_MAX + 1), "10", "10"]) - Test.new_error(["10", "10", str(config.UINT_MAX + 1), "10"]) - Test.new_error(["10", "10", "10", str(config.UINT_MAX + 1)]) - Test.new_error(["10", "10", "10", "10", str(config.UINT_MAX + 1)]) - - Test.new_error([str(-config.UINT_MAX), "10", "10", "10"]) - Test.new_error(["10", str(-config.UINT_MAX), "10", "10"]) - Test.new_error(["10", "10", str(-config.UINT_MAX), "10"]) - Test.new_error(["10", "10", "10", str(-config.UINT_MAX)]) - Test.new_error(["10", "10", "10", "10", str(-config.UINT_MAX)]) - - Test(0, 100, 10, 10) - Test(1, 100, 10, 10) - - Test(2, 100, 50, 50) - Test(3, 100, 50, 50) - Test(4, 100, 50, 50) - Test(5, 100, 50, 50) - Test(6, 100, 50, 50) - Test(7, 100, 50, 50) - - Test(100, 100, 50, 50) - - Test(10, 100, 100, 10) - - # Test(2, 50, 10, 10, infinite=True) - # Test(10, 50, 10, 10, infinite=True) - # Test(10, 100, 10, 10, infinite=True) - # Test(10, 200, 10, 10, infinite=True) + suite() try: - Test.run_all(config.PHILO_EXEC_PATHS[0]) + if args.philo == 0: + for philo in range(3): + Test.run_all(config.PHILO_EXEC_PATHS[philo]) + else: + Test.run_all(config.PHILO_EXEC_PATHS[args.philo - 1]) except KeyboardInterrupt: pass finally: @@ -117,11 +65,10 @@ def main(): if args.pager: subprocess.run([*config.PAGER_CMD, config.RESULT_FILE]) else: + print() + Test.print_summary() print("Read {} for more information".format(config.RESULT_FILE)) if __name__ == "__main__": main() - - - |
