[llvm-branch-commits] [llvm] [Dexter] Add !step node for testing stepping behaviour (PR #203844)
Orlando Cazalet-Hyams via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Jun 30 01:48:29 PDT 2026
================
@@ -156,3 +156,80 @@ def get_variable_metrics(
"missing_values": ScalarMetric(num_missing_values, improves_asc=False),
}
return metrics
+
+
+def lcs_len(a: List[int], b: List[int]) -> int:
+ """Returns the length of the longest common subsequence between a and b."""
+ lcs_table: List[List[int]] = [
+ [0 for _ in range(len(b) + 1)] for _ in range(len(a) + 1)
+ ]
+ for a_idx in range(len(a)):
+ for b_idx in range(len(b)):
+ if a[a_idx] == b[b_idx]:
+ lcs_table[a_idx + 1][b_idx + 1] = 1 + lcs_table[a_idx][b_idx]
+ else:
+ lcs_table[a_idx + 1][b_idx + 1] = max(
+ lcs_table[a_idx + 1][b_idx], lcs_table[a_idx][b_idx + 1]
+ )
+ return lcs_table[-1][-1]
+
+
+def get_step_metrics(
+ expect: Step, expected_lines: List[int], step_lines: List[int]
+) -> Dict[str, Metric]:
+ """Given an Expect node with its expected values and a list of all matches for that Expect in a debugger session,
+ returns the computed metrics for that Expect node."""
+
+ expected_line_set = set(expected_lines)
+ actual_line_set = set(step_lines)
+
+ total_line_steps = len(step_lines)
+ if expect.kind == "exactly" or expect.kind == "order":
+ num_matching_steps = lcs_len(expected_lines, step_lines)
+ # Inefficient, but not to the point that we care!
+ num_matching_steps_ignoring_order = lcs_len(
+ sorted(expected_lines), sorted(step_lines)
+ )
+
+ max_possible_correct_line_steps = len(expected_lines)
+ correct_line_steps = num_matching_steps
+ misordered_line_steps = num_matching_steps_ignoring_order - num_matching_steps
+ missing_lines = sum(1 for e in expected_line_set if e not in actual_line_set)
----------------
OCHyams wrote:
is `missing_lines = len(expected_line_set - actual_line_set)` clearer? I guess that's a bit wasteful constructing a throwaway set. Doesn't really matter either way so I'll leave it up to you
(there's another instance in the `else` branch)
https://github.com/llvm/llvm-project/pull/203844
More information about the llvm-branch-commits
mailing list