[2/2] testsuite: cleanup artifacts if not requested otherwise

Message ID 20261117120300.374231-3-felix.moessbauer@siemens.com
State Under Review
Headers show
Series Isolate test classes, make them reproducible | expand

Commit Message

Felix Moessbauer Nov. 17, 2026, 12:03 p.m. UTC
In CI runs we often see issues that only appear if executing tests
individually instead of all in a row. This happens, because subsequent
builds do not start in a fresh environment. To improve this, we now
clean the build/tmp* dirs after executing a test class. As avocado test
does not natively support this, we add the cleanup as a last test. Due
to our test-internal dependencies, we still cannot cleanup after each
testcase.

If the cleanup is not desired (e.g. for manual analysis), setting
-p cleanup=0 skips it.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 testsuite/README.md |  2 ++
 testsuite/cibase.py | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+)

Patch

diff --git a/testsuite/README.md b/testsuite/README.md
index 07bcfaf2..461e8c53 100644
--- a/testsuite/README.md
+++ b/testsuite/README.md
@@ -36,6 +36,8 @@  To generate a kas configuration for manual debugging, add `-p kasconfig=1`.
 The configuration is written when the test starts to
 `{build_dir}/kas-{testname}.yaml`.
 
+Artifacts are removed after each test class unless you pass `-p cleanup=0`.
+
 To build against a specific Debian snapshot date, add `-p sde=<SOURCE_DATE_EPOCH>`.
 
 ## Fast build test
diff --git a/testsuite/cibase.py b/testsuite/cibase.py
index 3f44e8ac..f824ae11 100755
--- a/testsuite/cibase.py
+++ b/testsuite/cibase.py
@@ -14,6 +14,24 @@  from avocado.utils import process
 
 
 class CIBaseTest(CIBuilder):
+    def test_cleanup_artifacts(self):
+        """
+        Workaround for missing class teardown support: Cleanup
+        the build/tmp so that the next test class starts in
+        a clean environment. This test comes last, according
+        to the python class inheritance order.
+        """
+        if not bool(int(self.params.get('cleanup', default=1))):
+            return
+
+        self.init()
+        rootless = bool(int(self.params.get('rootless', default=0)))
+        clean_cmd = f"{isar_root}/scripts/isar-clean-builddir"
+        if rootless:
+            clean_cmd += " --rootless"
+        for tmp_dir in glob.glob(self.build_dir + '/' + 'tmp*'):
+            process.run(f"{clean_cmd} {tmp_dir}")
+
     def perform_build_test(self, targets, should_fail=False, **kwargs):
         self.configure(targets=targets, **kwargs)