- 覆盖率实测(core-pr profile,19 目标 / 497 ctest 全 PASS / 118 gcda):
line 24.0305% (26677/111013), func 26.7484% (1243/4647), branch 15.08% (24717/163883)
- tools/coverage/baseline.json 写入实测 entry(target_count=19, expected_min_cases=480)
- core-pr line_pct_gate=22.0(floor(24.03)-2 留约 2pp 余量)
- vde_coverage_check.py: 修 write_summary None 拼接; gate 三态来源; baseline 目标漂移检测;
--list-profiles 打印 gate; update_baseline 增 target_count/expected_min_cases
- vde_fast_gate.py: 新增 --cmake-args(ccache launcher 注入)
- ctest_target_select.py: 新增 CLI(目标->ctest 用例名正则),nightly stability 复用
- pr-quality.yml: static-gate + fast-gate 三阶段(build/tests/determinism 复用 build 目录),
concurrency, permissions, actions/cache(ccache), 超时收紧
- nightly.yml: 新增 determinism-nightly(runs=5)/bench-nightly/windows-local-gate,
coverage-nightly 改 baseline 门禁 + core 扩展 report-only, ccache 缓存
- validate_workflows.py: job timeout/顶层 permissions/PR concurrency/构建缓存/仓库资产检查,
self-test 反例 9 个
- 新增 tools/ci/{run_local_gate.ps1, merge_gate_summaries.py, install_runner.md},
docs/planning/wave3/ci-notes.md
- docs/planning/capability-claims.json: 修复 planned-non-manifold-nmt 代码行号引用(337->417)
121 lines
4.7 KiB
Python
121 lines
4.7 KiB
Python
"""把 ctest 发现出来的测试名映射回「测试目标(可执行文件)」。
|
||
|
||
背景:tests/CMakeLists.txt 的 add_vde_test() 用 gtest_discover_tests() 注册
|
||
ctest 用例,ctest 名是 ``Suite.Case``(不带目标前缀,例:
|
||
``BrepTest.MakeBox_CreatesValidEntity``),因此 profile 里没法用
|
||
``-R "^(test_brep)\\."`` 这种「目标名当 ctest 名前缀」的正则来选目标。
|
||
|
||
本模块读取 ``ctest --show-only=json-v1`` 的测试列表,用每个测试 command[0]
|
||
(可执行文件路径)反查它属于哪个测试目标,再把目标集合展开成 ctest 用例名。
|
||
|
||
纯标准库;供 tools/vde_fast_gate.py 与 tools/vde_coverage_check.py 复用。
|
||
"""
|
||
|
||
import json
|
||
import os
|
||
import re
|
||
import subprocess
|
||
|
||
|
||
def _load_tests(ctest, build_dir, timeout=600):
|
||
cmd = [ctest, "--test-dir", build_dir, "--show-only=json-v1"]
|
||
proc = subprocess.run(cmd, stdout=subprocess.PIPE,
|
||
stderr=subprocess.PIPE, timeout=timeout)
|
||
text = proc.stdout.decode("utf-8", errors="replace")
|
||
start = text.find("{")
|
||
if start < 0:
|
||
raise RuntimeError("ctest --show-only=json-v1 没有输出 JSON: %r"
|
||
% text[:400])
|
||
return json.loads(text[start:]).get("tests") or []
|
||
|
||
|
||
def _target_of(test):
|
||
cmd = test.get("command") or []
|
||
if not cmd:
|
||
return None
|
||
base = os.path.basename(str(cmd[0])).lower()
|
||
if base.endswith(".exe"):
|
||
base = base[:-4]
|
||
return base or None
|
||
|
||
|
||
def resolve_target_tests(ctest, build_dir, targets):
|
||
"""返回 (names, missing):属于 targets 的 ctest 用例名,以及没有任何用例的目标。"""
|
||
wanted = {t.lower() for t in targets}
|
||
names = []
|
||
seen = set()
|
||
have = set()
|
||
for test in _load_tests(ctest, build_dir):
|
||
name = test.get("name")
|
||
if not name or name.endswith("_NOT_BUILT"):
|
||
continue
|
||
target = _target_of(test)
|
||
if not target:
|
||
continue
|
||
have.add(target)
|
||
if target in wanted and name not in seen:
|
||
seen.add(name)
|
||
names.append(name)
|
||
missing = sorted(t for t in targets if t.lower() not in have)
|
||
return names, missing
|
||
|
||
|
||
def chunk_regexes(names, chunk=100):
|
||
"""把用例名切成多个 ^(...)$ 正则,避免 Windows 命令行长度上限。"""
|
||
escaped = [re.escape(n) for n in names]
|
||
if not escaped:
|
||
return []
|
||
return ["^(" + "|".join(escaped[i:i + chunk]) + ")$"
|
||
for i in range(0, len(escaped), chunk)]
|
||
|
||
|
||
def main(argv=None):
|
||
"""CLI:按 profile 的 targets 生成 ctest -R 正则(供 nightly/本地脚本复用)。"""
|
||
import argparse
|
||
import sys
|
||
|
||
ap = argparse.ArgumentParser(description="按 target profile 生成 ctest -R 正则")
|
||
ap.add_argument("--profile", required=True, help="target_profiles.json 中的 profile 名")
|
||
ap.add_argument("--build-dir", required=True, help="已 configure/build 的目录")
|
||
ap.add_argument("--profiles-json", default=None, help="默认 tools/coverage/target_profiles.json")
|
||
ap.add_argument("--ctest", default="ctest")
|
||
ap.add_argument("--chunk", type=int, default=0, help=">0 时按批输出多条正则")
|
||
args = ap.parse_args(argv)
|
||
path = args.profiles_json or os.path.join(
|
||
os.path.dirname(os.path.abspath(__file__)), "target_profiles.json")
|
||
with open(path, encoding="utf-8") as fh:
|
||
data = json.load(fh)
|
||
profiles = data.get("profiles") or {}
|
||
cfg = profiles.get(args.profile)
|
||
if not isinstance(cfg, dict) and isinstance(data.get(args.profile), dict):
|
||
# determinism 是顶层配置块而非 profiles 成员(9 个确定性目标)
|
||
cfg = data[args.profile]
|
||
if not isinstance(cfg, dict):
|
||
options = sorted(set(profiles) | {k for k, v in data.items() if isinstance(v, dict)})
|
||
print("未知 profile: %s(可选: %s)" % (args.profile, ", ".join(options)),
|
||
file=sys.stderr)
|
||
return 2
|
||
flt = cfg.get("ctest_filter")
|
||
if flt:
|
||
print(flt)
|
||
return 0
|
||
names, missing = resolve_target_tests(args.ctest, args.build_dir,
|
||
cfg.get("targets") or [])
|
||
if missing:
|
||
print("WARN 以下目标没有 ctest 用例(可能未构建): %s" % ", ".join(missing),
|
||
file=sys.stderr)
|
||
regexes = (chunk_regexes(names, args.chunk) if args.chunk > 0
|
||
else ["^(" + "|".join(re.escape(n) for n in names) + ")$"]
|
||
if names else [])
|
||
if not regexes:
|
||
print("没有解析到任何 ctest 用例(build-dir=%s)" % args.build_dir, file=sys.stderr)
|
||
return 2
|
||
for regex in regexes:
|
||
print(regex)
|
||
return 2 if missing else 0
|
||
|
||
|
||
if __name__ == "__main__":
|
||
import sys
|
||
sys.exit(main())
|