image.domain\self_evolve\coverage_gap.mbt
58.3% · 35 / 60 points · 172 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # 覆盖缺口 self_evolve/coverage_gap - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// 测试覆盖盲区分析 — 分析测试覆盖盲区,找出未覆盖的算子/退化场景 - 7
// Coverage gap analysis: find untested or under-tested ops and degradation scenarios - 8
// - 9
// Phase 8 v297: 将覆盖分析从"自适应"推向"盲区发现" — 找出测试覆盖空白。 - 10
- 11
///| - 12
/// 覆盖盲区类型。 - 13
/// 描述 Coverage gap type. - 14
/// `#non_exhaustive` 表示未来可能添加新构造器 - 15
#derive(Eq, @debug.Debug) - 16
#non_exhaustive - 17
pub(all) enum GapKind { - 18
UntestedOp - 19
UnderTestedOp - 20
NoDegradationTest - 21
} - 22
- 23
///| - 24
pub extend GapKind with @debug.Debug::{to_repr} - 25
- 26
///| - 27
pub extend GapKind with Eq::{not_equal, equal} - 28
- 29
///| - 30
/// 单个覆盖盲区。 - 31
/// 描述 Single coverage gap. - 32
#derive(Eq, @debug.Debug) - 33
pub(all) struct CoverageGap { - 34
op_tag : String - 35
gap_kind : GapKind - 36
description : String - 37
} - 38
- 39
///| - 40
pub extend CoverageGap with @debug.Debug::{to_repr} - 41
- 42
///| - 43
pub extend CoverageGap with Eq::{not_equal, equal} - 44
- 45
///| - 46
/// 覆盖盲区报告。 - 47
/// 描述 Coverage gap report. - 48
#derive(Eq, @debug.Debug) - 49
pub(all) struct CoverageGapReport { - 50
gaps : Array[CoverageGap] - 51
total_gaps : Int32 - 52
untested_count : Int32 - 53
summary : String - 54
} - 55
- 56
///| - 57
pub extend CoverageGapReport with @debug.Debug::{to_repr} - 58
- 59
///| - 60
pub extend CoverageGapReport with Eq::{not_equal, equal} - 61
- 62
///| - 63
/// 计算单算子覆盖百分比。 - 64
/// 计算 Calculate coverage percentage for a single op. - 65
pub fn coverage_percentage(op : @imgir.IROp) -> Int32 { - 66●
let degs = detect_degradation(op) - 67●
let tests = evolve_test_suite([op]) - 68●
let base_coverage = if tests.length() >= 4 { - 69●
100 - 70●
} else if tests.length() >= 2 { - 71●
50 - 72○
} else if tests.length() >= 1 { - 73○
25 - 74
} else { - 75○
0 - 76
} - 77●
if degs.length() > 0 { - 78●
let penalty = degs.length() * 10 - 79
let result = base_coverage - penalty - 80
if result < 0 { - 81○
0 - 82
} else { - 83●
result - 84
} - 85
} else { - 86●
base_coverage - 87
} - 88
} - 89
- 90
///| - 91
/// 找出完全未测试的算子标签。 - 92
/// 查找 Find completely untested op tags. - 93
pub fn find_untested_ops() -> Array[String] { - 94●
let result : Array[String] = [] - 95●
for op in all_ops() { - 96●
let tests = evolve_test_suite([op]) - 97●
if tests.length() == 0 { - 98○
result.push(op.tag()) - 99
} - 100
} - 101
result - 102
} - 103
- 104
///| - 105
/// 找出测试不足的算子标签(覆盖 < 50%)。 - 106
/// 查找 Find under-tested op tags (coverage < 50%). - 107
pub fn find_under_tested_ops() -> Array[String] { - 108●
let result : Array[String] = [] - 109●
for op in all_ops() { - 110●
let cov = coverage_percentage(op) - 111
if cov < 50 { - 112○
result.push(op.tag()) - 113
} - 114
} - 115
result - 116
} - 117
- 118
///| - 119
/// 分析全算子测试覆盖盲区。 - 120
/// 描述 Analyze coverage gaps for all ops. - 121
pub fn analyze_coverage_gaps() -> CoverageGapReport { - 122●
let gaps : Array[CoverageGap] = [] - 123
let mut untested_count = 0 - 124●
for op in all_ops() { - 125●
let tests = evolve_test_suite([op]) - 126●
if tests.length() == 0 { - 127○
gaps.push({ - 128○
op_tag: op.tag(), - 129
gap_kind: UntestedOp, - 130○
description: op.tag() + " 完全未测试", - 131
}) - 132
untested_count = untested_count + 1 - 133
} else { - 134●
let cov = coverage_percentage(op) - 135
if cov < 50 { - 136○
gaps.push({ - 137○
op_tag: op.tag(), - 138
gap_kind: UnderTestedOp, - 139○
description: op.tag() + - 140
" 测试不足 (覆盖 " + - 141○
cov.to_string() + - 142
"%)", - 143
}) - 144
} - 145●
let degs = detect_degradation(op) - 146●
if degs.length() > 0 { - 147○
let has_deg_test = false - 148
if !has_deg_test { - 149○
gaps.push({ - 150○
op_tag: op.tag(), - 151
gap_kind: NoDegradationTest, - 152○
description: op.tag() + " 有退化但无退化测试", - 153
}) - 154
} - 155
} - 156
} - 157
} - 158●
let total = gaps.length() - 159
let summary = "覆盖盲区: " + - 160●
total.to_string() + - 161
" 处盲区, " + - 162●
untested_count.to_string() + - 163
" 个未测试算子" - 164
{ gaps, total_gaps: total, untested_count, summary, } - 165
} - 166
- 167
///| - 168
/// 覆盖盲区报告是否有盲区。 - 169
/// 描述 Whether coverage gap report has gaps. - 170
pub fn CoverageGapReport::has_gaps(self : CoverageGapReport) -> Bool { - 171●
self.total_gaps > 0 - 172
}