diff --git a/crates/Cargo.lock b/crates/Cargo.lock index 1703adb2..4c11cc71 100644 --- a/crates/Cargo.lock +++ b/crates/Cargo.lock @@ -227,6 +227,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + [[package]] name = "core_maths" version = "0.1.0" @@ -1108,6 +1114,15 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "num-bigint" version = "0.4.6" @@ -1549,6 +1564,21 @@ dependencies = [ "libc", ] +[[package]] +name = "sysinfo" +version = "0.30.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a5b4ddaee55fb2bea2bf0e5000747e5f5c0de765e5a5ff87f4cd106439f4bb3" +dependencies = [ + "cfg-if", + "core-foundation-sys", + "libc", + "ntapi", + "once_cell", + "rayon", + "windows", +] + [[package]] name = "test_utilities" version = "0.0.1" @@ -1558,6 +1588,7 @@ dependencies = [ "indicatif", "once_cell", "rayon", + "sysinfo", "walkdir", ] @@ -1881,6 +1912,25 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" +dependencies = [ + "windows-core", + "windows-targets", +] + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.52.0" diff --git a/crates/test_utilities/Cargo.toml b/crates/test_utilities/Cargo.toml index 0509bbec..3ea4c5bd 100644 --- a/crates/test_utilities/Cargo.toml +++ b/crates/test_utilities/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" once_cell = "1.17.0" rayon = "1.6.1" indicatif = { version = "0.17.2", features = ["rayon"] } +sysinfo = "0.30.0" # Only used for the "test commands" when validating/updating the valid-inputs list. [dev-dependencies] diff --git a/crates/test_utilities/src/lib.rs b/crates/test_utilities/src/lib.rs index 482f41b0..1c4a1878 100644 --- a/crates/test_utilities/src/lib.rs +++ b/crates/test_utilities/src/lib.rs @@ -2,6 +2,7 @@ use std::io; use std::io::BufRead; +use std::fs; use std::fs::File; use std::path::Path; use std::path::PathBuf; @@ -9,6 +10,7 @@ use std::path::PathBuf; use once_cell::sync::Lazy; use rayon::prelude::*; use indicatif::ParallelProgressIterator; +use sysinfo::System; const VALID_WASM_BINARIES_LIST_FILE: &str = "../../test-inputs/valid-wasm-binaries.txt"; @@ -36,7 +38,26 @@ pub fn for_each_valid_wasm_binary_in_test_set(test_fn: impl Fn(&Path) + Send + S // Abort parallel processing as early as possible. .panic_fuse() .progress() - .for_each(|path| test_fn(path)); + .for_each(|path| { + let module_size_bytes = fs::metadata(path) + .map(|file| file.len()) + .unwrap_or(0); + + const AST_BYTES_PER_INSTRUCTION_BYTE_APPROX: u64 = 100; + let memory_needed_for_ast_approx = module_size_bytes * AST_BYTES_PER_INSTRUCTION_BYTE_APPROX; + + let memory_available = { + let mut system = System::new(); + system.refresh_memory(); + system.available_memory() + }; + if memory_needed_for_ast_approx > memory_available { + eprintln!("Skipping {} due to running low on memory...\n\t{} bytes memory available\n\t{} bytes module size\n\t{} bytes approx. required", path.display(), memory_available, module_size_bytes, memory_needed_for_ast_approx); + return; + } + + test_fn(path)} + ); } /// Call WABT's wasm-validate tool on a file (WABT needs to be on $PATH).