Skip to content

Commit

Permalink
Allow specifying multiple feature sets and run all of them
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Aug 23, 2024
1 parent e39e317 commit 21a54d5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 18 deletions.
4 changes: 2 additions & 2 deletions hil-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ required-features = ["async", "embassy"]
[[test]]
name = "embassy_interrupt_executor"
harness = false
required-features = ["async", "embassy", "integrated-timers"]
required-features = ["async", "embassy"]

[[test]]
name = "twai"
Expand Down Expand Up @@ -166,7 +166,7 @@ digest = { version = "0.10.7", default-features = false }
elliptic-curve = { version = "0.13.8", default-features = false, features = ["sec1"] }
embassy-executor = { version = "0.6.0", default-features = false }
# Add the `embedded-test/defmt` feature for more verbose testing
embedded-test = { version = "0.4.0", default-features = false, git = "https://github.com/probe-rs/embedded-test.git", branch = "embassy" }
embedded-test = { version = "0.4.0", default-features = false }
fugit = "0.3.7"
hex-literal = "0.4.1"
nb = "1.1.0"
Expand Down
1 change: 1 addition & 0 deletions hil-test/tests/embassy_interrupt_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% FEATURES: integrated-timers
//% FEATURES: generic-queue

#![no_std]
#![no_main]
Expand Down
1 change: 1 addition & 0 deletions hil-test/tests/embassy_timers_executors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% FEATURES: integrated-timers
//% FEATURES: generic-queue

#![no_std]
#![no_main]
Expand Down
58 changes: 42 additions & 16 deletions xtask/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ pub enum Package {
pub struct Metadata {
example_path: PathBuf,
chips: Vec<Chip>,
features: Vec<String>,
feature_sets: Vec<Vec<String>>,
}

impl Metadata {
pub fn new(example_path: &Path, chips: Vec<Chip>, features: Vec<String>) -> Self {
pub fn new(example_path: &Path, chips: Vec<Chip>, feature_sets: Vec<Vec<String>>) -> Self {
let chips = if chips.is_empty() {
Chip::iter().collect()
} else {
Expand All @@ -71,7 +71,7 @@ impl Metadata {
Self {
example_path: example_path.to_path_buf(),
chips,
features,
feature_sets,
}
}

Expand All @@ -90,8 +90,8 @@ impl Metadata {
}

/// A list of all features required for building a given examples.
pub fn features(&self) -> &[String] {
&self.features
pub fn feature_sets(&self) -> &[Vec<String>] {
&self.feature_sets
}

/// If the specified chip is in the list of chips, then it is supported.
Expand Down Expand Up @@ -155,7 +155,7 @@ pub fn load_examples(path: &Path) -> Result<Vec<Metadata>> {
.with_context(|| format!("Could not read {}", path.display()))?;

let mut chips = Vec::new();
let mut features = Vec::new();
let mut feature_sets = Vec::new();

// We will indicate metadata lines using the `//%` prefix:
for line in text.lines().filter(|line| line.starts_with("//%")) {
Expand Down Expand Up @@ -183,13 +183,13 @@ pub fn load_examples(path: &Path) -> Result<Vec<Metadata>> {
.map(|s| Chip::from_str(s, false).unwrap())
.collect::<Vec<_>>();
} else if key == "FEATURES" {
features = split.into();
feature_sets.push(split.into());
} else {
log::warn!("Unrecognized metadata key '{key}', ignoring");
}
}

examples.push(Metadata::new(&path, chips, features));
examples.push(Metadata::new(&path, chips, feature_sets));
}

Ok(examples)
Expand All @@ -202,19 +202,45 @@ pub fn execute_app(
target: &str,
app: &Metadata,
action: CargoAction,
mut repeat: usize,
repeat: usize,
) -> Result<()> {
log::info!(
"Building example '{}' for '{}'",
app.example_path().display(),
chip
);
if !app.features().is_empty() {
log::info!(" Features: {}", app.features().join(","));

let feature_sets = if app.feature_sets().is_empty() {
vec![vec![]]
} else {
app.feature_sets().to_vec()
};

for features in feature_sets {
execute_app_with_features(package_path, chip, target, app, action, repeat, features)?;
}

Ok(())
}

/// Run or build the specified test or example for the specified chip, with the
/// specified features enabled.
pub fn execute_app_with_features(
package_path: &Path,
chip: Chip,
target: &str,
app: &Metadata,
action: CargoAction,
mut repeat: usize,
mut features: Vec<String>,
) -> Result<()> {
if !features.is_empty() {
log::info!("Features: {}", features.join(","));
}
features.push(chip.to_string());

let package = app.example_path().strip_prefix(package_path)?;
log::info!("Package: {:?}", package);
log::info!("Package: {}", package.display());
let (bin, subcommand) = if action == CargoAction::Build {
repeat = 1; // Do not repeat builds in a loop
let bin = if package.starts_with("src/bin") {
Expand All @@ -233,9 +259,6 @@ pub fn execute_app(
(format!("--example={}", app.name()), "run")
};

let mut features = app.features().to_vec();
features.push(chip.to_string());

let mut builder = CargoArgsBuilder::default()
.subcommand(subcommand)
.arg("--release")
Expand All @@ -256,7 +279,10 @@ pub fn execute_app(
let args = builder.build();
log::debug!("{args:#?}");

for _ in 0..repeat {
for i in 0..repeat {
if repeat != 1 {
log::info!("Run {}/{}", i + 1, repeat);
}
cargo::run(&args, package_path)?;
}

Expand Down

0 comments on commit 21a54d5

Please sign in to comment.