Skip to content

Commit 0e2a782

Browse files
Move check_debugger_output to the debugger module
1 parent ce18573 commit 0e2a782

File tree

2 files changed

+69
-64
lines changed

2 files changed

+69
-64
lines changed

src/tools/compiletest/src/runtest.rs

Lines changed: 10 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use crate::extract_gdb_version;
3939
use crate::is_android_gdb_target;
4040

4141
mod debugger;
42-
use debugger::DebuggerCommands;
42+
use debugger::{check_debugger_output, DebuggerCommands};
4343

4444
#[cfg(test)]
4545
mod tests;
@@ -726,7 +726,9 @@ impl<'test> TestCx<'test> {
726726
self.fatal_proc_rec("Error while running CDB", &debugger_run_result);
727727
}
728728

729-
self.check_debugger_output(&debugger_run_result, &check_lines);
729+
if let Err(e) = check_debugger_output(&debugger_run_result, &check_lines) {
730+
self.fatal_proc_rec(&e, &debugger_run_result);
731+
}
730732
}
731733

732734
fn run_debuginfo_gdb_test(&self) {
@@ -963,7 +965,9 @@ impl<'test> TestCx<'test> {
963965
self.fatal_proc_rec("gdb failed to execute", &debugger_run_result);
964966
}
965967

966-
self.check_debugger_output(&debugger_run_result, &check_lines);
968+
if let Err(e) = check_debugger_output(&debugger_run_result, &check_lines) {
969+
self.fatal_proc_rec(&e, &debugger_run_result);
970+
}
967971
}
968972

969973
fn run_debuginfo_lldb_test(&self) {
@@ -1100,7 +1104,9 @@ impl<'test> TestCx<'test> {
11001104
self.fatal_proc_rec("Error while running LLDB", &debugger_run_result);
11011105
}
11021106

1103-
self.check_debugger_output(&debugger_run_result, &check_lines);
1107+
if let Err(e) = check_debugger_output(&debugger_run_result, &check_lines) {
1108+
self.fatal_proc_rec(&e, &debugger_run_result);
1109+
}
11041110
}
11051111

11061112
fn run_lldb(
@@ -1183,66 +1189,6 @@ impl<'test> TestCx<'test> {
11831189
}
11841190
}
11851191

1186-
fn check_debugger_output(&self, debugger_run_result: &ProcRes, check_lines: &[String]) {
1187-
let num_check_lines = check_lines.len();
1188-
1189-
let mut check_line_index = 0;
1190-
for line in debugger_run_result.stdout.lines() {
1191-
if check_line_index >= num_check_lines {
1192-
break;
1193-
}
1194-
1195-
if check_single_line(line, &(check_lines[check_line_index])[..]) {
1196-
check_line_index += 1;
1197-
}
1198-
}
1199-
if check_line_index != num_check_lines && num_check_lines > 0 {
1200-
self.fatal_proc_rec(
1201-
&format!("line not found in debugger output: {}", check_lines[check_line_index]),
1202-
debugger_run_result,
1203-
);
1204-
}
1205-
1206-
fn check_single_line(line: &str, check_line: &str) -> bool {
1207-
// Allow check lines to leave parts unspecified (e.g., uninitialized
1208-
// bits in the wrong case of an enum) with the notation "[...]".
1209-
let line = line.trim();
1210-
let check_line = check_line.trim();
1211-
let can_start_anywhere = check_line.starts_with("[...]");
1212-
let can_end_anywhere = check_line.ends_with("[...]");
1213-
1214-
let check_fragments: Vec<&str> =
1215-
check_line.split("[...]").filter(|frag| !frag.is_empty()).collect();
1216-
if check_fragments.is_empty() {
1217-
return true;
1218-
}
1219-
1220-
let (mut rest, first_fragment) = if can_start_anywhere {
1221-
match line.find(check_fragments[0]) {
1222-
Some(pos) => (&line[pos + check_fragments[0].len()..], 1),
1223-
None => return false,
1224-
}
1225-
} else {
1226-
(line, 0)
1227-
};
1228-
1229-
for current_fragment in &check_fragments[first_fragment..] {
1230-
match rest.find(current_fragment) {
1231-
Some(pos) => {
1232-
rest = &rest[pos + current_fragment.len()..];
1233-
}
1234-
None => return false,
1235-
}
1236-
}
1237-
1238-
if !can_end_anywhere && !rest.is_empty() {
1239-
return false;
1240-
}
1241-
1242-
true
1243-
}
1244-
}
1245-
12461192
fn check_error_patterns(
12471193
&self,
12481194
output_to_check: &str,

src/tools/compiletest/src/runtest/debugger.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::common::Config;
2+
use crate::runtest::ProcRes;
23

34
use std::fs::File;
45
use std::io::{BufRead, BufReader};
@@ -54,3 +55,61 @@ impl DebuggerCommands {
5455
Ok(Self { commands, check_lines, breakpoint_lines })
5556
}
5657
}
58+
59+
pub(super) fn check_debugger_output(
60+
debugger_run_result: &ProcRes,
61+
check_lines: &[String],
62+
) -> Result<(), String> {
63+
let num_check_lines = check_lines.len();
64+
65+
let mut check_line_index = 0;
66+
for line in debugger_run_result.stdout.lines() {
67+
if check_line_index >= num_check_lines {
68+
break;
69+
}
70+
71+
if check_single_line(line, &(check_lines[check_line_index])[..]) {
72+
check_line_index += 1;
73+
}
74+
}
75+
if check_line_index != num_check_lines && num_check_lines > 0 {
76+
Err(format!("line not found in debugger output: {}", check_lines[check_line_index]))
77+
} else {
78+
Ok(())
79+
}
80+
}
81+
82+
fn check_single_line(line: &str, check_line: &str) -> bool {
83+
// Allow check lines to leave parts unspecified (e.g., uninitialized
84+
// bits in the wrong case of an enum) with the notation "[...]".
85+
let line = line.trim();
86+
let check_line = check_line.trim();
87+
let can_start_anywhere = check_line.starts_with("[...]");
88+
let can_end_anywhere = check_line.ends_with("[...]");
89+
90+
let check_fragments: Vec<&str> =
91+
check_line.split("[...]").filter(|frag| !frag.is_empty()).collect();
92+
if check_fragments.is_empty() {
93+
return true;
94+
}
95+
96+
let (mut rest, first_fragment) = if can_start_anywhere {
97+
match line.find(check_fragments[0]) {
98+
Some(pos) => (&line[pos + check_fragments[0].len()..], 1),
99+
None => return false,
100+
}
101+
} else {
102+
(line, 0)
103+
};
104+
105+
for current_fragment in &check_fragments[first_fragment..] {
106+
match rest.find(current_fragment) {
107+
Some(pos) => {
108+
rest = &rest[pos + current_fragment.len()..];
109+
}
110+
None => return false,
111+
}
112+
}
113+
114+
if !can_end_anywhere && !rest.is_empty() { false } else { true }
115+
}

0 commit comments

Comments
 (0)