Skip to content

Commit 4c9236b

Browse files
artemmukhinyopox
authored andcommitted
T: Split debugger settings for pretty-printers tests
* Each `Settings_%os%.toml` file can now contain separate sections to configure tests for GDB and LLDB * `native_rust` flag is no longer used for GDB because any GDB since version 7.12 provides native Rust support
1 parent 409dc09 commit 4c9236b

14 files changed

+144
-96
lines changed
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
test_dir = "./tests"
22
pretty_printers_path = "./../prettyPrinters/"
33
print_stdout = true
4-
native_rust = false
4+
5+
[lldb]
6+
python = "python3"
57
lldb_batchmode = "./lldb_batchmode.py"
68
lldb_lookup = "lldb_lookup"
7-
python = "python3"
9+
native_rust = true
10+
11+
[gdb]
812
gdb_lookup = "gdb_lookup"
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
test_dir = "./tests"
22
pretty_printers_path = "./../prettyPrinters/"
33
print_stdout = true
4-
native_rust = false
4+
5+
[lldb]
6+
python = "python"
57
lldb_batchmode = "./lldb_batchmode.py"
68
lldb_lookup = "lldb_lookup"
7-
python = "python"
9+
native_rust = false
10+
11+
[gdb]
812
gdb_lookup = "gdb_lookup"

pretty_printers_tests/src/main.rs

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,20 @@ struct Settings {
2626
test_dir: String,
2727
pretty_printers_path: String,
2828
print_stdout: bool,
29-
native_rust: bool,
29+
lldb: Option<LLDBSettings>,
30+
gdb: Option<GDBSettings>,
31+
}
32+
33+
#[derive(Deserialize)]
34+
struct LLDBSettings {
35+
python: String,
3036
lldb_batchmode: String,
3137
lldb_lookup: String,
32-
python: String,
38+
native_rust: bool
39+
}
40+
41+
#[derive(Deserialize)]
42+
struct GDBSettings {
3343
gdb_lookup: String
3444
}
3545

@@ -55,25 +65,30 @@ fn test(debugger: Debugger, path: String) -> Result<(), ()> {
5565
let settings: Settings = toml::from_str(&settings).expect(&format!("Invalid {}", SETTINGS));
5666

5767
let config = match debugger {
58-
Debugger::LLDB => Config::LLDB(LLDBConfig {
59-
test_dir: settings.test_dir.clone(),
60-
pretty_printers_path: settings.pretty_printers_path,
61-
lldb_batchmode: settings.lldb_batchmode,
62-
lldb_lookup: settings.lldb_lookup,
63-
lldb_python: path,
64-
python: settings.python,
65-
print_stdout: settings.print_stdout,
66-
native_rust: settings.native_rust,
67-
}),
68-
69-
Debugger::GDB => Config::GDB(GDBConfig {
70-
test_dir: settings.test_dir.clone(),
71-
pretty_printers_path: settings.pretty_printers_path,
72-
gdb: path,
73-
gdb_lookup: settings.gdb_lookup,
74-
print_stdout: settings.print_stdout,
75-
native_rust: settings.native_rust,
76-
})
68+
Debugger::LLDB => {
69+
let lldb_settings = settings.lldb.expect(&format!("No LLDB settings in {}", SETTINGS));
70+
Config::LLDB(LLDBConfig {
71+
test_dir: settings.test_dir.clone(),
72+
pretty_printers_path: settings.pretty_printers_path,
73+
print_stdout: settings.print_stdout,
74+
lldb_python: path,
75+
lldb_batchmode: lldb_settings.lldb_batchmode,
76+
lldb_lookup: lldb_settings.lldb_lookup,
77+
python: lldb_settings.python,
78+
native_rust: lldb_settings.native_rust,
79+
})
80+
},
81+
82+
Debugger::GDB => {
83+
let gdb_settings = settings.gdb.expect(&format!("No GDB settings in {}", SETTINGS));
84+
Config::GDB(GDBConfig {
85+
test_dir: settings.test_dir.clone(),
86+
pretty_printers_path: settings.pretty_printers_path,
87+
print_stdout: settings.print_stdout,
88+
gdb: path,
89+
gdb_lookup: gdb_settings.gdb_lookup,
90+
})
91+
}
7792
};
7893

7994
let src_dir = Path::new(&settings.test_dir);

pretty_printers_tests/src/test_runner.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,21 @@ pub enum Debugger { LLDB, GDB }
2525
pub struct LLDBConfig {
2626
pub test_dir: String,
2727
pub pretty_printers_path: String,
28+
pub print_stdout: bool,
29+
pub lldb_python: String,
2830
pub lldb_batchmode: String,
2931
pub lldb_lookup: String,
30-
pub lldb_python: String,
3132
pub python: String,
32-
pub print_stdout: bool,
3333
pub native_rust: bool,
3434
}
3535

3636
#[derive(Clone)]
3737
pub struct GDBConfig {
3838
pub test_dir: String,
3939
pub pretty_printers_path: String,
40+
pub print_stdout: bool,
4041
pub gdb: String,
4142
pub gdb_lookup: String,
42-
pub print_stdout: bool,
43-
pub native_rust: bool,
4443
}
4544

4645
#[derive(Clone)]
@@ -119,13 +118,7 @@ impl<'test> GDBTestRunner<'test> {
119118

120119
impl<'test> TestRunner<'test> for GDBTestRunner<'test> {
121120
fn run(&self) -> TestResult {
122-
let prefixes = if self.config.native_rust {
123-
static PREFIXES: &'static [&'static str] = &["gdb", "gdbr"];
124-
PREFIXES
125-
} else {
126-
static PREFIXES: &'static [&'static str] = &["gdb", "gdbg"];
127-
PREFIXES
128-
};
121+
let prefixes: &'static [&'static str] = &["gdb"];
129122

130123
// Parse debugger commands etc from test files
131124
let (commands, check_lines, breakpoint_lines) = match parse_debugger_commands(self.src_path, prefixes) {
@@ -164,9 +157,7 @@ impl<'test> TestRunner<'test> for GDBTestRunner<'test> {
164157
script_str.push_str(&format!("file {}\n", exe_file.to_str().unwrap()));
165158

166159
// Force GDB to print values in the Rust format.
167-
if self.config.native_rust {
168-
script_str.push_str("set language rust\n");
169-
}
160+
script_str.push_str("set language rust\n");
170161

171162
// Add line breakpoints
172163
let source_file_name = self.src_path.file_name().unwrap().to_string_lossy();
@@ -222,6 +213,9 @@ impl<'test> LLDBTestRunner<'test> {
222213

223214
impl<'test> TestRunner<'test> for LLDBTestRunner<'test> {
224215
fn run(&self) -> TestResult {
216+
// If `native_rust = true` in the `Settings_%os%.toml` configuration file,
217+
// the test runner will execute all commands that start with `lldb` or `lldbr`.
218+
// Otherwise, the test runner will execute commands that start with `lldb` or `lldbg`.
225219
let prefixes = if self.config.native_rust {
226220
static PREFIXES: &'static [&'static str] = &["lldb", "lldbr"];
227221
PREFIXES

pretty_printers_tests/tests/btree.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
// gdb-command:run
66

77
// gdb-command: print btree_set
8-
// gdbg-check:$1 = size=15 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}
8+
// gdb-check:$1 = size=15 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}
99

1010
// gdb-command: print btree_map
11-
// gdbg-check:$2 = size=15 = {[0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 5, [6] = 6, [7] = 7, [8] = 8, [9] = 9, [10] = 10, [11] = 11, [12] = 12, [13] = 13, [14] = 14}
11+
// gdb-check:$2 = size=15 = {[0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 5, [6] = 6, [7] = 7, [8] = 8, [9] = 9, [10] = 10, [11] = 11, [12] = 12, [13] = 13, [14] = 14}
1212

1313
// gdb-command: print zst_btree_map
14-
// gdbg-check:$3 = size=1 = {[()] = ()}
14+
// gdb-check:$3 = size=1 = {[()] = ()}
1515

1616
// gdb-command: print zst_btree_set
17-
// gdbg-check:$4 = size=1 = {()}
17+
// gdb-check:$4 = size=1 = {()}
1818

1919
use std::collections::{BTreeMap, BTreeSet};
2020

pretty_printers_tests/tests/enum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
// gdb-command:run
66

77
// gdb-command:print a
8-
// gdbg-check:[...]$1 = enum::EnumA::Var3 = {Var3 = enum::EnumA::Var3 = {a = 5, b = enum::TestEnumB::Var2 = {Var2 = enum::TestEnumB::Var2 = {a = 5, b = "hello", c = enum::EnumC[...] = {Var1 = size=1 = {8}}}}}}
8+
// gdb-check:[...]$1 = enum::EnumA::Var3 = {Var3 = enum::EnumA::Var3 = {a = 5, b = enum::TestEnumB::Var2 = {Var2 = enum::TestEnumB::Var2 = {a = 5, b = "hello", c = enum::EnumC[...] = {Var1 = size=1 = {8}}}}}}
99

1010
// gdb-command:print d
11-
// gdbg-check:[...]$2 = enum::EnumD
11+
// gdb-check:[...]$2 = enum::EnumD
1212

1313
enum EnumA {
1414
Var1 { a: u32 },

pretty_printers_tests/tests/ffi_strings.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,47 @@
66
// lldb-command:run
77

88
// lldb-command:print os_string
9-
// lldbg-check:[...]os_string = "A∆й中" [...]
9+
// lldbr-check:[...]os_string = "A∆й中" [...]
10+
// lldbg-check:[...]$0 = "A∆й中" [...]
1011
// lldb-command:print empty_os_string
11-
// lldbg-check:[...]empty_os_string = "" [...]
12+
// lldbr-check:[...]empty_os_string = "" [...]
13+
// lldbg-check:[...]$1 = "" [...]
1214
// lldb-command:print c_string1
13-
// lldbg-check:[...]c_string1 = "A∆й中" [...]
15+
// lldbr-check:[...]c_string1 = "A∆й中" [...]
16+
// lldbg-check:[...]$2 = "A∆й中" [...]
1417
// lldb-command:print path_buf
15-
// lldbg-check:[...]path_buf = "/a/b/∂" [...]
18+
// lldbr-check:[...]path_buf = "/a/b/∂" [...]
19+
// lldbg-check:[...]$3 = "/a/b/∂" [...]
1620
// lldb-command:print empty_path_buf
17-
// lldbg-check:[...]empty_path_buf = "" [...]
21+
// lldbr-check:[...]empty_path_buf = "" [...]
22+
// lldbg-check:[...]$4 = "" [...]
1823
// lldb-command:print os_str1
19-
// lldbg-check:[...]os_str1 = [...] "A∆й中"
24+
// lldbr-check:[...]os_str1 = [...] "A∆й中"
25+
// lldbg-check:[...]$5 = [...] "A∆й中"
2026
// lldb-command:print os_str2
21-
// lldbg-check:[...]os_str2 = [...] "A∆й中"
27+
// lldbr-check:[...]os_str2 = [...] "A∆й中"
28+
// lldbg-check:[...]$6 = [...] "A∆й中"
2229
// lldb-command:print empty_os_str
23-
// lldbg-check:[...]empty_os_str = [...] ""
30+
// lldbr-check:[...]empty_os_str = [...] ""
31+
// lldbg-check:[...]$7 = [...] ""
2432
// lldb-command:print path1
25-
// lldbg-check:[...]path1 = [...] "/a/b/∂"
33+
// lldbr-check:[...]path1 = [...] "/a/b/∂"
34+
// lldbg-check:[...]$8 = [...] "/a/b/∂"
2635
// lldb-command:print empty_path
27-
// lldbg-check:[...]empty_path = [...] ""
36+
// lldbr-check:[...]empty_path = [...] ""
37+
// lldbg-check:[...]$9 = [...] ""
2838
// lldb-command:print c_str1
29-
// lldbg-check:[...]c_str1 = [...] "abcd"
39+
// lldbr-check:[...]c_str1 = [...] "abcd"
40+
// lldbg-check:[...]$10 = [...] "abcd"
3041

3142
// === GDB TESTS ==================================================================================
3243

3344
// gdb-command:run
3445

3546
// gdb-command:print os_string
36-
// gdbg-check:[...]$1 = "A∆й中"
47+
// gdb-check:[...]$1 = "A∆й中"
3748
// gdb-command:print empty_os_string
38-
// gdbg-check:[...]$2 = ""
49+
// gdb-check:[...]$2 = ""
3950

4051

4152
use std::ffi::{CStr, CString, OsStr, OsString};

pretty_printers_tests/tests/hash_map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
// lldb-command:run
66

77
// lldb-command:print xs
8-
// lldbg-check:[...]xs = size=4 { [0] = { 0 = 1 1 = 10 } [1] = { 0 = 2 1 = 20 } [2] = { 0 = 3 1 = 30 } [3] = { 0 = 4 1 = 40 } }
8+
// lldbr-check:[...]xs = size=4 { [0] = { 0 = 1 1 = 10 } [1] = { 0 = 2 1 = 20 } [2] = { 0 = 3 1 = 30 } [3] = { 0 = 4 1 = 40 } }
99
// lldb-command:print ys
10-
// lldbg-check:[...]ys = size=4 { [0] = 1 [1] = 2 [2] = 3 [3] = 4 }
10+
// lldbr-check:[...]ys = size=4 { [0] = 1 [1] = 2 [2] = 3 [3] = 4 }
1111

1212
// === GDB TESTS ===================================================================================
1313

1414
// gdb-command:run
1515

1616
// gdb-command:print xs
17-
// gdbg-check:[...]$1 = size=4 = {[1] = 10, [2] = 20, [3] = 30, [4] = 40}
17+
// gdb-check:[...]$1 = size=4 = {[1] = 10, [2] = 20, [3] = 30, [4] = 40}
1818
// gdb-command:print ys
19-
// gdbg-check:[...]$2 = size=4 = {1, 2, 3, 4}
19+
// gdb-check:[...]$2 = size=4 = {1, 2, 3, 4}
2020

2121

2222
use std::collections::{HashMap, HashSet};

pretty_printers_tests/tests/nonzero.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33
// lldb-command:run
44

55
// lldb-command:print a
6-
// lldbg-check:[...]a = -1 [...]
6+
// lldbr-check:[...]a = -1 [...]
7+
// lldbg-check:[...]$0 = -1 [...]
78
// lldb-command:print b
8-
// lldbg-check:[...]b = 1024 [...]
9+
// lldbr-check:[...]b = 1024 [...]
10+
// lldbg-check:[...]$1 = 1024 [...]
911

1012
// === GDB TESTS ===================================================================================
1113

1214
// gdb-command:run
1315

1416
// gdb-command:print a
15-
// gdbg-check:[...]$1 = -1
17+
// gdb-check:[...]$1 = -1
1618

1719
// gdb-command:print b
18-
// gdbg-check:[...]$2 = 1024
20+
// gdb-check:[...]$2 = 1024
1921

2022
use std::num::{NonZeroI32, NonZeroUsize};
2123

pretty_printers_tests/tests/rc_arc.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55
// lldb-command:run
66

77
// lldb-command:print r
8-
// lldbg-check:[...]r = strong=2, weak=1 { value = 42 }
8+
// lldbr-check:[...]r = strong=2, weak=1 { value = 42 }
9+
// lldbg-check:[...]$0 = strong=2, weak=1 { value = 42 }
910
// lldb-command:print a
10-
// lldbg-check:[...]a = strong=2, weak=1 { data = 42 }
11+
// lldbr-check:[...]a = strong=2, weak=1 { data = 42 }
12+
// lldbg-check:[...]$1 = strong=2, weak=1 { data = 42 }
1113

1214
// === GDB TESTS ==================================================================================
1315

1416
// gdb-command:run
1517

1618
// gdb-command:print r
17-
// gdbg-check:[...]$1 = strong=2, weak=1 = {value = 42, strong = 2, weak = 1}
19+
// gdb-check:[...]$1 = strong=2, weak=1 = {value = 42, strong = 2, weak = 1}
1820
// gdb-command:print a
19-
// gdbg-check:[...]$2 = strong=2, weak=1 = {value = 42, strong = 2, weak = 1}
21+
// gdb-check:[...]$2 = strong=2, weak=1 = {value = 42, strong = 2, weak = 1}
2022

2123
use std::rc::Rc;
2224
use std::sync::Arc;

pretty_printers_tests/tests/string.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,48 @@
33
// lldb-command:run
44

55
// lldb-command:print s1
6-
// lldbg-check:[...]s1 = "A∆й中" [...]
6+
// lldbr-check:[...]s1 = "A∆й中" [...]
7+
// lldbg-check:[...]$0 = "A∆й中" [...]
78
// lldb-command:print s2
8-
// lldbg-check:[...]s2 = "A∆й中" [...]
9+
// lldbr-check:[...]s2 = "A∆й中" [...]
10+
// lldbg-check:[...]$1 = "A∆й中" [...]
911
// lldb-command:print s3
10-
// lldbg-check:[...]s3 = "A∆й中" [...]
12+
// lldbr-check:[...]s3 = "A∆й中" [...]
13+
// lldbg-check:[...]$2 = "A∆й中" [...]
1114
// lldb-command:print s4
12-
// lldbg-check:[...]s4 = "A∆й中" [...]
15+
// lldbr-check:[...]s4 = "A∆й中" [...]
16+
// lldbg-check:[...]$3 = "A∆й中" [...]
1317
// lldb-command:print s5
14-
// lldbg-check:[...]s5 = "A∆й中" [...]
18+
// lldbr-check:[...]s5 = "A∆й中" [...]
19+
// lldbg-check:[...]$4 = "A∆й中" [...]
1520
// lldb-command:print empty_s1
16-
// lldbg-check:[...]empty_s1 = "" [...]
21+
// lldbr-check:[...]empty_s1 = "" [...]
22+
// lldbg-check:[...]$5 = "" [...]
1723
// lldb-command:print empty_s2
18-
// lldbg-check:[...]empty_s2 = "" [...]
24+
// lldbr-check:[...]empty_s2 = "" [...]
25+
// lldbg-check:[...]$6 = "" [...]
1926
// lldb-command:print empty_s3
20-
// lldbg-check:[...]empty_s3 = "" [...]
27+
// lldbr-check:[...]empty_s3 = "" [...]
28+
// lldbg-check:[...]$7 = "" [...]
2129
// lldb-command:print empty_s4
22-
// lldbg-check:[...]empty_s4 = "" [...]
30+
// lldbr-check:[...]empty_s4 = "" [...]
31+
// lldbg-check:[...]$8 = "" [...]
2332
// lldb-command:print empty_s5
24-
// lldbg-check:[...]empty_s5 = "" [...]
33+
// lldbr-check:[...]empty_s5 = "" [...]
34+
// lldbg-check:[...]$9 = "" [...]
2535

2636
// === GDB TESTS ==================================================================================
2737

2838
// gdb-command:run
2939

3040
// gdb-command:print s1
31-
// gdbg-check:[...]$1 = "A∆й中"
41+
// gdb-check:[...]$1 = "A∆й中"
3242
// gdb-command:print s2
33-
// gdbg-check:[...]$2 = "A∆й中"
43+
// gdb-check:[...]$2 = "A∆й中"
3444
// gdb-command:print empty_s1
35-
// gdbg-check:[...]$3 = ""
45+
// gdb-check:[...]$3 = ""
3646
// gdb-command:print empty_s2
37-
// gdbg-check:[...]$4 = ""
47+
// gdb-check:[...]$4 = ""
3848

3949

4050
fn main() {

0 commit comments

Comments
 (0)