From 514ebf92a3fa3611bf7ec509fb64859e209af69c 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 --- .github/workflows/ci.yml | 20 +++++++++++--------- justfile | 4 ++-- src/db.rs | 14 +++++++++----- 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 +- 9 files changed, 29 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 69b94a48..f703e706 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 + just test_wasi diff --git a/justfile b/justfile index cf5e6f8b..c93dfe48 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_TARGET_WASM32_WASIP1_RUNNER="wasmtime --dir=/tmp/" 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..02dd65c5 100644 --- a/src/db.rs +++ b/src/db.rs @@ -971,6 +971,7 @@ impl std::fmt::Debug for Database { #[cfg(test)] mod test { + use std::fs::File; use crate::backends::FileBackend; use crate::{ CommitError, Database, DatabaseError, Durability, ReadableTable, StorageBackend, @@ -1049,9 +1050,10 @@ 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(), + FileBackend::new(file).unwrap(), 23, ); let db = Database::builder() @@ -1080,16 +1082,17 @@ 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(), + FileBackend::new(file).unwrap(), u64::MAX, ); let countdown = backend.countdown.clone(); @@ -1129,9 +1132,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() }