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-20 12:36:42 +0100
commit0cbb70183472112e6d02a7822cc890aa47b4387e (patch)
treedb291a34366f73fc52b105e0d14ffc8818ff0134
parent62c3960c3a4dbc28df8f917b67fd6ce180400d4e (diff)
downloadpoky-0cbb70183472112e6d02a7822cc890aa47b4387e.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: 57249316b6c66c5e17804e1b04f2d5cf0db92683) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit 0e19f31a1005f94105e1cef252abfffcef2aafad) Signed-off-by: Steve Sakoman <steve@sakoman.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 77ec939ad7..410789b815 100644
--- a/meta/lib/oeqa/utils/qemurunner.py
+++ b/meta/lib/oeqa/utils/qemurunner.py
@@ -467,6 +467,10 @@ class QemuRunner:
467 self.thread.stop() 467 self.thread.stop()
468 self.thread.join() 468 self.thread.join()
469 469
470 def allowexit(self):
471 if self.thread:
472 self.thread.allowexit()
473
470 def restart(self, qemuparams = None): 474 def restart(self, qemuparams = None):
471 self.logger.warning("Restarting qemu process") 475 self.logger.warning("Restarting qemu process")
472 if self.runqemu.poll() is None: 476 if self.runqemu.poll() is None:
@@ -560,6 +564,7 @@ class LoggingThread(threading.Thread):
560 self.logger = logger 564 self.logger = logger
561 self.readsock = None 565 self.readsock = None
562 self.running = False 566 self.running = False
567 self.canexit = False
563 568
564 self.errorevents = select.POLLERR | select.POLLHUP | select.POLLNVAL 569 self.errorevents = select.POLLERR | select.POLLHUP | select.POLLNVAL
565 self.readevents = select.POLLIN | select.POLLPRI 570 self.readevents = select.POLLIN | select.POLLPRI
@@ -593,6 +598,9 @@ class LoggingThread(threading.Thread):
593 self.close_ignore_error(self.writepipe) 598 self.close_ignore_error(self.writepipe)
594 self.running = False 599 self.running = False
595 600
601 def allowexit(self):
602 self.canexit = True
603
596 def eventloop(self): 604 def eventloop(self):
597 poll = select.poll() 605 poll = select.poll()
598 event_read_mask = self.errorevents | self.readevents 606 event_read_mask = self.errorevents | self.readevents
@@ -649,7 +657,9 @@ class LoggingThread(threading.Thread):
649 # happened. But for this code it counts as an 657 # happened. But for this code it counts as an
650 # error since the connection shouldn't go away 658 # error since the connection shouldn't go away
651 # until qemu exits. 659 # until qemu exits.
652 raise Exception("Console connection closed unexpectedly") 660 if not self.canexit:
661 raise Exception("Console connection closed unexpectedly")
662 return ''
653 663
654 return data 664 return data
655 665