From 45382e64cfe21c2638365540bda9c1bc48619b99 Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Tue, 19 Jul 2022 18:27:33 -0700 Subject: [PATCH 1/3] compiletest: allow using revisions with debuginfo tests --- src/tools/compiletest/src/runtest.rs | 27 ++++++++++----- src/tools/compiletest/src/runtest/debugger.rs | 33 ++++++++++++++++--- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 5517b5a12c393..26730fcec4cec 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -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), @@ -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), }; @@ -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), @@ -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), }; @@ -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."); } @@ -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), }; diff --git a/src/tools/compiletest/src/runtest/debugger.rs b/src/tools/compiletest/src/runtest/debugger.rs index cbd5e4c431f56..99394c3bfbfe4 100644 --- a/src/tools/compiletest/src/runtest/debugger.rs +++ b/src/tools/compiletest/src/runtest/debugger.rs @@ -16,6 +16,7 @@ impl DebuggerCommands { file: &Path, config: &Config, debugger_prefixes: &[&str], + rev: Option<&str>, ) -> Result { let directives = debugger_prefixes .iter() @@ -25,13 +26,38 @@ 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 (line, lnrev) = if line.starts_with("//") { + let line = line[2..].trim_start(); + if line.starts_with('[') { + if let Some(close_brace) = line.find(']') { + let open_brace = line.find('[').unwrap(); + let lnrev = &line[open_brace + 1..close_brace]; + let line = line[(close_brace + 1)..].trim_start(); + (line, Some(lnrev)) + } else { + panic!( + "malformed condition direction: expected `//[foo]`, found `{}`", + line + ) + } + } else { + (line, None) + } + } else { + (line.as_str(), None) + }; + + // 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); @@ -49,7 +75,6 @@ impl DebuggerCommands { } Err(e) => return Err(format!("Error while parsing debugger commands: {}", e)), } - counter += 1; } Ok(Self { commands, check_lines, breakpoint_lines }) From 8de7f0477a08d0edb199140d3fbc9444c99e69ac Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Tue, 19 Jul 2022 18:30:12 -0700 Subject: [PATCH 2/3] Use revision support to remove near identical debuginfo test. --- src/test/debuginfo/basic-types-globals-lto.rs | 81 ------------------- src/test/debuginfo/basic-types-globals.rs | 6 ++ 2 files changed, 6 insertions(+), 81 deletions(-) delete mode 100644 src/test/debuginfo/basic-types-globals-lto.rs diff --git a/src/test/debuginfo/basic-types-globals-lto.rs b/src/test/debuginfo/basic-types-globals-lto.rs deleted file mode 100644 index 1adf278ad32de..0000000000000 --- a/src/test/debuginfo/basic-types-globals-lto.rs +++ /dev/null @@ -1,81 +0,0 @@ -// Caveat - gdb doesn't know about UTF-32 character encoding and will print a -// rust char as only its numerical value. - -// min-lldb-version: 310 -// min-gdb-version: 8.0 - -// no-prefer-dynamic -// compile-flags:-g -C lto -// gdb-command:run -// gdbg-command:print 'basic_types_globals::B' -// gdbr-command:print B -// gdb-check:$1 = false -// gdbg-command:print 'basic_types_globals::I' -// gdbr-command:print I -// gdb-check:$2 = -1 -// gdbg-command:print 'basic_types_globals::C' -// gdbr-command:print/d C -// gdbg-check:$3 = 97 -// gdbr-check:$3 = 97 -// gdbg-command:print/d 'basic_types_globals::I8' -// gdbr-command:print I8 -// gdb-check:$4 = 68 -// gdbg-command:print 'basic_types_globals::I16' -// gdbr-command:print I16 -// gdb-check:$5 = -16 -// gdbg-command:print 'basic_types_globals::I32' -// gdbr-command:print I32 -// gdb-check:$6 = -32 -// gdbg-command:print 'basic_types_globals::I64' -// gdbr-command:print I64 -// gdb-check:$7 = -64 -// gdbg-command:print 'basic_types_globals::U' -// gdbr-command:print U -// gdb-check:$8 = 1 -// gdbg-command:print/d 'basic_types_globals::U8' -// gdbr-command:print U8 -// gdb-check:$9 = 100 -// gdbg-command:print 'basic_types_globals::U16' -// gdbr-command:print U16 -// gdb-check:$10 = 16 -// gdbg-command:print 'basic_types_globals::U32' -// gdbr-command:print U32 -// gdb-check:$11 = 32 -// gdbg-command:print 'basic_types_globals::U64' -// gdbr-command:print U64 -// gdb-check:$12 = 64 -// gdbg-command:print 'basic_types_globals::F32' -// gdbr-command:print F32 -// gdb-check:$13 = 2.5 -// gdbg-command:print 'basic_types_globals::F64' -// gdbr-command:print F64 -// gdb-check:$14 = 3.5 -// gdb-command:continue - -#![allow(unused_variables)] -#![feature(omit_gdb_pretty_printer_section)] -#![omit_gdb_pretty_printer_section] - -// N.B. These are `mut` only so they don't constant fold away. -static mut B: bool = false; -static mut I: isize = -1; -static mut C: char = 'a'; -static mut I8: i8 = 68; -static mut I16: i16 = -16; -static mut I32: i32 = -32; -static mut I64: i64 = -64; -static mut U: usize = 1; -static mut U8: u8 = 100; -static mut U16: u16 = 16; -static mut U32: u32 = 32; -static mut U64: u64 = 64; -static mut F32: f32 = 2.5; -static mut F64: f64 = 3.5; - -fn main() { - _zzz(); // #break - - let a = unsafe { (B, I, C, I8, I16, I32, I64, U, U8, U16, U32, U64, F32, F64) }; -} - -fn _zzz() {()} diff --git a/src/test/debuginfo/basic-types-globals.rs b/src/test/debuginfo/basic-types-globals.rs index 3602db39a4ec1..8a3df8ba2d18e 100644 --- a/src/test/debuginfo/basic-types-globals.rs +++ b/src/test/debuginfo/basic-types-globals.rs @@ -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 From 5d7cd652942e5ce4ca7c673a6e44618bae655598 Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Tue, 19 Jul 2022 19:13:33 -0700 Subject: [PATCH 3/3] compiletest: dedup revision line logic. --- src/tools/compiletest/src/header.rs | 36 +++++++++++++------ src/tools/compiletest/src/runtest/debugger.rs | 22 ++---------- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 17f2b77dab052..02f4d29a2f05f 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -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(testfile: &Path, rdr: R, it: &mut dyn FnMut(Option<&str>, &str)) { if testfile.is_dir() { return; @@ -557,17 +580,8 @@ fn iter_header(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); } } } diff --git a/src/tools/compiletest/src/runtest/debugger.rs b/src/tools/compiletest/src/runtest/debugger.rs index 99394c3bfbfe4..379ff0bab408a 100644 --- a/src/tools/compiletest/src/runtest/debugger.rs +++ b/src/tools/compiletest/src/runtest/debugger.rs @@ -1,4 +1,5 @@ use crate::common::Config; +use crate::header::line_directive; use crate::runtest::ProcRes; use std::fs::File; @@ -32,26 +33,7 @@ impl DebuggerCommands { counter += 1; match line { Ok(line) => { - let (line, lnrev) = if line.starts_with("//") { - let line = line[2..].trim_start(); - if line.starts_with('[') { - if let Some(close_brace) = line.find(']') { - let open_brace = line.find('[').unwrap(); - let lnrev = &line[open_brace + 1..close_brace]; - let line = line[(close_brace + 1)..].trim_start(); - (line, Some(lnrev)) - } else { - panic!( - "malformed condition direction: expected `//[foo]`, found `{}`", - line - ) - } - } else { - (line, None) - } - } else { - (line.as_str(), None) - }; + let (lnrev, line) = line_directive("//", &line).unwrap_or((None, &line)); // Skip any revision specific directive that doesn't match the current // revision being tested