pub struct LabRuntime {
pub state: RuntimeState,
pub scheduler: Arc<Mutex<LabScheduler>>,
pub oracles: OracleSuite,
/* private fields */
}Expand description
The deterministic lab runtime.
This runtime is designed for testing and provides:
- Virtual time instead of wall-clock time
- Deterministic scheduling based on a seed
- Trace capture for debugging and replay
- Chaos injection for stress testing
Fields§
§state: RuntimeStateRuntime state (public for tests and oracle access).
scheduler: Arc<Mutex<LabScheduler>>Scheduler.
oracles: OracleSuiteOracle suite for invariant verification.
Implementations§
Source§impl LabRuntime
impl LabRuntime
Sourcepub fn new(config: LabConfig) -> LabRuntime
pub fn new(config: LabConfig) -> LabRuntime
Creates a new lab runtime with the given configuration.
Sourcepub fn with_seed(seed: u64) -> LabRuntime
pub fn with_seed(seed: u64) -> LabRuntime
Creates a lab runtime with the default configuration.
Sourcepub fn lab_reactor(&self) -> &Arc<LabReactor>
pub fn lab_reactor(&self) -> &Arc<LabReactor>
Returns a handle to the lab reactor for deterministic I/O injection.
Sourcepub fn trace(&self) -> &TraceBufferHandle
pub fn trace(&self) -> &TraceBufferHandle
Returns a reference to the trace buffer handle.
Sourcepub fn detected_races(&self) -> RaceReport
pub fn detected_races(&self) -> RaceReport
Returns a race report derived from the current trace buffer.
Sourcepub fn chaos_stats(&self) -> &ChaosStats
pub fn chaos_stats(&self) -> &ChaosStats
Returns a reference to the chaos statistics.
Sourcepub fn certificate(&self) -> &ScheduleCertificate
pub fn certificate(&self) -> &ScheduleCertificate
Returns the schedule certificate for determinism verification.
Sourcepub fn has_replay_recording(&self) -> bool
pub fn has_replay_recording(&self) -> bool
Returns true if replay recording is enabled.
Sourcepub fn replay_recorder(&self) -> &TraceRecorder
pub fn replay_recorder(&self) -> &TraceRecorder
Returns a reference to the replay recorder.
Sourcepub fn take_replay_trace(&mut self) -> Option<ReplayTrace>
pub fn take_replay_trace(&mut self) -> Option<ReplayTrace>
Takes the replay trace, leaving an empty trace in place.
Returns None if recording is disabled.
Sourcepub fn finish_replay_trace(&mut self) -> Option<ReplayTrace>
pub fn finish_replay_trace(&mut self) -> Option<ReplayTrace>
Finishes recording and returns the replay trace.
This consumes the replay recorder. Returns None if recording is disabled.
Sourcepub fn is_quiescent(&self) -> bool
pub fn is_quiescent(&self) -> bool
Returns true if the runtime is quiescent.
Sourcepub fn advance_time(&mut self, nanos: u64)
pub fn advance_time(&mut self, nanos: u64)
Advances virtual time by the given number of nanoseconds.
Sourcepub fn advance_time_to(&mut self, time: Time)
pub fn advance_time_to(&mut self, time: Time)
Advances time to the given absolute time.
If the target time is before the current time, logs an error and does nothing (time cannot go backward).
Sourcepub fn advance_to_next_timer(&mut self) -> usize
pub fn advance_to_next_timer(&mut self) -> usize
Advances virtual time to the next timer deadline.
If a timer is pending, advances time to its deadline, processes the expired timer(s), and returns the number of wakeups triggered. Returns 0 if no timers are pending.
Sourcepub fn next_timer_deadline(&self) -> Option<Time>
pub fn next_timer_deadline(&self) -> Option<Time>
Returns the next timer deadline, if any timers are pending.
Sourcepub fn pending_timer_count(&self) -> usize
pub fn pending_timer_count(&self) -> usize
Returns the number of pending timers.
Sourcepub fn run_with_auto_advance(&mut self) -> VirtualTimeReport
pub fn run_with_auto_advance(&mut self) -> VirtualTimeReport
Runs until quiescent, automatically advancing virtual time to pending timer deadlines whenever all tasks are idle.
This enables “instant timeout testing”: a scenario that would take
24 hours of wall-clock time completes in <1 second because every
sleep/timeout deadline is jumped to instantly.
The loop is:
- Run until idle (no runnable tasks in scheduler).
- If timers are pending, advance time to next deadline → go to 1.
- If no timers and quiescent → done.
Returns a VirtualTimeReport with execution statistics.
Sourcepub fn pause_clock(&self)
pub fn pause_clock(&self)
Pauses the virtual clock, freezing time at the current value.
While paused, advance_time() and timer processing still work at the
LabRuntime level (they update the runtime’s own virtual_time field),
but the underlying VirtualClock visible to tasks via Cx::now() is
frozen. This is useful for testing timeout detection: tasks that call
Cx::now() will see time standing still while the runtime can still
orchestrate scheduling.
Sourcepub fn resume_clock(&self)
pub fn resume_clock(&self)
Resumes a paused virtual clock.
Sourcepub fn is_clock_paused(&self) -> bool
pub fn is_clock_paused(&self) -> bool
Returns true if the virtual clock is currently paused.
Sourcepub fn inject_clock_skew(&mut self, skew_nanos: u64)
pub fn inject_clock_skew(&mut self, skew_nanos: u64)
Injects a clock skew by jumping time forward by skew_nanos.
This simulates clock drift or NTP corrections. A warning is logged because large jumps may affect lease/timeout correctness.
Sourcepub fn run_until_quiescent(&mut self) -> u64
pub fn run_until_quiescent(&mut self) -> u64
Runs until quiescent or max steps reached.
Returns the number of steps executed.
Sourcepub fn run_until_idle(&mut self) -> u64
pub fn run_until_idle(&mut self) -> u64
Runs until there are no runnable tasks in the scheduler.
This is intentionally weaker than Self::run_until_quiescent:
- It does not require all tasks to complete.
- It does not require all obligations to be resolved.
Use this when a test wants to “poll once” until the system is idle (e.g. a task is blocked on a channel receive) without forcing full completion and drain.
Sourcepub fn run_until_quiescent_with_report(&mut self) -> LabRunReport
pub fn run_until_quiescent_with_report(&mut self) -> LabRunReport
Runs until quiescent (or max_steps is reached) and returns a structured report.
Sourcepub fn report(&mut self) -> LabRunReport
pub fn report(&mut self) -> LabRunReport
Build a structured report for the current runtime state.
This does not advance execution.
Sourcepub fn run_until_quiescent_spork_report(
&mut self,
app: impl Into<String>,
attachments: Vec<HarnessAttachmentRef>,
) -> SporkHarnessReport
pub fn run_until_quiescent_spork_report( &mut self, app: impl Into<String>, attachments: Vec<HarnessAttachmentRef>, ) -> SporkHarnessReport
Runs until quiescent (or max_steps is reached) and returns a Spork harness report.
Sourcepub fn spork_report(
&mut self,
app: impl Into<String>,
attachments: Vec<HarnessAttachmentRef>,
) -> SporkHarnessReport
pub fn spork_report( &mut self, app: impl Into<String>, attachments: Vec<HarnessAttachmentRef>, ) -> SporkHarnessReport
Build a Spork harness report for the current runtime state.
This does not advance execution.
Sourcepub fn build_crashpack_for_report(
&self,
run: &LabRunReport,
) -> Option<CrashPack>
pub fn build_crashpack_for_report( &self, run: &LabRunReport, ) -> Option<CrashPack>
Build an in-memory crashpack for a failing report.
Returns None for passing reports.
Sourcepub fn enable_deadline_monitoring(&mut self, config: MonitorConfig)
pub fn enable_deadline_monitoring(&mut self, config: MonitorConfig)
Enable deadline monitoring with the default warning handler.
Sourcepub fn enable_deadline_monitoring_with_handler<F>(
&mut self,
config: MonitorConfig,
f: F,
)
pub fn enable_deadline_monitoring_with_handler<F>( &mut self, config: MonitorConfig, f: F, )
Enable deadline monitoring with a custom warning handler.
Sourcepub fn deadline_monitor_mut(&mut self) -> Option<&mut DeadlineMonitor>
pub fn deadline_monitor_mut(&mut self) -> Option<&mut DeadlineMonitor>
Returns a mutable reference to the deadline monitor, if enabled.
Sourcepub fn step_for_test(&mut self)
pub fn step_for_test(&mut self)
Public wrapper for step() for use in tests.
This is useful for testing determinism across multiple step executions.
Sourcepub fn check_invariants(&mut self) -> Vec<InvariantViolation>
pub fn check_invariants(&mut self) -> Vec<InvariantViolation>
Checks invariants and returns any violations.