Skip to content

Commit 95a1636

Browse files
authored
Merge pull request #56 from ariel-os/v0.6.0+ariel-os
feat: add Ariel OS support
2 parents 19d3e0f + b2d893a commit 95a1636

File tree

8 files changed

+66
-19
lines changed

8 files changed

+66
-19
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## Unreleased
9+
10+
### Added
11+
12+
- Support [Ariel OS](https://ariel-os.org).
13+
814
## [0.6.0]
915

1016
### Added

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,8 @@ embassy = [
4646
# 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())]`
4747
external-executor = ["embedded-test-macros/external-executor"]
4848

49+
# Enables Ariel OS integration
50+
ariel-os = ["embedded-test-macros/ariel-os", "embassy"]
51+
4952
# enables the xtensa-specific semihosting implementation
5053
xtensa-semihosting = ["semihosting/openocd-semihosting"]

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ mod tests {
147147
| `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. |
148148
| `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())]`) |
149149
| `xtensa-semihosting` | No | Enables semihosting for xtensa targets. |
150+
| `ariel-os` | No | Enables [Ariel OS](https://ariel-os.github.io/ariel-os/dev/docs/book/testing.html) integration. |
150151

151152
Please also note the doc for
152153
the [Attribute Macro embedded_test::tests](https://docs.rs/embedded-test/latest/embedded-test/attr.tests.html).

build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ macro_rules! assert_unique_features {
2121

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

2526
let out = &PathBuf::from(env::var("OUT_DIR")?);
2627
let linker_script = fs::read_to_string("embedded-test.x")?;

macros/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ darling = "0.20.8"
2121
[features]
2222
embassy = []
2323
external-executor = []
24+
ariel-os = []
2425

2526
[dev-dependencies]
2627
trybuild = "1"

macros/src/lib.rs

+47-16
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@ fn tests_impl(args: TokenStream, input: TokenStream) -> parse::Result<TokenStrea
339339
}
340340
);
341341

342+
let task_path = if cfg!(feature = "ariel-os") {
343+
quote!(ariel_os::task)
344+
} else {
345+
quote!(#krate::export::task)
346+
};
347+
342348
// The closure that will be called, if the test should be runned.
343349
// This closure has the signature () -> !, so it will never return.
344350
// The closure will signal the test result via semihosting exit/abort instead
@@ -347,29 +353,37 @@ fn tests_impl(args: TokenStream, input: TokenStream) -> parse::Result<TokenStrea
347353
let cfgs = &test.cfgs;
348354
test_function_invokers.push(quote!(
349355
#(#cfgs)*
350-
#[#krate::export::task]
356+
#[#task_path]
351357
async fn #ident_invoker() {
352358
#init_run_and_check
353359
}
354360
));
355361

356-
let executor = if let Some(executor) = &macro_args.executor {
357-
quote! {
358-
#executor
359-
}
362+
if cfg!(feature = "ariel-os") {
363+
quote!(|| {
364+
ariel_os::asynch::spawner().must_spawn(#ident_invoker());
365+
ariel_os::thread::park();
366+
unreachable!();
367+
})
360368
} else {
361-
quote! {
362-
#krate::export::Executor::new()
363-
}
364-
};
369+
let executor = if let Some(executor) = &macro_args.executor {
370+
quote! {
371+
#executor
372+
}
373+
} else {
374+
quote! {
375+
#krate::export::Executor::new()
376+
}
377+
};
365378

366-
quote!(|| {
367-
let mut executor = #executor;
368-
let executor = unsafe { __make_static(&mut executor) };
369-
executor.run(|spawner| {
370-
spawner.must_spawn(#ident_invoker());
379+
quote!(|| {
380+
let mut executor = #executor;
381+
let executor = unsafe { __make_static(&mut executor) };
382+
executor.run(|spawner| {
383+
spawner.must_spawn(#ident_invoker());
384+
})
371385
})
372-
})
386+
}
373387
} else {
374388
quote!(|| {
375389
#init_run_and_check
@@ -420,6 +434,21 @@ fn tests_impl(args: TokenStream, input: TokenStream) -> parse::Result<TokenStrea
420434
};
421435
let setup = macro_args.setup;
422436

437+
let (thread_start, maybe_export_name) = if cfg!(feature = "ariel-os") {
438+
(
439+
quote!(
440+
// TODO: make stack size configurable
441+
#[ariel_os::thread(autostart, stacksize = 16384)]
442+
fn embedded_test_thread() {
443+
unsafe { __embedded_test_entry() }
444+
}
445+
),
446+
quote!(),
447+
)
448+
} else {
449+
(quote!(), quote!(#[export_name = "main"]))
450+
};
451+
423452
Ok(quote!(
424453
#[cfg(test)]
425454
mod #ident {
@@ -435,7 +464,9 @@ fn tests_impl(args: TokenStream, input: TokenStream) -> parse::Result<TokenStrea
435464
::core::mem::transmute(t)
436465
}
437466

438-
#[export_name = "main"]
467+
#thread_start
468+
469+
#maybe_export_name
439470
unsafe extern "C" fn __embedded_test_entry() -> ! {
440471
// The linker file will redirect this call to the function below.
441472
// This trick ensures that we get a compile error, if the linker file was not added to the rustflags.

src/export.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ pub fn ensure_linker_file_was_added_to_rustflags() -> ! {
1515
}
1616

1717
// Reexport the embassy stuff
18-
#[cfg(feature = "embassy")]
18+
#[cfg(all(feature = "embassy", not(feature = "ariel-os")))]
1919
pub use embassy_executor::task;
20-
#[cfg(all(feature = "embassy", not(feature = "external-executor")))]
20+
#[cfg(all(
21+
feature = "embassy",
22+
not(feature = "external-executor"),
23+
not(feature = "ariel-os")
24+
))]
2125
pub use embassy_executor::Executor; // Please activate the `executor-thread` or `executor-interrupt` feature on the embassy-executor crate (v0.7.x)!
2226

2327
const VERSION: u32 = 1; //Format version of our protocol between probe-rs and target running embedded-test

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod fmt;
88

99
pub use embedded_test_macros::tests;
1010

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

0 commit comments

Comments
 (0)