image.domain\self_evolve\coverage_gap.mbt

58.3% · 35 / 60 points · 172 lines

Background color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.

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