Skip to content

Commit

Permalink
Merge pull request #56 from ariel-os/v0.6.0+ariel-os
Browse files Browse the repository at this point in the history
feat: add Ariel OS support
  • Loading branch information
t-moe authored Feb 13, 2025
2 parents 19d3e0f + b2d893a commit 95a1636
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 19 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

- Support [Ariel OS](https://ariel-os.org).

## [0.6.0]

### Added
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,8 @@ embassy = [
# you will use your own executor by setting it via the `tasks` macro, e.g. `#[embedded_test::tests(executor = esp_hal::embassy::executor::thread::Executor::new())]`
external-executor = ["embedded-test-macros/external-executor"]

# Enables Ariel OS integration
ariel-os = ["embedded-test-macros/ariel-os", "embassy"]

# enables the xtensa-specific semihosting implementation
xtensa-semihosting = ["semihosting/openocd-semihosting"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ mod tests {
| `embassy` | No | Enables async test and init functions. Note: You need to enable at least one executor feature on the embassy-executor crate unless you are using the `external-executor` feature. |
| `external-executor` | No | Allows you to bring your own embassy executor which you need to pass to the `#[tests]` macro (e.g. `#[embedded_test::tests(executor = esp_hal::embassy::executor::thread::Executor::new())]`) |
| `xtensa-semihosting` | No | Enables semihosting for xtensa targets. |
| `ariel-os` | No | Enables [Ariel OS](https://ariel-os.github.io/ariel-os/dev/docs/book/testing.html) integration. |

Please also note the doc for
the [Attribute Macro embedded_test::tests](https://docs.rs/embedded-test/latest/embedded-test/attr.tests.html).
Expand Down
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ macro_rules! assert_unique_features {

fn main() -> Result<(), Box<dyn Error>> {
assert_unique_features!("log", "defmt");
assert_unique_features!("ariel-os", "external-executor");

let out = &PathBuf::from(env::var("OUT_DIR")?);
let linker_script = fs::read_to_string("embedded-test.x")?;
Expand Down
1 change: 1 addition & 0 deletions macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ darling = "0.20.8"
[features]
embassy = []
external-executor = []
ariel-os = []

[dev-dependencies]
trybuild = "1"
63 changes: 47 additions & 16 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,12 @@ fn tests_impl(args: TokenStream, input: TokenStream) -> parse::Result<TokenStrea
}
);

let task_path = if cfg!(feature = "ariel-os") {
quote!(ariel_os::task)
} else {
quote!(#krate::export::task)
};

// The closure that will be called, if the test should be runned.
// This closure has the signature () -> !, so it will never return.
// The closure will signal the test result via semihosting exit/abort instead
Expand All @@ -347,29 +353,37 @@ fn tests_impl(args: TokenStream, input: TokenStream) -> parse::Result<TokenStrea
let cfgs = &test.cfgs;
test_function_invokers.push(quote!(
#(#cfgs)*
#[#krate::export::task]
#[#task_path]
async fn #ident_invoker() {
#init_run_and_check
}
));

let executor = if let Some(executor) = &macro_args.executor {
quote! {
#executor
}
if cfg!(feature = "ariel-os") {
quote!(|| {
ariel_os::asynch::spawner().must_spawn(#ident_invoker());
ariel_os::thread::park();
unreachable!();
})
} else {
quote! {
#krate::export::Executor::new()
}
};
let executor = if let Some(executor) = &macro_args.executor {
quote! {
#executor
}
} else {
quote! {
#krate::export::Executor::new()
}
};

quote!(|| {
let mut executor = #executor;
let executor = unsafe { __make_static(&mut executor) };
executor.run(|spawner| {
spawner.must_spawn(#ident_invoker());
quote!(|| {
let mut executor = #executor;
let executor = unsafe { __make_static(&mut executor) };
executor.run(|spawner| {
spawner.must_spawn(#ident_invoker());
})
})
})
}
} else {
quote!(|| {
#init_run_and_check
Expand Down Expand Up @@ -420,6 +434,21 @@ fn tests_impl(args: TokenStream, input: TokenStream) -> parse::Result<TokenStrea
};
let setup = macro_args.setup;

let (thread_start, maybe_export_name) = if cfg!(feature = "ariel-os") {
(
quote!(
// TODO: make stack size configurable
#[ariel_os::thread(autostart, stacksize = 16384)]
fn embedded_test_thread() {
unsafe { __embedded_test_entry() }
}
),
quote!(),
)
} else {
(quote!(), quote!(#[export_name = "main"]))
};

Ok(quote!(
#[cfg(test)]
mod #ident {
Expand All @@ -435,7 +464,9 @@ fn tests_impl(args: TokenStream, input: TokenStream) -> parse::Result<TokenStrea
::core::mem::transmute(t)
}

#[export_name = "main"]
#thread_start

#maybe_export_name
unsafe extern "C" fn __embedded_test_entry() -> ! {
// The linker file will redirect this call to the function below.
// This trick ensures that we get a compile error, if the linker file was not added to the rustflags.
Expand Down
8 changes: 6 additions & 2 deletions src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ pub fn ensure_linker_file_was_added_to_rustflags() -> ! {
}

// Reexport the embassy stuff
#[cfg(feature = "embassy")]
#[cfg(all(feature = "embassy", not(feature = "ariel-os")))]
pub use embassy_executor::task;
#[cfg(all(feature = "embassy", not(feature = "external-executor")))]
#[cfg(all(
feature = "embassy",
not(feature = "external-executor"),
not(feature = "ariel-os")
))]
pub use embassy_executor::Executor; // Please activate the `executor-thread` or `executor-interrupt` feature on the embassy-executor crate (v0.7.x)!

const VERSION: u32 = 1; //Format version of our protocol between probe-rs and target running embedded-test
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod fmt;

pub use embedded_test_macros::tests;

#[cfg(feature = "panic-handler")]
#[cfg(all(feature = "panic-handler", not(feature = "ariel-os")))]
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
error!("====================== PANIC ======================");
Expand Down

0 comments on commit 95a1636

Please sign in to comment.