From 3ed9fd3140bca274e60a170c3c4ec1c49f45d090 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Sat, 31 Aug 2024 12:37:37 +0100 Subject: [PATCH] ci/bare-metal: Use section for boot messages from cros-servo Signed-off-by: Daniel Stone Part-of: --- .gitlab-ci/bare-metal/bm-init.sh | 2 ++ .gitlab-ci/bare-metal/cros_servo_run.py | 34 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/.gitlab-ci/bare-metal/bm-init.sh b/.gitlab-ci/bare-metal/bm-init.sh index 6935957b2c6..d55f8032516 100755 --- a/.gitlab-ci/bare-metal/bm-init.sh +++ b/.gitlab-ci/bare-metal/bm-init.sh @@ -5,6 +5,8 @@ # First stage: very basic setup to bring up network and /dev etc /init-stage1.sh +export CURRENT_SECTION=dut_boot + # Second stage: run jobs test $? -eq 0 && /init-stage2.sh diff --git a/.gitlab-ci/bare-metal/cros_servo_run.py b/.gitlab-ci/bare-metal/cros_servo_run.py index bb9d222a728..dd251c2dbce 100755 --- a/.gitlab-ci/bare-metal/cros_servo_run.py +++ b/.gitlab-ci/bare-metal/cros_servo_run.py @@ -4,12 +4,20 @@ # SPDX-License-Identifier: MIT import argparse +import datetime +import math +import os import re import sys from custom_logger import CustomLogger from serial_buffer import SerialBuffer +ANSI_ESCAPE="\x1b[0K" +ANSI_COLOUR="\x1b[0;36m" +ANSI_RESET="\x1b[0m" +SECTION_START="start" +SECTION_END="end" class CrosServoRun: def __init__(self, cpu, ec, test_timeout, logger): @@ -40,6 +48,31 @@ class CrosServoRun: print(RED + message + NO_COLOR) self.logger.update_status_fail(message) + def get_rel_timestamp(self): + now = datetime.datetime.now(tz=datetime.UTC) + then_env = os.getenv("CI_JOB_STARTED_AT") + if not then_env: + return "" + delta = now - datetime.datetime.fromisoformat(then_env) + return f"[{math.floor(delta.seconds / 60):02}:{(delta.seconds % 60):02}]" + + def get_cur_timestamp(self): + return str(int(datetime.datetime.timestamp(datetime.datetime.now()))) + + def print_gitlab_section(self, action, name, description, collapse=True): + assert action in [SECTION_START, SECTION_END] + out = ANSI_ESCAPE + "section_" + action + ":" + out += self.get_cur_timestamp() + ":" + out += name + if action == "start" and collapse: + out += "[collapsed=true]" + out += "\r" + ANSI_ESCAPE + ANSI_COLOUR + out += self.get_rel_timestamp() + " " + description + ANSI_RESET + print(out) + + def boot_section(self, action): + self.print_gitlab_section(action, "dut_boot", "Booting hardware device", True) + def run(self): # Flush any partial commands in the EC's prompt, then ask for a reboot. self.ec_write("\n") @@ -47,6 +80,7 @@ class CrosServoRun: bootloader_done = False self.logger.create_job_phase("boot") + self.boot_section(SECTION_START) tftp_failures = 0 # This is emitted right when the bootloader pauses to check for input. # Emit a ^N character to request network boot, because we don't have a