# ----------------------------------------------------------------------------------------------------------- # Copyright (c) 2025 Huawei Technologies Co., Ltd. # This program is free software, you can redistribute it and/or modify it under the terms and conditions of # CANN Open Software License Agreement Version 2.0 (the "License"). # Please refer to the License for details. You may not use this file except in compliance with the License. # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, # INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. # See LICENSE in the root of the software repository for the full text of the License. # ----------------------------------------------------------------------------------------------------------- # UTest 场景, 编译 Target 名称公共前缀 set(UTest_NamePrefix UTest) # UTest 场景, 公共配置 add_library(intf_pub_utest INTERFACE) target_compile_definitions(intf_pub_utest INTERFACE $<$:_GLIBCXX_USE_CXX11_ABI=0> # 必须设置, 以保证与 CANN 包内其他依赖库兼容 ASCENDC_OP_TEST ASCENDC_OP_TEST_UT $<$:CFG_BUILD_NDEBUG> $<$:CFG_BUILD_DEBUG> ) target_compile_options(intf_pub_utest INTERFACE -fPIC $<$:$,-fstack-protector-strong,-fstack-protector-all>> $<$:$,-fstack-protector-strong,-fstack-protector-all>> -g $<$:$<$:--coverage -fprofile-arcs -ftest-coverage>> $<$:-fsanitize=address -fsanitize-address-use-after-scope -fsanitize=leak> # 在 Clang 编译器场景下 使能 -fsanitize=undefined 会默认开启基本所有的 UBSAN 检查项, 只有以下检查项不会开启 # float-divide-by-zero, unsigned-integer-overflow, implicit-conversion, local-bounds 及 nullability-* 类检查. # 故在 Clang 编译器使能 UBSAN 场景下, 需开启 -fsanitize=undefined 使能时仍未开启的对应检查项 # 在 GNU 编译器场景下, 官方文档并未对使能 -fsanitize=undefined 时开启的默认检查项范围进行说明, 故手工开启常用基本检查项, 避免能力遗漏 $<$:-fsanitize=undefined -fsanitize=float-divide-by-zero -fno-sanitize=alignment> # $<$:$<$:-fsanitize=unsigned-integer-overflow>> # GNU 不支持这些检查项 # $<$:$<$:$<$:-fsanitize=implicit-conversion>>> # GNU 不支持这些检查项, Clang高版本才支持这些检查项 $<$:$<$:-fsanitize=shift -fsanitize=integer-divide-by-zero -fsanitize=signed-integer-overflow -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fsanitize=bool -fsanitize=enum -fsanitize=vptr>> $<$:-fno-omit-frame-pointer -fsanitize-recover=all> -Wall -fno-common -fno-strict-aliasing -Wundef -Wcast-qual -Wpointer-arith -Wdate-time -Wfloat-equal -Wformat=2 -Wshadow -Wsign-compare -Wunused-macros -Wvla -Wdisabled-optimization -Wempty-body -Wignored-qualifiers $<$:-Wimplicit-fallthrough=3> -Wtype-limits -Wshift-negative-value -Wswitch-default -Wframe-larger-than=67108864 # 67108864=65536 * 1024, 兼容 ASAN场景对栈的额外消耗 -Woverloaded-virtual -Wnon-virtual-dtor $<$:-Wshift-overflow=2> -Wshift-count-overflow -Wwrite-strings -Wmissing-format-attribute -Wformat-nonliteral -Wdelete-non-virtual-dtor $<$:-Wduplicated-cond> $<$:-Wtrampolines> $<$:-Wsized-deallocation> $<$:-Wlogical-op> $<$:-Wsuggest-attribute=format> $<$:-Wnested-externs> $<$:-Wduplicated-branches> $<$:-Wformat-signedness> $<$:-Wreturn-local-addr> -Wextra -Wredundant-decls -Wfloat-conversion $<$:-Wno-tautological-unsigned-enum-zero-compare> $<$:-fprofile-arcs -ftest-coverage> ) target_include_directories(intf_pub_utest INTERFACE ${ASCEND_CANN_PACKAGE_PATH}/include ${ASCEND_CANN_PACKAGE_PATH}/include/external ${ASCEND_CANN_PACKAGE_PATH}/include/experiment ${ASCEND_CANN_PACKAGE_PATH}/include/experiment/metadef ${ASCEND_CANN_PACKAGE_PATH}/include/experiment/runtime ${ASCEND_CANN_PACKAGE_PATH}/include/experiment/msprof ) if (TESTS_UT_OPS_TEST_CI_PR) target_compile_definitions(intf_pub_utest INTERFACE TESTS_UT_OPS_TEST_CI_PR ) endif () target_link_directories(intf_pub_utest INTERFACE ${ASCEND_CANN_PACKAGE_PATH}/lib64 ${ASCEND_CANN_PACKAGE_PATH}/runtime/lib64 ${ASCEND_CANN_PACKAGE_PATH}/runtime/lib64/stub ) target_link_libraries(intf_pub_utest INTERFACE $<$:$<$:gcov>> pthread ) target_link_options(intf_pub_utest INTERFACE $<$:$<$:-fprofile-arcs -ftest-coverage>> $<$:-fsanitize=address> $<$:-fsanitize=undefined> )