forked from eclipse-iceoryx/iceoryx2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[eclipse-iceoryx#361] Add timeout test for zero copy connection
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
iceoryx2-cal/tests/zero_copy_connection_posix_shared_memory_tests.rs
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,58 @@ | ||
// Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
// | ||
// See the NOTICE file(s) distributed with this work for additional | ||
// information regarding copyright ownership. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Apache Software License 2.0 which is available at | ||
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license | ||
// which is available at https://opensource.org/licenses/MIT. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
mod zero_copy_connection_posix_shared_memory_tests { | ||
use iceoryx2_bb_elementary::math::ToB64; | ||
use iceoryx2_bb_posix::creation_mode::CreationMode; | ||
use iceoryx2_bb_posix::permission::Permission; | ||
use iceoryx2_bb_posix::unique_system_id::UniqueSystemId; | ||
use iceoryx2_bb_system_types::file_name::*; | ||
use iceoryx2_bb_testing::assert_that; | ||
use iceoryx2_cal::named_concept::*; | ||
use iceoryx2_cal::zero_copy_connection::*; | ||
use std::time::Duration; | ||
|
||
const TIMEOUT: Duration = Duration::from_millis(100); | ||
|
||
fn generate_name() -> FileName { | ||
let mut file = FileName::new(b"test_").unwrap(); | ||
file.push_bytes(UniqueSystemId::new().unwrap().value().to_b64().as_bytes()) | ||
.unwrap(); | ||
file | ||
} | ||
|
||
#[test] | ||
fn waiting_for_initialization_works() { | ||
type Sut = iceoryx2_cal::zero_copy_connection::posix_shared_memory::Connection; | ||
let storage_name = generate_name(); | ||
let file_name = <Sut as NamedConceptMgmt>::Configuration::default() | ||
.path_for(&storage_name) | ||
.file_name(); | ||
|
||
let _raw_shm = iceoryx2_bb_posix::shared_memory::SharedMemoryBuilder::new(&file_name) | ||
.creation_mode(CreationMode::PurgeAndCreate) | ||
.size(1234) | ||
.has_ownership(true) | ||
.permission(Permission::OWNER_WRITE) | ||
.create() | ||
.unwrap(); | ||
|
||
let start = std::time::SystemTime::now(); | ||
let sut = <Sut as ZeroCopyConnection>::Builder::new(&storage_name) | ||
.timeout(TIMEOUT) | ||
.create_sender(1); | ||
|
||
assert_that!(start.elapsed().unwrap(), ge TIMEOUT); | ||
assert_that!(sut, is_err); | ||
assert_that!(sut.err().unwrap(), eq ZeroCopyCreationError::InitializationNotYetFinalized); | ||
} | ||
} |