diff --git a/test/conftest.py b/test/conftest.py index 065c002d35bc0a57300818f8f5ca76b4d008664f..0404cbe043b7adf2fe500c8ec9be23c974694dad 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 0000000000000000000000000000000000000000..613e23fc626af9e20b41d51eb5ba3fa0dd53d5bd --- /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 0000000000000000000000000000000000000000..4a2c7042628726ecf2aee175343cea691d758310 --- /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 0000000000000000000000000000000000000000..28edda87ebb9d86c0c4e9ba510935272ac2811b3 --- /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 0000000000000000000000000000000000000000..5fe39b7d933d3b80516976a0e14da38c3aa17c6d --- /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 c81f07dfc5d8245232b78a7c24c8f0243fb15b56..b15135e4079e44b18b96f9491cff3666e79dfe5b 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