iceoryx2_bb_testing/lib.rs
1// Copyright (c) 2023 Contributors to the Eclipse Foundation
2//
3// See the NOTICE file(s) distributed with this work for additional
4// information regarding copyright ownership.
5//
6// This program and the accompanying materials are made available under the
7// terms of the Apache Software License 2.0 which is available at
8// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
9// which is available at https://opensource.org/licenses/MIT.
10//
11// SPDX-License-Identifier: Apache-2.0 OR MIT
12
13//! Testing utilities and helpers.
14//!
15//! These utilities may leverage components in the building blocks layer of
16//! the architecture.
17//!
18//! Components from [`iceoryx2_pal_testing`] are re-exported for convenience
19//! of use in upper layers.
20
21#![cfg_attr(not(feature = "std"), no_std)]
22#![warn(clippy::alloc_instead_of_core)]
23#![warn(clippy::std_instead_of_alloc)]
24#![warn(clippy::std_instead_of_core)]
25
26extern crate alloc;
27
28pub use iceoryx2_pal_testing::*;
29pub mod abandon_tracker;
30pub mod instantiate_conformance_tests_macro;
31pub mod lifetime_tracker;
32pub mod test_harness;
33
34pub use inventory;
35#[cfg(feature = "std")]
36pub use libtest_mimic;
37
38/// Default number of test threads for the custom test harness.
39///
40/// Tests using [`iceoryx2_pal_testing::lifetime_tracker::LifetimeTracker`] rely on global mutable state that is not
41/// safe to access concurrently. Serial execution is required unless the caller
42/// explicitly overrides this via `--test-threads`.
43#[cfg(feature = "std")]
44pub const DEFAULT_TEST_THREADS: usize = 1;
45
46pub enum RunMode {
47 Normal,
48 Ignore(Option<&'static str>),
49 ExpectPanic(Option<&'static str>),
50}
51
52pub enum RequiresStd {
53 No,
54 Yes(Option<&'static str>),
55}
56
57pub struct TestCase {
58 pub module: &'static str,
59 pub name: &'static str,
60 pub test_fn: fn(),
61 pub run_mode: RunMode,
62 pub requires_std: RequiresStd,
63}
64inventory::collect!(TestCase);
65
66pub mod internal {
67 #[cfg(any(target_os = "linux", target_os = "nto"))]
68 pub use iceoryx2_pal_posix::posix::abort;
69 pub use iceoryx2_pal_print::cout;
70 pub use iceoryx2_pal_print::coutln;
71}