feat: DB管线补全 + 新增orchestrator_db/program_schema/to_sql + 清理临时脚本

This commit is contained in:
hangshuo652
2026-07-11 14:55:52 +08:00
parent 40e8a50ab4
commit af37e33b98
32 changed files with 3232 additions and 255 deletions
+51 -11
View File
@@ -176,7 +176,30 @@ def mark_coverage(decision_points, leaf_stats, branch_paths, fields):
leaf.covered_false = True
for dp in decision_points:
dp.implied_branches = set(dp.active_branches)
missing = None
if dp.kind == 'IF':
parsed = getattr(dp, 'parsed', None)
if parsed and is_field(parsed[0], fields):
has_T = 'T' in dp.active_branches
has_F = 'F' in dp.active_branches
if has_T and not has_F:
missing = 'F'
elif has_F and not has_T:
missing = 'T'
elif dp.kind == 'PERFORM':
parsed = getattr(dp, 'parsed', None)
if parsed and is_field(parsed[0], fields):
has_E = 'Enter' in dp.active_branches
has_S = 'Skip' in dp.active_branches
if has_E and not has_S:
missing = 'Skip'
elif has_S and not has_E:
missing = 'Enter'
if missing:
dp.implied_branches = {missing}
else:
dp.implied_branches = set(dp.active_branches)
def _match_constraint(c, parsed):
@@ -232,6 +255,14 @@ def _mark_if(dp, cons):
dp.active_branches.add('F')
except KeyError:
pass
else:
# All leaves are synthetic (e.g. FUNCTION MOD → _FUNC_MOD): can't match
# but path generator traversed both branches — mark both covered
all_synthetic = all(
not is_field(ls.field, []) for ls in dp.leaves
)
if all_synthetic:
dp.active_branches.update(['T', 'F'])
else:
matched = 0
for leaf in dp.leaves:
@@ -336,11 +367,10 @@ def _mark_search(dp, cons, fields=None):
continue
if isinstance(cond_tree, CondLeaf):
for c in cons:
if len(c) == 4:
if len(c) == 4 and c[3]:
base_c = re.sub(r'\s*\(.*?\)\s*$', '', c[0])
base_cond = re.sub(r'\s*\(.*?\)\s*$', '', cond_tree.field)
if base_c == base_cond and c[1] == cond_tree.op \
and str(c[2]) == str(cond_tree.value) and c[3]:
if base_c == base_cond:
branch_masks[i] = True
break
else:
@@ -424,12 +454,16 @@ def _get_fields_in_cond(cond_text):
def locate_decision_lines(decision_points, raw_source):
lines = raw_source.upper().splitlines()
used_indices = {} # label → last matched 0-indexed line number
for dp in decision_points:
patterns = _build_search_patterns(dp)
for i, line in enumerate(lines):
start = used_indices.get(dp.label, -1) + 1
for i in range(start, len(lines)):
line = lines[i]
for pat in patterns:
if re.search(pat, line):
dp.source_line = i + 1
used_indices[dp.label] = i
break
if dp.source_line:
break
@@ -1192,14 +1226,23 @@ def _find_proc_range(raw_source: str):
def run_coverage(branch_tree, branch_paths_with_assigns, fields,
raw_source, output_prefix, index_relpath=None,
gcov_data=None):
gcov_data=None, gcov_source=None):
decision_points, leaf_stats = collect_decision_points(branch_tree, fields)
mark_coverage(decision_points, leaf_stats, branch_paths_with_assigns, fields)
# Use gcov_source (preprocessed) for line location if available (matches gcov_data line numbers)
source_for_lines = gcov_source or raw_source
if source_for_lines:
locate_decision_lines(decision_points, source_for_lines)
if gcov_data:
mark_from_gcov(decision_points, gcov_data, branch_tree)
# leaf_stats 保留静态分析结果(gcov 无 -b 时不提供叶条件级别的分支数据)
mark_from_gcov(decision_points, gcov_data, branch_tree,
gcov_source or raw_source)
for dp in decision_points:
ln = dp.source_line
if ln > 0 and ln in gcov_data and gcov_data[ln] == 0:
dp.implied_branches.clear()
_source_note = ''
if gcov_data:
@@ -1210,9 +1253,6 @@ def run_coverage(branch_tree, branch_paths_with_assigns, fields,
'</div>'
)
if raw_source:
locate_decision_lines(decision_points, raw_source)
total = sum(len(dp.branch_names) for dp in decision_points)
covered = sum(len(dp.active_branches) for dp in decision_points)
implied = sum(len(dp.implied_branches) for dp in decision_points)