Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow the guideline of integration tests from the Rust book #7

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions commons/zenoh-shm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,13 @@ macro_rules! tested_crate_module {
};
}

#[macro_export]
macro_rules! test_helpers_module {
() => {
#[cfg(feature = "test")]
pub mod test_helpers;
};
}

pub mod api;
pub mod header;
pub mod posix_shm;
pub mod reader;
pub mod watchdog;
pub mod zsliceshm_access;

test_helpers_module!();

/// Informations about a [`SharedMemoryBuf`].
///
/// This that can be serialized and can be used to retrieve the [`SharedMemoryBuf`] in a remote process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
// ZettaScale Zenoh Team, <[email protected]>
//

use std::{sync::{Arc, atomic::AtomicBool}, thread::JoinHandle};
use std::{
sync::{atomic::AtomicBool, Arc},
thread::JoinHandle,
};

use zenoh_result::ZResult;

Expand Down Expand Up @@ -66,7 +69,7 @@ pub fn load_fn(

pub struct CpuLoad {
handle: Option<JoinHandle<()>>,
flag: Arc<AtomicBool>
flag: Arc<AtomicBool>,
}

impl Drop for CpuLoad {
Expand All @@ -89,16 +92,14 @@ impl CpuLoad {
Self::new(1)
}

fn new(thread_count: usize) -> Self {
fn new(thread_count: usize) -> Self {
let flag = Arc::new(AtomicBool::new(true));

let c_flag = flag.clone();
let handle = Some(std::thread::spawn(move || {
execute_concurrent(thread_count, 1, load_fn(c_flag));
}));

Self{handle, flag}


Self { handle, flag }
}
}

12 changes: 6 additions & 6 deletions commons/zenoh-shm/tests/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ use std::sync::atomic::Ordering::Relaxed;

use rand::Rng;
use zenoh_result::ZResult;
use zenoh_shm::{
header::{
descriptor::HeaderDescriptor, storage::GLOBAL_HEADER_STORAGE,
subscription::GLOBAL_HEADER_SUBSCRIPTION,
},
test_helpers::execute_concurrent,
use zenoh_shm::header::{
descriptor::HeaderDescriptor, storage::GLOBAL_HEADER_STORAGE,
subscription::GLOBAL_HEADER_SUBSCRIPTION,
};

pub mod common;
use common::execute_concurrent;

fn header_alloc_fn() -> impl Fn(usize, usize) -> ZResult<()> + Clone + Send + Sync + 'static {
|_task_index: usize, _iteration: usize| -> ZResult<()> {
let _allocated_header = GLOBAL_HEADER_STORAGE.allocate_header()?;
Expand Down
5 changes: 4 additions & 1 deletion commons/zenoh-shm/tests/periodic_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use std::{
time::{Duration, Instant},
};

use zenoh_shm::{test_helpers::CpuLoad, watchdog::periodic_task::PeriodicTask};
use zenoh_shm::watchdog::periodic_task::PeriodicTask;

pub mod common;
use common::CpuLoad;

const TASK_PERIOD: Duration = Duration::from_millis(50);
const TASK_DELTA: Duration = Duration::from_millis(5);
Expand Down
5 changes: 4 additions & 1 deletion commons/zenoh-shm/tests/posix_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
use std::{fmt::Debug, mem::size_of};

use num_traits::{AsPrimitive, PrimInt, Unsigned};
use zenoh_shm::{posix_shm::array::ArrayInSHM, test_helpers::TEST_SEGMENT_PREFIX};
use zenoh_shm::posix_shm::array::ArrayInSHM;

pub mod common;
use common::TEST_SEGMENT_PREFIX;

type TestSegmentID = u32;

Expand Down
8 changes: 4 additions & 4 deletions commons/zenoh-shm/tests/posix_segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

use std::{fmt::Display, slice};

use zenoh_shm::{
posix_shm::segment::Segment,
test_helpers::{validate_memory, TEST_SEGMENT_PREFIX},
};
use zenoh_shm::posix_shm::segment::Segment;

pub mod common;
use common::{validate_memory, TEST_SEGMENT_PREFIX};

fn validate_segment<ID>(segment1: &Segment<ID>, segment2: &Segment<ID>)
where
Expand Down
10 changes: 5 additions & 5 deletions commons/zenoh-shm/tests/watchdog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ use std::{
};

use zenoh_result::{bail, ZResult};
use zenoh_shm::{
test_helpers::{execute_concurrent, CpuLoad},
watchdog::{
confirmator::GLOBAL_CONFIRMATOR, storage::GLOBAL_STORAGE, validator::GLOBAL_VALIDATOR,
},
use zenoh_shm::watchdog::{
confirmator::GLOBAL_CONFIRMATOR, storage::GLOBAL_STORAGE, validator::GLOBAL_VALIDATOR,
};

pub mod common;
use common::{execute_concurrent, CpuLoad};

const VALIDATION_PERIOD: Duration = Duration::from_millis(100);
const CONFIRMATION_PERIOD: Duration = Duration::from_millis(50);

Expand Down
Loading