summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2021-05-05 19:15:29 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-05-06 11:16:23 +0100
commite293a3793573ad19f08663fbfcb8f7d9ee828ba4 (patch)
tree2e93082f6732571ef5f133c015b3d33977567d48 /meta/lib
parent27c77ee898268f398e74afbf0d4f441b38d1d905 (diff)
downloadpoky-e293a3793573ad19f08663fbfcb8f7d9ee828ba4.tar.gz
oeqa/qemurunner: Improve logging thread exit handling for qemu shutdown test
Rather than totally disabling the logging, inform it we're about to exit so we can log messages over the exit cleanly too. This aids debugging. It also avoids a race where the logging handler could still error whilst shutting down. Also remove a race window by notificing the handler of the shutdown first, before triggering it. This removes a race window I watched in local testing. (From OE-Core rev: 0e19f31a1005f94105e1cef252abfffcef2aafad) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oeqa/selftest/cases/runqemu.py9
-rw-r--r--meta/lib/oeqa/utils/qemurunner.py12
2 files changed, 15 insertions, 6 deletions
diff --git a/meta/lib/oeqa/selftest/cases/runqemu.py b/meta/lib/oeqa/selftest/cases/runqemu.py
index 7e676bcb41..da22f77b27 100644
--- a/meta/lib/oeqa/selftest/cases/runqemu.py
+++ b/meta/lib/oeqa/selftest/cases/runqemu.py
@@ -163,12 +163,11 @@ class QemuTest(OESelftestTestCase):
163 bitbake(cls.recipe) 163 bitbake(cls.recipe)
164 164
165 def _start_qemu_shutdown_check_if_shutdown_succeeded(self, qemu, timeout): 165 def _start_qemu_shutdown_check_if_shutdown_succeeded(self, qemu, timeout):
166 # Allow the runner's LoggingThread instance to exit without errors
167 # (such as the exception "Console connection closed unexpectedly")
168 # as qemu will disappear when we shut it down
169 qemu.runner.allowexit()
166 qemu.run_serial("shutdown -h now") 170 qemu.run_serial("shutdown -h now")
167 # Stop thread will stop the LoggingThread instance used for logging
168 # qemu through serial console, stop thread will prevent this code
169 # from facing exception (Console connection closed unexpectedly)
170 # when qemu was shutdown by the above shutdown command
171 qemu.runner.stop_thread()
172 time_track = 0 171 time_track = 0
173 try: 172 try:
174 while True: 173 while True:
diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py
index f6e1007288..cb0be5603c 100644
--- a/meta/lib/oeqa/utils/qemurunner.py
+++ b/meta/lib/oeqa/utils/qemurunner.py
@@ -534,6 +534,10 @@ class QemuRunner:
534 self.thread.stop() 534 self.thread.stop()
535 self.thread.join() 535 self.thread.join()
536 536
537 def allowexit(self):
538 if self.thread:
539 self.thread.allowexit()
540
537 def restart(self, qemuparams = None): 541 def restart(self, qemuparams = None):
538 self.logger.warning("Restarting qemu process") 542 self.logger.warning("Restarting qemu process")
539 if self.runqemu.poll() is None: 543 if self.runqemu.poll() is None:
@@ -630,6 +634,7 @@ class LoggingThread(threading.Thread):
630 self.logger = logger 634 self.logger = logger
631 self.readsock = None 635 self.readsock = None
632 self.running = False 636 self.running = False
637 self.canexit = False
633 638
634 self.errorevents = select.POLLERR | select.POLLHUP | select.POLLNVAL 639 self.errorevents = select.POLLERR | select.POLLHUP | select.POLLNVAL
635 self.readevents = select.POLLIN | select.POLLPRI 640 self.readevents = select.POLLIN | select.POLLPRI
@@ -663,6 +668,9 @@ class LoggingThread(threading.Thread):
663 self.close_ignore_error(self.writepipe) 668 self.close_ignore_error(self.writepipe)
664 self.running = False 669 self.running = False
665 670
671 def allowexit(self):
672 self.canexit = True
673
666 def eventloop(self): 674 def eventloop(self):
667 poll = select.poll() 675 poll = select.poll()
668 event_read_mask = self.errorevents | self.readevents 676 event_read_mask = self.errorevents | self.readevents
@@ -719,7 +727,9 @@ class LoggingThread(threading.Thread):
719 # happened. But for this code it counts as an 727 # happened. But for this code it counts as an
720 # error since the connection shouldn't go away 728 # error since the connection shouldn't go away
721 # until qemu exits. 729 # until qemu exits.
722 raise Exception("Console connection closed unexpectedly") 730 if not self.canexit:
731 raise Exception("Console connection closed unexpectedly")
732 return ''
723 733
724 return data 734 return data
725 735