Skip to content

Commit

Permalink
Enable wasi CI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cberner committed Sep 8, 2024
1 parent 8a611be commit c72b382
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[target.wasm32-wasip1]
runner = "wasmtime --dir=/tmp"

[target.wasm32-wasip2]
runner = "wasmtime --dir=/tmp"
20 changes: 11 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
20 changes: 9 additions & 11 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion tests/backward_compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion tests/basic_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const U64_TABLE: TableDefinition<u64, u64> = 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()
}
Expand Down
3 changes: 2 additions & 1 deletion tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const U64_TABLE: TableDefinition<u64, u64> = 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()
}
Expand Down Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion tests/multimap_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const U64_TABLE: MultimapTableDefinition<u64, u64> = 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()
}
Expand Down
2 changes: 1 addition & 1 deletion tests/multithreading_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit c72b382

Please sign in to comment.