|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright 2026 OpenHW Group |
| 3 | +# Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 4 | +# SPDX-License-Identifier: Apache-2.0 |
| 5 | + |
| 6 | +set -o pipefail |
| 7 | + |
| 8 | +RUN_LOG="$(pwd)/ci-results/run.log" |
| 9 | +FAILURE_SUMMARY="$(pwd)/ci-results/failure_summary.log" |
| 10 | +EXIT_CODE_FILE="$(pwd)/ci-results/exit_code" |
| 11 | + |
| 12 | +mkdir -p ci-results |
| 13 | +: > "${RUN_LOG}" |
| 14 | +: > "${FAILURE_SUMMARY}" |
| 15 | +echo "1" > "${EXIT_CODE_FILE}" |
| 16 | + |
| 17 | +TIER_NAME="${TIER_NAME:-Tier}" |
| 18 | +TIER_MODE="${TIER_MODE:-script}" |
| 19 | +TIER_CONFIG="${TIER_CONFIG:?TIER_CONFIG is required}" |
| 20 | +TIER_TESTCASE="${TIER_TESTCASE:?TIER_TESTCASE is required}" |
| 21 | +TIER_SIMULATOR="${TIER_SIMULATOR:?TIER_SIMULATOR is required}" |
| 22 | +TIER_INSTALL_SCRIPT="${TIER_INSTALL_SCRIPT:-}" |
| 23 | +TIER_TESTLIST="${TIER_TESTLIST:-}" |
| 24 | +TIER_TEST_NAME="${TIER_TEST_NAME:-}" |
| 25 | +TIER_LINKER="${TIER_LINKER:-}" |
| 26 | +TIER_HWCONFIG_OPTS="${TIER_HWCONFIG_OPTS:-}" |
| 27 | + |
| 28 | +log_info() { |
| 29 | + echo "$*" | tee -a "${RUN_LOG}" |
| 30 | +} |
| 31 | + |
| 32 | +run_logged() { |
| 33 | + set +e |
| 34 | + "$@" > >(tee -a "${RUN_LOG}") 2>&1 |
| 35 | + local cmd_rc=$? |
| 36 | + return "${cmd_rc}" |
| 37 | +} |
| 38 | + |
| 39 | +source_logged() { |
| 40 | + local script_path="$1" |
| 41 | + set +e |
| 42 | + # shellcheck source=/dev/null |
| 43 | + source "${script_path}" > >(tee -a "${RUN_LOG}") 2>&1 |
| 44 | + local source_rc=$? |
| 45 | + return "${source_rc}" |
| 46 | +} |
| 47 | + |
| 48 | +record_rc() { |
| 49 | + local step_rc="$1" |
| 50 | + if [ "${step_rc}" -ne 0 ] && [ "${rc}" -eq 0 ]; then |
| 51 | + rc="${step_rc}" |
| 52 | + fi |
| 53 | +} |
| 54 | + |
| 55 | +append_failure() { |
| 56 | + echo "$*" | tee -a "${FAILURE_SUMMARY}" >&2 |
| 57 | +} |
| 58 | + |
| 59 | +collect_reports() { |
| 60 | + find verif/sim -name "iss_regr.log" -exec cp {} ci-results/ \; 2>/dev/null || true |
| 61 | +} |
| 62 | + |
| 63 | +scan_for_failures() { |
| 64 | + local matches |
| 65 | + local -a scan_files=("${RUN_LOG}") |
| 66 | + |
| 67 | + while IFS= read -r -d '' file_path; do |
| 68 | + scan_files+=("${file_path}") |
| 69 | + done < <( |
| 70 | + find verif/sim -type f \ |
| 71 | + \( -name "*.log" -o -name "*.txt" -o -name "iss_regr.log" \) \ |
| 72 | + -print0 2>/dev/null || true |
| 73 | + ) |
| 74 | + |
| 75 | + matches="$( |
| 76 | + grep -HnE \ |
| 77 | + "\\[FAILED\\]|SIMULATION FAILED|(^|[^0-9])[1-9][0-9]* FAILED|ERROR return code:|bad syscall|unrecognized opcode|extension .* required|make(\\[[0-9]+\\])?: \\*\\*\\*.*Error|terminate called|Traceback \\(most recent call last\\)" \ |
| 78 | + "${scan_files[@]}" 2>/dev/null || true |
| 79 | + )" |
| 80 | + |
| 81 | + if [ -n "${matches}" ]; then |
| 82 | + append_failure "ERROR: ${TIER_NAME} job reported success, but failure patterns were found in logs." |
| 83 | + echo "${matches}" | tee -a "${FAILURE_SUMMARY}" >&2 |
| 84 | + return 1 |
| 85 | + fi |
| 86 | + |
| 87 | + return 0 |
| 88 | +} |
| 89 | + |
| 90 | +scan_iss_traces() { |
| 91 | + local matches="" |
| 92 | + local critical_patterns |
| 93 | + critical_patterns="ERROR return code:|bad syscall|unrecognized opcode|extension .* required|terminate called|Traceback \\(most recent call last\\)" |
| 94 | + |
| 95 | + while IFS= read -r -d '' file_path; do |
| 96 | + local critical_matches |
| 97 | + local last_status |
| 98 | + |
| 99 | + critical_matches="$(grep -HnE "${critical_patterns}" "${file_path}" 2>/dev/null || true)" |
| 100 | + if [ -n "${critical_matches}" ]; then |
| 101 | + matches+="${critical_matches}"$'\n' |
| 102 | + fi |
| 103 | + |
| 104 | + last_status="$( |
| 105 | + grep -nE "\\*\\*\\*[[:space:]]+(FAILED|SUCCESS)[[:space:]]+\\*\\*\\*|SIMULATION FAILED" "${file_path}" 2>/dev/null | tail -n 1 || true |
| 106 | + )" |
| 107 | + if [[ -n "${last_status}" && "${last_status}" != *"SUCCESS"* ]]; then |
| 108 | + matches+="${file_path}:${last_status}"$'\n' |
| 109 | + fi |
| 110 | + done < <(find verif/sim -type f -name "*.iss" -print0 2>/dev/null || true) |
| 111 | + |
| 112 | + if [ -n "${matches}" ]; then |
| 113 | + append_failure "ERROR: ${TIER_NAME} job reported success, but ISS trace failure patterns were found." |
| 114 | + printf "%s" "${matches}" | tee -a "${FAILURE_SUMMARY}" >&2 |
| 115 | + return 1 |
| 116 | + fi |
| 117 | + |
| 118 | + return 0 |
| 119 | +} |
| 120 | + |
| 121 | +rc=0 |
| 122 | + |
| 123 | +log_info "Running ${TIER_NAME}: ${TIER_CONFIG} / ${TIER_TESTCASE} (${TIER_MODE})" |
| 124 | + |
| 125 | +source_logged verif/sim/setup-env.sh |
| 126 | +record_rc "$?" |
| 127 | + |
| 128 | +if [ "${rc}" -eq 0 ]; then |
| 129 | + if [ "${TIER_MODE}" = "testlist" ]; then |
| 130 | + if [[ "${TIER_SIMULATOR}" == *"veri-testharness"* ]]; then |
| 131 | + source_logged verif/regress/install-verilator.sh |
| 132 | + record_rc "$?" |
| 133 | + fi |
| 134 | + |
| 135 | + if [ "${rc}" -eq 0 ]; then |
| 136 | + source_logged verif/regress/install-spike.sh |
| 137 | + record_rc "$?" |
| 138 | + fi |
| 139 | + |
| 140 | + if [ "${rc}" -eq 0 ] && [ -n "${TIER_INSTALL_SCRIPT}" ]; then |
| 141 | + source_logged "verif/regress/${TIER_INSTALL_SCRIPT}.sh" |
| 142 | + record_rc "$?" |
| 143 | + fi |
| 144 | + |
| 145 | + if [ "${rc}" -eq 0 ]; then |
| 146 | + cva6_cmd=( |
| 147 | + python3 cva6.py |
| 148 | + "--testlist=${TIER_TESTLIST}" |
| 149 | + --target "${TIER_CONFIG}" |
| 150 | + --iss_yaml=cva6.yaml |
| 151 | + "--iss=${TIER_SIMULATOR}" |
| 152 | + "--issrun_opts=+tb_performance_mode+debug_disable=1+UVM_VERBOSITY=UVM_NONE" |
| 153 | + ) |
| 154 | + |
| 155 | + if [ -n "${TIER_LINKER}" ]; then |
| 156 | + cva6_cmd+=("--linker=${TIER_LINKER}") |
| 157 | + fi |
| 158 | + |
| 159 | + if [ -n "${TIER_TEST_NAME}" ]; then |
| 160 | + cva6_cmd+=(--test "${TIER_TEST_NAME}") |
| 161 | + fi |
| 162 | + |
| 163 | + pushd verif/sim > /dev/null || rc=$? |
| 164 | + if [ "${rc}" -eq 0 ]; then |
| 165 | + run_logged "${cva6_cmd[@]}" |
| 166 | + record_rc "$?" |
| 167 | + fi |
| 168 | + popd > /dev/null || true |
| 169 | + fi |
| 170 | + else |
| 171 | + if [ -n "${TIER_HWCONFIG_OPTS}" ]; then |
| 172 | + export DV_HWCONFIG_OPTS="${TIER_HWCONFIG_OPTS}" |
| 173 | + fi |
| 174 | + |
| 175 | + run_logged env \ |
| 176 | + DV_SIMULATORS="${TIER_SIMULATOR}" \ |
| 177 | + DV_TARGET="${TIER_CONFIG}" \ |
| 178 | + bash -e "verif/regress/${TIER_TESTCASE}.sh" |
| 179 | + record_rc "$?" |
| 180 | + fi |
| 181 | +fi |
| 182 | + |
| 183 | +collect_reports |
| 184 | + |
| 185 | +if [ "${rc}" -eq 0 ] && ! compgen -G "verif/sim/out*" > /dev/null; then |
| 186 | + append_failure "ERROR: ${TIER_NAME} job reported success but produced no verif/sim/out* results." |
| 187 | + rc=1 |
| 188 | +fi |
| 189 | + |
| 190 | +if [ "${rc}" -eq 0 ] && ! scan_for_failures; then |
| 191 | + rc=1 |
| 192 | +fi |
| 193 | + |
| 194 | +if [ "${rc}" -eq 0 ] && ! scan_iss_traces; then |
| 195 | + rc=1 |
| 196 | +fi |
| 197 | + |
| 198 | +echo "${rc}" > "${EXIT_CODE_FILE}" |
| 199 | +exit "${rc}" |
0 commit comments