]> code.ossystems Code Review - openembedded-core.git/commitdiff
oeqa: Add sync call to command execution
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 19 Oct 2020 12:50:19 +0000 (13:50 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 20 Oct 2020 10:11:41 +0000 (11:11 +0100)
We previously put a sync call into devtool to try and combat the bitbake
timeout issues on the autobuilder. It isn't enough as the timeouts occur
mid test. They are also occurring on non-devtool tests.

Add in sync calls around command execution instead.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/lib/oeqa/selftest/cases/devtool.py
meta/lib/oeqa/selftest/cases/runcmd.py
meta/lib/oeqa/utils/commands.py

index 0185e670ad08304d09e497d3c9d25c6b7f497908..d3d2e04c20e3606a62007ac0a113836e5f4051e0 100644 (file)
@@ -107,13 +107,6 @@ class DevtoolBase(OESelftestTestCase):
                         'under the build directory')
         self.append_config(self.sstate_conf)
 
-    def tearDown(self):
-        # devtools tests are heavy on IO and if bitbake can't write out its caches, we see timeouts.
-        # call sync around the tests to ensure the IO queue doesn't get too large, taking any IO
-        # hit here rather than in bitbake shutdown.
-        super().tearDown()
-        os.system("sync")
-
     def _check_src_repo(self, repo_dir):
         """Check srctree git repository"""
         self.assertTrue(os.path.isdir(os.path.join(repo_dir, '.git')),
index a5ef1ea95faef032c25c65a08f457cd65b07a32d..fa6113d7faa9404d4643a2f545e0f0a3ba718234 100644 (file)
@@ -64,12 +64,12 @@ class RunCmdTests(OESelftestTestCase):
                                 runCmd, "echo foobar >&2; false", shell=True, assert_error=False)
 
     def test_output(self):
-        result = runCmd("echo stdout; echo stderr >&2", shell=True)
+        result = runCmd("echo stdout; echo stderr >&2", shell=True, sync=False)
         self.assertEqual("stdout\nstderr", result.output)
         self.assertEqual("", result.error)
 
     def test_output_split(self):
-        result = runCmd("echo stdout; echo stderr >&2", shell=True, stderr=subprocess.PIPE)
+        result = runCmd("echo stdout; echo stderr >&2", shell=True, stderr=subprocess.PIPE, sync=False)
         self.assertEqual("stdout", result.output)
         self.assertEqual("stderr", result.error)
 
@@ -77,7 +77,7 @@ class RunCmdTests(OESelftestTestCase):
         numthreads = threading.active_count()
         start = time.time()
         # Killing a hanging process only works when not using a shell?!
-        result = runCmd(['sleep', '60'], timeout=self.TIMEOUT, ignore_status=True)
+        result = runCmd(['sleep', '60'], timeout=self.TIMEOUT, ignore_status=True, sync=False)
         self.assertEqual(result.status, -signal.SIGTERM)
         end = time.time()
         self.assertLess(end - start, self.TIMEOUT + self.DELTA)
@@ -87,7 +87,7 @@ class RunCmdTests(OESelftestTestCase):
         numthreads = threading.active_count()
         start = time.time()
         # Killing a hanging process only works when not using a shell?!
-        result = runCmd(['sleep', '60'], timeout=self.TIMEOUT, ignore_status=True, stderr=subprocess.PIPE)
+        result = runCmd(['sleep', '60'], timeout=self.TIMEOUT, ignore_status=True, stderr=subprocess.PIPE, sync=False)
         self.assertEqual(result.status, -signal.SIGTERM)
         end = time.time()
         self.assertLess(end - start, self.TIMEOUT + self.DELTA)
@@ -95,7 +95,7 @@ class RunCmdTests(OESelftestTestCase):
 
     def test_stdin(self):
         numthreads = threading.active_count()
-        result = runCmd("cat", data=b"hello world", timeout=self.TIMEOUT)
+        result = runCmd("cat", data=b"hello world", timeout=self.TIMEOUT, sync=False)
         self.assertEqual("hello world", result.output)
         self.assertEqual(numthreads, threading.active_count(), msg="Thread counts were not equal before (%s) and after (%s), active threads: %s" % (numthreads, threading.active_count(), threading.enumerate()))
         self.assertEqual(numthreads, 1)
@@ -103,7 +103,7 @@ class RunCmdTests(OESelftestTestCase):
     def test_stdin_timeout(self):
         numthreads = threading.active_count()
         start = time.time()
-        result = runCmd(['sleep', '60'], data=b"hello world", timeout=self.TIMEOUT, ignore_status=True)
+        result = runCmd(['sleep', '60'], data=b"hello world", timeout=self.TIMEOUT, ignore_status=True, sync=False)
         self.assertEqual(result.status, -signal.SIGTERM)
         end = time.time()
         self.assertLess(end - start, self.TIMEOUT + self.DELTA)
@@ -111,12 +111,12 @@ class RunCmdTests(OESelftestTestCase):
 
     def test_log(self):
         log = MemLogger()
-        result = runCmd("echo stdout; echo stderr >&2", shell=True, output_log=log)
+        result = runCmd("echo stdout; echo stderr >&2", shell=True, output_log=log, sync=False)
         self.assertEqual(["Running: echo stdout; echo stderr >&2", "stdout", "stderr"], log.info_msgs)
         self.assertEqual([], log.error_msgs)
 
     def test_log_split(self):
         log = MemLogger()
-        result = runCmd("echo stdout; echo stderr >&2", shell=True, output_log=log, stderr=subprocess.PIPE)
+        result = runCmd("echo stdout; echo stderr >&2", shell=True, output_log=log, stderr=subprocess.PIPE, sync=False)
         self.assertEqual(["Running: echo stdout; echo stderr >&2", "stdout"], log.info_msgs)
         self.assertEqual(["stderr"], log.error_msgs)
index f7f8c16bf00732ac72b82b7bc497ecee71107f93..8059cbce3e1138d6d46b170ccf9cc68d5ec8087a 100644 (file)
@@ -167,7 +167,7 @@ class Result(object):
     pass
 
 
-def runCmd(command, ignore_status=False, timeout=None, assert_error=True,
+def runCmd(command, ignore_status=False, timeout=None, assert_error=True, sync=True,
           native_sysroot=None, limit_exc_output=0, output_log=None, **options):
     result = Result()
 
@@ -184,6 +184,12 @@ def runCmd(command, ignore_status=False, timeout=None, assert_error=True,
     cmd = Command(command, timeout=timeout, output_log=output_log, **options)
     cmd.run()
 
+    # tests can be heavy on IO and if bitbake can't write out its caches, we see timeouts.
+    # call sync around the tests to ensure the IO queue doesn't get too large, taking any IO
+    # hit here rather than in bitbake shutdown.
+    if sync:
+        os.system("sync")
+
     result.command = command
     result.status = cmd.status
     result.output = cmd.output