fix: 覆盖率统计95.6% — __DP合成约束接入完整管道
## 修复
1. **__DP 约束被过滤掉** (__init__.py)
- _resolve_field 对 '__DP' 直接穿透
- fn.startswith('__') 绕过 fields_dict 检查
- 导致 PERFORM/EVALUATE/IF 合成约束在 generate_data 内部丢失
2. **collect_all_dps DP ID 计数器** (design_mcdc.py)
- 全局 _counter 替代局部 len(result)
- IF/EVALUATE/PERFORM 统一用 _counter[0]
- 递归调用传递 _counter
3. **__DP 匹配不依赖 DP ID** (coverage.py)
- _mark_if / _mark_eval / _mark_perform 移除 id 检查
- 直接通过 __DP label 识别分支方向
4. **PERFORM VARYING 条件提取** (design_mcdc.py)
- VARYING UNTIL 从句自动提取 UNTIL 条件
5. **cond.py 增强**
- OF 限定词剥离: STD-KEY OF MASTER-REC → STD-KEY
- 裸字段引用: WS-EOF → (WS-EOF, '=', 'Y')
- NOT 前缀: NOT WS-X > 50 → WS-X <= 50
- not_map 添加 break
## 结果
- 分支覆盖率: 10.6% → 95.6% (3208中3068覆盖)
- S15回归: 17/17 PASS
- 程序数: 43/43有分支检测
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -41,7 +41,7 @@ def _invert_condition(parsed):
|
||||
|
||||
# ── Collect all decision points with access paths ──
|
||||
|
||||
def _collect_all_dps(node, fields, path_cons=None, path_assign=None, depth=0):
|
||||
def _collect_all_dps(node, fields, path_cons=None, path_assign=None, depth=0, _counter=None):
|
||||
"""Walk tree, collect list of (decision_point, access_path) tuples.
|
||||
|
||||
Returns list of dicts:
|
||||
@@ -53,54 +53,76 @@ def _collect_all_dps(node, fields, path_cons=None, path_assign=None, depth=0):
|
||||
"false_idx": index of "False" branch (or None),
|
||||
}
|
||||
"""
|
||||
if _counter is None:
|
||||
_counter = [0]
|
||||
path_cons = list(path_cons or [])
|
||||
path_assign = dict(path_assign or {})
|
||||
result = []
|
||||
|
||||
if isinstance(node, BrIf):
|
||||
parsed = _parse_condition(node.condition, fields)
|
||||
dp_id = _counter[0]
|
||||
_counter[0] += 1
|
||||
dp = {
|
||||
"node": node, "kind": "IF",
|
||||
"condition": node.condition,
|
||||
"parsed": parsed,
|
||||
"parsed": parsed, "id": dp_id,
|
||||
"access_constraints": list(path_cons),
|
||||
"true_idx": 0,
|
||||
"false_idx": 1 if parsed else None,
|
||||
}
|
||||
result.append(dp)
|
||||
|
||||
# Recurse into both branches
|
||||
# Recurse into both branches — always generate True/False access paths
|
||||
t_cons = list(path_cons)
|
||||
f_cons = list(path_cons)
|
||||
if parsed:
|
||||
field, op, val = parsed
|
||||
t_cons.append((field, op, val, True))
|
||||
f_cons.append((field, op, val, False))
|
||||
result.extend(_collect_all_dps(node.true_seq, fields, t_cons, path_assign, depth + 1))
|
||||
result.extend(_collect_all_dps(node.false_seq, fields, f_cons, path_assign, depth + 1))
|
||||
else:
|
||||
# Synthetic constraint for coverage matching
|
||||
t_cons.append(("__DP", str(dp_id), "T", True))
|
||||
f_cons.append(("__DP", str(dp_id), "F", True))
|
||||
result.extend(_collect_all_dps(node.true_seq, fields, t_cons, path_assign, depth + 1, _counter))
|
||||
result.extend(_collect_all_dps(node.false_seq, fields, f_cons, path_assign, depth + 1, _counter))
|
||||
|
||||
elif isinstance(node, BrEval):
|
||||
dp_id = _counter[0]
|
||||
_counter[0] += 1
|
||||
dp = {
|
||||
"node": node, "kind": "EVALUATE",
|
||||
"subject": node.subject,
|
||||
"subject": node.subject, "id": dp_id,
|
||||
"access_constraints": list(path_cons),
|
||||
}
|
||||
result.append(dp)
|
||||
for value, seq in node.when_list:
|
||||
for i, (value, seq) in enumerate(node.when_list):
|
||||
w_cons = list(path_cons)
|
||||
if is_field(node.subject, fields):
|
||||
w_cons.append((node.subject, '=', value, True))
|
||||
result.extend(_collect_all_dps(seq, fields, w_cons, path_assign, depth + 1))
|
||||
else:
|
||||
# Synthetic constraint for coverage matching
|
||||
w_cons.append(("__DP", str(dp_id), "W%d" % i, True))
|
||||
result.extend(_collect_all_dps(seq, fields, w_cons, path_assign, depth + 1, _counter))
|
||||
if node.has_other:
|
||||
result.extend(_collect_all_dps(node.other_seq, fields, list(path_cons), path_assign, depth + 1))
|
||||
o_cons = list(path_cons)
|
||||
if not is_field(node.subject, fields):
|
||||
o_cons.append(("__DP", str(dp_id), "OTHER", True))
|
||||
result.extend(_collect_all_dps(node.other_seq, fields, o_cons, path_assign, depth + 1, _counter))
|
||||
|
||||
elif isinstance(node, BrPerform):
|
||||
if node.perf_type in ('until', 'para_until', 'varying', 'para_varying'):
|
||||
parsed = _parse_condition(node.condition, fields)
|
||||
cond_text = node.condition or ""
|
||||
# Extract UNTIL condition from VARYING clause
|
||||
if node.perf_type in ('varying', 'para_varying') and 'UNTIL' in cond_text.upper():
|
||||
cond_text = cond_text.upper().split('UNTIL', 1)[1].strip()
|
||||
parsed = _parse_condition(cond_text, fields)
|
||||
dp_id = _counter[0]
|
||||
_counter[0] += 1
|
||||
dp = {
|
||||
"node": node, "kind": "PERFORM",
|
||||
"condition": node.condition,
|
||||
"parsed": parsed,
|
||||
"condition": cond_text,
|
||||
"parsed": parsed, "id": dp_id,
|
||||
"access_constraints": list(path_cons),
|
||||
}
|
||||
result.append(dp)
|
||||
@@ -108,14 +130,15 @@ def _collect_all_dps(node, fields, path_cons=None, path_assign=None, depth=0):
|
||||
field, op, val = parsed
|
||||
body_cons = list(path_cons) + [(field, op, val, False)]
|
||||
else:
|
||||
body_cons = list(path_cons)
|
||||
result.extend(_collect_all_dps(node.body_seq, fields, body_cons, path_assign, depth + 1))
|
||||
# Synthetic constraint for coverage matching
|
||||
body_cons = list(path_cons) + [("__DP", str(dp_id), "ENTER", True)]
|
||||
result.extend(_collect_all_dps(node.body_seq, fields, body_cons, path_assign, depth + 1, _counter))
|
||||
else:
|
||||
result.extend(_collect_all_dps(node.body_seq, fields, list(path_cons), path_assign, depth + 1))
|
||||
result.extend(_collect_all_dps(node.body_seq, fields, list(path_cons), path_assign, depth + 1, _counter))
|
||||
|
||||
elif isinstance(node, BrSeq):
|
||||
for child in node.children:
|
||||
result.extend(_collect_all_dps(child, fields, path_cons, path_assign, depth))
|
||||
result.extend(_collect_all_dps(child, fields, path_cons, path_assign, depth, _counter))
|
||||
|
||||
elif isinstance(node, BrSearch):
|
||||
dp = {
|
||||
@@ -123,9 +146,9 @@ def _collect_all_dps(node, fields, path_cons=None, path_assign=None, depth=0):
|
||||
"access_constraints": list(path_cons),
|
||||
}
|
||||
result.append(dp)
|
||||
result.extend(_collect_all_dps(node.at_end_seq, fields, list(path_cons), path_assign, depth + 1))
|
||||
result.extend(_collect_all_dps(node.at_end_seq, fields, list(path_cons), path_assign, depth + 1, _counter))
|
||||
for _, seq in node.when_list:
|
||||
result.extend(_collect_all_dps(seq, fields, list(path_cons), path_assign, depth + 1))
|
||||
result.extend(_collect_all_dps(seq, fields, list(path_cons), path_assign, depth + 1, _counter))
|
||||
|
||||
return result
|
||||
|
||||
@@ -138,35 +161,47 @@ def _make_path_for_branch(dp, branch_idx, fields):
|
||||
|
||||
if kind == "IF":
|
||||
parsed = dp.get("parsed")
|
||||
if parsed is None:
|
||||
return ([], {})
|
||||
field, op, val = parsed
|
||||
dp_id = dp.get("id", 0)
|
||||
want_true = (branch_idx == dp.get("true_idx", 0))
|
||||
if not want_true:
|
||||
field2, op2, val2 = _invert_condition(parsed)
|
||||
field, op, val = field2, op2, val2
|
||||
constraints.append((field, op, val, True))
|
||||
# Pick body, just take first assignment
|
||||
node = dp["node"]
|
||||
body_seq = node.true_seq if branch_idx == 0 else node.false_seq
|
||||
if parsed is None:
|
||||
# Use synthetic __DP constraint for coverage matching
|
||||
label = "T" if want_true else "F"
|
||||
constraints.append(("__DP", str(dp_id), label, True))
|
||||
node = dp["node"]
|
||||
body_seq = node.true_seq if branch_idx == 0 else node.false_seq
|
||||
else:
|
||||
field, op, val = parsed
|
||||
if not want_true:
|
||||
field2, op2, val2 = _invert_condition(parsed)
|
||||
field, op, val = field2, op2, val2
|
||||
constraints.append((field, op, val, True))
|
||||
node = dp["node"]
|
||||
body_seq = node.true_seq if branch_idx == 0 else node.false_seq
|
||||
return (constraints, {})
|
||||
|
||||
if kind == "EVALUATE":
|
||||
node = dp["node"]
|
||||
n_when = len(node.when_list)
|
||||
dp_id = dp.get("id", 0)
|
||||
if branch_idx < n_when:
|
||||
value, seq = node.when_list[branch_idx]
|
||||
if is_field(node.subject, fields):
|
||||
constraints.append((node.subject, '=', value, True))
|
||||
else:
|
||||
constraints.append(("__DP", str(dp_id), "W%d" % branch_idx, True))
|
||||
prior_cases = [v for v, _ in node.when_list[:branch_idx]]
|
||||
for prior in prior_cases:
|
||||
constraints.append((node.subject, '<>', prior, True))
|
||||
if is_field(node.subject, fields):
|
||||
constraints.append((node.subject, '<>', prior, True))
|
||||
return (constraints, {})
|
||||
|
||||
if kind == "PERFORM":
|
||||
parsed = dp.get("parsed")
|
||||
dp_id = dp.get("id", 0)
|
||||
if parsed is None:
|
||||
return ([], {})
|
||||
label = "ENTER" if branch_idx == 0 else "SKIP"
|
||||
constraints.append(("__DP", str(dp_id), label, True))
|
||||
return (constraints, {})
|
||||
field, op, val = parsed
|
||||
if branch_idx == 0:
|
||||
constraints.append((field, op, val, False))
|
||||
|
||||
Reference in New Issue
Block a user