From c72b3824f17e48987b12e352fe0063513852fc74 Mon Sep 17 00:00:00 2001 From: Christopher Berner Date: Sat, 7 Sep 2024 11:56:07 -0700 Subject: [PATCH] Enable wasi CI tests --- .cargo/config.toml | 5 +++++ .github/workflows/ci.yml | 20 +++++++++++--------- justfile | 4 ++-- src/db.rs | 20 +++++++++----------- src/lib.rs | 2 +- tests/backward_compatibility.rs | 2 +- tests/basic_tests.rs | 2 +- tests/integration_tests.rs | 3 ++- tests/multimap_tests.rs | 2 +- tests/multithreading_tests.rs | 2 +- 10 files changed, 34 insertions(+), 28 deletions(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000..d29291e3 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,5 @@ +[target.wasm32-wasip1] +runner = "wasmtime --dir=/tmp" + +[target.wasm32-wasip2] +runner = "wasmtime --dir=/tmp" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 69b94a48..fcc193bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,6 +52,11 @@ jobs: # For some reason this is required to run the fuzzer on OSX rustup target add x86_64-apple-darwin + - name: Setup wasmtime + uses: bytecodealliance/actions/wasmtime/setup@v1 + with: + version: "24.0.0" + - name: Install cargo-deny if: steps.rust-cache.outputs.cache-hit != 'true' run: rustup run --install 1.74 cargo install --force --version 0.14.17 cargo-deny --locked @@ -98,12 +103,9 @@ jobs: pip3 install maturin just test_py -# Re-enable when this works on stable -# - name: Run WASI tests -# if: startsWith(matrix.os, 'macos') -# run: | -# rustup toolchain install nightly -# rustup target add wasm32-wasi -# brew install wasmtime -# cargo install --force --version 0.1.27 cargo-wasi --locked -# just test_wasi + - name: Run WASI tests + if: runner.os != 'Windows' + run: | + rustup toolchain install nightly + rustup target add wasm32-wasip1 --toolchain=nightly + RUSTFLAGS="" just test_wasi diff --git a/justfile b/justfile index cf5e6f8b..b40c7661 100644 --- a/justfile +++ b/justfile @@ -27,8 +27,8 @@ install_py: pre test: pre RUST_BACKTRACE=1 cargo test -test_wasi: pre - CARGO_TARGET_WASM32_WASI_RUNNER="wasmtime --mapdir=/::$TMPDIR" cargo +nightly wasi test -- --nocapture +test_wasi: + cargo +nightly test --target=wasm32-wasip1 -- --nocapture bench bench='lmdb_benchmark': pre cargo bench --bench {{bench}} diff --git a/src/db.rs b/src/db.rs index f09fdcbd..face0bab 100644 --- a/src/db.rs +++ b/src/db.rs @@ -976,6 +976,7 @@ mod test { CommitError, Database, DatabaseError, Durability, ReadableTable, StorageBackend, StorageError, TableDefinition, TransactionError, }; + use std::fs::File; use std::io::{ErrorKind, Read, Seek, SeekFrom}; use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::Arc; @@ -1049,11 +1050,9 @@ mod test { #[test] fn crash_regression4() { let tmpfile = crate::create_tempfile(); + let (file, path) = tmpfile.into_parts(); - let backend = FailingBackend::new( - FileBackend::new(tmpfile.as_file().try_clone().unwrap()).unwrap(), - 23, - ); + let backend = FailingBackend::new(FileBackend::new(file).unwrap(), 23); let db = Database::builder() .set_cache_size(12686) .set_page_size(8 * 1024) @@ -1080,18 +1079,16 @@ mod test { .set_cache_size(1024 * 1024) .set_page_size(8 * 1024) .set_region_size(32 * 4096) - .create(tmpfile.path()) + .create(&path) .unwrap(); } #[test] fn transient_io_error() { let tmpfile = crate::create_tempfile(); + let (file, path) = tmpfile.into_parts(); - let backend = FailingBackend::new( - FileBackend::new(tmpfile.as_file().try_clone().unwrap()).unwrap(), - u64::MAX, - ); + let backend = FailingBackend::new(FileBackend::new(file).unwrap(), u64::MAX); let countdown = backend.countdown.clone(); let db = Database::builder() .set_cache_size(0) @@ -1129,9 +1126,10 @@ mod test { drop(db); // Check that recovery flag is set, even though the error has "cleared" - tmpfile.as_file().seek(SeekFrom::Start(9)).unwrap(); + let mut file = File::open(&path).unwrap(); + file.seek(SeekFrom::Start(9)).unwrap(); let mut god_byte = vec![0u8]; - assert_eq!(tmpfile.as_file().read(&mut god_byte).unwrap(), 1); + assert_eq!(file.read(&mut god_byte).unwrap(), 1); assert_ne!(god_byte[0] & 2, 0); } diff --git a/src/lib.rs b/src/lib.rs index b24f0142..ebe148fe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -96,7 +96,7 @@ mod types; #[cfg(test)] fn create_tempfile() -> tempfile::NamedTempFile { if cfg!(target_os = "wasi") { - tempfile::NamedTempFile::new_in("/").unwrap() + tempfile::NamedTempFile::new_in("/tmp").unwrap() } else { tempfile::NamedTempFile::new().unwrap() } diff --git a/tests/backward_compatibility.rs b/tests/backward_compatibility.rs index 1aba7e78..5eb241a4 100644 --- a/tests/backward_compatibility.rs +++ b/tests/backward_compatibility.rs @@ -253,7 +253,7 @@ impl TestData for (u64, &'static str) { fn create_tempfile() -> tempfile::NamedTempFile { if cfg!(target_os = "wasi") { - tempfile::NamedTempFile::new_in("/").unwrap() + tempfile::NamedTempFile::new_in("/tmp").unwrap() } else { tempfile::NamedTempFile::new().unwrap() } diff --git a/tests/basic_tests.rs b/tests/basic_tests.rs index f07fdf3a..8a0c1d60 100644 --- a/tests/basic_tests.rs +++ b/tests/basic_tests.rs @@ -14,7 +14,7 @@ const U64_TABLE: TableDefinition = TableDefinition::new("u64"); fn create_tempfile() -> tempfile::NamedTempFile { if cfg!(target_os = "wasi") { - tempfile::NamedTempFile::new_in("/").unwrap() + tempfile::NamedTempFile::new_in("/tmp").unwrap() } else { tempfile::NamedTempFile::new().unwrap() } diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 8d23b946..e96d5c7b 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -24,7 +24,7 @@ const U64_TABLE: TableDefinition = TableDefinition::new("u64"); fn create_tempfile() -> tempfile::NamedTempFile { if cfg!(target_os = "wasi") { - tempfile::NamedTempFile::new_in("/").unwrap() + tempfile::NamedTempFile::new_in("/tmp").unwrap() } else { tempfile::NamedTempFile::new().unwrap() } @@ -299,6 +299,7 @@ fn large_values() { // Note: this test requires > 3GiB of memory #[test] +#[cfg(target_pointer_width = "64")] fn value_too_large() { let tmpfile = create_tempfile(); diff --git a/tests/multimap_tests.rs b/tests/multimap_tests.rs index 9a0d03c4..9cd6f11c 100644 --- a/tests/multimap_tests.rs +++ b/tests/multimap_tests.rs @@ -9,7 +9,7 @@ const U64_TABLE: MultimapTableDefinition = MultimapTableDefinition::ne fn create_tempfile() -> tempfile::NamedTempFile { if cfg!(target_os = "wasi") { - tempfile::NamedTempFile::new_in("/").unwrap() + tempfile::NamedTempFile::new_in("/tmp").unwrap() } else { tempfile::NamedTempFile::new().unwrap() } diff --git a/tests/multithreading_tests.rs b/tests/multithreading_tests.rs index eb9a6855..fe63ab91 100644 --- a/tests/multithreading_tests.rs +++ b/tests/multithreading_tests.rs @@ -6,7 +6,7 @@ mod multithreading_test { fn create_tempfile() -> tempfile::NamedTempFile { if cfg!(target_os = "wasi") { - tempfile::NamedTempFile::new_in("/").unwrap() + tempfile::NamedTempFile::new_in("/tmp").unwrap() } else { tempfile::NamedTempFile::new().unwrap() }