macro_rules! continue_if {
($cond:expr $(,)?) => { ... };
($cond:expr, $($arg:tt)+) => { ... };
}sim only.Expand description
Continues the current simulation instance only if the given condition holds, otherwise stopping and discarding the instance.
This is the same concept as assume in verification tools and property-based testing
libraries (e.g. kani::assume or proptest’s prop_assume!). It is useful inside
simulation tests (crate::sim::flow::SimFlow::fuzz,
crate::sim::flow::SimFlow::exhaustive, and the corresponding
crate::sim::compiled::CompiledSim APIs) to restrict exploration to executions that
satisfy some precondition. When the condition is false, the current instance is stopped
and discarded: it is not treated as a test failure (and will never be recorded as a
fuzzing reproducer), and the fuzzer / exhaustive search simply moves on to the next
instance. If logging is enabled (always during replays, or when HYDRO_SIM_LOG=1), the
failed assumption is logged.
Like the standard assert! macro, an optional custom message with format arguments can be
provided.
flow.sim().fuzz(async || {
in_send.send_many([1, 2]);
let all: Vec<u32> = out_recv.collect().await;
hydro_lang::sim::continue_if!(all.len() == 2, "expected both values in one batch, got {:?}", all);
// ... assertions that only make sense when the assumption holds ...
});