Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiletest: Allow using revisions with debuginfo tests. #99488

Merged
merged 3 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 0 additions & 81 deletions src/test/debuginfo/basic-types-globals-lto.rs

This file was deleted.

6 changes: 6 additions & 0 deletions src/test/debuginfo/basic-types-globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
// min-lldb-version: 310
// min-gdb-version: 8.0

// revisions: lto no-lto

// compile-flags:-g

// [lto] compile-flags:-C lto
// [lto] no-prefer-dynamic

// gdb-command:run
// gdbg-command:print 'basic_types_globals::B'
// gdbr-command:print B
Expand Down
36 changes: 25 additions & 11 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,29 @@ impl TestProps {
}
}

pub fn line_directive<'line>(
comment: &str,
ln: &'line str,
) -> Option<(Option<&'line str>, &'line str)> {
if ln.starts_with(comment) {
let ln = ln[comment.len()..].trim_start();
if ln.starts_with('[') {
// A comment like `//[foo]` is specific to revision `foo`
if let Some(close_brace) = ln.find(']') {
let lncfg = &ln[1..close_brace];

Some((Some(lncfg), ln[(close_brace + 1)..].trim_start()))
} else {
panic!("malformed condition directive: expected `{}[foo]`, found `{}`", comment, ln)
}
} else {
Some((None, ln))
}
} else {
None
}
}

fn iter_header<R: Read>(testfile: &Path, rdr: R, it: &mut dyn FnMut(Option<&str>, &str)) {
if testfile.is_dir() {
return;
Expand All @@ -557,17 +580,8 @@ fn iter_header<R: Read>(testfile: &Path, rdr: R, it: &mut dyn FnMut(Option<&str>
let ln = ln.trim();
if ln.starts_with("fn") || ln.starts_with("mod") {
return;
} else if ln.starts_with(comment) && ln[comment.len()..].trim_start().starts_with('[') {
// A comment like `//[foo]` is specific to revision `foo`
if let Some(close_brace) = ln.find(']') {
let open_brace = ln.find('[').unwrap();
let lncfg = &ln[open_brace + 1..close_brace];
it(Some(lncfg), ln[(close_brace + 1)..].trim_start());
} else {
panic!("malformed condition directive: expected `{}[foo]`, found `{}`", comment, ln)
}
} else if ln.starts_with(comment) {
it(None, ln[comment.len()..].trim_start());
} else if let Some((lncfg, ln)) = line_directive(comment, ln) {
it(lncfg, ln);
}
}
}
Expand Down
27 changes: 18 additions & 9 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,6 @@ impl<'test> TestCx<'test> {
}

fn run_debuginfo_cdb_test(&self) {
assert!(self.revision.is_none(), "revisions not relevant here");

let config = Config {
target_rustcflags: self.cleanup_debug_info_options(&self.config.target_rustcflags),
host_rustcflags: self.cleanup_debug_info_options(&self.config.host_rustcflags),
Expand Down Expand Up @@ -695,7 +693,12 @@ impl<'test> TestCx<'test> {

// Parse debugger commands etc from test files
let DebuggerCommands { commands, check_lines, breakpoint_lines, .. } =
match DebuggerCommands::parse_from(&self.testpaths.file, self.config, prefixes) {
match DebuggerCommands::parse_from(
&self.testpaths.file,
self.config,
prefixes,
self.revision,
) {
Ok(cmds) => cmds,
Err(e) => self.fatal(&e),
};
Expand Down Expand Up @@ -756,8 +759,6 @@ impl<'test> TestCx<'test> {
}

fn run_debuginfo_gdb_test(&self) {
assert!(self.revision.is_none(), "revisions not relevant here");

let config = Config {
target_rustcflags: self.cleanup_debug_info_options(&self.config.target_rustcflags),
host_rustcflags: self.cleanup_debug_info_options(&self.config.host_rustcflags),
Expand All @@ -783,7 +784,12 @@ impl<'test> TestCx<'test> {
};

let DebuggerCommands { commands, check_lines, breakpoint_lines } =
match DebuggerCommands::parse_from(&self.testpaths.file, self.config, prefixes) {
match DebuggerCommands::parse_from(
&self.testpaths.file,
self.config,
prefixes,
self.revision,
) {
Ok(cmds) => cmds,
Err(e) => self.fatal(&e),
};
Expand Down Expand Up @@ -1005,8 +1011,6 @@ impl<'test> TestCx<'test> {
}

fn run_debuginfo_lldb_test(&self) {
assert!(self.revision.is_none(), "revisions not relevant here");

if self.config.lldb_python_dir.is_none() {
self.fatal("Can't run LLDB test because LLDB's python path is not set.");
}
Expand Down Expand Up @@ -1059,7 +1063,12 @@ impl<'test> TestCx<'test> {

// Parse debugger commands etc from test files
let DebuggerCommands { commands, check_lines, breakpoint_lines, .. } =
match DebuggerCommands::parse_from(&self.testpaths.file, self.config, prefixes) {
match DebuggerCommands::parse_from(
&self.testpaths.file,
self.config,
prefixes,
self.revision,
) {
Ok(cmds) => cmds,
Err(e) => self.fatal(&e),
};
Expand Down
15 changes: 11 additions & 4 deletions src/tools/compiletest/src/runtest/debugger.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::common::Config;
use crate::header::line_directive;
use crate::runtest::ProcRes;

use std::fs::File;
Expand All @@ -16,6 +17,7 @@ impl DebuggerCommands {
file: &Path,
config: &Config,
debugger_prefixes: &[&str],
rev: Option<&str>,
) -> Result<Self, String> {
let directives = debugger_prefixes
.iter()
Expand All @@ -25,13 +27,19 @@ impl DebuggerCommands {
let mut breakpoint_lines = vec![];
let mut commands = vec![];
let mut check_lines = vec![];
let mut counter = 1;
let mut counter = 0;
let reader = BufReader::new(File::open(file).unwrap());
for line in reader.lines() {
counter += 1;
match line {
Ok(line) => {
let line =
if line.starts_with("//") { line[2..].trim_start() } else { line.as_str() };
let (lnrev, line) = line_directive("//", &line).unwrap_or((None, &line));

// Skip any revision specific directive that doesn't match the current
// revision being tested
if lnrev.is_some() && lnrev != rev {
continue;
}

if line.contains("#break") {
breakpoint_lines.push(counter);
Expand All @@ -49,7 +57,6 @@ impl DebuggerCommands {
}
Err(e) => return Err(format!("Error while parsing debugger commands: {}", e)),
}
counter += 1;
}

Ok(Self { commands, check_lines, breakpoint_lines })
Expand Down