From 8fc7c39a6207a395f2cdbfbb2159f71f41935933 Mon Sep 17 00:00:00 2001 From: Igor Zhirkov Date: Mon, 22 Apr 2024 19:45:10 +0200 Subject: [PATCH] Extract workflow and improve argument parsing. --- .../src/compiler_tester/arguments.rs | 8 +++-- compiler_tester/src/compiler_tester/main.rs | 8 +---- compiler_tester/src/lib.rs | 12 ++------ compiler_tester/src/workflow.rs | 29 +++++++++++++++++++ fuzzer/fuzz_targets/common.rs | 3 +- 5 files changed, 39 insertions(+), 21 deletions(-) create mode 100644 compiler_tester/src/workflow.rs diff --git a/compiler_tester/src/compiler_tester/arguments.rs b/compiler_tester/src/compiler_tester/arguments.rs index f6d5a7a7..207079e3 100644 --- a/compiler_tester/src/compiler_tester/arguments.rs +++ b/compiler_tester/src/compiler_tester/arguments.rs @@ -6,6 +6,8 @@ use std::path::PathBuf; use structopt::StructOpt; +use compiler_tester::workflow::Workflow; + /// /// The compiler tester arguments. /// @@ -104,9 +106,9 @@ pub struct Arguments { #[structopt(long = "llvm-debug-logging")] pub llvm_debug_logging: bool, - /// Builds the test code but does not run tests. - #[structopt(long = "build-only")] - pub build_only: bool, + /// Choose between `build` to compile tests only without running them, and `run` to compile and run them. + #[structopt(long = "workflow", default_value = "run")] + pub workflow: Workflow, } impl Arguments { diff --git a/compiler_tester/src/compiler_tester/main.rs b/compiler_tester/src/compiler_tester/main.rs index 3a988d3a..9d8d6535 100644 --- a/compiler_tester/src/compiler_tester/main.rs +++ b/compiler_tester/src/compiler_tester/main.rs @@ -11,7 +11,6 @@ use std::time::Instant; use colored::Colorize; use self::arguments::Arguments; -use compiler_tester::Workflow; /// The rayon worker stack size. const RAYON_WORKER_STACK_SIZE: usize = 16 * 1024 * 1024; @@ -93,16 +92,11 @@ fn main_inner(arguments: Arguments) -> anyhow::Result<()> { let filters = compiler_tester::Filters::new(arguments.paths, arguments.modes, arguments.groups); - let workflow = if arguments.build_only { - Workflow::BuildOnly - } else { - Workflow::BuildAndRun - }; let compiler_tester = compiler_tester::CompilerTester::new( summary.clone(), filters, debug_config.clone(), - workflow, + arguments.workflow, )?; let binary_download_config_paths = vec![ diff --git a/compiler_tester/src/lib.rs b/compiler_tester/src/lib.rs index 5814b062..23173531 100644 --- a/compiler_tester/src/lib.rs +++ b/compiler_tester/src/lib.rs @@ -10,6 +10,7 @@ pub(crate) mod summary; pub(crate) mod test; pub(crate) mod utils; pub(crate) mod vm; +pub mod workflow; pub use self::filters::Filters; pub use self::llvm_options::LLVMOptions; @@ -26,6 +27,7 @@ use std::sync::Mutex; use itertools::Itertools; use rayon::iter::IntoParallelIterator; use rayon::iter::ParallelIterator; +use workflow::Workflow; pub use crate::compilers::eravm::EraVMCompiler; pub use crate::compilers::llvm::LLVMCompiler; @@ -53,16 +55,6 @@ pub const TRACE_DIRECTORY: &str = "./trace/"; /// type Test = (Arc, Arc, Mode); -/// -/// Describes sets of actions that compiler tester is able to perform. -/// -pub enum Workflow { - /// Only build tests but not execute them. - BuildOnly, - /// Build and execute tests. - BuildAndRun, -} - /// /// The compiler tester. /// diff --git a/compiler_tester/src/workflow.rs b/compiler_tester/src/workflow.rs new file mode 100644 index 00000000..06601aee --- /dev/null +++ b/compiler_tester/src/workflow.rs @@ -0,0 +1,29 @@ +//! +//! Compiler tester workflows +//! + +/// +/// Describes sets of actions that compiler tester is able to perform. +/// +#[derive(Debug)] +pub enum Workflow { + /// Only build tests but not execute them. + BuildOnly, + /// Build and execute tests. + BuildAndRun, +} +use std::str::FromStr; + +// any error type implementing Display is acceptable. +type ParseError = &'static str; + +impl FromStr for Workflow { + type Err = ParseError; + fn from_str(day: &str) -> Result { + match day { + "build" => Ok(Workflow::BuildOnly), + "run" => Ok(Workflow::BuildAndRun), + _ => Err("Could not parse workflow. Supported workflows: build, run."), + } + } +} diff --git a/fuzzer/fuzz_targets/common.rs b/fuzzer/fuzz_targets/common.rs index b3023f60..eb9f04b5 100644 --- a/fuzzer/fuzz_targets/common.rs +++ b/fuzzer/fuzz_targets/common.rs @@ -3,7 +3,8 @@ use std::{ sync::Arc, }; -use compiler_tester::{Buildable, EthereumTest, Mode, SolidityCompiler, SolidityMode, Summary, Workflow}; +use compiler_tester::{Buildable, EthereumTest, Mode, SolidityCompiler, SolidityMode, Summary}; +use compiler_tester::workflow::Workflow; pub use solidity_adapter::{ test::function_call::parser::{ lexical::token::{