From 0dcf13c457a40d2c66500957c3d86a71cea9acae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Madon?= <mael.madon@irit.fr> Date: Fri, 28 Oct 2022 08:48:44 +0200 Subject: [PATCH] test: add simple tests with expected output on example workload --- test/conftest.py | 20 ++- .../example_arrival_t0.SABjson | 128 ++++++++++++++++ .../example_arrival_t0_nodyn.SABjson | 138 ++++++++++++++++++ test/expected_output/example_last_t30.SABjson | 72 +++++++++ test/expected_output/example_max_t0.SABjson | 85 +++++++++++ test/test_expected_outputs.py | 32 +++- 6 files changed, 461 insertions(+), 14 deletions(-) create mode 100644 test/expected_output/example_arrival_t0.SABjson create mode 100644 test/expected_output/example_arrival_t0_nodyn.SABjson create mode 100644 test/expected_output/example_last_t30.SABjson create mode 100644 test/expected_output/example_max_t0.SABjson diff --git a/test/conftest.py b/test/conftest.py index 065c002..0404cbe 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,3 +1,4 @@ +from cgi import test import os, subprocess class KTH_WL: @@ -24,16 +25,19 @@ def run_script(delim, else: pfx = input_swf.split("/")[-1].split(".")[0] test_name = f"{pfx}_{delim}_t{threshold}" + if not dyn_red: + test_name += "_nodyn" out_dir = os.path.abspath(f'test-out/{test_name}') create_dir_rec_if_needed(out_dir) - if not graph: - cp = subprocess.run(['python3', 'swf2userSessions.py', - '-a', str(threshold), '-q', input_swf, out_dir], - check=True) - else: - cp = subprocess.run(['python3', 'swf2userSessions.py', - '-a', str(threshold), '--graph', '-q', input_swf, out_dir], - check=True) + args = ['python3', 'swf2userSessions.py', + f'--{delim}', str(threshold), '-q', input_swf, out_dir] + if graph: + args.append("--graph") + if not dyn_red: + args.append("--no_dynamic_reduction") + + cp = subprocess.run(args, check=True) + return out_dir, cp \ No newline at end of file diff --git a/test/expected_output/example_arrival_t0.SABjson b/test/expected_output/example_arrival_t0.SABjson new file mode 100644 index 0000000..613e23f --- /dev/null +++ b/test/expected_output/example_arrival_t0.SABjson @@ -0,0 +1,128 @@ +{ + "description": "user1", + "date": "2022-10-27 14:22:15.027304", + "nb_res": 4, + "version": 1, + "sessions": [ + { + "id": 1, + "first_submit_time": 0, + "preceding_sessions": [], + "thinking_time_after_preceding_session": [], + "nb_jobs": 1, + "jobs": [ + { + "id": 1, + "profile": "2400.0", + "res": 4, + "subtime": 0, + "walltime": 2592000.0 + } + ] + }, + { + "id": 2, + "first_submit_time": 3000.0, + "preceding_sessions": [ + 1 + ], + "thinking_time_after_preceding_session": [ + 600.0 + ], + "nb_jobs": 1, + "jobs": [ + { + "id": 2, + "profile": "9600.0", + "res": 4, + "subtime": 0.0, + "walltime": 2592000.0 + } + ] + }, + { + "id": 3, + "first_submit_time": 7800.0, + "preceding_sessions": [ + 1 + ], + "thinking_time_after_preceding_session": [ + 5400.0 + ], + "nb_jobs": 1, + "jobs": [ + { + "id": 3, + "profile": "10800.0", + "res": 4, + "subtime": 0.0, + "walltime": 2592000.0 + } + ] + }, + { + "id": 4, + "first_submit_time": 16200.0, + "preceding_sessions": [ + 2 + ], + "thinking_time_after_preceding_session": [ + 3600.0 + ], + "nb_jobs": 1, + "jobs": [ + { + "id": 4, + "profile": "3600.0", + "res": 4, + "subtime": 0.0, + "walltime": 2592000.0 + } + ] + }, + { + "id": 5, + "first_submit_time": 24000.0, + "preceding_sessions": [ + 3, + 4 + ], + "thinking_time_after_preceding_session": [ + 5400.0, + 4200.0 + ], + "nb_jobs": 1, + "jobs": [ + { + "id": 5, + "profile": "5400.0", + "res": 4, + "subtime": 0.0, + "walltime": 2592000.0 + } + ] + }, + { + "id": 6, + "first_submit_time": 24600.0, + "preceding_sessions": [ + 3, + 4 + ], + "thinking_time_after_preceding_session": [ + 6000.0, + 4800.0 + ], + "nb_jobs": 1, + "jobs": [ + { + "id": 6, + "profile": "4200.0", + "res": 4, + "subtime": 0.0, + "walltime": 2592000.0 + } + ] + } + ] +} \ No newline at end of file diff --git a/test/expected_output/example_arrival_t0_nodyn.SABjson b/test/expected_output/example_arrival_t0_nodyn.SABjson new file mode 100644 index 0000000..4a2c704 --- /dev/null +++ b/test/expected_output/example_arrival_t0_nodyn.SABjson @@ -0,0 +1,138 @@ +{ + "description": "user1", + "date": "2022-10-27 14:59:54.678020", + "nb_res": 4, + "version": 1, + "sessions": [ + { + "id": 1, + "first_submit_time": 0, + "preceding_sessions": [], + "thinking_time_after_preceding_session": [], + "nb_jobs": 1, + "jobs": [ + { + "id": 1, + "profile": "2400.0", + "res": 4, + "subtime": 0, + "walltime": 2592000.0 + } + ] + }, + { + "id": 2, + "first_submit_time": 3000.0, + "preceding_sessions": [ + 1 + ], + "thinking_time_after_preceding_session": [ + 600.0 + ], + "nb_jobs": 1, + "jobs": [ + { + "id": 2, + "profile": "9600.0", + "res": 4, + "subtime": 0.0, + "walltime": 2592000.0 + } + ] + }, + { + "id": 3, + "first_submit_time": 7800.0, + "preceding_sessions": [ + 1 + ], + "thinking_time_after_preceding_session": [ + 5400.0 + ], + "nb_jobs": 1, + "jobs": [ + { + "id": 3, + "profile": "10800.0", + "res": 4, + "subtime": 0.0, + "walltime": 2592000.0 + } + ] + }, + { + "id": 4, + "first_submit_time": 16200.0, + "preceding_sessions": [ + 1, + 2 + ], + "thinking_time_after_preceding_session": [ + 13800.0, + 3600.0 + ], + "nb_jobs": 1, + "jobs": [ + { + "id": 4, + "profile": "3600.0", + "res": 4, + "subtime": 0.0, + "walltime": 2592000.0 + } + ] + }, + { + "id": 5, + "first_submit_time": 24000.0, + "preceding_sessions": [ + 1, + 2, + 3, + 4 + ], + "thinking_time_after_preceding_session": [ + 21600.0, + 11400.0, + 5400.0, + 4200.0 + ], + "nb_jobs": 1, + "jobs": [ + { + "id": 5, + "profile": "5400.0", + "res": 4, + "subtime": 0.0, + "walltime": 2592000.0 + } + ] + }, + { + "id": 6, + "first_submit_time": 24600.0, + "preceding_sessions": [ + 1, + 2, + 3, + 4 + ], + "thinking_time_after_preceding_session": [ + 22200.0, + 12000.0, + 6000.0, + 4800.0 + ], + "nb_jobs": 1, + "jobs": [ + { + "id": 6, + "profile": "4200.0", + "res": 4, + "subtime": 0.0, + "walltime": 2592000.0 + } + ] + } + ] +} \ No newline at end of file diff --git a/test/expected_output/example_last_t30.SABjson b/test/expected_output/example_last_t30.SABjson new file mode 100644 index 0000000..28edda8 --- /dev/null +++ b/test/expected_output/example_last_t30.SABjson @@ -0,0 +1,72 @@ +{ + "description": "user1", + "date": "2022-10-28 08:46:00.449651", + "nb_res": 4, + "version": 1, + "sessions": [ + { + "id": 1, + "first_submit_time": 0, + "preceding_sessions": [], + "thinking_time_after_preceding_session": [], + "nb_jobs": 4, + "jobs": [ + { + "id": 1, + "profile": "2400.0", + "res": 4, + "subtime": 0, + "walltime": 2592000.0 + }, + { + "id": 2, + "profile": "9600.0", + "res": 4, + "subtime": 3000.0, + "walltime": 2592000.0 + }, + { + "id": 3, + "profile": "10800.0", + "res": 4, + "subtime": 7800.0, + "walltime": 2592000.0 + }, + { + "id": 4, + "profile": "3600.0", + "res": 4, + "subtime": 16200.0, + "walltime": 2592000.0 + } + ] + }, + { + "id": 2, + "first_submit_time": 24000.0, + "preceding_sessions": [ + 1 + ], + "thinking_time_after_preceding_session": [ + 4200.0 + ], + "nb_jobs": 2, + "jobs": [ + { + "id": 5, + "profile": "5400.0", + "res": 4, + "subtime": 0.0, + "walltime": 2592000.0 + }, + { + "id": 6, + "profile": "4200.0", + "res": 4, + "subtime": 600.0, + "walltime": 2592000.0 + } + ] + } + ] +} \ No newline at end of file diff --git a/test/expected_output/example_max_t0.SABjson b/test/expected_output/example_max_t0.SABjson new file mode 100644 index 0000000..5fe39b7 --- /dev/null +++ b/test/expected_output/example_max_t0.SABjson @@ -0,0 +1,85 @@ +{ + "description": "user1", + "date": "2022-10-27 14:16:55.285646", + "nb_res": 4, + "version": 1, + "sessions": [ + { + "id": 1, + "first_submit_time": 0, + "preceding_sessions": [], + "thinking_time_after_preceding_session": [], + "nb_jobs": 1, + "jobs": [ + { + "id": 1, + "profile": "2400.0", + "res": 4, + "subtime": 0, + "walltime": 2592000.0 + } + ] + }, + { + "id": 2, + "first_submit_time": 3000.0, + "preceding_sessions": [ + 1 + ], + "thinking_time_after_preceding_session": [ + 600.0 + ], + "nb_jobs": 3, + "jobs": [ + { + "id": 2, + "profile": "9600.0", + "res": 4, + "subtime": 0.0, + "walltime": 2592000.0 + }, + { + "id": 3, + "profile": "10800.0", + "res": 4, + "subtime": 4800.0, + "walltime": 2592000.0 + }, + { + "id": 4, + "profile": "3600.0", + "res": 4, + "subtime": 13200.0, + "walltime": 2592000.0 + } + ] + }, + { + "id": 3, + "first_submit_time": 24000.0, + "preceding_sessions": [ + 2 + ], + "thinking_time_after_preceding_session": [ + 4200.0 + ], + "nb_jobs": 2, + "jobs": [ + { + "id": 5, + "profile": "5400.0", + "res": 4, + "subtime": 0.0, + "walltime": 2592000.0 + }, + { + "id": 6, + "profile": "4200.0", + "res": 4, + "subtime": 600.0, + "walltime": 2592000.0 + } + ] + } + ] +} \ No newline at end of file diff --git a/test/test_expected_outputs.py b/test/test_expected_outputs.py index c81f07d..b15135e 100644 --- a/test/test_expected_outputs.py +++ b/test/test_expected_outputs.py @@ -11,12 +11,8 @@ def load_output(file_name): with open(os.path.abspath(f"test-out/{file_name}/1.SABjson"), "r") as fd: return json.load(fd) - -def test_example_workload(): - - test_name = "example_arrival_t60" - _, _ = run_script(delim="arrival", threshold=60, input_swf="workloads/example.swf", graph=True) - +def compare_with_expected_output(test_name): + """Compare JSON field by field (better than a diff because 'description', 'date', 'version' fields could be different, as well as the format of some number)""" obtained = load_output(test_name) expected = load_expected_output(test_name) @@ -37,3 +33,27 @@ def test_example_workload(): assert float(j_e["subtime"]) == float(j_o["subtime"]) assert float(j_e["walltime"]) == float(j_o["walltime"]) + +def test_example_workload(): + """Simple tests with example workload""" + + test_name = "example_arrival_t60" + run_script(delim="arrival", threshold=60, input_swf="workloads/example.swf") + compare_with_expected_output(test_name) + + test_name = "example_arrival_t0" + run_script(delim="arrival", threshold=0, input_swf="workloads/example.swf") + compare_with_expected_output(test_name) + + test_name = "example_arrival_t0_nodyn" + run_script(delim="arrival", threshold=0, input_swf="workloads/example.swf", + dyn_red=False) + compare_with_expected_output(test_name) + + test_name = "example_max_t0" + run_script(delim="max", threshold=0, input_swf="workloads/example.swf") + compare_with_expected_output(test_name) + + test_name = "example_last_t30" + run_script(delim="last", threshold=30, input_swf="workloads/example.swf") + compare_with_expected_output(test_name) \ No newline at end of file -- GitLab