summaryrefslogtreecommitdiffstats
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-15 17:18:21 +0100
commit6ad4febbcdb3e0024c888367f2af48a5222292f5 (patch)
treeb08fb3eb05ec073aa1482659add3969568e02471
parent6f1d6448c5b2711f04e6b3798aef10b39669bcac (diff)
downloadpoky-6ad4febbcdb3e0024c888367f2af48a5222292f5.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: 7f931dce4484a2740b419b2d25830fc453748a0c) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit 0e19f31a1005f94105e1cef252abfffcef2aafad) Signed-off-by: Anuj Mittal <anuj.mittal@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-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 278904ba0b..84f7c5e76d 100644
--- a/meta/lib/oeqa/utils/qemurunner.py
+++ b/meta/lib/oeqa/utils/qemurunner.py
@@ -471,6 +471,10 @@ class QemuRunner:
471 self.thread.stop() 471 self.thread.stop()
472 self.thread.join() 472 self.thread.join()
473 473
474 def allowexit(self):
475 if self.thread:
476 self.thread.allowexit()
477
474 def restart(self, qemuparams = None): 478 def restart(self, qemuparams = None):
475 self.logger.warning("Restarting qemu process") 479 self.logger.warning("Restarting qemu process")
476 if self.runqemu.poll() is None: 480 if self.runqemu.poll() is None:
@@ -564,6 +568,7 @@ class LoggingThread(threading.Thread):
564 self.logger = logger 568 self.logger = logger
565 self.readsock = None 569 self.readsock = None
566 self.running = False 570 self.running = False
571 self.canexit = False
567 572
568 self.errorevents = select.POLLERR | select.POLLHUP | select.POLLNVAL 573 self.errorevents = select.POLLERR | select.POLLHUP | select.POLLNVAL
569 self.readevents = select.POLLIN | select.POLLPRI 574 self.readevents = select.POLLIN | select.POLLPRI
@@ -597,6 +602,9 @@ class LoggingThread(threading.Thread):
597 self.close_ignore_error(self.writepipe) 602 self.close_ignore_error(self.writepipe)
598 self.running = False 603 self.running = False
599 604
605 def allowexit(self):
606 self.canexit = True
607
600 def eventloop(self): 608 def eventloop(self):
601 poll = select.poll() 609 poll = select.poll()
602 event_read_mask = self.errorevents | self.readevents 610 event_read_mask = self.errorevents | self.readevents
@@ -653,7 +661,9 @@ class LoggingThread(threading.Thread):
653 # happened. But for this code it counts as an 661 # happened. But for this code it counts as an
654 # error since the connection shouldn't go away 662 # error since the connection shouldn't go away
655 # until qemu exits. 663 # until qemu exits.
656 raise Exception("Console connection closed unexpectedly") 664 if not self.canexit:
665 raise Exception("Console connection closed unexpectedly")
666 return ''
657 667
658 return data 668 return data
659 669