nordisk_alloc/
selftest.rs1pub const ASPECT_FUNCTIONAL: &str = "functional";
16
17#[cfg(feature = "testmatrix")]
24#[inline]
25pub fn emit(component: &str, check: &str, ok: bool, detail: &str) {
26 nornir_testmatrix::functional_status(component, check, ok, detail);
27}
28
29#[cfg(not(feature = "testmatrix"))]
33#[inline]
34pub fn emit(_component: &str, _check: &str, _ok: bool, _detail: &str) {}
35
36#[macro_export]
40macro_rules! assert_emit {
41 ($component:expr, $check:expr, $ok:expr, $($detail:tt)+) => {{
42 let __ok: bool = $ok;
43 let __detail = ::std::format!($($detail)+);
44 $crate::selftest::emit($component, $check, __ok, &__detail);
45 ::std::assert!(__ok, "{}::{} — {}", $component, $check, __detail);
46 }};
47}
48
49#[cfg(all(test, feature = "testmatrix"))]
51mod wiring {
52 use crate::{
53 current_purge_delay_ms, product_purge_delay_env, purge_delay_plan, purge_delay_plan_from,
54 PurgeDelayPlan, DEFAULT_PURGE_DELAY_MS, MIMALLOC_V3_DEFAULT_PURGE_DELAY_MS,
55 };
56
57 #[test]
61 fn emits_honest_rows_for_allocator_surfaces() {
62 let shipped = current_purge_delay_ms();
63 assert_emit!(
64 "nordisk-alloc",
65 "shipped_default_is_v3s_1000ms",
66 shipped == MIMALLOC_V3_DEFAULT_PURGE_DELAY_MS,
67 "linked mimalloc reports purge_delay={shipped} ms"
68 );
69
70 let d = purge_delay_plan(None);
71 assert_emit!(
72 "nordisk-alloc",
73 "unset_installs_the_safe_default",
74 d == PurgeDelayPlan::Set(DEFAULT_PURGE_DELAY_MS),
75 "plan(None)={d:?}"
76 );
77
78 let typo = purge_delay_plan(Some("ten"));
79 assert_emit!(
80 "nordisk-alloc",
81 "a_typo_falls_forward_not_back",
82 typo == PurgeDelayPlan::Set(DEFAULT_PURGE_DELAY_MS),
83 "plan(\"ten\")={typo:?}"
84 );
85
86 let name = product_purge_delay_env("dwarves");
87 assert_emit!(
88 "nordisk-alloc",
89 "the_products_deployed_variable_survives_the_lift",
90 name == "DWARVES_MIMALLOC_PURGE_DELAY_MS",
91 "product_purge_delay_env(dwarves)={name}"
92 );
93
94 let shadow = purge_delay_plan_from(Some(""), Some("off"));
95 assert_emit!(
96 "nordisk-alloc",
97 "an_empty_product_value_does_not_shadow_the_fleet",
98 shadow == PurgeDelayPlan::LeaveAlone,
99 "plan_from(\"\", \"off\")={shadow:?}"
100 );
101
102 crate::selftest::emit(
104 "nordisk-alloc",
105 "the_installed_value_is_not_v3s_default",
106 DEFAULT_PURGE_DELAY_MS != MIMALLOC_V3_DEFAULT_PURGE_DELAY_MS,
107 &format!("installs {DEFAULT_PURGE_DELAY_MS} ms, v3 ships {MIMALLOC_V3_DEFAULT_PURGE_DELAY_MS} ms"),
108 );
109
110 let rows = nornir_testmatrix::drain_functional_rows();
111 let has = |t: &str, pass: bool| {
112 rows.iter().any(|r| {
113 r.suite == "nordisk-alloc" && r.test_name == t && (r.status == "pass") == pass
114 })
115 };
116 assert!(has("shipped_default_is_v3s_1000ms", true), "rows={rows:?}");
117 assert!(
118 has("unset_installs_the_safe_default", true),
119 "rows={rows:?}"
120 );
121 assert!(has("a_typo_falls_forward_not_back", true), "rows={rows:?}");
122 assert!(
123 has("the_products_deployed_variable_survives_the_lift", true),
124 "rows={rows:?}"
125 );
126 assert!(
127 has("an_empty_product_value_does_not_shadow_the_fleet", true),
128 "rows={rows:?}"
129 );
130 assert!(
131 has("the_installed_value_is_not_v3s_default", true),
132 "rows={rows:?}"
133 );
134 assert!(
135 rows.iter().all(|r| r.aspect == "functional"),
136 "rows={rows:?}"
137 );
138 }
139}