[Concept,16/19] test: py: Send poweroff on every sandbox shutdown

Message ID 20260314231618.338113-17-sjg@u-boot.org
State New
Headers
Series test: Fix pytest inter-test side effects |

Commit Message

Simon Glass March 14, 2026, 11:16 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

When --malloc-dump is active, only the final close() sends poweroff to
trigger state_uninit(). Intermediate shutdowns from cleanup_spawn()
(used by restart_uboot and failure cleanup) just close the PTY, so
those sessions never write a dump file.

Send poweroff before every shutdown path so each sandbox session
produces a dump. This makes the dump sequence numbers sequential.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 test/py/console_sandbox.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
  

Patch

diff --git a/test/py/console_sandbox.py b/test/py/console_sandbox.py
index 424e3ad2dd7..21625140dbb 100644
--- a/test/py/console_sandbox.py
+++ b/test/py/console_sandbox.py
@@ -93,8 +93,8 @@  class ConsoleSandbox(ConsoleBase):
             self.sandbox_flags = []
             self.use_dtb = True
 
-    def close(self):
-        """Terminate the sandbox, using poweroff for a clean shutdown.
+    def _poweroff_if_needed(self):
+        """Send poweroff for a clean shutdown if malloc-dump is active.
 
         When --malloc-dump is active we need state_uninit() to run, so
         send 'poweroff' instead of just closing the PTY.
@@ -108,6 +108,15 @@  class ConsoleSandbox(ConsoleBase):
                     time.sleep(0.1)
             except:
                 pass
+
+    def cleanup_spawn(self):
+        """Shut down sandbox, using poweroff for a clean shutdown."""
+        self._poweroff_if_needed()
+        super().cleanup_spawn()
+
+    def close(self):
+        """Terminate sandbox, using poweroff for a clean shutdown."""
+        self._poweroff_if_needed()
         super().close()
 
     def kill(self, sig):