diff --git a/Cargo.toml b/Cargo.toml index 328c86c66..8ac02dab6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -90,7 +90,7 @@ fallible-iterator = "0.3.0" criterion = "0.5" chrono = { version = "0.4.42", default-features = false } hex = "0.4" -antithesis_sdk = "0.2" +antithesis_sdk = { version = "0.2", default-features = false } cfg-if = "1.0.0" tracing-appender = "0.2.3" env_logger = { version = "0.11.6", default-features = false } diff --git a/bindings/rust/src/lib.rs b/bindings/rust/src/lib.rs index d8d597cc6..8cd47d599 100644 --- a/bindings/rust/src/lib.rs +++ b/bindings/rust/src/lib.rs @@ -153,14 +153,14 @@ impl Builder { match vfs_choice { "memory" => Ok(Arc::new(turso_core::MemoryIO::new())), "syscall" => { - #[cfg(target_family = "unix")] + #[cfg(all(target_family = "unix", not(miri)))] { Ok(Arc::new( turso_core::UnixIO::new() .map_err(|e| Error::SqlExecutionFailure(e.to_string()))?, )) } - #[cfg(not(target_family = "unix"))] + #[cfg(any(not(target_family = "unix"), miri))] { Ok(Arc::new( turso_core::PlatformIO::new() @@ -168,12 +168,12 @@ impl Builder { )) } } - #[cfg(target_os = "linux")] + #[cfg(all(target_os = "linux", not(miri)))] "io_uring" => Ok(Arc::new( turso_core::UringIO::new() .map_err(|e| Error::SqlExecutionFailure(e.to_string()))?, )), - #[cfg(not(target_os = "linux"))] + #[cfg(any(not(target_os = "linux"), miri))] "io_uring" => Err(Error::SqlExecutionFailure( "io_uring is only available on Linux targets".to_string(), )), diff --git a/core/Cargo.toml b/core/Cargo.toml index a795f9d8c..d5651a2e4 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -15,7 +15,7 @@ path = "lib.rs" [features] default = ["fs", "uuid", "time", "json", "series", "encryption"] -antithesis = ["dep:antithesis_sdk"] +antithesis = ["dep:antithesis_sdk", "antithesis_sdk?/full"] tracing_release = ["tracing/release_max_level_info"] conn_raw_api = [] fs = ["turso_ext/vfs"] diff --git a/core/storage/btree.rs b/core/storage/btree.rs index 31e89b01f..65659c4b3 100644 --- a/core/storage/btree.rs +++ b/core/storage/btree.rs @@ -2857,7 +2857,8 @@ impl BTreeCursor { // load sibling pages // start loading right page first - let mut pgno: u32 = unsafe { right_pointer.cast::().read().swap_bytes() }; + let mut pgno: u32 = + unsafe { right_pointer.cast::().read_unaligned().swap_bytes() }; let current_sibling = sibling_pointer; let mut group = CompletionGroup::new(|_| {}); for i in (0..=current_sibling).rev() { diff --git a/simulator/run-miri.sh b/simulator/run-miri.sh new file mode 100755 index 000000000..e065f3c68 --- /dev/null +++ b/simulator/run-miri.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +ARGS=("$@") + +# Intercept the seed if it's passed +while [[ $# -gt 0 ]]; do + case $1 in + -s=*|--seed=*) + seed="${1#*=}" + shift + ;; + -s|--seed) + seed="$2" + shift 2 + ;; + *) + shift + ;; + esac +done +# Otherwise make one up +if [ -z "$seed" ]; then + # Dump 8 bytes of /dev/random as decimal u64 + seed=$(od -An -N8 -tu8 /dev/random | tr -d ' ') + ARGS+=("--seed" "${seed}") + echo "Generated seed for Miri and simulator: ${seed}" +else + echo "Intercepted simulator seed to pass to Miri: ${seed}" +fi + +MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-disable-stacked-borrows -Zmiri-seed=${seed}" cargo +nightly miri run --bin limbo_sim -- "${ARGS[@]}" diff --git a/simulator/runner/cli.rs b/simulator/runner/cli.rs index 8a941dde1..97062dd2d 100644 --- a/simulator/runner/cli.rs +++ b/simulator/runner/cli.rs @@ -30,7 +30,7 @@ pub struct SimulatorCLI { short = 'n', long, help = "change the maximum size of the randomly generated sequence of interactions", - default_value_t = 5000, + default_value_t = normal_or_miri(5000, 50), value_parser = clap::value_parser!(u32).range(1..) )] pub maximum_tests: u32, @@ -38,7 +38,7 @@ pub struct SimulatorCLI { short = 'k', long, help = "change the minimum size of the randomly generated sequence of interactions", - default_value_t = 1000, + default_value_t = normal_or_miri(1000, 10), value_parser = clap::value_parser!(u32).range(1..) )] pub minimum_tests: u32, @@ -149,7 +149,8 @@ pub struct SimulatorCLI { pub keep_files: bool, #[clap( long, - help = "Disable the SQLite integrity check at the end of a simulation" + help = "Disable the SQLite integrity check at the end of a simulation", + default_value_t = normal_or_miri(false, true) )] pub disable_integrity_check: bool, #[clap( @@ -279,3 +280,7 @@ impl ValueParserFactory for ProfileType { ProfileTypeParser } } + +const fn normal_or_miri(normal_val: T, miri_val: T) -> T { + if cfg!(miri) { miri_val } else { normal_val } +} diff --git a/stress/Cargo.toml b/stress/Cargo.toml index 077f5f003..7221e80ca 100644 --- a/stress/Cargo.toml +++ b/stress/Cargo.toml @@ -16,7 +16,7 @@ path = "main.rs" [features] default = ["experimental_indexes"] -antithesis = ["turso/antithesis"] +antithesis = ["turso/antithesis", "antithesis_sdk/full"] experimental_indexes = [] [dependencies] diff --git a/stress/main.rs b/stress/main.rs index 7c899e0ab..879002547 100644 --- a/stress/main.rs +++ b/stress/main.rs @@ -642,9 +642,11 @@ async fn main() -> Result<(), Box> { println!("Done. SQL statements written to {}", opts.log_file); println!("Database file: {db_file}"); - println!("Running SQLite Integrity check"); - - integrity_check(std::path::Path::new(&db_file))?; + #[cfg(not(miri))] + { + println!("Running SQLite Integrity check"); + integrity_check(std::path::Path::new(&db_file))?; + } Ok(()) } diff --git a/stress/opts.rs b/stress/opts.rs index 796f85847..aac93f67d 100644 --- a/stress/opts.rs +++ b/stress/opts.rs @@ -21,7 +21,7 @@ pub struct Opts { short = 'i', long, help = "the number of iterations", - default_value_t = 100000 + default_value_t = normal_or_miri(100_000, 1000) )] pub nr_iterations: usize, @@ -75,3 +75,11 @@ pub struct Opts { )] pub busy_timeout: u64, } + +const fn normal_or_miri(normal_val: T, miri_val: T) -> T { + if cfg!(miri) { + miri_val + } else { + normal_val + } +} diff --git a/stress/run-miri.sh b/stress/run-miri.sh new file mode 100755 index 000000000..2de0069e5 --- /dev/null +++ b/stress/run-miri.sh @@ -0,0 +1,4 @@ +#!/bin/bash + + +MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-disable-stacked-borrows" cargo +nightly miri run -p turso_stress -- "$@"