1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-31 12:49:46 +00:00

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>
This commit is contained in:
Richard Purdie
2021-05-05 19:15:29 +01:00
parent 27c77ee898
commit e293a37935
2 changed files with 15 additions and 6 deletions
+4 -5
View File
@@ -163,12 +163,11 @@ class QemuTest(OESelftestTestCase):
bitbake(cls.recipe) bitbake(cls.recipe)
def _start_qemu_shutdown_check_if_shutdown_succeeded(self, qemu, timeout): def _start_qemu_shutdown_check_if_shutdown_succeeded(self, qemu, timeout):
# Allow the runner's LoggingThread instance to exit without errors
# (such as the exception "Console connection closed unexpectedly")
# as qemu will disappear when we shut it down
qemu.runner.allowexit()
qemu.run_serial("shutdown -h now") qemu.run_serial("shutdown -h now")
# Stop thread will stop the LoggingThread instance used for logging
# qemu through serial console, stop thread will prevent this code
# from facing exception (Console connection closed unexpectedly)
# when qemu was shutdown by the above shutdown command
qemu.runner.stop_thread()
time_track = 0 time_track = 0
try: try:
while True: while True:
+11 -1
View File
@@ -534,6 +534,10 @@ class QemuRunner:
self.thread.stop() self.thread.stop()
self.thread.join() self.thread.join()
def allowexit(self):
if self.thread:
self.thread.allowexit()
def restart(self, qemuparams = None): def restart(self, qemuparams = None):
self.logger.warning("Restarting qemu process") self.logger.warning("Restarting qemu process")
if self.runqemu.poll() is None: if self.runqemu.poll() is None:
@@ -630,6 +634,7 @@ class LoggingThread(threading.Thread):
self.logger = logger self.logger = logger
self.readsock = None self.readsock = None
self.running = False self.running = False
self.canexit = False
self.errorevents = select.POLLERR | select.POLLHUP | select.POLLNVAL self.errorevents = select.POLLERR | select.POLLHUP | select.POLLNVAL
self.readevents = select.POLLIN | select.POLLPRI self.readevents = select.POLLIN | select.POLLPRI
@@ -663,6 +668,9 @@ class LoggingThread(threading.Thread):
self.close_ignore_error(self.writepipe) self.close_ignore_error(self.writepipe)
self.running = False self.running = False
def allowexit(self):
self.canexit = True
def eventloop(self): def eventloop(self):
poll = select.poll() poll = select.poll()
event_read_mask = self.errorevents | self.readevents event_read_mask = self.errorevents | self.readevents
@@ -719,7 +727,9 @@ class LoggingThread(threading.Thread):
# happened. But for this code it counts as an # happened. But for this code it counts as an
# error since the connection shouldn't go away # error since the connection shouldn't go away
# until qemu exits. # until qemu exits.
raise Exception("Console connection closed unexpectedly") if not self.canexit:
raise Exception("Console connection closed unexpectedly")
return ''
return data return data