From e2a4877e316ce6a3ee795c27773d2cdc9c090233 Mon Sep 17 00:00:00 2001 From: "Victor M. Alvarez" Date: Mon, 25 Mar 2024 10:21:19 +0100 Subject: [PATCH] tests: parallelize module tests --- Cargo.lock | 1 + Cargo.toml | 3 +++ lib/Cargo.toml | 5 +++-- lib/src/modules/tests.rs | 15 ++++++++++----- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 32c08eb3a..e811315bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4264,6 +4264,7 @@ dependencies = [ "protobuf", "protobuf-codegen", "protobuf-parse", + "rayon", "regex-automata 0.4.6 (git+https://github.com/plusvic/regex.git?rev=50a708b)", "regex-syntax 0.8.2 (git+https://github.com/plusvic/regex.git?rev=50a708b)", "roxmltree", diff --git a/Cargo.toml b/Cargo.toml index e60ea286b..0d008c2bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,6 +48,7 @@ env_logger = "0.11.3" fmmap = "0.3.3" globwalk = "0.9.1" goldenfile = "1.6.0" +ihex = "3.0.0" indenter = "0.3.3" indexmap = "2.2.6" intaglio = "1.9.1" @@ -76,6 +77,7 @@ protobuf-codegen = { git = "https://github.com/plusvic/rust-protobuf.git", rev = protobuf-json-mapping = { git = "https://github.com/plusvic/rust-protobuf.git", rev = "b484d8a7" } protobuf-parse = { git = "https://github.com/plusvic/rust-protobuf.git", rev = "b484d8a7" } protobuf-support = { git = "https://github.com/plusvic/rust-protobuf.git", rev = "b484d8a7" } +rayon = "1.5.3" regex-syntax = { git = "https://github.com/plusvic/regex.git", rev = "50a708b" } regex-automata = { git = "https://github.com/plusvic/regex.git", rev = "50a708b" } roxmltree = "0.19.0" @@ -95,6 +97,7 @@ yara-x-macros = { path = "macros" } yara-x-parser = { path = "parser" } yara-x-proto = { path = "proto" } yara-x-proto-yaml = { path = "proto-yaml" } +zip = "0.6.2" # Special profile that builds a release binary with link-time optimization. # Compiling with this profile takes a while, but the resulting binary is diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 83d71b1ed..70871ea0e 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -208,7 +208,8 @@ yara-x-proto = { workspace = true } [dev-dependencies] globwalk = { workspace = true } goldenfile = { workspace = true } -ihex = "3.0.0" +ihex = { workspace = true } pretty_assertions = { workspace = true } +rayon = { workspace = true } yara-x-proto-yaml = { workspace = true } -zip = "0.6.6" +zip = { workspace = true } diff --git a/lib/src/modules/tests.rs b/lib/src/modules/tests.rs index 98f488e06..93ffb227f 100644 --- a/lib/src/modules/tests.rs +++ b/lib/src/modules/tests.rs @@ -2,6 +2,8 @@ use std::fs::File; use std::io::Read; use std::path::Path; +use rayon::prelude::*; + /// Utility function that receives the content of an [`Intel HEX`][1] (ihex) /// file and returns the binary data contained in it. /// @@ -94,11 +96,14 @@ pub fn create_binary_from_zipped_ihex>(path: P) -> Vec { #[test] fn test_modules() { // Create goldenfile mint. - let mut mint = goldenfile::Mint::new("."); + let files: Vec<_> = globwalk::glob("src/modules/**/*.in.zip") + .unwrap() + .flatten() + .map(|entry| entry.into_path()) + .collect(); - for entry in globwalk::glob("src/modules/**/*.in.zip").unwrap().flatten() { - // Path to the .in.zip file. - let path = entry.into_path(); + files.into_par_iter().for_each(|path| { + let mut mint = goldenfile::Mint::new("."); // Read the data encoded in the .in.zip file. let data = create_binary_from_zipped_ihex(&path); @@ -140,5 +145,5 @@ fn test_modules() { let mut yaml = yara_x_proto_yaml::Serializer::new(output_file); yaml.serialize(output).unwrap(); - } + }); }