From 9783e40db65f181fc9e4c30434b16f4cb57aff58 Mon Sep 17 00:00:00 2001 From: sanjeeb Date: Thu, 20 Aug 2026 02:09:38 +0530 Subject: [PATCH] test: cover nested watchdog suppression --- msim/src/sim/runtime/mod.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/msim/src/sim/runtime/mod.rs b/msim/src/sim/runtime/mod.rs index 1634923..67a5834 100644 --- a/msim/src/sim/runtime/mod.rs +++ b/msim/src/sim/runtime/mod.rs @@ -625,6 +625,33 @@ mod tests { use super::start_watchdog_with; use crate::{runtime::Runtime, time}; + #[test] + fn test_nested_watchdog_suppression() { + let runtime = Runtime::new(); + let handle = runtime.handle(); + + assert!(!handle.is_watchdog_suppressed()); + + let outer_guard = handle.suppress_watchdog(); + assert!(handle.is_watchdog_suppressed()); + + { + let inner_guard = handle.suppress_watchdog(); + assert!(handle.is_watchdog_suppressed()); + + drop(inner_guard); + + // Dropping the inner guard must not re-enable the watchdog + // while the outer guard is still active. + assert!(handle.is_watchdog_suppressed()); + } + + drop(outer_guard); + + // The watchdog should resume only after all guards are dropped. + assert!(!handle.is_watchdog_suppressed()); + } + #[test] fn test_watchdog() { // This test will panic if logging is enabled since the logging happens outside of a