Skip to content

Commit

Permalink
Extend output for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrLSD committed Apr 11, 2024
1 parent 753ba4d commit d282946
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 31 deletions.
48 changes: 24 additions & 24 deletions evm-tests/jsontests/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clap::{arg, command, value_parser, Arg, ArgAction, Command};
use ethjson::spec::ForkSpec;
use evm_jsontests::state as statetests;
use evm_jsontests::state::TestExecutionResult;
use evm_jsontests::state::{TestExecutionResult, VerboseOutput};
use evm_jsontests::vm as vmtests;
use std::collections::HashMap;
use std::fs;
Expand Down Expand Up @@ -68,17 +68,19 @@ fn main() {
None
};

let verbose = matches.get_flag("verbose");
let _very_verbose = matches.get_flag("very_verbose");
let verbose_failed = matches.get_flag("verbose_failed");
let verbose_output = VerboseOutput {
verbose: matches.get_flag("verbose"),
verbose_failed: matches.get_flag("verbose_failed"),
very_verbose: matches.get_flag("very_verbose"),
};
let mut tests_result = TestExecutionResult::new();
for src_name in matches.get_many::<PathBuf>("PATH").unwrap() {
let path = Path::new(src_name);
assert!(path.exists(), "data source is not exist");
if path.is_file() {
run_test_for_file(&spec, verbose, verbose_failed, path, &mut tests_result);
run_test_for_file(&spec, &verbose_output, path, &mut tests_result);
} else if path.is_dir() {
run_test_for_dir(&spec, verbose, verbose_failed, path, &mut tests_result);
run_test_for_dir(&spec, &verbose_output, path, &mut tests_result);
}
}
println!("\nTOTAL: {}", tests_result.total);
Expand All @@ -88,8 +90,7 @@ fn main() {

fn run_test_for_dir(
spec: &Option<ForkSpec>,
verbose: bool,
verbose_failed: bool,
verbose_output: &VerboseOutput,
dir_name: &Path,
tests_result: &mut TestExecutionResult,
) {
Expand All @@ -106,29 +107,28 @@ fn run_test_for_dir(
}
let path = entry.path();
if path.is_dir() {
run_test_for_dir(spec, verbose, verbose_failed, path.as_path(), tests_result);
run_test_for_dir(spec, verbose_output, path.as_path(), tests_result);
} else {
run_test_for_file(spec, verbose, verbose_failed, path.as_path(), tests_result);
run_test_for_file(spec, verbose_output, path.as_path(), tests_result);
}
}
}

fn run_test_for_file(
spec: &Option<ForkSpec>,
verbose: bool,
verbose_failed: bool,
verbose_output: &VerboseOutput,
file_name: &Path,
tests_result: &mut TestExecutionResult,
) {
if should_skip(file_name) {
if verbose {
if verbose_output.verbose {
println!("Skipping test case {:?}", file_name);
}
return;
}
if verbose {
if verbose_output.verbose {
println!(
"RUM for: {}",
"RUN for: {}",
short_test_file_name(file_name.to_str().unwrap())
);
}
Expand All @@ -139,29 +139,29 @@ fn run_test_for_file(
.expect("Parse test cases failed");

for (name, test) in test_suite {
let test_res = statetests::test(&name, test, false, spec.clone());
let test_res = statetests::test(verbose_output.clone(), &name, test, spec.clone());

if test_res.failed > 0 {
if verbose {
println!("Tests count: {}", test_res.total);
if verbose_output.verbose {
println!("Tests count:\t{}", test_res.total);
println!(
"Failed: {} {}\n",
"Failed:\t\t{} - {}\n",
test_res.failed,
short_test_file_name(file_name.to_str().unwrap())
);
} else if verbose_failed {
} else if verbose_output.verbose_failed {
println!(
"RUM for: {}",
"RUN for: {}",
short_test_file_name(file_name.to_str().unwrap())
);
println!("Tests count: {}", test_res.total);
println!("Tests count:\t{}", test_res.total);
println!(
"Failed: {} {}\n",
"Failed:\t\t{} - {}\n",
test_res.failed,
short_test_file_name(file_name.to_str().unwrap())
);
}
} else if verbose {
} else if verbose_output.verbose {
println!("Tests count: {}\n", test_res.total);
}

Expand Down
22 changes: 15 additions & 7 deletions evm-tests/jsontests/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ use std::collections::BTreeMap;
use std::convert::TryInto;
use std::str::FromStr;

#[derive(Default, Debug, Clone)]
pub struct VerboseOutput {
pub verbose: bool,
pub verbose_failed: bool,
pub very_verbose: bool,
}

#[derive(Clone, Debug)]
pub struct FailedTestDetails {
pub name: String,
Expand Down Expand Up @@ -248,9 +255,9 @@ impl JsonPrecompile {
}

pub fn test(
verbose_output: VerboseOutput,
name: &str,
test: Test,
print_output: bool,
specific_spec: Option<ForkSpec>,
) -> TestExecutionResult {
use std::thread;
Expand All @@ -261,17 +268,17 @@ pub fn test(
// Spawn thread with explicit stack size
let child = thread::Builder::new()
.stack_size(STACK_SIZE)
.spawn(move || test_run(&name, test, print_output, specific_spec))
.spawn(move || test_run(&verbose_output, &name, test, specific_spec))
.unwrap();

// Wait for thread to join
child.join().unwrap()
}

fn test_run(
verbose_output: &VerboseOutput,
name: &str,
test: Test,
print_output: bool,
specific_spec: Option<ForkSpec>,
) -> TestExecutionResult {
let mut tests_result = TestExecutionResult::new();
Expand All @@ -289,7 +296,7 @@ fn test_run(
ForkSpec::Merge => (Config::merge(), true),
ForkSpec::Paris => (Config::merge(), true),
ForkSpec::Shanghai => (Config::shanghai(), true),
ForkSpec::Cancun => (Config::cancun(), false),
ForkSpec::Cancun => (Config::cancun(), true),
spec => {
println!("Skip spec {spec:?}");
continue;
Expand Down Expand Up @@ -322,8 +329,8 @@ fn test_run(
.map_or_else(U256::zero, |acc| acc.balance);

for (i, state) in states.iter().enumerate() {
if print_output {
print!("Running {}:{:?}:{} ... ", name, spec, i);
if verbose_output.very_verbose {
print!(" [{:?}] {}:{} ... ", spec, name, i);
flush();
}

Expand Down Expand Up @@ -433,7 +440,8 @@ fn test_run(
spec: spec.clone(),
});
tests_result.failed += 1;
} else if print_output {
println!("failed\t<----");
} else if verbose_output.very_verbose {
println!("passed");
}
}
Expand Down

0 comments on commit d282946

Please sign in to comment.