Skip to content

Commit 3073d7e

Browse files
bors[bot]EmilgardisDisasm
committed
Merge #221
221: Improve ci r=therealprof a=Emilgardis This pr includes - Support for the changes done in v0.13 - `--toolchain foo` to specify what toolchain to build the chips with (makes building locally easier, no need to rebuild `svd2rust-regress`) - Add support for `--chip XXX YYY` - Added validators to chip, manufacturer and architecture - `-vv` will now output all stderr logs - Added `--list` to quickly troubleshoot what test cases will be run - A patched ATSAMD21G18A svd, thanks to @wez ## Open "issues" - Should we ignore case when filtering? - Should a `--chip XXX` always run even if it is set to only run on `--long-test` (and possibly `--bad-test`) - Add a `--` command to pass arguments to `svd2rust` and possibly also a way to pass arguments to `cargo check` - Colorize output - Add regress:beta test to gitlab-runner - Move test cases to a or multiple config file(s) (e.g json/toml/yaml) cc @jamesmunns Co-authored-by: Emil Gardström <[email protected]> Co-authored-by: Vadim Kaushan <[email protected]>
2 parents 1e456c1 + e6cefa5 commit 3073d7e

File tree

5 files changed

+184
-59
lines changed

5 files changed

+184
-59
lines changed

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ regress:nightly:
1515
- rustup component add rustfmt-preview
1616
- cd ci/svd2rust-regress
1717
- rm -rf ./output
18-
- cargo run --release -- --long-test --format --verbose
18+
- cargo run --release -- --long-test --format --verbose --nightly

ci/svd2rust-regress/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::PathBuf;
22
error_chain!{
33
errors {
4-
ProcessFailed(command: String, stderr: Option<PathBuf>, stdout: Option<PathBuf>) {
4+
ProcessFailed(command: String, stderr: Option<PathBuf>, stdout: Option<PathBuf>, previous_processes_stderr: Vec<PathBuf>) {
55
description("Process Failed")
66
display("Process Failed - {}", command)
77
}

ci/svd2rust-regress/src/main.rs

Lines changed: 98 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,23 @@ struct Opt {
3232
/// (which must be already built)
3333
#[structopt(short = "p", long = "svd2rust-path", parse(from_os_str))]
3434
bin_path: Option<PathBuf>,
35+
36+
// TODO: Consider using the same strategy cargo uses for passing args to rustc via `--`
37+
/// Run svd2rust with `--nightly`
38+
#[structopt(long = "nightly")]
39+
nightly: bool,
3540

3641
/// Filter by chip name, case sensitive, may be combined with other filters
37-
#[structopt(short = "c", long = "chip")]
38-
chip: Option<String>,
42+
#[structopt(short = "c", long = "chip", raw(validator = "validate_chips"))]
43+
chip: Vec<String>,
3944

4045
/// Filter by manufacturer, case sensitive, may be combined with other filters
41-
#[structopt(short = "m", long = "manufacturer")]
46+
#[structopt(short = "m", long = "manufacturer", raw(validator = "validate_manufacturer"))]
4247
mfgr: Option<String>,
4348

4449
/// Filter by architecture, case sensitive, may be combined with other filters
4550
/// Options are: "CortexM", "RiscV", and "Msp430"
46-
#[structopt(short = "a", long = "architecture")]
51+
#[structopt(short = "a", long = "architecture", raw(validator = "validate_architecture"))]
4752
arch: Option<String>,
4853

4954
/// Include tests expected to fail (will cause a non-zero return code)
@@ -54,19 +59,50 @@ struct Opt {
5459
#[structopt(short = "f", long = "format")]
5560
format: bool,
5661

62+
/// Print all available test using the specified filters
63+
#[structopt(long = "list")]
64+
list: bool,
65+
5766
/// Path to an `rustfmt` binary, relative or absolute.
5867
/// Defaults to `$(rustup which rustfmt)`
5968
#[structopt(long = "rustfmt_bin_path", parse(from_os_str))]
6069
rustfmt_bin_path: Option<PathBuf>,
6170

71+
/// Specify what rustup toolchain to use when compiling chip(s)
72+
#[structopt(long = "toolchain", env = "RUSTUP_TOOLCHAIN")]
73+
rustup_toolchain: Option<String>,
74+
6275
/// Use verbose output
6376
#[structopt(long = "verbose", short = "v", parse(from_occurrences))]
6477
verbose: u8,
6578
// TODO: Specify smaller subset of tests? Maybe with tags?
66-
// TODO: Early fail
6779
// TODO: Compile svd2rust?
6880
}
6981

82+
fn validate_chips(s: String) -> Result<(), String>{
83+
if tests::TESTS.iter().any(|t| t.chip == s) {
84+
Ok(())
85+
} else {
86+
Err(format!("Chip `{}` is not a valid value", s))
87+
}
88+
}
89+
90+
fn validate_architecture(s: String) -> Result<(), String>{
91+
if tests::TESTS.iter().any(|t| format!("{:?}", t.arch) == s) {
92+
Ok(())
93+
} else {
94+
Err(format!("Architecture `{}` is not a valid value", s))
95+
}
96+
}
97+
98+
fn validate_manufacturer(s: String) -> Result<(), String>{
99+
if tests::TESTS.iter().any(|t| format!("{:?}", t.mfgr) == s) {
100+
Ok(())
101+
} else {
102+
Err(format!("Manufacturer `{}` is not a valid value", s))
103+
}
104+
}
105+
70106
/// Validate any assumptions made by this program
71107
fn validate_tests(tests: &[&tests::TestCase]) {
72108
use std::collections::HashSet;
@@ -88,6 +124,18 @@ fn validate_tests(tests: &[&tests::TestCase]) {
88124
}
89125
}
90126

127+
fn read_file(path: &PathBuf, buf: &mut String) {
128+
if buf.is_empty() {
129+
buf.push_str(&format!("{}\n", path.display()));
130+
} else {
131+
buf.push_str(&format!("\n{}\n", path.display()));
132+
}
133+
File::open(path)
134+
.expect("Couldn't open file")
135+
.read_to_string(buf)
136+
.expect("Couldn't read file to string");
137+
}
138+
91139
fn main() {
92140
let opt = Opt::from_args();
93141

@@ -138,6 +186,12 @@ fn main() {
138186
default_rustfmt.as_ref()
139187
}
140188
};
189+
190+
// Set RUSTUP_TOOLCHAIN if needed
191+
if let Some(toolchain) = &opt.rustup_toolchain {
192+
::std::env::set_var("RUSTUP_TOOLCHAIN", toolchain);
193+
}
194+
141195
// collect enabled tests
142196
let tests = tests::TESTS
143197
.iter()
@@ -161,8 +215,8 @@ fn main() {
161215
})
162216
// Specify chip - note: may match multiple
163217
.filter(|t| {
164-
if let Some(ref chip) = opt.chip {
165-
chip == t.chip
218+
if !opt.chip.is_empty() {
219+
opt.chip.iter().any(|c| c == t.chip)
166220
} else {
167221
true
168222
}
@@ -171,36 +225,55 @@ fn main() {
171225
.filter(|t| opt.bad_tests || t.should_pass)
172226
.collect::<Vec<_>>();
173227

228+
if opt.list {
229+
// FIXME: Prettier output
230+
eprintln!("{:?}", tests.iter().map(|t| t.name()).collect::<Vec<_>>());
231+
exit(0);
232+
}
233+
if tests.is_empty() {
234+
eprintln!("No tests run, you might want to use `--bad-tests` and/or `--long-test`");
235+
}
236+
174237
let any_fails = AtomicBool::new(false);
175238

176239
// TODO: It would be more efficient to reuse directories, so we don't
177240
// have to rebuild all the deps crates
178241
tests.par_iter().for_each(|t| {
179242
let start = Instant::now();
180243

181-
match svd_test::test(t, &bin_path, rustfmt_bin_path) {
182-
Ok(()) => {
183-
// TODO: If verbosity is > 1, print every logged stderr
184-
eprintln!(
185-
"Passed: {} - {} seconds",
186-
t.name(),
187-
start.elapsed().as_secs()
188-
);
244+
match svd_test::test(t, &bin_path, rustfmt_bin_path, opt.nightly, opt.verbose) {
245+
Ok(s) => {
246+
if let Some(stderrs) = s {
247+
let mut buf = String::new();
248+
for stderr in stderrs {
249+
read_file(&stderr, &mut buf);
250+
}
251+
eprintln!(
252+
"Passed: {} - {} seconds\n{}",
253+
t.name(),
254+
start.elapsed().as_secs(),
255+
buf
256+
);
257+
} else {
258+
eprintln!(
259+
"Passed: {} - {} seconds",
260+
t.name(),
261+
start.elapsed().as_secs()
262+
);
263+
}
189264
}
190265
Err(e) => {
191266
any_fails.store(true, Ordering::Release);
192267
let additional_info = if opt.verbose > 0 {
193268
match e.kind() {
194-
&errors::ErrorKind::ProcessFailed(ref command, _, Some(ref stderr))
195-
if command == "cargo check" =>
196-
{
197-
let mut buf = String::new();
198-
// Unwrap is safe
199-
File::open(stderr)
200-
.expect("Couldn't open file")
201-
.read_to_string(&mut buf)
202-
.expect("Couldn't read file to string");
203-
buf.insert_str(0, &format!("\n---{:?}---\n", stderr.as_os_str()));
269+
&errors::ErrorKind::ProcessFailed(_, _, Some(ref stderr), ref previous_processes_stderr) => {
270+
let mut buf = String::new();
271+
if opt.verbose > 1 {
272+
for stderr in previous_processes_stderr {
273+
read_file(&stderr, &mut buf);
274+
}
275+
}
276+
read_file(&stderr, &mut buf);
204277
buf
205278
}
206279
_ => "".into(),

0 commit comments

Comments
 (0)