Skip to content

Commit

Permalink
feat: Add run-elfs xtask subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioGasquez committed May 2, 2024
1 parent 7c12168 commit daf8746
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 22 deletions.
24 changes: 2 additions & 22 deletions .github/workflows/hil.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ jobs:
- soc: esp32s3
runner: esp32s3-usb
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: tests-${{ matrix.target.soc }}
Expand All @@ -118,25 +119,4 @@ jobs:
- name: Run Tests
run: |
export PATH=$PATH:/home/espressif/.cargo/bin
failed_tests=() # Initialize an empty array to hold failed tests
for test_file in "tests-${{ matrix.target.soc }}"/*; do
echo "Running test: $test_file"
if ! probe-rs run --chip ${{ matrix.target.soc }} "$test_file"; then
failed_tests+=("$test_file") # Add failed test to the array
fi
done
# Cleanup
rm -rf tests-${{ matrix.target.soc }}
# Report all failed tests at the end
if [ ${#failed_tests[@]} -gt 0 ]; then
echo "The following tests failed:"
for failed_test in "${failed_tests[@]}"; do
echo "- $failed_test"
done
exit 1 # Return a non-zero exit code to indicate failure
else
echo "All tests passed!"
fi
cargo xtask run-elfs ${{ matrix.target.soc }} tests-${{ matrix.target.soc }}
45 changes: 45 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
fs,
path::{Path, PathBuf},
process::Command,
};

use anyhow::{bail, Result};
Expand Down Expand Up @@ -29,6 +30,8 @@ enum Cli {
RunExample(RunExampleArgs),
/// Run all applicable tests or the specified test for a specified chip.
RunTests(TestsArgs),
/// Run all ELFs in a folder.
RunElfs(RunElfArgs),
}

#[derive(Debug, Args)]
Expand Down Expand Up @@ -114,6 +117,15 @@ struct TestsArgs {
test: Option<String>,
}

#[derive(Debug, Args)]
struct RunElfArgs {
/// Which chip to run the tests for.
#[arg(value_enum)]
chip: Chip,
/// Path to the ELFs.
path: PathBuf,
}

// ----------------------------------------------------------------------------
// Application

Expand All @@ -134,6 +146,7 @@ fn main() -> Result<()> {
Cli::GenerateEfuseFields(args) => generate_efuse_src(&workspace, args),
Cli::RunExample(args) => run_example(&workspace, args),
Cli::RunTests(args) => execute_tests(&workspace, args, CargoAction::Run),
Cli::RunElfs(args) => run_elfs(args),
}
}

Expand Down Expand Up @@ -396,6 +409,38 @@ fn execute_tests(
Ok(())
}

fn run_elfs(args: RunElfArgs) -> Result<(), anyhow::Error> {
let elfs = fs::read_dir(&args.path)?;
let mut failed_elfs: Vec<String> = Vec::new();
for elf in elfs {
let elf = elf?;
let elf_path = elf.path();
let elf_name = elf_path.file_name().unwrap().to_str().unwrap();
let elf_name = elf_name.split('.').next().unwrap();
let elf_name = elf_name.to_string();
println!("Running '{}' test", elf_name);

let command = Command::new("probe-rs")
.arg("run")
.arg("--chip")
.arg(args.chip.to_string())
.arg(elf_path)
.output()
.expect("Failed to execute probe-rs run command");
let stdout = String::from_utf8_lossy(&command.stdout);
let stderr = String::from_utf8_lossy(&command.stderr);
println!("{}\n{}", stderr, stdout);
if !command.status.success() {
failed_elfs.push(elf_name);
}
}

if !failed_elfs.is_empty() {
bail!("Failed tests: {:?}", failed_elfs);
}

Ok(())
}
// ----------------------------------------------------------------------------
// Helper Functions

Expand Down

0 comments on commit daf8746

Please sign in to comment.