iceoryx2_pal_testing/
lib.rs1#![cfg_attr(not(feature = "std"), no_std)]
21#![warn(clippy::alloc_instead_of_core)]
22#![warn(clippy::std_instead_of_alloc)]
23#![warn(clippy::std_instead_of_core)]
24
25extern crate alloc;
26
27#[macro_use]
28pub mod assert;
29pub mod lifetime_tracker;
30pub mod memory;
31pub mod watchdog;
32
33#[macro_export(local_inner_macros)]
34macro_rules! test_requires {
35 { $condition:expr } => {
36 if !$condition { return; }
37 }
38}
39
40#[macro_export(local_inner_macros)]
41macro_rules! test_fail {
42 ($($e:expr),*) => {
43 core::panic!(
44 "test failed: {} {} {}",
45 assert_that![color_start],
46 alloc::format!($($e),*),
47 assert_that![color_end]
48 )
49 };
50}
51
52pub const AT_LEAST_TIMING_VARIANCE: f32 = iceoryx2_pal_configuration::AT_LEAST_TIMING_VARIANCE;
53
54#[doc(hidden)]
55pub fn is_terminal() -> bool {
56 #[cfg(feature = "std")]
57 {
58 use std::io::IsTerminal;
59 std::io::stderr().is_terminal()
60 }
61 #[cfg(all(not(feature = "std"), any(target_os = "linux", target_os = "nto",)))]
62 {
63 true
64 }
65 #[cfg(all(
66 not(feature = "std"),
67 not(any(target_os = "linux", target_os = "nto",))
68 ))]
69 {
70 false
71 }
72}
73
74#[doc(hidden)]
75pub fn spin_until<F, G>(mut condition: F, _guard: G)
76where
77 F: FnMut() -> bool,
78{
79 loop {
80 if condition() {
81 break;
82 }
83
84 #[cfg(feature = "std")]
85 {
86 std::thread::yield_now();
87 std::thread::sleep(core::time::Duration::from_millis(10));
88 std::thread::yield_now();
89 }
90
91 #[cfg(not(feature = "std"))]
92 core::hint::spin_loop();
93 }
94}