selection_capture/
linux_subscriber.rs1use crate::native_subscriber::define_native_subscriber_core;
2use crate::LinuxObserverBridge;
3
4define_native_subscriber_core!(
5 observer_bridge = LinuxObserverBridge,
6 runtime_adapter_type = LinuxNativeRuntimeAdapter,
7 stats_type = LinuxNativeSubscriberStats,
8 ensure_hook_fn = ensure_linux_native_subscriber_hook_installed,
9 stats_fn = linux_native_subscriber_stats,
10 set_adapter_fn = set_linux_native_runtime_adapter,
11 adapter_registered_fn = linux_native_runtime_adapter_registered,
12 reset_fn = reset_linux_native_subscriber_for_tests,
13);
14
15#[cfg(test)]
16mod tests {
17 use super::*;
18 use crate::linux_observer::linux_observer_test_lock;
19
20 #[test]
21 fn lifecycle_hook_drives_subscriber_stats() {
22 let _guard = linux_observer_test_lock()
23 .lock()
24 .expect("test lock poisoned");
25 let _ = LinuxObserverBridge::stop();
26 LinuxObserverBridge::set_lifecycle_hook(None);
27 reset_linux_native_subscriber_for_tests();
28
29 ensure_linux_native_subscriber_hook_installed();
30 let before = linux_native_subscriber_stats();
31
32 let _ = LinuxObserverBridge::start();
33 let started = linux_native_subscriber_stats();
34 assert!(started.starts >= before.starts);
35 assert_eq!(started.stops, before.stops);
36 assert!(started.active || LinuxObserverBridge::is_active());
37
38 let _ = LinuxObserverBridge::stop();
39 let stopped = linux_native_subscriber_stats();
40 assert!(stopped.starts >= started.starts);
41 assert!(stopped.stops >= started.stops);
42 assert!(!stopped.active || LinuxObserverBridge::is_active());
43 }
44
45 #[test]
46 fn runtime_adapter_failures_are_recorded() {
47 fn adapter(_active: bool) -> bool {
48 false
49 }
50
51 let _guard = linux_observer_test_lock()
52 .lock()
53 .expect("test lock poisoned");
54 let _ = LinuxObserverBridge::stop();
55 LinuxObserverBridge::set_lifecycle_hook(None);
56 reset_linux_native_subscriber_for_tests();
57 set_linux_native_runtime_adapter(Some(adapter));
58 ensure_linux_native_subscriber_hook_installed();
59
60 let _ = LinuxObserverBridge::start();
61 let _ = LinuxObserverBridge::stop();
62
63 let stats = linux_native_subscriber_stats();
64 assert!(stats.adapter_attempts >= 2);
65 assert!(stats.adapter_failures >= 2);
66 }
67}