Skip to content

Commit

Permalink
tests: parallelize module tests
Browse files Browse the repository at this point in the history
  • Loading branch information
plusvic committed Mar 25, 2024
1 parent df93f14 commit e2a4877
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
15 changes: 10 additions & 5 deletions lib/src/modules/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -94,11 +96,14 @@ pub fn create_binary_from_zipped_ihex<P: AsRef<Path>>(path: P) -> Vec<u8> {
#[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);
Expand Down Expand Up @@ -140,5 +145,5 @@ fn test_modules() {
let mut yaml = yara_x_proto_yaml::Serializer::new(output_file);

yaml.serialize(output).unwrap();
}
});
}

0 comments on commit e2a4877

Please sign in to comment.