Skip to content

Commit

Permalink
Allow running tests repeatedly
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Aug 15, 2024
1 parent 59de2d8 commit 529ee74
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
4 changes: 2 additions & 2 deletions hil-test/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[target.'cfg(target_arch = "riscv32")']
runner = "probe-rs run"
runner = "probe-rs run --preverify"
rustflags = [
"-C", "link-arg=-Tlinkall.x",
"-C", "link-arg=-Tembedded-test.x",
Expand All @@ -8,7 +8,7 @@ rustflags = [
]

[target.'cfg(target_arch = "xtensa")']
runner = "probe-rs run"
runner = "probe-rs run --preverify"
rustflags = [
"-C", "link-arg=-nostartfiles",
"-C", "link-arg=-Wl,-Tlinkall.x",
Expand Down
2 changes: 1 addition & 1 deletion xtask/src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use anyhow::{bail, Result};

use crate::windows_safe_path;

#[derive(Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum CargoAction {
Build,
Run,
Expand Down
12 changes: 9 additions & 3 deletions xtask/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ pub fn execute_app(
chip: Chip,
target: &str,
app: &Metadata,
action: &CargoAction,
action: CargoAction,
mut repeat: usize,
) -> Result<()> {
log::info!(
"Building example '{}' for '{}'",
Expand All @@ -214,7 +215,8 @@ pub fn execute_app(

let package = app.example_path().strip_prefix(package_path)?;
log::info!("Package: {:?}", package);
let (bin, subcommand) = if action == &CargoAction::Build {
let (bin, subcommand) = if action == CargoAction::Build {
repeat = 1; // Do not repeat builds in a loop
let bin = if package.starts_with("src/bin") {
format!("--bin={}", app.name())
} else if package.starts_with("tests") {
Expand Down Expand Up @@ -254,7 +256,11 @@ pub fn execute_app(
let args = builder.build();
log::debug!("{args:#?}");

cargo::run(&args, package_path)
for _ in 0..repeat {
cargo::run(&args, package_path)?;
}

Ok(())
}

/// Build the specified package, using the given toolchain/target/features if
Expand Down
32 changes: 27 additions & 5 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ struct TestArgs {
/// Optional test to act on (all tests used if omitted)
#[arg(short = 't', long)]
test: Option<String>,
/// Repeat the tests for a specific number of times.
#[arg(long)]
repeat: Option<usize>,
}

#[derive(Debug, Args)]
Expand Down Expand Up @@ -231,7 +234,8 @@ fn build_examples(args: ExampleArgs, examples: Vec<Metadata>, package_path: &Pat
args.chip,
target,
example,
&CargoAction::Build,
CargoAction::Build,
1,
)
} else if args.example.is_some() {
// An invalid argument was provided:
Expand All @@ -244,7 +248,8 @@ fn build_examples(args: ExampleArgs, examples: Vec<Metadata>, package_path: &Pat
args.chip,
target,
example,
&CargoAction::Build,
CargoAction::Build,
1,
)
})
}
Expand All @@ -262,7 +267,8 @@ fn run_example(args: ExampleArgs, examples: Vec<Metadata>, package_path: &Path)
args.chip,
target,
&example,
&CargoAction::Run,
CargoAction::Run,
1,
)
} else {
bail!("Example not found or unsupported for the given chip")
Expand All @@ -287,13 +293,29 @@ fn tests(workspace: &Path, args: TestArgs, action: CargoAction) -> Result<()> {

// Execute the specified action:
if let Some(test) = tests.iter().find(|test| Some(test.name()) == args.test) {
xtask::execute_app(&package_path, args.chip, target, &test, &action)
xtask::execute_app(
&package_path,
args.chip,
target,
&test,
action,
args.repeat.unwrap_or(1),
)
} else if args.test.is_some() {
bail!("Test not found or unsupported for the given chip")
} else {
let mut failed = Vec::new();
for test in tests {
if xtask::execute_app(&package_path, args.chip, target, &test, &action).is_err() {
if xtask::execute_app(
&package_path,
args.chip,
target,
&test,
action,
args.repeat.unwrap_or(1),
)
.is_err()
{
failed.push(test.name());
}
}
Expand Down

0 comments on commit 529ee74

Please sign in to comment.