Skip to content
Snippets Groups Projects
Commit 0dcf13c4 authored by Maël Madon's avatar Maël Madon
Browse files

test: add simple tests with expected output on example workload

parent 79cd131d
Branches
No related tags found
No related merge requests found
from cgi import test
import os, subprocess import os, subprocess
class KTH_WL: class KTH_WL:
...@@ -24,16 +25,19 @@ def run_script(delim, ...@@ -24,16 +25,19 @@ def run_script(delim,
else: else:
pfx = input_swf.split("/")[-1].split(".")[0] pfx = input_swf.split("/")[-1].split(".")[0]
test_name = f"{pfx}_{delim}_t{threshold}" test_name = f"{pfx}_{delim}_t{threshold}"
if not dyn_red:
test_name += "_nodyn"
out_dir = os.path.abspath(f'test-out/{test_name}') out_dir = os.path.abspath(f'test-out/{test_name}')
create_dir_rec_if_needed(out_dir) create_dir_rec_if_needed(out_dir)
if not graph: args = ['python3', 'swf2userSessions.py',
cp = subprocess.run(['python3', 'swf2userSessions.py', f'--{delim}', str(threshold), '-q', input_swf, out_dir]
'-a', str(threshold), '-q', input_swf, out_dir], if graph:
check=True) args.append("--graph")
else: if not dyn_red:
cp = subprocess.run(['python3', 'swf2userSessions.py', args.append("--no_dynamic_reduction")
'-a', str(threshold), '--graph', '-q', input_swf, out_dir],
check=True) cp = subprocess.run(args, check=True)
return out_dir, cp return out_dir, cp
\ No newline at end of file
{
"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
{
"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
{
"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
{
"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
...@@ -11,12 +11,8 @@ def load_output(file_name): ...@@ -11,12 +11,8 @@ def load_output(file_name):
with open(os.path.abspath(f"test-out/{file_name}/1.SABjson"), "r") as fd: with open(os.path.abspath(f"test-out/{file_name}/1.SABjson"), "r") as fd:
return json.load(fd) return json.load(fd)
def compare_with_expected_output(test_name):
def test_example_workload(): """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)"""
test_name = "example_arrival_t60"
_, _ = run_script(delim="arrival", threshold=60, input_swf="workloads/example.swf", graph=True)
obtained = load_output(test_name) obtained = load_output(test_name)
expected = load_expected_output(test_name) expected = load_expected_output(test_name)
...@@ -37,3 +33,27 @@ def test_example_workload(): ...@@ -37,3 +33,27 @@ def test_example_workload():
assert float(j_e["subtime"]) == float(j_o["subtime"]) assert float(j_e["subtime"]) == float(j_o["subtime"])
assert float(j_e["walltime"]) == float(j_o["walltime"]) 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment