From 4874c27a214b21e722961a70d767b66abf25c5b7 Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Sun, 8 Dec 2024 16:50:52 +0100 Subject: [PATCH] [ci] Create GitHub groups in log outputs for FPGA tests The log are quite long and GitHub provides a feature where the output group can split lines into groups. This is achieved by using the --run_under command of bazel test. This allows to run a script that then invokes the test runner. This only thing this script does is print the grouping commands. Signed-off-by: Amaury Pouly --- ci/scripts/BUILD | 8 ++++++++ ci/scripts/run-fpga-tests.sh | 1 + ci/scripts/run_test.sh | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 ci/scripts/BUILD create mode 100755 ci/scripts/run_test.sh diff --git a/ci/scripts/BUILD b/ci/scripts/BUILD new file mode 100644 index 00000000000000..3d165499d5efd5 --- /dev/null +++ b/ci/scripts/BUILD @@ -0,0 +1,8 @@ +# Copyright lowRISC contributors (OpenTitan project). +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 + +sh_binary( + name = "run_test", + srcs = ["run_test.sh"], +) diff --git a/ci/scripts/run-fpga-tests.sh b/ci/scripts/run-fpga-tests.sh index f5265d9f9fe4a7..dee05a5a8c2f9a 100755 --- a/ci/scripts/run-fpga-tests.sh +++ b/ci/scripts/run-fpga-tests.sh @@ -47,6 +47,7 @@ trap './bazelisk.sh run //sw/host/opentitantool -- --rcfile= --interface=${fpga} ./bazelisk.sh run //sw/host/opentitantool -- --rcfile= --interface="$fpga" fpga get-sam3x-fw-version || true ./bazelisk.sh test \ + --run_under=//ci/scripts:run_test \ --define DISABLE_VERILATOR_BUILD=true \ --nokeep_going \ --test_timeout_filters=short,moderate \ diff --git a/ci/scripts/run_test.sh b/ci/scripts/run_test.sh new file mode 100755 index 00000000000000..1810971aac5dd9 --- /dev/null +++ b/ci/scripts/run_test.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# Copyright lowRISC contributors (OpenTitan project). +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 + +# Print a special GitHub command to create a group in the log's output: +# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#grouping-log-lines +# +# Test variables are documented here: +# https://bazel.build/reference/test-encyclopedia +if [ -z "$TEST_RUN_NUMBER" ]; then + RUN_NR="" +else + RUN_NR="(Run $TEST_RUN_NUMBER)" +fi + +function cleanup { + echo "::endgroup::" +} + +echo "::group::$TEST_TARGET $RUN_NR" +# NOTE Even if the command fails, we still want to continue to print +# the endgroup command. +trap cleanup SIGINT SIGTERM EXIT +$@