Skip to content

Commit

Permalink
[#51] More robust concurrecny tests, ignore platform specific thread …
Browse files Browse the repository at this point in the history
…documentation example
  • Loading branch information
elfenpiff committed Dec 22, 2023
1 parent e013e30 commit 8cae210
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion iceoryx2-bb/posix/src/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
//!
//! ## Create a highly customized thread with guarded stack
//!
//! ```
//! ```ignore
//! use iceoryx2_bb_posix::thread::*;
//! use iceoryx2_bb_posix::scheduler::*;
//! use iceoryx2_bb_posix::system_configuration::*;
Expand Down
6 changes: 5 additions & 1 deletion iceoryx2-bb/posix/tests/condition_variable_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@

use iceoryx2_bb_posix::condition_variable::*;
use iceoryx2_bb_testing::assert_that;
use iceoryx2_bb_testing::watchdog::Watchdog;
use std::sync::atomic::{AtomicI32, Ordering};
use std::sync::Arc;
use std::thread;
use std::time::Duration;
use std::time::Instant;

static TIMEOUT: Duration = Duration::from_millis(10);
static TIMEOUT: Duration = Duration::from_millis(100);

#[test]
fn multi_condition_variable_construction_works() {
Expand Down Expand Up @@ -369,6 +370,7 @@ fn condition_variable_modify_notify_all_signals_all_waiters() {

#[test]
fn condition_variable_modify_notify_one_signals_one_waiter() {
let _watchdog = Watchdog::new(Duration::from_secs(10));
let handle = MutexHandle::<ConditionVariableData<i32>>::new();
thread::scope(|s| {
let counter = Arc::new(AtomicI32::new(0));
Expand Down Expand Up @@ -396,6 +398,8 @@ fn condition_variable_modify_notify_one_signals_one_waiter() {
let counter_old_1 = counter.load(Ordering::Relaxed);
sut.modify_notify_one(|value| *value = 2213).unwrap();

while counter.load(Ordering::Relaxed) == 0 {}

thread::sleep(TIMEOUT);
let counter_old_2 = counter.load(Ordering::Relaxed);
sut.modify_notify_one(|value| *value = 2213).unwrap();
Expand Down
1 change: 1 addition & 0 deletions iceoryx2-bb/posix/tests/mutex_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ fn mutex_can_be_recovered_when_thread_died() {

#[test]
fn mutex_in_unrecoverable_state_if_state_of_leaked_mutex_is_not_repaired() {
let _watchdog = Watchdog::new(Duration::from_secs(10));
let handle = MutexHandle::<i32>::new();
let sut = MutexBuilder::new()
.thread_termination_behavior(MutexThreadTerminationBehavior::ReleaseWhenLocked)
Expand Down
15 changes: 10 additions & 5 deletions iceoryx2-bb/threadsafe/tests/trigger_queue_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ use std::time::Duration;
use iceoryx2_bb_posix::clock::{nanosleep, Time};
use iceoryx2_bb_posix::mutex::MutexHandle;
use iceoryx2_bb_testing::assert_that;
use iceoryx2_bb_testing::watchdog::Watchdog;
use iceoryx2_bb_threadsafe::trigger_queue::*;

const TIMEOUT: Duration = Duration::from_millis(25);
const TIMEOUT: Duration = Duration::from_millis(100);
const SUT_CAPACITY: usize = 128;
type Sut<'a> = TriggerQueue<'a, usize, SUT_CAPACITY>;

Expand Down Expand Up @@ -153,6 +154,7 @@ fn trigger_queue_blocking_push_blocks_until_there_is_space_again() {
let mtx_handle = MutexHandle::new();
let free_handle = UnnamedSemaphoreHandle::new();
let used_handle = UnnamedSemaphoreHandle::new();
let _watchdog = Watchdog::new(Duration::from_secs(10));

let sut = Sut::new(&mtx_handle, &free_handle, &used_handle);

Expand All @@ -170,10 +172,11 @@ fn trigger_queue_blocking_push_blocks_until_there_is_space_again() {
nanosleep(TIMEOUT).unwrap();
let counter_old = counter.load(Ordering::Relaxed);
sut.blocking_pop();
nanosleep(TIMEOUT).unwrap();

assert_that!(counter_old, eq 0);
assert_that!(counter.load(Ordering::Relaxed), eq 1);

// if the thread is not unblocked the counter stays zero until the watchdog intervenes
while counter.load(Ordering::Relaxed) == 0 {}
});
}

Expand All @@ -182,6 +185,7 @@ fn trigger_queue_blocking_pop_blocks_until_there_is_something_pushed() {
let mtx_handle = MutexHandle::new();
let free_handle = UnnamedSemaphoreHandle::new();
let used_handle = UnnamedSemaphoreHandle::new();
let _watchdog = Watchdog::new(Duration::from_secs(10));

let sut = Sut::new(&mtx_handle, &free_handle, &used_handle);

Expand All @@ -196,10 +200,11 @@ fn trigger_queue_blocking_pop_blocks_until_there_is_something_pushed() {
nanosleep(TIMEOUT).unwrap();
let counter_old = counter.load(Ordering::Relaxed);
sut.blocking_push(0);
nanosleep(TIMEOUT).unwrap();

assert_that!(counter_old, eq 0);
assert_that!(counter.load(Ordering::Relaxed), eq 1);

// if the thread is not unblocked the counter stays zero until the watchdog intervenes
while counter.load(Ordering::Relaxed) == 0 {}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ impl<const NUMBER_OF_THREADS: usize> ThreadInWait<NUMBER_OF_THREADS> {
loop {
let mut wait_for_thread = false;
for v in &self.thread_in_wait {
if v.load(Ordering::Relaxed) == false {
if !v.load(Ordering::Relaxed) {
wait_for_thread = true;
break;
}
}

if wait_for_thread == false {
if !wait_for_thread {
break;
}
}
Expand Down

0 comments on commit 8cae210

Please sign in to comment.