]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
oeqa/selftest: Fix single threaded race issue
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 6 Oct 2025 13:09:02 +0000 (14:09 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Wed, 8 Oct 2025 12:55:29 +0000 (13:55 +0100)
oe-selftest sets up separate build directories to run the tests in.
To to this, environment paths pointing at the previous build directory
are updated. In the multi-threaded case this is fine as the thread is
destroyed and the parent remains unchanged but in the single threaded
case, the environment is broken afterwards. This can mean we try and access
a directory which is in the process of being deleted (e.g. by clobberdir).

Restore the environment afterwards regardless to ensure the single threaded
case doesn't try and access the build directory which is now being deleted.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/lib/oeqa/selftest/context.py

index 16f82c6737d19fb10c525cff9e2f41d2bbe89350..c9eb48172539ac394ce9aab201ff1527a859865d 100644 (file)
@@ -44,9 +44,13 @@ class NonConcurrentTestSuite(unittest.TestSuite):
         self.bb_vars = bb_vars
 
     def run(self, result):
+        origenv = os.environ.copy()
         (builddir, newbuilddir) = self.setupfunc("-st", None, self.suite)
         ret = super().run(result)
+        # In forks we don't have to restore but in a single process, restore cwd and the env
         os.chdir(builddir)
+        for e in origenv:
+            os.environ[e] = origenv[e]
         if newbuilddir and ret.wasSuccessful() and self.removefunc:
             self.removefunc(newbuilddir)