Skip to content

Commit ac66b04

Browse files
committed
Run both lldb and gdb tests
Currently lldb tests are run only on macOS, and gdb tests are only run elsewhere. This patch changes this to run tests depending on what is available. One test is changed, as it was previously marked as failing on macOS, whereas really it is a generic failure with lldb. Closes #54721
1 parent 71d3a71 commit ac66b04

File tree

6 files changed

+183
-62
lines changed

6 files changed

+183
-62
lines changed

src/bootstrap/test.rs

+6-14
Original file line numberDiff line numberDiff line change
@@ -812,8 +812,7 @@ default_test!(Incremental {
812812

813813
default_test!(Debuginfo {
814814
path: "src/test/debuginfo",
815-
// What this runs varies depending on the native platform being apple
816-
mode: "debuginfo-XXX",
815+
mode: "debuginfo",
817816
suite: "debuginfo"
818817
});
819818

@@ -950,18 +949,11 @@ impl Step for Compiletest {
950949
return;
951950
}
952951

953-
if mode == "debuginfo-XXX" {
954-
return if builder.config.build.contains("apple") {
955-
builder.ensure(Compiletest {
956-
mode: "debuginfo-lldb",
957-
..self
958-
});
959-
} else {
960-
builder.ensure(Compiletest {
961-
mode: "debuginfo-gdb",
962-
..self
963-
});
964-
};
952+
if mode == "debuginfo" {
953+
return builder.ensure(Compiletest {
954+
mode: "debuginfo-both",
955+
..self
956+
});
965957
}
966958

967959
builder.ensure(dist::DebuggerScripts {

src/test/debuginfo/lexical-scope-with-macro.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
// min-lldb-version: 310
12-
// ignore-macos FIXME #48807
12+
// ignore-lldb FIXME #48807
1313

1414
// compile-flags:-g -Zdebug-macros
1515

src/tools/compiletest/src/common.rs

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub enum Mode {
2525
RunPass,
2626
RunPassValgrind,
2727
Pretty,
28+
DebugInfoBoth,
2829
DebugInfoGdb,
2930
DebugInfoLldb,
3031
Codegen,
@@ -60,6 +61,7 @@ impl FromStr for Mode {
6061
"run-pass" => Ok(RunPass),
6162
"run-pass-valgrind" => Ok(RunPassValgrind),
6263
"pretty" => Ok(Pretty),
64+
"debuginfo-both" => Ok(DebugInfoBoth),
6365
"debuginfo-lldb" => Ok(DebugInfoLldb),
6466
"debuginfo-gdb" => Ok(DebugInfoGdb),
6567
"codegen" => Ok(Codegen),
@@ -83,6 +85,7 @@ impl fmt::Display for Mode {
8385
RunPass => "run-pass",
8486
RunPassValgrind => "run-pass-valgrind",
8587
Pretty => "pretty",
88+
DebugInfoBoth => "debuginfo-both",
8689
DebugInfoGdb => "debuginfo-gdb",
8790
DebugInfoLldb => "debuginfo-lldb",
8891
Codegen => "codegen",

src/tools/compiletest/src/header.rs

+130-27
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,62 @@ use util;
1919

2020
use extract_gdb_version;
2121

22+
/// Whether to ignore the test.
23+
#[derive(Clone, Copy, PartialEq, Debug)]
24+
pub enum Ignore {
25+
/// Run it.
26+
Run,
27+
/// Ignore it totally.
28+
Ignore,
29+
/// Ignore only the gdb test, but run the lldb test.
30+
IgnoreGdb,
31+
/// Ignore only the lldb test, but run the gdb test.
32+
IgnoreLldb,
33+
}
34+
35+
impl Ignore {
36+
pub fn can_run_gdb(&self) -> bool {
37+
*self == Ignore::Run || *self == Ignore::IgnoreLldb
38+
}
39+
40+
pub fn can_run_lldb(&self) -> bool {
41+
*self == Ignore::Run || *self == Ignore::IgnoreGdb
42+
}
43+
44+
pub fn no_gdb(&self) -> Ignore {
45+
match *self {
46+
Ignore::Run => Ignore::IgnoreGdb,
47+
Ignore::IgnoreGdb => Ignore::IgnoreGdb,
48+
_ => Ignore::Ignore,
49+
}
50+
}
51+
52+
pub fn no_lldb(&self) -> Ignore {
53+
match *self {
54+
Ignore::Run => Ignore::IgnoreLldb,
55+
Ignore::IgnoreLldb => Ignore::IgnoreLldb,
56+
_ => Ignore::Ignore,
57+
}
58+
}
59+
}
60+
61+
/// The result of parse_cfg_name_directive.
62+
#[derive(Clone, Copy, PartialEq, Debug)]
63+
enum ParsedNameDirective {
64+
/// No match.
65+
NoMatch,
66+
/// Match.
67+
Match,
68+
/// Mode was DebugInfoBoth and this matched gdb.
69+
MatchGdb,
70+
/// Mode was DebugInfoBoth and this matched lldb.
71+
MatchLldb,
72+
}
73+
2274
/// Properties which must be known very early, before actually running
2375
/// the test.
2476
pub struct EarlyProps {
25-
pub ignore: bool,
77+
pub ignore: Ignore,
2678
pub should_fail: bool,
2779
pub aux: Vec<String>,
2880
pub revisions: Vec<String>,
@@ -31,20 +83,55 @@ pub struct EarlyProps {
3183
impl EarlyProps {
3284
pub fn from_file(config: &Config, testfile: &Path) -> Self {
3385
let mut props = EarlyProps {
34-
ignore: false,
86+
ignore: Ignore::Run,
3587
should_fail: false,
3688
aux: Vec::new(),
3789
revisions: vec![],
3890
};
3991

92+
if config.mode == common::DebugInfoBoth {
93+
if config.lldb_python_dir.is_none() {
94+
props.ignore = props.ignore.no_lldb();
95+
}
96+
if config.gdb_version.is_none() {
97+
props.ignore = props.ignore.no_gdb();
98+
}
99+
}
100+
40101
iter_header(testfile, None, &mut |ln| {
41102
// we should check if any only-<platform> exists and if it exists
42103
// and does not matches the current platform, skip the test
43-
props.ignore = props.ignore || config.parse_cfg_name_directive(ln, "ignore")
44-
|| (config.has_cfg_prefix(ln, "only")
45-
&& !config.parse_cfg_name_directive(ln, "only"))
46-
|| ignore_gdb(config, ln) || ignore_lldb(config, ln)
47-
|| ignore_llvm(config, ln);
104+
if props.ignore != Ignore::Ignore {
105+
props.ignore = match config.parse_cfg_name_directive(ln, "ignore") {
106+
ParsedNameDirective::Match => Ignore::Ignore,
107+
ParsedNameDirective::NoMatch => props.ignore,
108+
ParsedNameDirective::MatchGdb => props.ignore.no_gdb(),
109+
ParsedNameDirective::MatchLldb => props.ignore.no_lldb(),
110+
};
111+
112+
if config.has_cfg_prefix(ln, "only") {
113+
props.ignore = match config.parse_cfg_name_directive(ln, "only") {
114+
ParsedNameDirective::Match => props.ignore,
115+
ParsedNameDirective::NoMatch => Ignore::Ignore,
116+
ParsedNameDirective::MatchLldb => props.ignore.no_gdb(),
117+
ParsedNameDirective::MatchGdb => props.ignore.no_lldb(),
118+
};
119+
}
120+
121+
if ignore_llvm(config, ln) {
122+
props.ignore = Ignore::Ignore;
123+
}
124+
}
125+
126+
if (config.mode == common::DebugInfoGdb || config.mode == common::DebugInfoBoth) &&
127+
props.ignore.can_run_gdb() && ignore_gdb(config, ln) {
128+
props.ignore = props.ignore.no_gdb();
129+
}
130+
131+
if (config.mode == common::DebugInfoLldb || config.mode == common::DebugInfoBoth) &&
132+
props.ignore.can_run_lldb() && ignore_lldb(config, ln) {
133+
props.ignore = props.ignore.no_lldb();
134+
}
48135

49136
if let Some(s) = config.parse_aux_build(ln) {
50137
props.aux.push(s);
@@ -60,10 +147,6 @@ impl EarlyProps {
60147
return props;
61148

62149
fn ignore_gdb(config: &Config, line: &str) -> bool {
63-
if config.mode != common::DebugInfoGdb {
64-
return false;
65-
}
66-
67150
if let Some(actual_version) = config.gdb_version {
68151
if line.starts_with("min-gdb-version") {
69152
let (start_ver, end_ver) = extract_gdb_version_range(line);
@@ -120,10 +203,6 @@ impl EarlyProps {
120203
}
121204

122205
fn ignore_lldb(config: &Config, line: &str) -> bool {
123-
if config.mode != common::DebugInfoLldb {
124-
return false;
125-
}
126-
127206
if let Some(ref actual_version) = config.lldb_version {
128207
if line.starts_with("min-lldb-version") {
129208
let min_version = line.trim_right()
@@ -604,7 +683,7 @@ impl Config {
604683
}
605684

606685
fn parse_custom_normalization(&self, mut line: &str, prefix: &str) -> Option<(String, String)> {
607-
if self.parse_cfg_name_directive(line, prefix) {
686+
if self.parse_cfg_name_directive(line, prefix) == ParsedNameDirective::Match {
608687
let from = match parse_normalization_string(&mut line) {
609688
Some(s) => s,
610689
None => return None,
@@ -620,35 +699,59 @@ impl Config {
620699
}
621700

622701
/// Parses a name-value directive which contains config-specific information, e.g. `ignore-x86`
623-
/// or `normalize-stderr-32bit`. Returns `true` if the line matches it.
624-
fn parse_cfg_name_directive(&self, line: &str, prefix: &str) -> bool {
702+
/// or `normalize-stderr-32bit`.
703+
fn parse_cfg_name_directive(&self, line: &str, prefix: &str) -> ParsedNameDirective {
625704
if line.starts_with(prefix) && line.as_bytes().get(prefix.len()) == Some(&b'-') {
626705
let name = line[prefix.len() + 1..]
627706
.split(&[':', ' '][..])
628707
.next()
629708
.unwrap();
630709

631-
name == "test" ||
710+
if name == "test" ||
632711
util::matches_os(&self.target, name) || // target
633712
name == util::get_arch(&self.target) || // architecture
634713
name == util::get_pointer_width(&self.target) || // pointer width
635714
name == self.stage_id.split('-').next().unwrap() || // stage
636715
Some(name) == util::get_env(&self.target) || // env
637-
match self.mode {
638-
common::DebugInfoGdb => name == "gdb",
639-
common::DebugInfoLldb => name == "lldb",
640-
common::Pretty => name == "pretty",
641-
_ => false,
642-
} ||
643716
(self.target != self.host && name == "cross-compile") ||
644717
match self.compare_mode {
645718
Some(CompareMode::Nll) => name == "compare-mode-nll",
646719
Some(CompareMode::Polonius) => name == "compare-mode-polonius",
647720
None => false,
648721
} ||
649-
(cfg!(debug_assertions) && name == "debug")
722+
(cfg!(debug_assertions) && name == "debug") {
723+
ParsedNameDirective::Match
724+
} else {
725+
match self.mode {
726+
common::DebugInfoBoth => {
727+
if name == "gdb" {
728+
ParsedNameDirective::MatchGdb
729+
} else if name == "lldb" {
730+
ParsedNameDirective::MatchLldb
731+
} else {
732+
ParsedNameDirective::NoMatch
733+
}
734+
},
735+
common::DebugInfoGdb => if name == "gdb" {
736+
ParsedNameDirective::Match
737+
} else {
738+
ParsedNameDirective::NoMatch
739+
},
740+
common::DebugInfoLldb => if name == "lldb" {
741+
ParsedNameDirective::Match
742+
} else {
743+
ParsedNameDirective::NoMatch
744+
},
745+
common::Pretty => if name == "pretty" {
746+
ParsedNameDirective::Match
747+
} else {
748+
ParsedNameDirective::NoMatch
749+
},
750+
_ => ParsedNameDirective::NoMatch,
751+
}
752+
}
650753
} else {
651-
false
754+
ParsedNameDirective::NoMatch
652755
}
653756
}
654757

src/tools/compiletest/src/main.rs

+25-9
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extern crate rustfix;
3232
use common::CompareMode;
3333
use common::{expected_output_path, output_base_dir, output_relative_path, UI_EXTENSIONS};
3434
use common::{Config, TestPaths};
35-
use common::{DebugInfoGdb, DebugInfoLldb, Mode, Pretty};
35+
use common::{DebugInfoBoth, DebugInfoGdb, DebugInfoLldb, Mode, Pretty};
3636
use filetime::FileTime;
3737
use getopts::Options;
3838
use std::env;
@@ -44,7 +44,7 @@ use std::process::Command;
4444
use test::ColorConfig;
4545
use util::logv;
4646

47-
use self::header::EarlyProps;
47+
use self::header::{EarlyProps, Ignore};
4848

4949
pub mod common;
5050
pub mod errors;
@@ -425,7 +425,7 @@ pub fn opt_str2(maybestr: Option<String>) -> String {
425425

426426
pub fn run_tests(config: &Config) {
427427
if config.target.contains("android") {
428-
if let DebugInfoGdb = config.mode {
428+
if config.mode == DebugInfoGdb || config.mode == DebugInfoBoth {
429429
println!(
430430
"{} debug-info test uses tcp 5039 port.\
431431
please reserve it",
@@ -443,7 +443,9 @@ pub fn run_tests(config: &Config) {
443443
}
444444

445445
match config.mode {
446-
DebugInfoLldb => {
446+
// Note that we don't need to emit the gdb warning when
447+
// DebugInfoBoth, so it is ok to list that here.
448+
DebugInfoBoth | DebugInfoLldb => {
447449
if let Some(lldb_version) = config.lldb_version.as_ref() {
448450
if is_blacklisted_lldb_version(&lldb_version[..]) {
449451
println!(
@@ -647,23 +649,26 @@ pub fn make_test(config: &Config, testpaths: &TestPaths) -> Vec<test::TestDescAn
647649
.into_iter()
648650
.map(|revision| {
649651
// Debugging emscripten code doesn't make sense today
650-
let ignore = early_props.ignore
652+
let ignore = early_props.ignore == Ignore::Ignore
651653
|| !up_to_date(
652654
config,
653655
testpaths,
654656
&early_props,
655657
revision.map(|s| s.as_str()),
656658
)
657-
|| (config.mode == DebugInfoGdb || config.mode == DebugInfoLldb)
658-
&& config.target.contains("emscripten");
659+
|| ((config.mode == DebugInfoBoth ||
660+
config.mode == DebugInfoGdb || config.mode == DebugInfoLldb)
661+
&& config.target.contains("emscripten"))
662+
|| (config.mode == DebugInfoGdb && !early_props.ignore.can_run_gdb())
663+
|| (config.mode == DebugInfoLldb && !early_props.ignore.can_run_lldb());
659664
test::TestDescAndFn {
660665
desc: test::TestDesc {
661666
name: make_test_name(config, testpaths, revision),
662667
ignore,
663668
should_panic,
664669
allow_fail: false,
665670
},
666-
testfn: make_test_closure(config, testpaths, revision),
671+
testfn: make_test_closure(config, early_props.ignore, testpaths, revision),
667672
}
668673
})
669674
.collect()
@@ -774,10 +779,21 @@ fn make_test_name(
774779

775780
fn make_test_closure(
776781
config: &Config,
782+
ignore: Ignore,
777783
testpaths: &TestPaths,
778784
revision: Option<&String>,
779785
) -> test::TestFn {
780-
let config = config.clone();
786+
let mut config = config.clone();
787+
if config.mode == DebugInfoBoth {
788+
// If both gdb and lldb were ignored, then the test as a whole
789+
// would be ignored.
790+
if !ignore.can_run_gdb() {
791+
config.mode = DebugInfoLldb;
792+
} else if !ignore.can_run_lldb() {
793+
config.mode = DebugInfoGdb;
794+
}
795+
}
796+
781797
let testpaths = testpaths.clone();
782798
let revision = revision.cloned();
783799
test::DynTestFn(Box::new(move || {

0 commit comments

Comments
 (0)