thun-res/vlink / .agents/skills/asan
asan
Verified以 AddressSanitizer(ENABLE_TEST_SANITIZE=ON)构建并运行 vlink-test 单元测试,复现 CI 的 ASan 门禁。用户要求"跑 asan"、"内存检测测试"、 排查 ci-test 的 sanitize 失败时使用。
ASan 单元测试
ENABLE_TEST_SANITIZE=ON 时,根 CMakeLists.txt 对 vlink 库目标调用
vlink_test_sanitize()(cmake/functions/common.cmake:45),追加
-fsanitize=address 编译与链接选项;随后构建并运行 vlink-test 触发
被测库代码。支持 Windows/QNX 之外的 GCC/Clang 目标;不满足条件时会
告警跳过。CI 中只有 Linux job 开启此项
(.github/workflows/ci-test.yml)。
1. 执行
先从仓库任意子目录解析根目录:
REPO_ROOT="$(git rev-parse --show-toplevel)"
BUILD_DIR_REL=build-ai/skill_asan
BUILD_DIR="$REPO_ROOT/$BUILD_DIR_REL"
export PYTHONPYCACHEPREFIX="$BUILD_DIR/__pycache__"
PHYSICAL_CORES=
case "$(uname -s 2>/dev/null)" in
Linux)
PHYSICAL_CORES="$(
LC_ALL=C lscpu -p=CORE,SOCKET 2>/dev/null |
awk -F, '
$1 !~ /^#/ && $1 ~ /^[0-9]+$/ && $2 ~ /^[0-9]+$/ {
cores[$2 SUBSEP $1] = 1
}
END {
for (core in cores) {
count++
}
if (count > 0) {
print count
}
}'
)" || PHYSICAL_CORES=
;;
Darwin)
PHYSICAL_CORES="$(sysctl -n hw.physicalcpu 2>/dev/null)" || PHYSICAL_CORES=
;;
esac
case "$PHYSICAL_CORES" in
'' | *[!0-9]* | 0) PHYSICAL_CORES=1 ;;
esac
if [ "$PHYSICAL_CORES" -gt 1 ]; then
BUILD_JOBS=$((PHYSICAL_CORES - 1))
else
BUILD_JOBS=1
fi
-
配置(AI 专用构建目录):
cmake -S "$REPO_ROOT" -B "$BUILD_DIR" \ -DCMAKE_BUILD_TYPE=Release \ -DENABLE_CXX_STD_20=OFF \ -DENABLE_TEST=ON \ -DENABLE_TEST_WARN=ON \ -DENABLE_TEST_SANITIZE=ON \ -DENABLE_TEST_COVERAGE=OFF \ -DENABLE_PROXY=ON \ -DENABLE_EXAMPLES=OFF配置前确认 Fast DDS 或 Cyclone DDS 可被 CMake 找到。CMake 将
ENABLE_PROXY改回 OFF 或未生成vlink-proxytarget 均为配置 失败,不得继续测试。 -
构建:
cmake --build "$BUILD_DIR" --target vlink-test vlink-proxy --parallel "$BUILD_JOBS" -
运行测试。复用 CI 脚本,确保先启动测试依赖的
vlink-proxy,并沿用 CI 的超时、并行度和排除规则:export ASAN_OPTIONS=detect_odr_violation=0 cd "$REPO_ROOT" BUILD_DIR="$BUILD_DIR_REL" bash .github/scripts/run-posix-ci-tests.sh
2. 结果处理
detect_odr_violation=0是 CI 既有约定(共享库场景误报),不要再额外 放宽ASAN_OPTIONS。BUILD_JOBS必须严格等于max(真实物理核心数 - 1, 1)。禁止改用 逻辑 CPU 数、裸--parallel/-j或固定高并行度;无法可靠获取物理 核心数时固定单核,且同一时刻只运行一个本地构建,防止编译卡死或耗尽 内存。- 默认
BUILD_DIR_REL为build-ai/skill_asan;正被其他任务使用时先改为build-ai/skill_asan_<task_name>,再派生BUILD_DIR,不得共用或清理 其他构建目录。 - ASan 报告(heap-use-after-free、leak、stack-buffer-overflow 等)一律 按真实缺陷报告;用户同时要求修复时再定位并修改源码,不通过 suppression 文件消音。
- 只在用户显式调用本 skill 时才执行构建与测试;日常改码流程仍遵循
AGENTS.md强制规则第 3 条(不主动构建)。
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |