Skip to content

Commit ba37a69

Browse files
committed
Auto merge of rust-lang#113306 - tgross35:debuginfo-better-output, r=Mark-Simulacrum
Update debuginfo test runner to provide more useful output This change makes debuginfo tests more user friendly. Changes: - Print all lines that fail to match the patterns instead of just the first - Provide better error messages that also say what did match - Strip leading whitespace from directives so they are not skipped if indented - Improve documentation and improve nesting on some related items As an example, given the following intentional fail (and a few not shown): ```rust // from tests/debuginfo/rc_arc.rs // cdb-command:dx rc,d // cdb-check:rc,d : 111 [Type: alloc::rc::Rc<i32>] // cdb-check: [Reference count] : 11 [Type: core::cell FAIL::Cell<usize>] // cdb-check: [Weak reference count] : 2 [Type: core::cell FAIL::Cell<usize>] ``` The current output (tested in rust-lang#113313) will show: ``` 2023-07-04T08:10:00.1939267Z ---- [debuginfo-cdb] tests\debuginfo\rc_arc.rs stdout ---- 2023-07-04T08:10:00.1942182Z 2023-07-04T08:10:00.1957463Z error: line not found in debugger output: [Reference count] : 11 [Type: core:: cell FAIL::Cell<usize>] 2023-07-04T08:10:00.1958272Z status: exit code: 0 ``` With this chane, you are able to see all failures in that check group, as well as what parts were successful. The output is now: ``` 2023-07-04T09:45:57.2514224Z error: check directive(s) from `C:\a\rust\rust\tests\debuginfo\rc_arc.rs` not found in debugger output. errors: 2023-07-04T09:45:57.2514631Z (rc_arc.rs:31) ` [Reference count] : 11 [Type: core::cell FAIL::Cell<usize>]` 2023-07-04T09:45:57.2514908Z (rc_arc.rs:32) ` [Weak reference count] : 2 [Type: core::cell FAIL::Cell<usize>]` 2023-07-04T09:45:57.2515181Z (rc_arc.rs:41) ` [Reference count] : 21 [Type: core::sync::atomic FAIL::AtomicUsize]` 2023-07-04T09:45:57.2515452Z (rc_arc.rs:50) `dyn_rc,d [Type: alloc::rc::Rc<dyn$<core::fmt FAIL::Debug> >]` 2023-07-04T09:45:57.2515695Z the following subset of check directive(s) was found successfully:: 2023-07-04T09:45:57.2516080Z (rc_arc.rs:30) `rc,d : 111 [Type: alloc::rc::Rc<i32>]` 2023-07-04T09:45:57.2516312Z (rc_arc.rs:35) `weak_rc,d : 111 [Type: alloc::rc::Weak<i32>]` 2023-07-04T09:45:57.2516555Z (rc_arc.rs:36) ` [Reference count] : 11 [Type: core::cell::Cell<usize>]` 2023-07-04T09:45:57.2516881Z (rc_arc.rs:37) ` [Weak reference count] : 2 [Type: core::cell::Cell<usize>]` ... ``` Which makes it easier to see what did and didn't succeed without manual comparison against the source test file.
2 parents 1861088 + b0a18cb commit ba37a69

File tree

3 files changed

+131
-108
lines changed

3 files changed

+131
-108
lines changed

src/tools/compiletest/src/header.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -588,21 +588,22 @@ impl TestProps {
588588
}
589589
}
590590

591+
/// Extract a `(Option<line_config>, directive)` directive from a line if comment is present.
591592
pub fn line_directive<'line>(
592593
comment: &str,
593594
ln: &'line str,
594595
) -> Option<(Option<&'line str>, &'line str)> {
596+
let ln = ln.trim_start();
595597
if ln.starts_with(comment) {
596598
let ln = ln[comment.len()..].trim_start();
597599
if ln.starts_with('[') {
598600
// A comment like `//[foo]` is specific to revision `foo`
599-
if let Some(close_brace) = ln.find(']') {
600-
let lncfg = &ln[1..close_brace];
601+
let Some(close_brace) = ln.find(']') else {
602+
panic!("malformed condition directive: expected `{}[foo]`, found `{}`", comment, ln);
603+
};
601604

602-
Some((Some(lncfg), ln[(close_brace + 1)..].trim_start()))
603-
} else {
604-
panic!("malformed condition directive: expected `{}[foo]`, found `{}`", comment, ln)
605-
}
605+
let lncfg = &ln[1..close_brace];
606+
Some((Some(lncfg), ln[(close_brace + 1)..].trim_start()))
606607
} else {
607608
Some((None, ln))
608609
}

src/tools/compiletest/src/runtest.rs

+35-43
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use crate::extract_gdb_version;
4141
use crate::is_android_gdb_target;
4242

4343
mod debugger;
44-
use debugger::{check_debugger_output, DebuggerCommands};
44+
use debugger::DebuggerCommands;
4545

4646
#[cfg(test)]
4747
mod tests;
@@ -997,16 +997,13 @@ impl<'test> TestCx<'test> {
997997
};
998998

999999
// Parse debugger commands etc from test files
1000-
let DebuggerCommands { commands, check_lines, breakpoint_lines, .. } =
1001-
match DebuggerCommands::parse_from(
1002-
&self.testpaths.file,
1003-
self.config,
1004-
prefixes,
1005-
self.revision,
1006-
) {
1007-
Ok(cmds) => cmds,
1008-
Err(e) => self.fatal(&e),
1009-
};
1000+
let dbg_cmds = DebuggerCommands::parse_from(
1001+
&self.testpaths.file,
1002+
self.config,
1003+
prefixes,
1004+
self.revision,
1005+
)
1006+
.unwrap_or_else(|e| self.fatal(&e));
10101007

10111008
// https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-commands
10121009
let mut script_str = String::with_capacity(2048);
@@ -1023,12 +1020,12 @@ impl<'test> TestCx<'test> {
10231020

10241021
// Set breakpoints on every line that contains the string "#break"
10251022
let source_file_name = self.testpaths.file.file_name().unwrap().to_string_lossy();
1026-
for line in &breakpoint_lines {
1023+
for line in &dbg_cmds.breakpoint_lines {
10271024
script_str.push_str(&format!("bp `{}:{}`\n", source_file_name, line));
10281025
}
10291026

10301027
// Append the other `cdb-command:`s
1031-
for line in &commands {
1028+
for line in &dbg_cmds.commands {
10321029
script_str.push_str(line);
10331030
script_str.push_str("\n");
10341031
}
@@ -1058,7 +1055,7 @@ impl<'test> TestCx<'test> {
10581055
self.fatal_proc_rec("Error while running CDB", &debugger_run_result);
10591056
}
10601057

1061-
if let Err(e) = check_debugger_output(&debugger_run_result, &check_lines) {
1058+
if let Err(e) = dbg_cmds.check_output(&debugger_run_result) {
10621059
self.fatal_proc_rec(&e, &debugger_run_result);
10631060
}
10641061
}
@@ -1088,17 +1085,14 @@ impl<'test> TestCx<'test> {
10881085
PREFIXES
10891086
};
10901087

1091-
let DebuggerCommands { commands, check_lines, breakpoint_lines } =
1092-
match DebuggerCommands::parse_from(
1093-
&self.testpaths.file,
1094-
self.config,
1095-
prefixes,
1096-
self.revision,
1097-
) {
1098-
Ok(cmds) => cmds,
1099-
Err(e) => self.fatal(&e),
1100-
};
1101-
let mut cmds = commands.join("\n");
1088+
let dbg_cmds = DebuggerCommands::parse_from(
1089+
&self.testpaths.file,
1090+
self.config,
1091+
prefixes,
1092+
self.revision,
1093+
)
1094+
.unwrap_or_else(|e| self.fatal(&e));
1095+
let mut cmds = dbg_cmds.commands.join("\n");
11021096

11031097
// compile test file (it should have 'compile-flags:-g' in the header)
11041098
let should_run = self.run_if_enabled();
@@ -1132,13 +1126,14 @@ impl<'test> TestCx<'test> {
11321126
./{}/stage2/lib/rustlib/{}/lib/\n",
11331127
self.config.host, self.config.target
11341128
));
1135-
for line in &breakpoint_lines {
1129+
for line in &dbg_cmds.breakpoint_lines {
11361130
script_str.push_str(
1137-
&format!(
1131+
format!(
11381132
"break {:?}:{}\n",
11391133
self.testpaths.file.file_name().unwrap().to_string_lossy(),
11401134
*line
1141-
)[..],
1135+
)
1136+
.as_str(),
11421137
);
11431138
}
11441139
script_str.push_str(&cmds);
@@ -1279,7 +1274,7 @@ impl<'test> TestCx<'test> {
12791274
}
12801275

12811276
// Add line breakpoints
1282-
for line in &breakpoint_lines {
1277+
for line in &dbg_cmds.breakpoint_lines {
12831278
script_str.push_str(&format!(
12841279
"break '{}':{}\n",
12851280
self.testpaths.file.file_name().unwrap().to_string_lossy(),
@@ -1315,7 +1310,7 @@ impl<'test> TestCx<'test> {
13151310
self.fatal_proc_rec("gdb failed to execute", &debugger_run_result);
13161311
}
13171312

1318-
if let Err(e) = check_debugger_output(&debugger_run_result, &check_lines) {
1313+
if let Err(e) = dbg_cmds.check_output(&debugger_run_result) {
13191314
self.fatal_proc_rec(&e, &debugger_run_result);
13201315
}
13211316
}
@@ -1372,16 +1367,13 @@ impl<'test> TestCx<'test> {
13721367
};
13731368

13741369
// Parse debugger commands etc from test files
1375-
let DebuggerCommands { commands, check_lines, breakpoint_lines, .. } =
1376-
match DebuggerCommands::parse_from(
1377-
&self.testpaths.file,
1378-
self.config,
1379-
prefixes,
1380-
self.revision,
1381-
) {
1382-
Ok(cmds) => cmds,
1383-
Err(e) => self.fatal(&e),
1384-
};
1370+
let dbg_cmds = DebuggerCommands::parse_from(
1371+
&self.testpaths.file,
1372+
self.config,
1373+
prefixes,
1374+
self.revision,
1375+
)
1376+
.unwrap_or_else(|e| self.fatal(&e));
13851377

13861378
// Write debugger script:
13871379
// We don't want to hang when calling `quit` while the process is still running
@@ -1430,15 +1422,15 @@ impl<'test> TestCx<'test> {
14301422

14311423
// Set breakpoints on every line that contains the string "#break"
14321424
let source_file_name = self.testpaths.file.file_name().unwrap().to_string_lossy();
1433-
for line in &breakpoint_lines {
1425+
for line in &dbg_cmds.breakpoint_lines {
14341426
script_str.push_str(&format!(
14351427
"breakpoint set --file '{}' --line {}\n",
14361428
source_file_name, line
14371429
));
14381430
}
14391431

14401432
// Append the other commands
1441-
for line in &commands {
1433+
for line in &dbg_cmds.commands {
14421434
script_str.push_str(line);
14431435
script_str.push_str("\n");
14441436
}
@@ -1458,7 +1450,7 @@ impl<'test> TestCx<'test> {
14581450
self.fatal_proc_rec("Error while running LLDB", &debugger_run_result);
14591451
}
14601452

1461-
if let Err(e) = check_debugger_output(&debugger_run_result, &check_lines) {
1453+
if let Err(e) = dbg_cmds.check_output(&debugger_run_result) {
14621454
self.fatal_proc_rec(&e, &debugger_run_result);
14631455
}
14641456
}

0 commit comments

Comments
 (0)