-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8ce6d9
commit 40e8d59
Showing
6 changed files
with
287 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
name: Build and Run Integration tests | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
workflow_dispatch: | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
# Cancel any currently running workflows from the same PR, branch, or | ||
# tag when a new workflow is triggered. | ||
# | ||
# https://stackoverflow.com/a/66336834 | ||
concurrency: | ||
cancel-in-progress: true | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
|
||
|
||
jobs: | ||
build: | ||
name: Generate and Build App | ||
strategy: | ||
fail-fast: false | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: dtolnay/rust-toolchain@nightly | ||
with: | ||
target: riscv32imac-unknown-none-elf | ||
components: clippy,rustfmt,rust-src | ||
|
||
- uses: Swatinem/rust-cache@v2 | ||
|
||
- name: Install cargo-generate (binary) | ||
continue-on-error: true | ||
id: binary | ||
run: | | ||
VERSION="$(git ls-remote --refs --sort="version:refname" --tags "https://github.com/cargo-generate/cargo-generate" | cut -d/ -f3- | tail -n1)" | ||
sudo curl \ | ||
-L "https://github.com/cargo-generate/cargo-generate/releases/latest/download/cargo-generate-$VERSION-x86_64-unknown-linux-gnu.tar.gz" \ | ||
-o "/home/runner/.cargo/bin/cargo-generate.tar.gz" | ||
tar xf "/home/runner/.cargo/bin/cargo-generate.tar.gz" -C "/home/runner/.cargo/bin/" | ||
chmod u+x "/home/runner/.cargo/bin/cargo-generate" | ||
- name: Install cargo-generate (source) | ||
if: steps.binary.outcome != 'success' | ||
run: cargo install cargo-generate | ||
|
||
- run: cargo generate esp-rs/esp-template --name app -d mcu=esp32c3 -d advanced=false | ||
|
||
- run: cargo build --release | ||
working-directory: app | ||
|
||
- uses: actions/upload-artifact@v3 | ||
with: | ||
name: esp32c3_app | ||
path: /home/runner/work/espflash/espflash/app/target/riscv32imc-unknown-none-elf/release/app | ||
if-no-files-found: error | ||
|
||
run-target: | ||
name: Run Tests on Target | ||
if: ${{ github.repository_owner == 'esp-rs' }} | ||
needs: build | ||
runs-on: [self-hosted, linux, x64, esp32c3] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/download-artifact@v3 | ||
with: | ||
name: esp32c3_app | ||
path: espflash/esp32c3_app | ||
|
||
- uses: ./.github/actions/setup-target | ||
with: | ||
arch: x86_64 | ||
target: x86_64-unknown-linux-gnu | ||
|
||
- name: Run Tests | ||
run: ESPFLASH_PORT=/dev/ttyACM0 ESPFLASH_APP=esp32c3_app/app cargo test |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,3 +84,8 @@ cli = [ | |
] | ||
|
||
raspberry = ["dep:rppal"] | ||
|
||
|
||
[dev-dependencies] | ||
assert_cmd = "2.0.12" | ||
# predicates = "3.0.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use assert_cmd::prelude::*; // Add methods on commands | ||
// use predicates::prelude::*; // Used for writing assertions | ||
use std::process::Command; // Run programs | ||
|
||
#[test] | ||
fn flash() -> Result<(), Box<dyn std::error::Error>> { | ||
// board-info | ||
let mut cmd: Command = Command::cargo_bin("espflash")?; | ||
|
||
cmd.arg("board-info"); | ||
cmd.assert().success(); | ||
|
||
let mut cmd = Command::cargo_bin("espflash")?; | ||
|
||
// flash | ||
let image = std::env::var("ESPFLASH_APP").expect("ESPFLASH_APP not set"); | ||
|
||
cmd.arg("flash").arg(image); | ||
cmd.assert().success(); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#[test] | ||
fn flash_test() { | ||
use espflash::cli::{ | ||
config::Config, connect, erase_partitions, flash_elf_image, monitor::LogFormat, | ||
parse_partition_table, ConnectArgs, EspflashProgress, FlashArgs, FlashConfigArgs, | ||
}; | ||
use espflash::targets::Chip; | ||
use std::{fs, path::PathBuf}; | ||
|
||
// let image = PathBuf::from("esp32c3"); | ||
let image = PathBuf::from(std::env::var("ESPFLASH_APP").expect("ESPFLASH_APP not set")); | ||
let port = std::env::var("ESPFLASH_PORT").expect("ESPFLASH_PORT not set"); | ||
|
||
let config = Config::default(); | ||
|
||
let conn = ConnectArgs { | ||
baud: Some(460800), | ||
chip: Some(Chip::Esp32c3), | ||
confirm_port: false, | ||
no_stub: false, | ||
port: Some(port), | ||
}; | ||
|
||
let mut flasher = connect(&conn, &config).unwrap(); | ||
|
||
let flash_config_args = FlashConfigArgs { | ||
flash_freq: None, | ||
flash_mode: None, | ||
flash_size: None, | ||
}; | ||
|
||
if let Some(flash_size) = flash_config_args.flash_size { | ||
flasher.set_flash_size(flash_size); | ||
} | ||
|
||
let flash_args = FlashArgs { | ||
bootloader: None, | ||
erase_parts: None, | ||
erase_data_parts: None, | ||
format: None, | ||
log_format: LogFormat::Serial, | ||
monitor: true, | ||
monitor_baud: None, | ||
partition_table: None, | ||
target_app_partition: None, | ||
partition_table_offset: None, | ||
ram: false, | ||
}; | ||
|
||
// Read the ELF data from the build path and load it to the target. | ||
let elf_data = fs::read(&image).unwrap(); | ||
|
||
if flash_args.ram { | ||
flasher | ||
.load_elf_to_ram(&elf_data, Some(&mut EspflashProgress::default())) | ||
.unwrap(); | ||
} else { | ||
let bootloader = flash_args.bootloader.as_deref(); | ||
let partition_table = flash_args.partition_table.as_deref(); | ||
|
||
// if let Some(path) = bootloader { | ||
// println!("Bootloader: {}", path.display()); | ||
// } | ||
// if let Some(path) = partition_table { | ||
// println!("Partition table: {}", path.display()); | ||
// } | ||
|
||
let partition_table = match partition_table { | ||
Some(path) => Some(parse_partition_table(path).unwrap()), | ||
None => None, | ||
}; | ||
|
||
if flash_args.erase_parts.is_some() || flash_args.erase_data_parts.is_some() { | ||
erase_partitions( | ||
&mut flasher, | ||
partition_table.clone(), | ||
flash_args.erase_parts, | ||
flash_args.erase_data_parts, | ||
) | ||
.unwrap(); | ||
} | ||
|
||
flash_elf_image( | ||
&mut flasher, | ||
&elf_data, | ||
bootloader, | ||
partition_table, | ||
flash_args.target_app_partition, | ||
flash_args.format, | ||
flash_config_args.flash_mode, | ||
flash_config_args.flash_size, | ||
flash_config_args.flash_freq, | ||
flash_args.partition_table_offset, | ||
) | ||
.unwrap(); | ||
} | ||
// println!("Firmware flashing completed. "); | ||
} |