-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from hashmismatch/tests_staticlib_examples
Ported tests to compile into static libraries using examples
- Loading branch information
Showing
31 changed files
with
1,024 additions
and
893 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
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 |
---|---|---|
|
@@ -5,11 +5,50 @@ authors = ["Rudi Benkovic <[email protected]>"] | |
|
||
[lib] | ||
name = "qemu_stm32_tests" | ||
crate-type = ["lib"] | ||
|
||
[dependencies] | ||
freertos_rs = { path = "../" } | ||
|
||
[dependencies.lazy_static] | ||
version = "1.3.0" | ||
features = ["spin_no_std"] | ||
features = ["spin_no_std"] | ||
|
||
[[example]] | ||
name = "test_basics" | ||
crate-type = ["staticlib"] | ||
|
||
[[example]] | ||
name = "test_delay" | ||
crate-type = ["staticlib"] | ||
|
||
[[example]] | ||
name = "test_mutex" | ||
crate-type = ["staticlib"] | ||
|
||
[[example]] | ||
name = "test_mem_leaks1" | ||
crate-type = ["staticlib"] | ||
|
||
[[example]] | ||
name = "test_timers" | ||
crate-type = ["staticlib"] | ||
|
||
[[example]] | ||
name = "test_stats" | ||
crate-type = ["staticlib"] | ||
|
||
[[example]] | ||
name = "test_processor" | ||
crate-type = ["staticlib"] | ||
|
||
[[example]] | ||
name = "test_sample1" | ||
crate-type = ["staticlib"] | ||
|
||
[[example]] | ||
name = "test_isr_timer4_notify" | ||
crate-type = ["staticlib"] | ||
|
||
[[example]] | ||
name = "test_isr_timer4_queue" | ||
crate-type = ["staticlib"] |
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,24 @@ | ||
#![no_main] | ||
#![no_std] | ||
|
||
#[macro_use] | ||
extern crate qemu_stm32_tests; | ||
|
||
use qemu_stm32_tests::prelude::v1::*; | ||
|
||
freertos_rs_test!(TestBasics); | ||
|
||
pub struct TestBasics; | ||
impl Test for TestBasics { | ||
fn run<T: Testbed>(tb: &T) { | ||
let check = shim_sanity_check(); | ||
if check.is_err() { | ||
T::debug_print(&format!("Shim sanity check failed: {:?}", check)); | ||
T::exit_test(1); | ||
} | ||
|
||
T::debug_print("Type sizes are OK!"); | ||
|
||
T::exit_test(0); | ||
} | ||
} |
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,77 @@ | ||
#![no_main] | ||
#![no_std] | ||
|
||
#[macro_use] | ||
extern crate qemu_stm32_tests; | ||
|
||
use qemu_stm32_tests::prelude::v1::*; | ||
|
||
freertos_rs_test!(TestDelay); | ||
|
||
pub struct TestDelay; | ||
impl Test for TestDelay { | ||
fn run<T: Testbed>(tb: &T) { | ||
let main_task = Task::new().name("main").start(|| { | ||
let start = FreeRtosUtils::get_tick_count(); | ||
|
||
let counter = Arc::new(Mutex::new(0).unwrap()); | ||
|
||
{ | ||
let counter = counter.clone(); | ||
let delay_task = Task::new().name("delay").start(move || { | ||
for _ in 0..10 { | ||
CurrentTask::delay(Duration::ms(100)); | ||
|
||
// increase the counter and immediately release it | ||
{ | ||
let mut counter = counter.lock(Duration::infinite()).unwrap(); | ||
*counter += 1; | ||
} | ||
} | ||
}).unwrap(); | ||
} | ||
|
||
CurrentTask::delay(Duration::ms(550)); | ||
|
||
{ | ||
let counter = counter.lock(Duration::infinite()).unwrap(); | ||
assert_eq!(*counter, 5); | ||
} | ||
|
||
CurrentTask::delay(Duration::ms(500)); | ||
|
||
{ | ||
let counter = counter.lock(Duration::infinite()).unwrap(); | ||
assert_eq!(*counter, 10); | ||
} | ||
|
||
// negative test: the counter should never increment | ||
{ | ||
let counter = Arc::new(Mutex::new(0).unwrap()); | ||
{ | ||
let counter = counter.clone(); | ||
let task = Task::new().name("delay_long").start(move || { | ||
for _ in 0..10 { | ||
CurrentTask::delay(Duration::ms(1000)); | ||
|
||
// increase the counter and immediately release it | ||
{ | ||
let mut counter = counter.lock(Duration::infinite()).unwrap(); | ||
*counter += 1; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
CurrentTask::delay(Duration::ms(500)); | ||
let counter = counter.lock(Duration::infinite()).unwrap(); | ||
assert_eq!(*counter, 0); | ||
} | ||
|
||
T::exit_test(0); | ||
}); | ||
|
||
let main_task = main_task.unwrap(); | ||
T::start_kernel(); | ||
} | ||
} |
Oops, something went wrong.