* Run multiple examples/tests

* Adapt some qa-tests
This commit is contained in:
Björn Quentin 2025-01-03 15:31:19 +01:00 committed by GitHub
parent 19eb7728bb
commit dc2b968491
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 134 additions and 13 deletions

View File

@ -12,6 +12,7 @@
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% FEATURES: embassy-generic-timers
//% TAG: bmp180
#![no_std]
#![no_main]

View File

@ -7,6 +7,7 @@
//! - SCL => GPIO5
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% TAG: bmp180
#![no_std]
#![no_main]

View File

@ -23,6 +23,7 @@
//! register is set.
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% TAG: flashchip
#![no_std]
#![no_main]

View File

@ -46,16 +46,14 @@ fn main() -> ! {
function_in_ram as *const ()
);
unsafe {
println!("SOME_INITED_DATA {:x?}", SOME_INITED_DATA);
println!("SOME_PERSISTENT_DATA {:x?}", SOME_PERSISTENT_DATA);
println!("SOME_ZEROED_DATA {:x?}", SOME_ZEROED_DATA);
assert_eq!(&[0xaa, 0xbb], &SOME_INITED_DATA);
assert_eq!(&[0; 8], &SOME_ZEROED_DATA);
SOME_INITED_DATA[0] = 0xff;
SOME_ZEROED_DATA[0] = 0xff;
println!("SOME_INITED_DATA {:x?}", SOME_INITED_DATA);
println!("SOME_PERSISTENT_DATA {:x?}", SOME_PERSISTENT_DATA);
println!("SOME_ZEROED_DATA {:x?}", SOME_ZEROED_DATA);
assert_eq!(&[0xff, 0xbb], &SOME_INITED_DATA);
assert_eq!(&[0xff, 0, 0, 0, 0, 0, 0, 0], &SOME_ZEROED_DATA);
if SOME_PERSISTENT_DATA[1] == 0xff {
SOME_PERSISTENT_DATA[1] = 0;
@ -69,17 +67,22 @@ fn main() -> ! {
"RTC_FAST function located at {:p}",
function_in_rtc_ram as *const ()
);
println!("Result {}", function_in_rtc_ram());
assert_eq!(42, function_in_rtc_ram());
println!("Restarting in ~ 10 seconds.");
let mut i = 10;
loop {
function_in_ram();
assert_eq!(42, function_in_rtc_ram());
function_in_ram(i);
i = i.saturating_sub(1);
delay.delay(1.secs());
}
}
#[ram]
fn function_in_ram() {
println!("Hello world!");
fn function_in_ram(count: u32) {
println!("{}", count);
}
#[ram(rtc_fast)]

View File

@ -23,6 +23,7 @@
//! register is set.
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% TAG: flashchip
#![no_std]
#![no_main]

View File

@ -9,6 +9,7 @@ anyhow = "1.0.93"
basic-toml = "0.1.9"
chrono = "0.4.38"
clap = { version = "4.5.20", features = ["derive", "wrap_help"] }
console = "0.15.10"
csv = "1.3.1"
env_logger = "0.11.5"
esp-metadata = { path = "../esp-metadata", features = ["clap"] }

View File

@ -59,14 +59,24 @@ pub struct Metadata {
example_path: PathBuf,
chip: Chip,
feature_set: Vec<String>,
tag: Option<String>,
description: Option<String>,
}
impl Metadata {
pub fn new(example_path: &Path, chip: Chip, feature_set: Vec<String>) -> Self {
pub fn new(
example_path: &Path,
chip: Chip,
feature_set: Vec<String>,
tag: Option<String>,
description: Option<String>,
) -> Self {
Self {
example_path: example_path.to_path_buf(),
chip,
feature_set,
tag,
description,
}
}
@ -93,6 +103,16 @@ impl Metadata {
pub fn supports_chip(&self, chip: Chip) -> bool {
self.chip == chip
}
/// Optional tag of the example.
pub fn tag(&self) -> Option<String> {
self.tag.clone()
}
/// Optional description of the example.
pub fn description(&self) -> Option<String> {
self.description.clone()
}
}
#[derive(Debug, Clone, Copy, Display, ValueEnum)]
@ -203,6 +223,17 @@ pub fn load_examples(path: &Path, action: CargoAction) -> Result<Vec<Metadata>>
let mut chips = Chip::iter().collect::<Vec<_>>();
let mut feature_sets = Vec::new();
let mut chip_features = HashMap::new();
let mut tag = None;
let mut description = None;
// collect `//!` as description
for line in text.lines().filter(|line| line.starts_with("//!")) {
let line = line.trim_start_matches("//!");
let mut descr: String = description.unwrap_or_default();
descr.push_str(line);
descr.push('\n');
description = Some(descr);
}
// We will indicate metadata lines using the `//%` prefix:
for line in text.lines().filter(|line| line.starts_with("//%")) {
@ -250,6 +281,8 @@ pub fn load_examples(path: &Path, action: CargoAction) -> Result<Vec<Metadata>>
for chip in chips {
chip_features.insert(chip, values.clone());
}
} else if key.starts_with("TAG") {
tag = Some(value.to_string());
} else {
log::warn!("Unrecognized metadata key '{key}', ignoring");
}
@ -274,7 +307,13 @@ pub fn load_examples(path: &Path, action: CargoAction) -> Result<Vec<Metadata>>
feature_set.sort();
}
examples.push(Metadata::new(&path, *chip, feature_set.clone()));
examples.push(Metadata::new(
&path,
*chip,
feature_set.clone(),
tag.clone(),
description.clone(),
));
}
}
}

View File

@ -244,7 +244,8 @@ fn examples(workspace: &Path, mut args: ExampleArgs, action: CargoAction) -> Res
// Execute the specified action:
match action {
CargoAction::Build => build_examples(args, examples, &package_path),
CargoAction::Run => run_example(args, examples, &package_path),
CargoAction::Run if args.example.is_some() => run_example(args, examples, &package_path),
CargoAction::Run => run_examples(args, examples, &package_path),
}
}
@ -318,6 +319,79 @@ fn run_example(args: ExampleArgs, examples: Vec<Metadata>, package_path: &Path)
Ok(())
}
fn run_examples(args: ExampleArgs, examples: Vec<Metadata>, package_path: &Path) -> Result<()> {
// Determine the appropriate build target for the given package and chip:
let target = target_triple(args.package, &args.chip)?;
// Filter the examples down to only the binaries we're interested in
let mut examples: Vec<Metadata> = examples
.iter()
.filter(|ex| ex.supports_chip(args.chip))
.cloned()
.collect();
examples.sort_by_key(|ex| ex.tag());
let console = console::Term::stdout();
for example in examples {
let mut skip = false;
log::info!("Running example '{}'", example.name());
if let Some(description) = example.description() {
log::info!(
"\n\n{}\n\nPress ENTER to run example, `s` to skip",
description.trim()
);
} else {
log::info!("\n\nPress ENTER to run example, `s` to skip");
}
loop {
let key = console.read_key();
match key {
Ok(console::Key::Enter) => break,
Ok(console::Key::Char('s')) => {
skip = true;
break;
}
_ => (),
}
}
if !skip {
while !skip
&& xtask::execute_app(
package_path,
args.chip,
target,
&example,
CargoAction::Run,
1,
args.debug,
)
.is_err()
{
log::info!("Failed to run example. Retry or skip? (r/s)");
loop {
let key = console.read_key();
match key {
Ok(console::Key::Char('r')) => break,
Ok(console::Key::Char('s')) => {
skip = true;
break;
}
_ => (),
}
}
}
}
}
Ok(())
}
fn tests(workspace: &Path, args: TestArgs, action: CargoAction) -> Result<()> {
// Absolute path of the 'hil-test' package's root:
let package_path = xtask::windows_safe_path(&workspace.join("hil-test"));