]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
test: Try to shut down the lab console gracefully
authorSimon Glass <sjg@chromium.org>
Tue, 12 Nov 2024 14:13:22 +0000 (07:13 -0700)
committerTom Rini <trini@konsulko.com>
Wed, 13 Nov 2024 18:01:35 +0000 (12:01 -0600)
Send the Labgrid quit characters to ask it to exit gracefully. This
typically allows it to power off the board being used. Only do this when
labgrid is being used (detected with an env var).

If that doesn't work, try the less graceful approach.

The normal approach for pytest is to simply kill the child process. This
makes Labgrid exit immediately. Thus it does not get a chance to execute
the 'off' part of strategy (which may power it off) and release the
device.

Without this, every board disconnect leaves the board in a bad state,
requiring separate steps to recover the board, then power it off.

The action is conditional on since USE_LABGRID_SJG being set, so only
affects operation if the Labgrid-sjg integration is being used.

Signed-off-by: Simon Glass <sjg@chromium.org>
test/py/u_boot_spawn.py

index 9fa05057848a14af7500f25065ba008ba2ca63c5..c703454389db6c93c99752cbce0cf2f2c4b2fbda 100644 (file)
@@ -17,6 +17,9 @@ import termios
 import time
 import traceback
 
+# Character to send (twice) to exit the terminal
+EXIT_CHAR = 0x1d    # FS (Ctrl + ])
+
 class Timeout(Exception):
     """An exception sub-class that indicates that a timeout occurred."""
 
@@ -311,15 +314,28 @@ class Spawn:
             None.
 
         Returns:
-            Nothing.
+            str: Type of closure completed
         """
-
+        # For Labgrid-sjg, ask it is exit gracefully, so it can transition the
+        # board to the final state (like 'off') before exiting.
+        if os.environ.get('USE_LABGRID_SJG'):
+            self.send(chr(EXIT_CHAR) * 2)
+
+            # Wait about 10 seconds for Labgrid to close and power off the board
+            for _ in range(100):
+                if not self.isalive():
+                    return 'normal'
+                time.sleep(0.1)
+
+        # That didn't work, so try closing the PTY
         os.close(self.fd)
         for _ in range(100):
             if not self.isalive():
-                break
+                return 'break'
             time.sleep(0.1)
 
+        return 'timeout'
+
     def get_expect_output(self):
         """Return the output read by expect()