[OE-core] [PATCH] oeqa/tinfoil: Improve test_wait_event for race issues

Richard Purdie richard.purdie at linuxfoundation.org
Fri Jul 7 13:59:13 UTC 2017


The test could break in a variety of ways:

a) If BB_HEARTBEAT_EVENT was less than ~0.25 it would hang indefinitely
b) The mask is set after draining the event queue meaning a heartbeat event
   could have happened
c) The test exits once it sees the events it wants, it doesn't check for
   spurious events such as heartbeats which shouldn't have occured.
d) The hardcoded delay of 0.25 is nasty and shouldn't be needed.

I found a bitbake bug and fixed that meaning we don't need the delay any
more which fixes d). That means a) is no longer an issue either.

We now set the mask, then drain the queue meaning no spurious events should
be able to sneak in. The test is also tweaked to wait for 5s in total to
ensure spurious events don't occur such as heartbeat events we shouldn't see.

[YOCTO #11045]

Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 meta/lib/oeqa/selftest/cases/tinfoil.py | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/meta/lib/oeqa/selftest/cases/tinfoil.py b/meta/lib/oeqa/selftest/cases/tinfoil.py
index 3a58761..aa1af7e 100644
--- a/meta/lib/oeqa/selftest/cases/tinfoil.py
+++ b/meta/lib/oeqa/selftest/cases/tinfoil.py
@@ -1,5 +1,6 @@
 import os
 import re
+import time
 import bb.tinfoil
 
 from oeqa.selftest.case import OESelftestTestCase
@@ -102,21 +103,26 @@ class TinfoilTests(OESelftestTestCase):
     def test_wait_event(self):
         with bb.tinfoil.Tinfoil() as tinfoil:
             tinfoil.prepare(config_only=True)
-            # Need to drain events otherwise events that will be masked will still be in the queue
-            while tinfoil.wait_event(0.25):
-                pass
+
             tinfoil.set_event_mask(['bb.event.FilesMatchingFound', 'bb.command.CommandCompleted'])
+
+            # Need to drain events otherwise events that were masked may still be in the queue
+            while tinfoil.wait_event():
+                pass
+
             pattern = 'conf'
             res = tinfoil.run_command('findFilesMatchingInDir', pattern, 'conf/machine')
             self.assertTrue(res)
 
             eventreceived = False
-            waitcount = 5
-            while waitcount > 0:
+            commandcomplete = False
+            start = time.time()
+            # Wait for 5s in total so we'd detect spurious heartbeat events for example
+            while time.time() - start < 5:
                 event = tinfoil.wait_event(1)
                 if event:
                     if isinstance(event, bb.command.CommandCompleted):
-                        break
+                        commandcomplete = True
                     elif isinstance(event, bb.event.FilesMatchingFound):
                         self.assertEqual(pattern, event._pattern)
                         self.assertIn('qemuarm.conf', event._matches)
@@ -124,9 +130,7 @@ class TinfoilTests(OESelftestTestCase):
                     else:
                         self.fail('Unexpected event: %s' % event)
 
-                waitcount = waitcount - 1
-
-            self.assertNotEqual(waitcount, 0, 'Timed out waiting for CommandCompleted event from bitbake server')
+            self.assertTrue(commandcomplete, 'Timed out waiting for CommandCompleted event from bitbake server')
             self.assertTrue(eventreceived, 'Did not receive FilesMatchingFound event from bitbake server')
 
     @OETestID(1576)
-- 
2.7.4




More information about the Openembedded-core mailing list