]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: Don't keep journals for skipped tests
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 7 May 2024 09:50:11 +0000 (11:50 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 7 May 2024 15:34:42 +0000 (17:34 +0200)
Let's make sure we don't save journals for tests that were skipped.

test/integration-test-wrapper.py

index 575403344e4f5dbd243902c915ae099ba1351f18..25b903c4e6a3d75d8508e3bc6c00685c68361ed1 100755 (executable)
@@ -144,24 +144,29 @@ def main():
     ]
 
     result = subprocess.run(cmd)
+
     # Return code 123 is the expected success code
-    if result.returncode != 123:
-        if result.returncode != 77 and journal_file:
-            cmd = [
-                'journalctl',
-                '--no-hostname',
-                '-o', 'short-monotonic',
-                '--file', journal_file,
-                '-u', test_unit,
-                '-p', 'info',
-            ]
-            print("Test failed, relevant logs can be viewed with: \n\n"
-                  f"{shlex.join(str(a) for a in cmd)}\n", file=sys.stderr)
-        exit(result.returncode or 1)
+    if result.returncode in (123, 77):
+        # Do not keep journal files for tests that don't fail.
+        if journal_file:
+            journal_file.unlink(missing_ok=True)
+
+        exit(0 if result.returncode == 123 else 77)
 
-    # Do not keep journal files for tests that don't fail.
     if journal_file:
-        journal_file.unlink(missing_ok=True)
+        cmd = [
+            'journalctl',
+            '--no-hostname',
+            '-o', 'short-monotonic',
+            '--file', journal_file,
+            '-u', test_unit,
+            '-p', 'info',
+        ]
+        print("Test failed, relevant logs can be viewed with: \n\n"
+              f"{shlex.join(str(a) for a in cmd)}\n", file=sys.stderr)
+
+    # 0 also means we failed so translate that to a non-zero exit code to mark the test as failed.
+    exit(result.returncode or 1)
 
 
 if __name__ == '__main__':