From a9d7c91ab09be18446aae4fff95d1f8812bb52a2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ma=C3=ABl=20Madon?= <mael.madon@irit.fr>
Date: Fri, 28 Oct 2022 09:55:27 +0200
Subject: [PATCH] test: add expected output for edge cases. Still need to test
 and debug

---
 test/conftest.py                              | 24 +++---
 test/expected_output/load_platform.SABjson    | 44 +++++-----
 test/expected_output/many_following.SABjson   | 14 +--
 test/expected_output/many_preceding.SABjson   |  8 +-
 .../many_start_sessions.SABjson               | 86 -------------------
 test/expected_output/zero_think_time.SABjson  |  2 +-
 test/test_expected_outputs.py                 | 16 +++-
 test/workload/load_platform.swf               |  9 ++
 test/workload/many_following.swf              |  9 ++
 test/workload/many_preceding.swf              |  9 ++
 test/workload/no_session.swf                  |  4 +
 test/workload/one_session_many_jobs.swf       | 13 +++
 test/workload/zero_think_time.swf             |  6 ++
 13 files changed, 111 insertions(+), 133 deletions(-)
 delete mode 100644 test/expected_output/many_start_sessions.SABjson
 create mode 100644 test/workload/load_platform.swf
 create mode 100644 test/workload/many_following.swf
 create mode 100644 test/workload/many_preceding.swf
 create mode 100644 test/workload/no_session.swf
 create mode 100644 test/workload/one_session_many_jobs.swf
 create mode 100644 test/workload/zero_think_time.swf

diff --git a/test/conftest.py b/test/conftest.py
index 0404cbe..ecc9802 100644
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -15,18 +15,18 @@ def create_dir_rec_if_needed(dirname):
         os.makedirs(dirname)
 
 
-def run_script(delim,
-             threshold,
-             input_swf=KTH_WL.swf_file,
-             dyn_red=True,
-             graph=False):
-    if input_swf == KTH_WL.swf_file:
-        pfx = "KTH"
-    else:
-        pfx = input_swf.split("/")[-1].split(".")[0]
-    test_name = f"{pfx}_{delim}_t{threshold}"
-    if not dyn_red:
-        test_name += "_nodyn"
+def run_script(delim, threshold,
+              input_swf=KTH_WL.swf_file, test_name=None,
+              dyn_red=True, graph=False):
+    if test_name is None:
+        if input_swf == KTH_WL.swf_file:
+            pfx = "KTH"
+        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)
 
diff --git a/test/expected_output/load_platform.SABjson b/test/expected_output/load_platform.SABjson
index d035a6e..3cfb240 100644
--- a/test/expected_output/load_platform.SABjson
+++ b/test/expected_output/load_platform.SABjson
@@ -36,18 +36,25 @@
         },
         {
             "id": 3,
-            "first_submit_time": 10000.0,
+            "first_submit_time": 9000.0,
             "preceding_sessions": [
                 2
             ],
             "thinking_time_after_preceding_session": [
-                7000.0
+                6000.0
             ],
-            "nb_jobs": 1,
+            "nb_jobs": 2,
             "jobs": [
                 {
-                    "id": 3,
-                    "profile": "1000",
+                    "id": 5,
+                    "profile": "5000",
+                    "res": 16,
+                    "subtime": 0.0,
+                    "walltime": 2592000.0
+                },
+                {
+                    "id": 6,
+                    "profile": "5000",
                     "res": 16,
                     "subtime": 0.0,
                     "walltime": 2592000.0
@@ -56,17 +63,17 @@
         },
         {
             "id": 4,
-            "first_submit_time": 12000.0,
+            "first_submit_time": 10000.0,
             "preceding_sessions": [
-                3
+                2
             ],
             "thinking_time_after_preceding_session": [
-                1000.0
+                7000.0
             ],
             "nb_jobs": 1,
             "jobs": [
                 {
-                    "id": 4,
+                    "id": 3,
                     "profile": "1000",
                     "res": 16,
                     "subtime": 0.0,
@@ -76,25 +83,18 @@
         },
         {
             "id": 5,
-            "first_submit_time": 9000.0,
+            "first_submit_time": 12000.0,
             "preceding_sessions": [
-                2
+                4
             ],
             "thinking_time_after_preceding_session": [
-                6000.0
+                1000.0
             ],
-            "nb_jobs": 2,
+            "nb_jobs": 1,
             "jobs": [
                 {
-                    "id": 5,
-                    "profile": "5000",
-                    "res": 16,
-                    "subtime": 0.0,
-                    "walltime": 2592000.0
-                },
-                {
-                    "id": 6,
-                    "profile": "5000",
+                    "id": 4,
+                    "profile": "1000",
                     "res": 16,
                     "subtime": 0.0,
                     "walltime": 2592000.0
diff --git a/test/expected_output/many_following.SABjson b/test/expected_output/many_following.SABjson
index 35a1e9c..f493068 100644
--- a/test/expected_output/many_following.SABjson
+++ b/test/expected_output/many_following.SABjson
@@ -1,5 +1,5 @@
 {
-    "description": "A session (session 1) has five followers, four with a think time of 1000s and one with a think time of 2000s.",
+    "description": "A session (session 1) has five followers: four with a think time of 1000s, 1001s, 1002s and 1003s respectively (had to be changed compared to the batmen test) and one with a think time of 2000s.",
     "nb_res": 16,
     "sessions": [
         {
@@ -36,9 +36,9 @@
         },
         {
             "id": 3,
-            "first_submit_time": 2000.0,
+            "first_submit_time": 2001.0,
             "preceding_sessions": [1],
-            "thinking_time_after_preceding_session": [1000],
+            "thinking_time_after_preceding_session": [1001],
             "nb_jobs": 1,
             "jobs": [
                 {
@@ -52,9 +52,9 @@
         },
         {
             "id": 4,
-            "first_submit_time": 2000.0,
+            "first_submit_time": 2002.0,
             "preceding_sessions": [1],
-            "thinking_time_after_preceding_session": [1000],
+            "thinking_time_after_preceding_session": [1002],
             "nb_jobs": 1,
             "jobs": [
                 {
@@ -68,9 +68,9 @@
         },
         {
             "id": 5,
-            "first_submit_time": 2000.0,
+            "first_submit_time": 2003.0,
             "preceding_sessions": [1],
-            "thinking_time_after_preceding_session": [1000],
+            "thinking_time_after_preceding_session": [1003],
             "nb_jobs": 1,
             "jobs": [
                 {
diff --git a/test/expected_output/many_preceding.SABjson b/test/expected_output/many_preceding.SABjson
index 8ca4d28..6cde957 100644
--- a/test/expected_output/many_preceding.SABjson
+++ b/test/expected_output/many_preceding.SABjson
@@ -1,5 +1,5 @@
 {
-    "description": "A session (session 6) depends on five others, with a think time of 1000s.",
+    "description": "A session (session 6) depends on five others, with a think time of 1000s. Slightly different than batmen version.",
     "nb_res": 16,
     "sessions": [
         {
@@ -20,14 +20,14 @@
         },
         {
             "id": 2,
-            "first_submit_time": 1000.0,
+            "first_submit_time": 1001.0,
             "preceding_sessions": [],
             "thinking_time_after_preceding_session": [],
             "nb_jobs": 1,
             "jobs": [
                 {
                     "id": 2,
-                    "profile": "2000",
+                    "profile": "1500",
                     "res": 16,
                     "subtime": 0.0,
                     "walltime": 2592000.0
@@ -36,7 +36,7 @@
         },
         {
             "id": 3,
-            "first_submit_time": 1000.0,
+            "first_submit_time": 1002.0,
             "preceding_sessions": [],
             "thinking_time_after_preceding_session": [],
             "nb_jobs": 1,
diff --git a/test/expected_output/many_start_sessions.SABjson b/test/expected_output/many_start_sessions.SABjson
deleted file mode 100644
index 2a48296..0000000
--- a/test/expected_output/many_start_sessions.SABjson
+++ /dev/null
@@ -1,86 +0,0 @@
-{
-    "description": "Five start sessions with no dependency between them.",
-    "nb_res": 16,
-    "sessions": [
-        {
-            "id": 1,
-            "first_submit_time": 1000.0,
-            "preceding_sessions": [],
-            "thinking_time_after_preceding_session": [],
-            "nb_jobs": 1,
-            "jobs": [
-                {
-                    "id": 1,
-                    "profile": "1000",
-                    "res": 16,
-                    "subtime": 0.0,
-                    "walltime": 2592000.0
-                }
-            ]
-        },
-        {
-            "id": 2,
-            "first_submit_time": 1000.0,
-            "preceding_sessions": [],
-            "thinking_time_after_preceding_session": [],
-            "nb_jobs": 1,
-            "jobs": [
-                {
-                    "id": 2,
-                    "profile": "2000",
-                    "res": 16,
-                    "subtime": 0.0,
-                    "walltime": 2592000.0
-                }
-            ]
-        },
-        {
-            "id": 3,
-            "first_submit_time": 1000.0,
-            "preceding_sessions": [],
-            "thinking_time_after_preceding_session": [],
-            "nb_jobs": 1,
-            "jobs": [
-                {
-                    "id": 3,
-                    "profile": "1000",
-                    "res": 16,
-                    "subtime": 0.0,
-                    "walltime": 2592000.0
-                }
-            ]
-        },
-        {
-            "id": 4,
-            "first_submit_time": 1500.0,
-            "preceding_sessions": [],
-            "thinking_time_after_preceding_session": [],
-            "nb_jobs": 1,
-            "jobs": [
-                {
-                    "id": 4,
-                    "profile": "1000",
-                    "res": 16,
-                    "subtime": 0.0,
-                    "walltime": 2592000.0
-                }
-            ]
-        },
-        {
-            "id": 5,
-            "first_submit_time": 2000.0,
-            "preceding_sessions": [],
-            "thinking_time_after_preceding_session": [],
-            "nb_jobs": 1,
-            "jobs": [
-                {
-                    "id": 5,
-                    "profile": "1000",
-                    "res": 16,
-                    "subtime": 0.0,
-                    "walltime": 2592000.0
-                }
-            ]
-        }
-    ]
-}
\ No newline at end of file
diff --git a/test/expected_output/zero_think_time.SABjson b/test/expected_output/zero_think_time.SABjson
index f88e328..278d842 100644
--- a/test/expected_output/zero_think_time.SABjson
+++ b/test/expected_output/zero_think_time.SABjson
@@ -20,7 +20,7 @@
         },
         {
             "id": 2,
-            "first_submit_time": 2000.0,
+            "first_submit_time": 1000.0,
             "preceding_sessions": [1],
             "thinking_time_after_preceding_session": [0],
             "nb_jobs": 1,
diff --git a/test/test_expected_outputs.py b/test/test_expected_outputs.py
index b15135e..1866c77 100644
--- a/test/test_expected_outputs.py
+++ b/test/test_expected_outputs.py
@@ -56,4 +56,18 @@ def test_example_workload():
 
     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
+    compare_with_expected_output(test_name)
+
+def test_edge_cases():
+    """Hand written SWF and SABjson files, testing some edge cases.
+    Same tests than in batmen."""
+
+    test_name = "load_platform"
+    run_script(delim="arrival", threshold=10, 
+               input_swf=f"test/workload/{test_name}.swf", test_name=test_name)
+    compare_with_expected_output(test_name)
+
+    test_name = "many_following"
+    run_script(delim="arrival", threshold=0, 
+               input_swf=f"test/workload/{test_name}.swf", test_name=test_name)
+    compare_with_expected_output(test_name)
diff --git a/test/workload/load_platform.swf b/test/workload/load_platform.swf
new file mode 100644
index 0000000..dd1ebc4
--- /dev/null
+++ b/test/workload/load_platform.swf
@@ -0,0 +1,9 @@
+; Written by hand.
+; Expected to produce load_platform.SABjson with arrival_t10
+
+    1        0      0   1000   16     -1    -1   16  2592000    -1  1  1  1  -1 -1 -1 -1 -1
+    2     2000      0   1000   16     -1    -1   16  2592000    -1  1  1  1  -1 -1 -1 -1 -1
+    5     9000      0   5000   16     -1    -1   16  2592000    -1  1  1  1  -1 -1 -1 -1 -1
+    6     9000      0   5000   16     -1    -1   16  2592000    -1  1  1  1  -1 -1 -1 -1 -1
+    3    10000      0   1000   16     -1    -1   16  2592000    -1  1  1  1  -1 -1 -1 -1 -1
+    4    12000      0   1000   16     -1    -1   16  2592000    -1  1  1  1  -1 -1 -1 -1 -1
diff --git a/test/workload/many_following.swf b/test/workload/many_following.swf
new file mode 100644
index 0000000..01ea036
--- /dev/null
+++ b/test/workload/many_following.swf
@@ -0,0 +1,9 @@
+; Written by hand.
+; Expected to produce many_following.SABjson with arrival_t0
+
+    1        0      0   1000   16     -1    -1   16  2592000    -1  1  1  1  -1 -1 -1 -1 -1
+    2     2000      0   2000   16     -1    -1   16  2592000    -1  1  1  1  -1 -1 -1 -1 -1
+    3     2001      0   1000   16     -1    -1   16  2592000    -1  1  1  1  -1 -1 -1 -1 -1
+    4     2002      0   1000   16     -1    -1   16  2592000    -1  1  1  1  -1 -1 -1 -1 -1
+    5     2003      0   1000   16     -1    -1   16  2592000    -1  1  1  1  -1 -1 -1 -1 -1
+    6     3000      0   1000   16     -1    -1   16  2592000    -1  1  1  1  -1 -1 -1 -1 -1
diff --git a/test/workload/many_preceding.swf b/test/workload/many_preceding.swf
new file mode 100644
index 0000000..107c63f
--- /dev/null
+++ b/test/workload/many_preceding.swf
@@ -0,0 +1,9 @@
+; Written by hand.
+; Expected to produce many_preceding.SABjson with arrival_t0
+
+    1     1000   1000   1000   16     -1    -1   16  2592000    -1  1  1  1  -1 -1 -1 -1 -1
+    2     1001    499   1500   16     -1    -1   16  2592000    -1  1  1  1  -1 -1 -1 -1 -1
+    3     1002    998   1000   16     -1    -1   16  2592000    -1  1  1  1  -1 -1 -1 -1 -1
+    4     1500    500   1000   16     -1    -1   16  2592000    -1  1  1  1  -1 -1 -1 -1 -1
+    5     2000      0   1000   16     -1    -1   16  2592000    -1  1  1  1  -1 -1 -1 -1 -1
+    6     4000      0   1000   16     -1    -1   16  2592000    -1  1  1  1  -1 -1 -1 -1 -1
diff --git a/test/workload/no_session.swf b/test/workload/no_session.swf
new file mode 100644
index 0000000..5ccaf6a
--- /dev/null
+++ b/test/workload/no_session.swf
@@ -0,0 +1,4 @@
+; Written by hand.
+; Expected to produce no_session.SABjson, whatever the delimitation approach
+
+
diff --git a/test/workload/one_session_many_jobs.swf b/test/workload/one_session_many_jobs.swf
new file mode 100644
index 0000000..c1a26ce
--- /dev/null
+++ b/test/workload/one_session_many_jobs.swf
@@ -0,0 +1,13 @@
+; Written by hand.
+; Expected to produce one_session_many_jobs.SABjson with last_t10
+
+  750        0      0    450   16     -1    -1   16  86400      -1  1  1  1  -1 -1 -1 -1 -1
+  751      591      0    210   16     -1    -1   16  86400      -1  1  1  1  -1 -1 -1 -1 -1
+  752      767      0  81540   16     -1    -1   16  163068     -1  1  1  1  -1 -1 -1 -1 -1
+  757      895      0  86140   16     -1    -1   16  172260     -1  1  1  1  -1 -1 -1 -1 -1
+  758      959      0  86130   16     -1    -1   16  172250     -1  1  1  1  -1 -1 -1 -1 -1
+  768     1537      0    920   16     -1    -1   16  86400      -1  1  1  1  -1 -1 -1 -1 -1
+  781     1841      0    290   16     -1    -1   16  86400      -1  1  1  1  -1 -1 -1 -1 -1
+  791     2068      0  86130   16     -1    -1   16  172248     -1  1  1  1  -1 -1 -1 -1 -1
+  794     2149      0  86120   16     -1    -1   16  172226     -1  1  1  1  -1 -1 -1 -1 -1
+  795     2533      0  86130   16     -1    -1   16  172246     -1  1  1  1  -1 -1 -1 -1 -1
diff --git a/test/workload/zero_think_time.swf b/test/workload/zero_think_time.swf
new file mode 100644
index 0000000..230bef0
--- /dev/null
+++ b/test/workload/zero_think_time.swf
@@ -0,0 +1,6 @@
+; Written by hand.
+; Expected to produce many_preceding.SABjson with last_t0
+
+    1        0   1000   1000   16     -1    -1   16  2592000    -1  1  1  1  -1 -1 -1 -1 -1
+    2     2000      0   2000   16     -1    -1   16  2592000    -1  1  1  1  -1 -1 -1 -1 -1
+
-- 
GitLab