Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bc7af664 authored by Zach Johnson's avatar Zach Johnson
Browse files

Fix yellow terminal color, line up verbose output

Also fix test config labels to match the names inside the test

stack_under_test -> dut
cert_stack -> cert

Test: cert/run --host
Tag: #gd-refactor
Bug: 145007149
Change-Id: I43eb1a38298ec3db98c0b90776528cea83f001d8
parent d54932d2
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@
                    "grpc_port": "8898",
                    "grpc_root_server_port": "8896",
                    "signal_port": "8894",
                    "label": "cert_stack",
                    "label": "cert",
                    "serial_number": "CERT",
                    "name": "Cert Device",
                    "cmd":
@@ -30,7 +30,7 @@
                    "grpc_port": "8899",
                    "grpc_root_server_port": "8897",
                    "signal_port": "8895",
                    "label": "stack_under_test",
                    "label": "dut",
                    "serial_number": "DUT",
                    "name": "DUT Device",
                    "cmd":
+9 −4
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ class AsyncSubprocessLogger:
    from STDOUT from subprocess.Popen
    """
    WAIT_TIMEOUT_SECONDS = 10
    PROCESS_TAG_MIN_WIDTH = 24

    def __init__(self,
                 process: subprocess.Popen,
@@ -72,13 +73,17 @@ class AsyncSubprocessLogger:
        self.executor.shutdown(wait=False)

    def __logging_loop(self):
        if self.color:
            loggableTag = "[%s%s%s]" % (self.color, self.tag, TerminalColor.END)
        else:
            loggableTag = "[%s]" % self.tag
        tagLength = len(re.sub('[^\w\s]', '', loggableTag))
        if tagLength < self.PROCESS_TAG_MIN_WIDTH:
            loggableTag += " " * (self.PROCESS_TAG_MIN_WIDTH - tagLength)
        with ExitStack() as stack:
            log_files = [stack.enter_context(open(file_path, 'w')) for file_path in self.log_file_paths]
            for line in self.process.stdout:
                for log_file in log_files:
                    log_file.write(line)
                if self.log_to_stdout:
                    if self.color:
                        print("[%s%s%s] %s" % (self.color, self.tag, TerminalColor.END, line.strip()))
                    else:
                        print("[%s] %s" % (self.tag, line.strip()))
                    print("{}{}".format(loggableTag, line.strip()))
+1 −1
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ class GdBaseTestClass(BaseTestClass):
            self.rootcanal_logger = AsyncSubprocessLogger(
                self.rootcanal_process, [self.rootcanal_logpath],
                log_to_stdout=self.verbose_mode,
                tag="root_canal",
                tag="rootcanal",
                color=TerminalColor.MAGENTA)

            # Modify the device config to include the correct root-canal port
+2 −2
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
                    "grpc_port": "8998",
                    "grpc_root_server_port": "8996",
                    "signal_port": "8994",
                    "label": "cert_stack",
                    "label": "cert",
                    "name": "Cert Device",
                    "cmd":
                    [
@@ -32,7 +32,7 @@
                    "grpc_port": "8999",
                    "grpc_root_server_port": "8997",
                    "signal_port": "8995",
                    "label": "stack_under_test",
                    "label": "dut",
                    "name": "DUT Device",
                    "cmd":
                    [
+7 −1
Original line number Diff line number Diff line
@@ -27,12 +27,18 @@ def pretty_print(request):

class LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor):

    TAG_MIN_WIDTH = 24

    def __init__(self, name):
        self.name = name
        self.loggableTag = "[host ▶▶▶▶▶ %s]" % self.name
        tagLength = len(re.sub('[^\w\s]', '', self.loggableTag)) + 11
        if tagLength < self.TAG_MIN_WIDTH:
            self.loggableTag += " " * (self.TAG_MIN_WIDTH - tagLength)

    def _intercept_call(self, continuation, client_call_details, request_or_iterator):
        return continuation(client_call_details, request_or_iterator)

    def intercept_unary_unary(self, continuation, client_call_details, request):
        print('[host ▶▶▶▶▶ ' + self.name + '] ' + client_call_details.method + ' ' + pretty_print(request))
        print("%s%s %s" % (self.loggableTag, client_call_details.method, pretty_print(request)))
        return self._intercept_call(continuation, client_call_details, request)
Loading