已合并
fix: UT门禁拦截 #127
哈喽Kiter创建于 8月21日
fix: UT门禁拦截 #127
已合并
共 4 个文件变更+98-33
| @@ -1,4 +1,5 @@ | |||
| 1 | #!/bin/bash | 1 | #!/bin/bash |
| 2 | + | ||
| 2 | # ---------------------------------------------------------------------------------------------------------- | 3 | # ---------------------------------------------------------------------------------------------------------- |
| 3 | # Copyright (c) 2026 Huawei Technologies Co., Ltd. | 4 | # Copyright (c) 2026 Huawei Technologies Co., Ltd. |
| 4 | # This program is free software, you can redistribute it and/or modify it under the terms and conditions of | 5 | # This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| @@ -9,6 +10,8 @@ | |||
| 9 | # See LICENSE in the root of the software repository for the full text of the License. | 10 | # See LICENSE in the root of the software repository for the full text of the License. |
| 10 | # ---------------------------------------------------------------------------------------------------------- | 11 | # ---------------------------------------------------------------------------------------------------------- |
| 11 | 12 | ||
| 13 | +set -euo pipefail | ||
| 14 | + | ||
| 12 | SCRIPT_DIR=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")") | 15 | SCRIPT_DIR=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")") |
| 13 | 16 | ||
| 14 | UT_DIR="${SCRIPT_DIR}/tests/ut" | 17 | UT_DIR="${SCRIPT_DIR}/tests/ut" |
| @@ -43,10 +43,11 @@ if [[ -n "${LCOV_MAJOR}" && "${LCOV_MAJOR}" -ge 2 ]]; then | |||
| 43 | fi | 43 | fi |
| 44 | 44 | ||
| 45 | lcov -c -d "${BUILD_DIR}" -o "${COV_FILE}" ${EXTRA_ARGS} | 45 | lcov -c -d "${BUILD_DIR}" -o "${COV_FILE}" ${EXTRA_ARGS} |
| 46 | +# Project headers are staged under this build directory and must remain in the report. | ||
| 46 | lcov -r "${COV_FILE}" \ | 47 | lcov -r "${COV_FILE}" \ |
| 47 | "${CANN_PATH}/*" \ | 48 | "${CANN_PATH}/*" \ |
| 48 | "/home/jenkins/opensource/*" \ | 49 | "/home/jenkins/opensource/*" \ |
| 49 | - "${ROOT_DIR}/build/*" \ | 50 | + "${BUILD_DIR}/ut-hcomm/_deps/*" \ |
| 50 | "${ROOT_DIR}/build_out/*" \ | 51 | "${ROOT_DIR}/build_out/*" \ |
| 51 | "${ROOT_DIR}/output/*" \ | 52 | "${ROOT_DIR}/output/*" \ |
| 52 | "${ROOT_DIR}/tests/*" \ | 53 | "${ROOT_DIR}/tests/*" \ |
| @@ -0,0 +1,53 @@ | |||
| 1 | +#!/bin/bash | ||
| 2 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 3 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 4 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 11 | + | ||
| 12 | +set -o pipefail | ||
| 13 | + | ||
| 14 | +if [[ $# -eq 0 ]]; then | ||
| 15 | + echo "Usage: $0 <test-command> [args...]" >&2 | ||
| 16 | + exit 2 | ||
| 17 | +fi | ||
| 18 | + | ||
| 19 | +if ! output_file=$(mktemp); then | ||
| 20 | + echo "Failed to create temporary output file" >&2 | ||
| 21 | + exit 1 | ||
| 22 | +fi | ||
| 23 | +trap 'rm -f "${output_file}"' EXIT | ||
| 24 | + | ||
| 25 | +"$@" 2>&1 | tee "${output_file}" | ||
| 26 | +pipeline_status=("${PIPESTATUS[@]}") | ||
| 27 | +test_status=${pipeline_status[0]} | ||
| 28 | +tee_status=${pipeline_status[1]} | ||
| 29 | + | ||
| 30 | +if [[ ${test_status} -ne 0 ]]; then | ||
| 31 | + exit "${test_status}" | ||
| 32 | +fi | ||
| 33 | +if [[ ${tee_status} -ne 0 ]]; then | ||
| 34 | + echo "Failed to save test output (tee status: ${tee_status})" >&2 | ||
| 35 | + exit "${tee_status}" | ||
| 36 | +fi | ||
| 37 | + | ||
| 38 | +# Keep the output check as a fallback for runners that incorrectly return 0 | ||
| 39 | +# after printing a GTest failure summary. | ||
| 40 | +grep -Eq '\[[[:space:]]*FAILED[[:space:]]*\]|FAILED TESTS' "${output_file}" | ||
| 41 | +grep_status=$? | ||
| 42 | +case ${grep_status} in | ||
| 43 | + 0) | ||
| 44 | + exit 1 | ||
| 45 | + ;; | ||
| 46 | + 1) | ||
| 47 | + exit 0 | ||
| 48 | + ;; | ||
| 49 | + *) | ||
| 50 | + echo "Failed to inspect test output (grep status: ${grep_status})" >&2 | ||
| 51 | + exit "${grep_status}" | ||
| 52 | + ;; | ||
| 53 | +esac | ||
| @@ -29,6 +29,10 @@ set(TEST_MOD "all" CACHE STRING "Comma-separated UT targets to build and run, or | |||
| 29 | option(ASCCOMM_UT_RUN_AFTER_BUILD "Run UT targets after build" ON) | 29 | option(ASCCOMM_UT_RUN_AFTER_BUILD "Run UT targets after build" ON) |
| 30 | option(ENABLE_GCOV "Enable gcov coverage for UT targets" OFF) | 30 | option(ENABLE_GCOV "Enable gcov coverage for UT targets" OFF) |
| 31 | 31 | ||
| 32 | +if(ENABLE_GCOV AND NOT ASCCOMM_UT_RUN_AFTER_BUILD) | ||
| 33 | + message(FATAL_ERROR "ENABLE_GCOV requires ASCCOMM_UT_RUN_AFTER_BUILD=ON") | ||
| 34 | +endif() | ||
| 35 | + | ||
| 32 | if(CUSTOM_ASCEND_CANN_PACKAGE_PATH) | 36 | if(CUSTOM_ASCEND_CANN_PACKAGE_PATH) |
| 33 | set(_ASCEND_CANN_PACKAGE_PATH "${CUSTOM_ASCEND_CANN_PACKAGE_PATH}") | 37 | set(_ASCEND_CANN_PACKAGE_PATH "${CUSTOM_ASCEND_CANN_PACKAGE_PATH}") |
| 34 | elseif(DEFINED ASCEND_CANN_PACKAGE_PATH) | 38 | elseif(DEFINED ASCEND_CANN_PACKAGE_PATH) |
| @@ -165,6 +169,7 @@ add_custom_target(prepare_asccomm_ut_header_layout | |||
| 165 | ) | 169 | ) |
| 166 | 170 | ||
| 167 | set(ASCCOMM_COVERAGE_SCRIPT ${ASCCOMM_ROOT}/scripts/generate_cpp_cov.sh) | 171 | set(ASCCOMM_COVERAGE_SCRIPT ${ASCCOMM_ROOT}/scripts/generate_cpp_cov.sh) |
| 172 | +set(ASCCOMM_GTEST_RUNNER ${ASCCOMM_ROOT}/scripts/run_gtest.sh) | ||
| 168 | 173 | ||
| 169 | function(run_llt_test) | 174 | function(run_llt_test) |
| 170 | cmake_parse_arguments(LLT "" "TARGET;TASK_NUM;ENV_FILE" "FILTERS;RUNTIME_DIRS" ${ARGN}) | 175 | cmake_parse_arguments(LLT "" "TARGET;TASK_NUM;ENV_FILE" "FILTERS;RUNTIME_DIRS" ${ARGN}) |
| @@ -175,6 +180,40 @@ function(run_llt_test) | |||
| 175 | return() | 180 | return() |
| 176 | endif() | 181 | endif() |
| 177 | 182 | ||
| 183 | + if(NOT ASCCOMM_UT_RUN_AFTER_BUILD) | ||
| 184 | + return() | ||
| 185 | + endif() | ||
| 186 | + | ||
| 187 | + if(LLT_ENV_FILE) | ||
| 188 | + set(ENV_PREFIX . ${LLT_ENV_FILE} &&) | ||
| 189 | + else() | ||
| 190 | + set(ENV_PREFIX "") | ||
| 191 | + endif() | ||
| 192 | + | ||
| 193 | + set(_llt_runtime_dirs ${LLT_RUNTIME_DIRS}) | ||
| 194 | + string(REPLACE ";" ":" _llt_ld_library_path "${_llt_runtime_dirs}") | ||
| 195 | + | ||
| 196 | + set(_llt_run_target ${LLT_TARGET}_run) | ||
| 197 | + if(LLT_FILTERS) | ||
| 198 | + set(_llt_run_commands) | ||
| 199 | + foreach(test_filter ${LLT_FILTERS}) | ||
| 200 | + list(APPEND _llt_run_commands | ||
| 201 | + COMMAND ${ENV_PREFIX} bash ${ASCCOMM_GTEST_RUNNER} ${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=${_llt_ld_library_path}:$ENV{LD_LIBRARY_PATH}" $<TARGET_FILE:${LLT_TARGET}> --gtest_filter=${test_filter} | ||
| 202 | + ) | ||
| 203 | + endforeach() | ||
| 204 | + add_custom_target(${_llt_run_target} ALL | ||
| 205 | + ${_llt_run_commands} | ||
| 206 | + COMMENT "Run ${LLT_TARGET} filtered tests" | ||
| 207 | + ) | ||
| 208 | + else() | ||
| 209 | + add_custom_target(${_llt_run_target} ALL | ||
| 210 | + COMMAND ${CMAKE_COMMAND} -E make_directory ${LLT_WORK_DIR} | ||
| 211 | + COMMAND ${ENV_PREFIX} ${CMAKE_COMMAND} -E chdir ${LLT_WORK_DIR} bash ${ASCCOMM_GTEST_RUNNER} ${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=${_llt_ld_library_path}:$ENV{LD_LIBRARY_PATH}" $<TARGET_FILE:${LLT_TARGET}> | ||
| 212 | + COMMENT "Run ${LLT_TARGET}" | ||
| 213 | + ) | ||
| 214 | + endif() | ||
| 215 | + add_dependencies(${_llt_run_target} ${LLT_TARGET}) | ||
| 216 | + | ||
| 178 | if(ENABLE_GCOV) | 217 | if(ENABLE_GCOV) |
| 179 | set(_collect_coverage_data_target collect_coverage_data) | 218 | set(_collect_coverage_data_target collect_coverage_data) |
| 180 | 219 | ||
| @@ -191,39 +230,8 @@ function(run_llt_test) | |||
| 191 | ) | 230 | ) |
| 192 | endif() | 231 | endif() |
| 193 | 232 | ||
| 194 | - add_dependencies(${_collect_coverage_data_target} ${LLT_TARGET}) | 233 | + add_dependencies(${_collect_coverage_data_target} ${_llt_run_target}) |
| 195 | endif() | 234 | endif() |
| 196 | - | ||
| 197 | - if(NOT ASCCOMM_UT_RUN_AFTER_BUILD) | ||
| 198 | - return() | ||
| 199 | - endif() | ||
| 200 | - | ||
| 201 | - if(LLT_ENV_FILE) | ||
| 202 | - set(ENV_PREFIX . ${LLT_ENV_FILE} &&) | ||
| 203 | - else() | ||
| 204 | - set(ENV_PREFIX "") | ||
| 205 | - endif() | ||
| 206 | - | ||
| 207 | - set(_llt_runtime_dirs ${LLT_RUNTIME_DIRS}) | ||
| 208 | - string(REPLACE ";" ":" _llt_ld_library_path "${_llt_runtime_dirs}") | ||
| 209 | - | ||
| 210 | - if(LLT_FILTERS) | ||
| 211 | - foreach(test_filter ${LLT_FILTERS}) | ||
| 212 | - add_custom_command( | ||
| 213 | - TARGET ${LLT_TARGET} POST_BUILD | ||
| 214 | - COMMAND ${ENV_PREFIX} ${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=${_llt_ld_library_path}:$ENV{LD_LIBRARY_PATH}" $<TARGET_FILE:${LLT_TARGET}> --gtest_filter=${test_filter} | ||
| 215 | - COMMENT "Run ${LLT_TARGET} ${test_filter}" | ||
| 216 | - ) | ||
| 217 | - endforeach() | ||
| 218 | - return() | ||
| 219 | - endif() | ||
| 220 | - | ||
| 221 | - add_custom_command( | ||
| 222 | - TARGET ${LLT_TARGET} POST_BUILD | ||
| 223 | - COMMAND ${CMAKE_COMMAND} -E make_directory ${LLT_WORK_DIR} | ||
| 224 | - COMMAND ${ENV_PREFIX} ${CMAKE_COMMAND} -E chdir ${LLT_WORK_DIR} ${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=${_llt_ld_library_path}:$ENV{LD_LIBRARY_PATH}" $<TARGET_FILE:${LLT_TARGET}> | ||
| 225 | - COMMENT "Run ${LLT_TARGET}" | ||
| 226 | - ) | ||
| 227 | endfunction() | 235 | endfunction() |
| 228 | 236 | ||
| 229 | add_library(asccomm_ccu_host_launch STATIC | 237 | add_library(asccomm_ccu_host_launch STATIC |