use epics_libcom_rs::runtime::task::{
PriorityApplied, RT_PRIORITY_ENV, RtPolicy, ThreadPriority, apply_to_current_thread,
sched_calls_made,
};
#[test]
fn a_default_process_never_calls_the_os_scheduler() {
assert_eq!(
std::env::var_os(RT_PRIORITY_ENV),
None,
"this test measures the default; run it with {RT_PRIORITY_ENV} unset"
);
assert_eq!(
RtPolicy::current(),
RtPolicy::Disabled,
"an unset switch must resolve to off on a hosted target"
);
let wired = [
ThreadPriority::Custom(ThreadPriority::ScanLow.value() - 1),
ThreadPriority::Custom(ThreadPriority::ScanLow.value() + 4),
ThreadPriority::Custom(ThreadPriority::ScanHigh.value() + 1),
ThreadPriority::ScanHigh,
ThreadPriority::ScanLow,
ThreadPriority::CaServerLow,
ThreadPriority::Custom(ThreadPriority::CaServerLow.value() - 1),
];
for p in wired {
assert_eq!(
apply_to_current_thread(p),
PriorityApplied::Disabled,
"{p:?} must not reach the scheduler with the switch off"
);
}
let workers: Vec<_> = wired
.into_iter()
.map(|p| std::thread::spawn(move || apply_to_current_thread(p)))
.collect();
for w in workers {
assert_eq!(
w.join().expect("worker panicked"),
PriorityApplied::Disabled
);
}
assert_eq!(
sched_calls_made(),
0,
"a default process must make no pthread_setschedparam call at all — \
not even the one-off range probe"
);
}