Browse Source

runfvp: Fix verbose output when using --console

Start a new thread to simultaneously log the output of FVP and the
telnet output if the --verbose flag is passed to runfvp. So that
ConsolePortParser can read the same stream, use itertools.tee to
temporarily duplicate the stream.

Use a custom log format string with an escape character to ensure that
log output always starts at the beginning of a line when interleaved
with console output.

Issue-Id: SCM-5314
Signed-off-by: Peter Hoyes <Peter.Hoyes@arm.com>
Change-Id: I3e815d9d899425e0d2af619524f09f2eda87562c
Signed-off-by: Jon Mason <jon.mason@arm.com>
Peter Hoyes 2 năm trước cách đây
mục cha
commit
d5f132b199
1 tập tin đã thay đổi với 14 bổ sung2 xóa
  1. 14 2
      scripts/runfvp

+ 14 - 2
scripts/runfvp

@@ -1,9 +1,11 @@
 #! /usr/bin/env python3
 
+import itertools
 import os
 import pathlib
 import signal
 import sys
+import threading
 
 import logging
 logger = logging.getLogger("RunFVP")
@@ -36,7 +38,8 @@ def parse_args(arguments):
         fvp_args = []
 
     args = parser.parse_args(args=arguments)
-    logging.basicConfig(level=args.verbose and logging.DEBUG or logging.WARNING)
+    logging.basicConfig(level=args.verbose and logging.DEBUG or logging.WARNING,
+                        format='\033[G%(levelname)s: %(message)s')
 
     # If we're hooking up the console, don't start any terminals
     if args.console:
@@ -56,8 +59,17 @@ def start_fvp(args, config, extra_args):
             if not expected_terminal:
                 logger.error("--console used but FVP_CONSOLE not set in machine configuration")
                 return 1
-            parser = runner.ConsolePortParser(fvp.stdout)
+            port_stdout, log_stdout = itertools.tee(fvp.stdout, 2)
+            parser = runner.ConsolePortParser(port_stdout)
             port = parser.parse_port(expected_terminal)
+
+            def debug_log():
+                for line in log_stdout:
+                    line = line.strip().decode(errors='ignore')
+                    logger.debug(f'FVP output: {line}')
+            log_thread = threading.Thread(None, debug_log)
+            log_thread.start()
+
             telnet = fvp.create_telnet(port)
             telnet.wait()
             logger.debug(f"Telnet quit, cancelling tasks")