summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/selftest/cases/tinfoil.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2017-07-07 13:55:06 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-07-08 13:34:46 +0100
commit854c8c2e4c24ea3ddfec6e5b5f6477f0620510e4 (patch)
tree414eb8e4d4d6c90feb3428d066a3573557c6ad97 /meta/lib/oeqa/selftest/cases/tinfoil.py
parentaf950e2c0923996788fa147feddbf4a9522b30f4 (diff)
downloadpoky-854c8c2e4c24ea3ddfec6e5b5f6477f0620510e4.tar.gz
oeqa/tinfoil: Improve test_wait_event for race issues
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] (From OE-Core rev: 7dd5dfc4d56f1201110d947ce1ca3c6d64fbc7da) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/selftest/cases/tinfoil.py')
-rw-r--r--meta/lib/oeqa/selftest/cases/tinfoil.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/meta/lib/oeqa/selftest/cases/tinfoil.py b/meta/lib/oeqa/selftest/cases/tinfoil.py
index 3a58761c00..aa1af7e042 100644
--- a/meta/lib/oeqa/selftest/cases/tinfoil.py
+++ b/meta/lib/oeqa/selftest/cases/tinfoil.py
@@ -1,5 +1,6 @@
1import os 1import os
2import re 2import re
3import time
3import bb.tinfoil 4import bb.tinfoil
4 5
5from oeqa.selftest.case import OESelftestTestCase 6from oeqa.selftest.case import OESelftestTestCase
@@ -102,21 +103,26 @@ class TinfoilTests(OESelftestTestCase):
102 def test_wait_event(self): 103 def test_wait_event(self):
103 with bb.tinfoil.Tinfoil() as tinfoil: 104 with bb.tinfoil.Tinfoil() as tinfoil:
104 tinfoil.prepare(config_only=True) 105 tinfoil.prepare(config_only=True)
105 # Need to drain events otherwise events that will be masked will still be in the queue 106
106 while tinfoil.wait_event(0.25):
107 pass
108 tinfoil.set_event_mask(['bb.event.FilesMatchingFound', 'bb.command.CommandCompleted']) 107 tinfoil.set_event_mask(['bb.event.FilesMatchingFound', 'bb.command.CommandCompleted'])
108
109 # Need to drain events otherwise events that were masked may still be in the queue
110 while tinfoil.wait_event():
111 pass
112
109 pattern = 'conf' 113 pattern = 'conf'
110 res = tinfoil.run_command('findFilesMatchingInDir', pattern, 'conf/machine') 114 res = tinfoil.run_command('findFilesMatchingInDir', pattern, 'conf/machine')
111 self.assertTrue(res) 115 self.assertTrue(res)
112 116
113 eventreceived = False 117 eventreceived = False
114 waitcount = 5 118 commandcomplete = False
115 while waitcount > 0: 119 start = time.time()
120 # Wait for 5s in total so we'd detect spurious heartbeat events for example
121 while time.time() - start < 5:
116 event = tinfoil.wait_event(1) 122 event = tinfoil.wait_event(1)
117 if event: 123 if event:
118 if isinstance(event, bb.command.CommandCompleted): 124 if isinstance(event, bb.command.CommandCompleted):
119 break 125 commandcomplete = True
120 elif isinstance(event, bb.event.FilesMatchingFound): 126 elif isinstance(event, bb.event.FilesMatchingFound):
121 self.assertEqual(pattern, event._pattern) 127 self.assertEqual(pattern, event._pattern)
122 self.assertIn('qemuarm.conf', event._matches) 128 self.assertIn('qemuarm.conf', event._matches)
@@ -124,9 +130,7 @@ class TinfoilTests(OESelftestTestCase):
124 else: 130 else:
125 self.fail('Unexpected event: %s' % event) 131 self.fail('Unexpected event: %s' % event)
126 132
127 waitcount = waitcount - 1 133 self.assertTrue(commandcomplete, 'Timed out waiting for CommandCompleted event from bitbake server')
128
129 self.assertNotEqual(waitcount, 0, 'Timed out waiting for CommandCompleted event from bitbake server')
130 self.assertTrue(eventreceived, 'Did not receive FilesMatchingFound event from bitbake server') 134 self.assertTrue(eventreceived, 'Did not receive FilesMatchingFound event from bitbake server')
131 135
132 @OETestID(1576) 136 @OETestID(1576)