Skip to content

Commit

Permalink
add test script and end of test conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
tullom committed Jan 23, 2025
1 parent 092dca8 commit 7c0b61e
Show file tree
Hide file tree
Showing 25 changed files with 155 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/rt685s-evk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ futures = { version = "0.3.30", default-features = false, features = [
] }
mimxrt600-fcb = "0.1.0"
rand = { version = "0.8.5", default-features = false }
test-parser-macros = { path = "../../../test-parser/test-parser-macros" }
test-parser-macros = { git = "https://github.com/tullom/test-parser", optional = true }

[profile.release]
lto = true # better optimizations

[features]
test-parser = []
test-parser = ["dep:test-parser-macros"]
3 changes: 3 additions & 0 deletions examples/rt685s-evk/src/bin/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ async fn main(_spawner: Spawner) {

info!("ADC sample = {:#x}", data);

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();

Timer::after_millis(1000).await;
}
}
4 changes: 4 additions & 0 deletions examples/rt685s-evk/src/bin/clocks-blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ async fn main(_spawner: Spawner) {
loop {
info!("Toggling LED");
led.toggle();

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();

Timer::after_millis(1000).await;
}
}
3 changes: 3 additions & 0 deletions examples/rt685s-evk/src/bin/crc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ async fn main(_spawner: Spawner) {

defmt::assert_eq!(output, 0xebfebe9a);

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();

cortex_m::asm::bkpt();
}
3 changes: 3 additions & 0 deletions examples/rt685s-evk/src/bin/dma-mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,7 @@ async fn main(_spawner: Spawner) {
test_dma_channel!(p, DMA0_CH31, 31);

info!("DMA transfer tests completed");

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();
}
3 changes: 3 additions & 0 deletions examples/rt685s-evk/src/bin/gpio-async-input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ async fn main(spawner: Spawner) {

let mut ticker = Ticker::every(Duration::from_millis(100));

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();

spawner.spawn(monitor_task(monitor)).unwrap();

loop {
Expand Down
4 changes: 4 additions & 0 deletions examples/rt685s-evk/src/bin/gpio-blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ async fn main(_spawner: Spawner) {
loop {
info!("Toggling LED");
led.toggle();

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();

Timer::after_millis(1000).await;
}
}
3 changes: 3 additions & 0 deletions examples/rt685s-evk/src/bin/gpio-flex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ async fn main(_spawner: Spawner) {
// check pin level is high
assert!(flex.is_high());

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();

loop {
Timer::after_millis(1000).await;
}
Expand Down
3 changes: 3 additions & 0 deletions examples/rt685s-evk/src/bin/gpio-input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ async fn main(_spawner: Spawner) {

let monitor = gpio::Input::new(p.PIO1_0, gpio::Pull::None, gpio::Inverter::Disabled);

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();

loop {
info!("Pin level is {}", monitor.get_level());
Timer::after_millis(1000).await;
Expand Down
3 changes: 3 additions & 0 deletions examples/rt685s-evk/src/bin/hello-world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ async fn main(_spawner: Spawner) {

info!("Hello world");

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();

loop {
Timer::after_millis(1000).await;
}
Expand Down
3 changes: 3 additions & 0 deletions examples/rt685s-evk/src/bin/i2c-loopback-async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ async fn main(spawner: Spawner) {

let master = I2cMaster::new_async(p.FLEXCOMM4, p.PIO0_29, p.PIO0_30, Irqs, Speed::Standard, p.DMA0_CH9).unwrap();

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();

spawner.must_spawn(master_service(master));
spawner.must_spawn(slave_service(slave));
}
4 changes: 4 additions & 0 deletions examples/rt685s-evk/src/bin/i2c-master-async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ async fn main(_spawner: Spawner) {
}

info!("i2c example - Done! Busy Loop...");

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();

loop {
Timer::after_millis(1000).await;
}
Expand Down
4 changes: 4 additions & 0 deletions examples/rt685s-evk/src/bin/i2c-master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ async fn main(_spawner: Spawner) {
}

info!("i2c example - Done! Busy Loop...");

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();

loop {
Timer::after_millis(1000).await;
}
Expand Down
3 changes: 3 additions & 0 deletions examples/rt685s-evk/src/bin/i2c-slave-async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,8 @@ async fn main(spawner: Spawner) {
info!("i2cs example - I2c::new");
let i2c = I2cSlave::new_async(p.FLEXCOMM2, p.PIO0_18, p.PIO0_17, Irqs, SLAVE_ADDR.unwrap(), p.DMA0_CH4).unwrap();

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();

spawner.must_spawn(slave_service(i2c));
}
3 changes: 3 additions & 0 deletions examples/rt685s-evk/src/bin/i2c-slave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,8 @@ async fn main(spawner: Spawner) {
info!("i2cs example - I2c::new");
let i2c = I2cSlave::new_blocking(p.FLEXCOMM2, p.PIO0_18, p.PIO0_17, SLAVE_ADDR.unwrap()).unwrap();

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();

spawner.must_spawn(slave_service(i2c));
}
3 changes: 3 additions & 0 deletions examples/rt685s-evk/src/bin/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ async fn main(_spawner: Spawner) {
Timer::after_millis(100).await;
}

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();

Timer::after_millis(1000).await;
}
}
3 changes: 3 additions & 0 deletions examples/rt685s-evk/src/bin/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ async fn main(_spawner: Spawner) {
let mut rng = Rng::new(p.RNG, Irqs);
let mut buf = [0u8; 65];

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();

// Async interface
unwrap!(rng.async_fill_bytes(&mut buf).await);
info!("random bytes: {:02x}", buf);
Expand Down
3 changes: 3 additions & 0 deletions examples/rt685s-evk/src/bin/rtc-time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ async fn main(_spawner: Spawner) {
let p = embassy_imxrt::init(Default::default());
let r = RtcDatetime::new(p.RTC);

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();

let datetime = Datetime {
year: 2024,
month: 10,
Expand Down
3 changes: 3 additions & 0 deletions examples/rt685s-evk/src/bin/sha256-async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,7 @@ async fn main(_spawner: Spawner) {
]
);
trace!("Hashes complete");

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();
}
3 changes: 3 additions & 0 deletions examples/rt685s-evk/src/bin/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,7 @@ async fn main(_spawner: Spawner) {
]
);
trace!("Hashes complete");

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();
}
79 changes: 79 additions & 0 deletions examples/rt685s-evk/src/bin/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash

# Get all examples in the current directory (i.e., all Rust source files)
files=(*.rs)

testCounter=0
failedCounter=0
failed=false

# Arrays to store names of the tests that failed in debug and release modes
failedArrDebug=()
failedArrRelease=()

# We build examples first to generate build artifacts so we can quickly run tests
echo "Building examples... [debug]"
timeout 3m cargo build --features test-parser
if [ $? -eq 1 ]; then
echo "Failed to build examples [debug]"
exit 1
fi
echo "Building examples... [release]"
timeout 3m cargo build --release --features test-parser
if [ $? -eq 1 ]; then
echo "Failed to build examples [release]"
exit 1
fi

# Loop through each .rs file (representing individual tests)
for file in "${files[@]}"; do

# Strip the ".rs" extension from the filename to use it as the test name
strippedName="${file%.rs}"
((testCounter++))
echo "Executing test ${testCounter}: ${strippedName} [debug]"

# Run the test in debug mode using `cargo run` and timeout after 1 minute.
# The output of the `cargo run` command is piped into `test-parser` to check for test success or failure.
timeout 1m cargo run --bin "$strippedName" --features test-parser | test-parser -s TEST-SUCCESS -f TEST-FAIL

if [ $? -eq 1 ]; then
# If the test failed, log it, mark the failure, and increment failure counter
echo "The last command failed with exit code 1."
failedArrDebug+=("$strippedName")
failed=true
((failedCounter++))
fi

((testCounter++))
echo "Executing test ${testCounter}: ${strippedName} [release]"

# Run the test in release mode using `cargo run` with the --release flag
timeout 1m cargo run --bin "$strippedName" --features test-parser --release | test-parser -s TEST-SUCCESS -f TEST-FAIL

if [ $? -eq 1 ]; then
echo "The last command failed with exit code 1."
failedArrRelease+=("$strippedName")
failed=true
((failedCounter++))
fi
done

echo -e "\n========END OF TESTS SUMMARY========"
((successCounter = testCounter - failedCounter))
echo -e "${successCounter} / ${testCounter} tests passed\n"

# If there were failed tests, display them and exit with a non-zero code to indicate failure
if [ "$failed" = true ]; then
echo "Some tests failed: "
for failure in "${failedArrDebug[@]}"; do
echo "${failure} [debug]"
done
for failure in "${failedArrRelease[@]}"; do
echo "${failure} [release]"
done
exit 1
else
echo "All tests passed!"
exit 0
fi
4 changes: 4 additions & 0 deletions examples/rt685s-evk/src/bin/time-driver-blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ async fn main(_spawner: Spawner) -> ! {
loop {
info!("Toggling GPIO0_26 (Blue LED)");
led.toggle();

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();

Timer::after_millis(5000).await;
}
}
3 changes: 3 additions & 0 deletions examples/rt685s-evk/src/bin/uart-async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,7 @@ async fn main(spawner: Spawner) {
)
.unwrap();
spawner.must_spawn(usart2_task(usart2));

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();
}
3 changes: 3 additions & 0 deletions examples/rt685s-evk/src/bin/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,7 @@ async fn main(spawner: Spawner) {

let usart2 = UartTx::new_blocking(p.FLEXCOMM2, p.PIO0_15, Default::default()).unwrap();
spawner.must_spawn(usart2_task(usart2));

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();
}
3 changes: 3 additions & 0 deletions examples/rt685s-evk/src/bin/wwdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ async fn main(_spawner: Spawner) {
wwdt.unleash();
info!("Watchdog enabled!");

#[cfg(feature = "test-parser")]
test_parser_macros::pass_test();

// Feed 5 times, afterwards watchdog will reset CPU
let mut feed_count = 5;
loop {
Expand Down

0 comments on commit 7c0b61e

Please sign in to comment.