Skip to main content

shuttle_engine/
lib.rs

1#![deny(warnings, missing_debug_implementations)]
2#![allow(dead_code, clippy::new_without_default)]
3
4pub mod annotations;
5pub mod config;
6pub mod current;
7pub mod future;
8pub mod hint;
9pub mod runtime;
10pub mod scheduler;
11pub mod sync_types;
12pub mod thread_support;
13
14pub use config::{
15    Config, ContinuationFunctionBehavior, FailurePersistence, MaxSteps, UngracefulShutdownConfig,
16    UNGRACEFUL_SHUTDOWN_CONFIG,
17};
18pub use runtime::runner::{PortfolioRunner, Runner};
19pub use sync_types::{ResourceSignature, ResourceType};
20
21/// If this environment variable is set, then Shuttle will capture the backtrace of each task and display
22/// the backtraces in the panic message.
23/// Capturing backtraces is quite expensive, so this should only be set when debugging a failing test.
24pub const CAPTURE_BACKTRACE: &str = "SHUTTLE_CAPTURE_BACKTRACE";
25
26/// The random seed used to initialize either the `RandomScheduler` or `PctScheduler`
27/// (both in the `shuttle-schedulers` crate)
28const RANDOM_SEED: &str = "SHUTTLE_RANDOM_SEED";
29
30/// If this is set, then warnings about Shuttle's modelling of weak memory and differences between Shuttle's
31/// version of LazyStatic and the regular version of LazyStatic will not be emitted.
32pub const SILENCE_WARNINGS: &str = "SHUTTLE_SILENCE_WARNINGS";
33
34/// Used in the annotation scheduler to specify where to write the annotations.
35pub const ANNOTATION_FILE: &str = "SHUTTLE_ANNOTATION_FILE";
36
37#[cfg(feature = "annotation")]
38pub fn annotation_file() -> String {
39    std::env::var(ANNOTATION_FILE).unwrap_or_else(|_| "annotated.json".to_string())
40}
41
42pub fn silence_warnings() -> bool {
43    std::env::var(SILENCE_WARNINGS).is_ok()
44}
45
46pub fn backtrace_enabled() -> bool {
47    std::env::var(CAPTURE_BACKTRACE).is_ok()
48}
49
50pub fn seed_from_env(fallback_seed: u64) -> u64 {
51    let seed_env = std::env::var(RANDOM_SEED);
52    match seed_env {
53        Ok(s) => match s.as_str().parse::<u64>() {
54            Ok(seed) => {
55                tracing::info!(
56                    "Initializing scheduler with the seed provided by {}: {}",
57                    RANDOM_SEED,
58                    seed
59                );
60                seed
61            }
62            Err(err) => panic!("The seed provided by {RANDOM_SEED} is not a valid u64: {err}"),
63        },
64        Err(_) => fallback_seed,
65    }
66}