已合并
【UBSE】IT框架支持asan扫描 #1418
【UBSE】IT框架支持asan扫描 #1418
已合并
lisong_hw创建于 11 天前
lisong_hw
lisong_hw
11 天前

当前PR是否有AI参与:

[x] 否

[ ] 是
__1. AI Agent 平台:
__2. AI 模型:
__3. Prompt上下文 :

参考:openEuler社区《生成式AI工具使用与开源贡献政策》

PR功能描述 / 为什么需要这个合入**:

该PR关联的issue

(格式为fixes #<issue号>, 或者resolves #<issue号>): fixes #

希望检视人员了解:

likedislike
Pull Request已成功合入, 合并人@openeuler-ci-bot
(感谢 lisong_hw 的贡献)
lisong_hwlisong_hw
11 天前 创建了 pull request,commit fd1e2750
atomgit-bot
atomgit-bot
11 天前 评论:

变更摘要

该 PR 为 UT 测试构建链路新增 AddressSanitizer(ASAN)扫描机制:在 build.sh 中新增独立的 asan 构建类型与专用构建目录,通过 CMake 开关 ASAN_BUILD 注入 -fsanitize=address 等编译/链接选项,并新增 scripts/run_test.sh(统一测试运行器)与 scripts/asan_report.sh(ASAN 日志合并与报告提取)两个脚本;同时针对 ASAN 运行期行为(未初始化内存、operator new[] 拦截、栈上越界读取等)批量改造既有 UT 用例,使 ASAN 门禁下测试可稳定运行并输出扫描报告,而不阻断构建。

主要改动

  • 构建脚本新增 asan 构建类型与独立构建目录build.shBUILD_DIRS 中注册 cmake-build-asan,当 enable_asan=ON 时强制使用该目录(避免污染常规构建与覆盖率数据),并新增 ASAN 工具链探测(编译 -fsanitize=address 探针程序)与报告模式 ASAN_OPTIONSdetect_leaks=1abort_on_error=0:halt_on_error=0:exitcode=0 等,错误不中断、进程以 0 退出),构建完成后调用 scripts/asan_report.sh 汇总报告。
  • CMake 侧注入 ASAN 编译链接选项并接入统一运行器scripts/cmake/building.cmakeASAN_BUILD=ON 时添加 -fsanitize=address -fsanitize-recover=address -fno-omit-frame-pointer 编译选项与 -fsanitize=address 链接选项;scripts/cmake/utils.cmakeadd_utadd_independent_exec_ut 宏在 ASAN 构建下将 RUN_TEST 包装为 scripts/run_test.sh
  • 新增 ASAN 报告与测试运行脚本scripts/asan_report.sh 合并 asan_log.<pid> 日志、统计 Address/LeakSanitizer 错误总数,过滤 gtest/mockcpp/libasan 框架噪音并提取每个错误的类型、SUMMARY 与源码栈帧,汇总写入 asan_save.logscripts/run_test.sh 负责运行测试二进制、留存输出(可配置 UBSE_TEST_OUTPUT_DIR)并按 gtest 标记行展示结果。
  • UT 用例的 ASAN 兼容性改造test_ubs_engine_mem.cpptest_ubs_engine_topo.cpp 将数组分配缓冲区的 delete 修正为 delete[]UbsMemShmListForAllSchene 改用 malloc+memcpy_s 复制响应数据;test_ubse_logger.cppstd::copy_n 全部替换为带长度校验的 memcpy_stest_ubse_mem_api_convert.cpp 修正 uint32_t 字段误用 sizeof(uint64_t) 的越界拷贝,test_ubse_com_engine.cpp 显式 SetBodyLen(0) 消除未初始化 bodyLen_
  • ASAN 下不可稳定运行的用例条件跳过:多个测试文件在 __SANITIZE_ADDRESS__ 下通过 GTEST_SKIP() 跳过依赖未初始化栈垃圾(Get1825PfeRespMsg_InvalidBbNumUbseMemCreateWithCandidateReqUnpackSuccess)、依赖 mockcpp 拦截 operator new[]ubs_virt_agent_sync_task_query_AllocateMemoryFailedHandlerServerReq_AllocFailUbseGetDirConnectInfoFromRemote_AllocFail)或涉及后台线程竞态的用例(RollBackFailureCreatesBgThreadNonexistentFilePath);test/UT/main.cpp 在 ASAN 下不再调用 SetupSignalHandlers()test_ubse_com_base.cpp 移除 SafeDeleteArray(data) 冗余释放。
likedislike
atomgit-bot
atomgit-bot
11 天前 评论:

代码审查

✅ 未发现问题

likedislike
openeuler-ci-botopeneuler-ci-bot成员
11 天前 将hlinbo,shw030915,Gao_Victor,qmyyxtl,caowaterman设为审查人
openeuler-ci-botopeneuler-ci-bot成员
11 天前 添加了label:sig/sig-UB-ServiceCore
此处折叠了114条消息 查看更多
xuchenfeng成员
2 天前 评论:

/lgtm

likedislike
openeuler-ci-botopeneuler-ci-bot成员
2 天前 添加了label:lgtm-xuchenfengcleancode
openeuler-ci-bot
openeuler-ci-bot成员
2 天前 评论:

Review Code Feedback

  • The label lgtm-xuchenfengcleancode was added to this pull request. It means that xuchenfengcleancode reviewed the code changes. 👋
Tips
  • If this pull request is not merged while all conditions are met, comment /check-pr to try again. 😄
likedislike
openeuler-ci-botopeneuler-ci-bot成员
2 天前 关闭了关联的issue
openeuler-ci-botopeneuler-ci-bot成员
2 天前 合入了pull request,合并节点 SHA:06c9ffdf9a5bbbe339de7cc5cc9cee54edcb17a2