From 8a90f94a79ed36cf358c127a860b538eabe191af Mon Sep 17 00:00:00 2001 From: Devashish Dixit Date: Thu, 14 Jul 2022 10:15:16 +0800 Subject: [PATCH 1/4] Fix libwasmvm tests for windows and check it in CI --- .circleci/config.yml | 26 ++++++++++++++++++++++++++ libwasmvm/Cargo.lock | 8 ++++++++ libwasmvm/Cargo.toml | 2 ++ libwasmvm/src/cache.rs | 31 ++++++++++++++++++------------- 4 files changed, 54 insertions(+), 13 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 69416d282..d6d7a8580 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,5 +1,8 @@ version: 2.1 +orbs: + win: circleci/windows@4.1.1 + jobs: # All checks on the codebase that can run in parallel to build_shared_library libwasmvm_sanity: @@ -182,6 +185,28 @@ jobs: command: make test-safety - run: make build-go + rust-unit-tests-windows: + executor: + name: win/default + shell: powershell.exe + environment: + CARGO_NET_GIT_FETCH_WITH_CLI: "true" + steps: + - checkout + - run: + name: Install Rustup + command: choco install rustup.install + - run: + name: Install Rust + command: rustup default 1.59.0 + - run: + name: Show Rust version information + command: rustc --version; cargo --version; rustup --version + - run: + name: Run unit tests + working_directory: libwasmvm + command: cargo test + test_alpine_build: machine: image: ubuntu-2004:202101-01 @@ -283,6 +308,7 @@ workflows: - tidy-go - format-scripts - lint-scripts + - rust-unit-tests-windows - build_shared_library: filters: # required since other jobs with tag filters require this one tags: diff --git a/libwasmvm/Cargo.lock b/libwasmvm/Cargo.lock index 16878b87b..42decd98d 100644 --- a/libwasmvm/Cargo.lock +++ b/libwasmvm/Cargo.lock @@ -37,6 +37,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "assert_approx_eq" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c07dab4369547dbe5114677b33fbbf724971019f3818172d59a97a61c774ffd" + [[package]] name = "atty" version = "0.2.14" @@ -1848,7 +1854,9 @@ checksum = "52144d4c78e5cf8b055ceab8e5fa22814ce4315d6002ad32cfd914f37c12fd65" name = "wasmvm" version = "1.0.0" dependencies = [ + "assert_approx_eq", "cbindgen", + "cfg-if", "cosmwasm-std", "cosmwasm-vm", "errno", diff --git a/libwasmvm/Cargo.toml b/libwasmvm/Cargo.toml index a2ebc679e..a54558a13 100644 --- a/libwasmvm/Cargo.toml +++ b/libwasmvm/Cargo.toml @@ -34,6 +34,8 @@ thiserror = "1.0" hex = "0.4" [dev-dependencies] +assert_approx_eq = "1.1.0" +cfg-if = "1.0.0" serde = { version = "1.0.103", default-features = false, features = ["derive"] } tempfile = "3.1.0" diff --git a/libwasmvm/src/cache.rs b/libwasmvm/src/cache.rs index 5351d1d4a..c883dc3b2 100644 --- a/libwasmvm/src/cache.rs +++ b/libwasmvm/src/cache.rs @@ -371,7 +371,13 @@ mod tests { assert!(cache_ptr.is_null()); assert!(error_msg.is_some()); let msg = String::from_utf8(error_msg.consume().unwrap()).unwrap(); - assert_eq!(msg, "Error calling the VM: Cache error: Error creating directory broken\u{0}dir/state: data provided contains a nul byte"); + cfg_if::cfg_if! { + if #[cfg(windows)] { + assert_eq!(msg, "Error calling the VM: Cache error: Error creating directory broken\u{0}dir\\state: strings passed to WinAPI cannot contain NULs"); + } else { + assert_eq!(msg, "Error calling the VM: Cache error: Error creating directory broken\u{0}dir/state: data provided contains a nul byte"); + } + } } #[test] @@ -693,18 +699,17 @@ mod tests { let mut error_msg = UnmanagedVector::default(); let metrics = get_metrics(cache_ptr, Some(&mut error_msg)); let _ = error_msg.consume(); - assert_eq!( - metrics, - Metrics { - hits_pinned_memory_cache: 0, - hits_memory_cache: 0, - hits_fs_cache: 1, - misses: 0, - elements_pinned_memory_cache: 1, - elements_memory_cache: 0, - size_pinned_memory_cache: 5665691, - size_memory_cache: 0, - } + assert_eq!(metrics.hits_pinned_memory_cache, 0); + assert_eq!(metrics.hits_memory_cache, 0); + assert_eq!(metrics.hits_fs_cache, 1); + assert_eq!(metrics.misses, 0); + assert_eq!(metrics.elements_pinned_memory_cache, 1); + assert_eq!(metrics.elements_memory_cache, 0); + assert_eq!(metrics.size_memory_cache, 0); + assert_approx_eq::assert_approx_eq!( + i128::from(metrics.size_pinned_memory_cache), + 5665691, + 665691 ); // Unpin From 7b64f9fa94c6cf7244b2e4d52b20a19bdd7053c9 Mon Sep 17 00:00:00 2001 From: Devashish Dixit Date: Thu, 14 Jul 2022 10:28:41 +0800 Subject: [PATCH 2/4] Install specific rustup version --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d6d7a8580..5fe0740d0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -195,7 +195,7 @@ jobs: - checkout - run: name: Install Rustup - command: choco install rustup.install + command: choco install rustup.install --version 1.25.0 - run: name: Install Rust command: rustup default 1.59.0 From 671dfd8005b3600618fd2f3e2cf32c24d1c88ff2 Mon Sep 17 00:00:00 2001 From: Devashish Dixit Date: Thu, 14 Jul 2022 10:32:03 +0800 Subject: [PATCH 3/4] Install rustup 1.24.3 on windows --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5fe0740d0..08d99d7d5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -195,7 +195,7 @@ jobs: - checkout - run: name: Install Rustup - command: choco install rustup.install --version 1.25.0 + command: choco install rustup.install --version 1.24.3 - run: name: Install Rust command: rustup default 1.59.0 From 4a10447772408d67ba0b4c757333e3e8ee92c131 Mon Sep 17 00:00:00 2001 From: Devashish Dixit Date: Thu, 14 Jul 2022 10:39:06 +0800 Subject: [PATCH 4/4] Provide checksums manually for windows rustup installation --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 08d99d7d5..d3a04370d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -195,7 +195,7 @@ jobs: - checkout - run: name: Install Rustup - command: choco install rustup.install --version 1.24.3 + command: choco install rustup.install --checksum 79442f66a969a504febda49ee9158a90ad9e94913209ccdca3c22ef86d635c31 --checksum64 2220DDB49FEA0E0945B1B5913E33D66BD223A67F19FD1C116BE0318DE7ED9D9C - run: name: Install Rust command: rustup default 1.59.0