summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2020-10-19 13:50:19 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-10-30 17:23:19 +0000
commit13936f5f35fcb36d23f45f9fedebf0b115c99db0 (patch)
tree8bc67a7408c290d41d55189452fa85ae2c894ac6 /meta/lib
parente91f098c1940ef5cf51c72ddbec510665eb0c340 (diff)
downloadpoky-13936f5f35fcb36d23f45f9fedebf0b115c99db0.tar.gz
oeqa: Add sync call to command execution
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. (From OE-Core rev: ed912771ea98c42f61bf927b1ca708650b0bed4c) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit ceca5ed121e2b54415a7ab3a217882e4ea86923a) Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oeqa/selftest/cases/runcmd.py16
-rw-r--r--meta/lib/oeqa/utils/commands.py8
2 files changed, 15 insertions, 9 deletions
diff --git a/meta/lib/oeqa/selftest/cases/runcmd.py b/meta/lib/oeqa/selftest/cases/runcmd.py
index a5ef1ea95f..fa6113d7fa 100644
--- a/meta/lib/oeqa/selftest/cases/runcmd.py
+++ b/meta/lib/oeqa/selftest/cases/runcmd.py
@@ -64,12 +64,12 @@ class RunCmdTests(OESelftestTestCase):
64 runCmd, "echo foobar >&2; false", shell=True, assert_error=False) 64 runCmd, "echo foobar >&2; false", shell=True, assert_error=False)
65 65
66 def test_output(self): 66 def test_output(self):
67 result = runCmd("echo stdout; echo stderr >&2", shell=True) 67 result = runCmd("echo stdout; echo stderr >&2", shell=True, sync=False)
68 self.assertEqual("stdout\nstderr", result.output) 68 self.assertEqual("stdout\nstderr", result.output)
69 self.assertEqual("", result.error) 69 self.assertEqual("", result.error)
70 70
71 def test_output_split(self): 71 def test_output_split(self):
72 result = runCmd("echo stdout; echo stderr >&2", shell=True, stderr=subprocess.PIPE) 72 result = runCmd("echo stdout; echo stderr >&2", shell=True, stderr=subprocess.PIPE, sync=False)
73 self.assertEqual("stdout", result.output) 73 self.assertEqual("stdout", result.output)
74 self.assertEqual("stderr", result.error) 74 self.assertEqual("stderr", result.error)
75 75
@@ -77,7 +77,7 @@ class RunCmdTests(OESelftestTestCase):
77 numthreads = threading.active_count() 77 numthreads = threading.active_count()
78 start = time.time() 78 start = time.time()
79 # Killing a hanging process only works when not using a shell?! 79 # Killing a hanging process only works when not using a shell?!
80 result = runCmd(['sleep', '60'], timeout=self.TIMEOUT, ignore_status=True) 80 result = runCmd(['sleep', '60'], timeout=self.TIMEOUT, ignore_status=True, sync=False)
81 self.assertEqual(result.status, -signal.SIGTERM) 81 self.assertEqual(result.status, -signal.SIGTERM)
82 end = time.time() 82 end = time.time()
83 self.assertLess(end - start, self.TIMEOUT + self.DELTA) 83 self.assertLess(end - start, self.TIMEOUT + self.DELTA)
@@ -87,7 +87,7 @@ class RunCmdTests(OESelftestTestCase):
87 numthreads = threading.active_count() 87 numthreads = threading.active_count()
88 start = time.time() 88 start = time.time()
89 # Killing a hanging process only works when not using a shell?! 89 # Killing a hanging process only works when not using a shell?!
90 result = runCmd(['sleep', '60'], timeout=self.TIMEOUT, ignore_status=True, stderr=subprocess.PIPE) 90 result = runCmd(['sleep', '60'], timeout=self.TIMEOUT, ignore_status=True, stderr=subprocess.PIPE, sync=False)
91 self.assertEqual(result.status, -signal.SIGTERM) 91 self.assertEqual(result.status, -signal.SIGTERM)
92 end = time.time() 92 end = time.time()
93 self.assertLess(end - start, self.TIMEOUT + self.DELTA) 93 self.assertLess(end - start, self.TIMEOUT + self.DELTA)
@@ -95,7 +95,7 @@ class RunCmdTests(OESelftestTestCase):
95 95
96 def test_stdin(self): 96 def test_stdin(self):
97 numthreads = threading.active_count() 97 numthreads = threading.active_count()
98 result = runCmd("cat", data=b"hello world", timeout=self.TIMEOUT) 98 result = runCmd("cat", data=b"hello world", timeout=self.TIMEOUT, sync=False)
99 self.assertEqual("hello world", result.output) 99 self.assertEqual("hello world", result.output)
100 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())) 100 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()))
101 self.assertEqual(numthreads, 1) 101 self.assertEqual(numthreads, 1)
@@ -103,7 +103,7 @@ class RunCmdTests(OESelftestTestCase):
103 def test_stdin_timeout(self): 103 def test_stdin_timeout(self):
104 numthreads = threading.active_count() 104 numthreads = threading.active_count()
105 start = time.time() 105 start = time.time()
106 result = runCmd(['sleep', '60'], data=b"hello world", timeout=self.TIMEOUT, ignore_status=True) 106 result = runCmd(['sleep', '60'], data=b"hello world", timeout=self.TIMEOUT, ignore_status=True, sync=False)
107 self.assertEqual(result.status, -signal.SIGTERM) 107 self.assertEqual(result.status, -signal.SIGTERM)
108 end = time.time() 108 end = time.time()
109 self.assertLess(end - start, self.TIMEOUT + self.DELTA) 109 self.assertLess(end - start, self.TIMEOUT + self.DELTA)
@@ -111,12 +111,12 @@ class RunCmdTests(OESelftestTestCase):
111 111
112 def test_log(self): 112 def test_log(self):
113 log = MemLogger() 113 log = MemLogger()
114 result = runCmd("echo stdout; echo stderr >&2", shell=True, output_log=log) 114 result = runCmd("echo stdout; echo stderr >&2", shell=True, output_log=log, sync=False)
115 self.assertEqual(["Running: echo stdout; echo stderr >&2", "stdout", "stderr"], log.info_msgs) 115 self.assertEqual(["Running: echo stdout; echo stderr >&2", "stdout", "stderr"], log.info_msgs)
116 self.assertEqual([], log.error_msgs) 116 self.assertEqual([], log.error_msgs)
117 117
118 def test_log_split(self): 118 def test_log_split(self):
119 log = MemLogger() 119 log = MemLogger()
120 result = runCmd("echo stdout; echo stderr >&2", shell=True, output_log=log, stderr=subprocess.PIPE) 120 result = runCmd("echo stdout; echo stderr >&2", shell=True, output_log=log, stderr=subprocess.PIPE, sync=False)
121 self.assertEqual(["Running: echo stdout; echo stderr >&2", "stdout"], log.info_msgs) 121 self.assertEqual(["Running: echo stdout; echo stderr >&2", "stdout"], log.info_msgs)
122 self.assertEqual(["stderr"], log.error_msgs) 122 self.assertEqual(["stderr"], log.error_msgs)
diff --git a/meta/lib/oeqa/utils/commands.py b/meta/lib/oeqa/utils/commands.py
index f7f8c16bf0..8059cbce3e 100644
--- a/meta/lib/oeqa/utils/commands.py
+++ b/meta/lib/oeqa/utils/commands.py
@@ -167,7 +167,7 @@ class Result(object):
167 pass 167 pass
168 168
169 169
170def runCmd(command, ignore_status=False, timeout=None, assert_error=True, 170def runCmd(command, ignore_status=False, timeout=None, assert_error=True, sync=True,
171 native_sysroot=None, limit_exc_output=0, output_log=None, **options): 171 native_sysroot=None, limit_exc_output=0, output_log=None, **options):
172 result = Result() 172 result = Result()
173 173
@@ -184,6 +184,12 @@ def runCmd(command, ignore_status=False, timeout=None, assert_error=True,
184 cmd = Command(command, timeout=timeout, output_log=output_log, **options) 184 cmd = Command(command, timeout=timeout, output_log=output_log, **options)
185 cmd.run() 185 cmd.run()
186 186
187 # tests can be heavy on IO and if bitbake can't write out its caches, we see timeouts.
188 # call sync around the tests to ensure the IO queue doesn't get too large, taking any IO
189 # hit here rather than in bitbake shutdown.
190 if sync:
191 os.system("sync")
192
187 result.command = command 193 result.command = command
188 result.status = cmd.status 194 result.status = cmd.status
189 result.output = cmd.output 195 result.output = cmd.output