From a4fde262d38f96c56e8f4d75b5694cb11e4fb7c6 Mon Sep 17 00:00:00 2001 From: Igor Zhirkov Date: Mon, 15 Apr 2024 17:42:26 +0200 Subject: [PATCH 1/4] feature: tests can be compiled without execution --- .../src/compiler_tester/arguments.rs | 4 ++++ compiler_tester/src/compiler_tester/main.rs | 14 ++++++++++-- compiler_tester/src/lib.rs | 22 +++++++++++++++++-- fuzzer/fuzz_targets/common.rs | 3 ++- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/compiler_tester/src/compiler_tester/arguments.rs b/compiler_tester/src/compiler_tester/arguments.rs index b42bb078..f6d5a7a7 100644 --- a/compiler_tester/src/compiler_tester/arguments.rs +++ b/compiler_tester/src/compiler_tester/arguments.rs @@ -103,6 +103,10 @@ pub struct Arguments { /// Sets the `debug logging` option in LLVM. #[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, } impl Arguments { diff --git a/compiler_tester/src/compiler_tester/main.rs b/compiler_tester/src/compiler_tester/main.rs index 5dbd45cd..3a988d3a 100644 --- a/compiler_tester/src/compiler_tester/main.rs +++ b/compiler_tester/src/compiler_tester/main.rs @@ -11,6 +11,7 @@ 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; @@ -92,8 +93,17 @@ fn main_inner(arguments: Arguments) -> anyhow::Result<()> { let filters = compiler_tester::Filters::new(arguments.paths, arguments.modes, arguments.groups); - let compiler_tester = - compiler_tester::CompilerTester::new(summary.clone(), filters, debug_config.clone())?; + 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, + )?; let binary_download_config_paths = vec![ arguments diff --git a/compiler_tester/src/lib.rs b/compiler_tester/src/lib.rs index cb58ea9a..5814b062 100644 --- a/compiler_tester/src/lib.rs +++ b/compiler_tester/src/lib.rs @@ -53,6 +53,16 @@ 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. /// @@ -63,6 +73,8 @@ pub struct CompilerTester { pub filters: Filters, /// The debug config. pub debug_config: Option, + /// Actions to perform. + pub workflow: Workflow, } impl CompilerTester { @@ -98,11 +110,13 @@ impl CompilerTester { summary: Arc>, filters: Filters, debug_config: Option, + workflow: Workflow, ) -> anyhow::Result { Ok(Self { summary, filters, debug_config, + workflow, }) } @@ -131,7 +145,9 @@ impl CompilerTester { &self.filters, specialized_debug_config, ) { - test.run::(self.summary.clone(), vm.clone()); + if let Workflow::BuildAndRun = self.workflow { + test.run::(self.summary.clone(), vm.clone()) + }; } }) .collect(); @@ -160,7 +176,9 @@ impl CompilerTester { &self.filters, specialized_debug_config, ) { - test.run(self.summary.clone()); + if let Workflow::BuildAndRun = self.workflow { + test.run(self.summary.clone()) + }; } }) .collect(); diff --git a/fuzzer/fuzz_targets/common.rs b/fuzzer/fuzz_targets/common.rs index bb2463f0..b3023f60 100644 --- a/fuzzer/fuzz_targets/common.rs +++ b/fuzzer/fuzz_targets/common.rs @@ -3,7 +3,7 @@ use std::{ sync::Arc, }; -use compiler_tester::{Buildable, EthereumTest, Mode, SolidityCompiler, SolidityMode, Summary}; +use compiler_tester::{Buildable, EthereumTest, Mode, SolidityCompiler, SolidityMode, Summary, Workflow}; pub use solidity_adapter::{ test::function_call::parser::{ lexical::token::{ @@ -173,6 +173,7 @@ pub fn build_and_run(test: EthereumTest) -> anyhow::Result { compiler_tester::Summary::new(true, false).wrap(), compiler_tester::Filters::new(vec![], vec![], vec![]), None, + Workflow::BuildAndRun )?; zkevm_tester::runners::compiler_tests::set_tracing_mode( zkevm_tester::runners::compiler_tests::VmTracingOptions::from_u64(0), From 8fc7c39a6207a395f2cdbfbb2159f71f41935933 Mon Sep 17 00:00:00 2001 From: Igor Zhirkov Date: Mon, 22 Apr 2024 19:45:10 +0200 Subject: [PATCH 2/4] 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::{ From 46384f043ad7ce81e42e54fb88c565440105ae19 Mon Sep 17 00:00:00 2001 From: Oleksandr Zarudnyi Date: Mon, 22 Apr 2024 20:21:03 +0200 Subject: [PATCH 3/4] Update workflow.rs --- compiler_tester/src/workflow.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler_tester/src/workflow.rs b/compiler_tester/src/workflow.rs index 06601aee..bc86bcf5 100644 --- a/compiler_tester/src/workflow.rs +++ b/compiler_tester/src/workflow.rs @@ -1,7 +1,9 @@ //! -//! Compiler tester workflows +//! The compiler tester workflows. //! +use std::str::FromStr; + /// /// Describes sets of actions that compiler tester is able to perform. /// @@ -12,13 +14,13 @@ pub enum Workflow { /// 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), From 830f458b4c6cd5d1a1e9d8b3f9705f3fc91fee18 Mon Sep 17 00:00:00 2001 From: Igor Zhirkov Date: Tue, 23 Apr 2024 00:59:40 +0200 Subject: [PATCH 4/4] fixup! Extract workflow and improve argument parsing. --- compiler_tester/src/compiler_tester/arguments.rs | 2 +- compiler_tester/src/lib.rs | 4 ++-- compiler_tester/src/workflow.rs | 7 ++----- fuzzer/fuzz_targets/common.rs | 4 ++-- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/compiler_tester/src/compiler_tester/arguments.rs b/compiler_tester/src/compiler_tester/arguments.rs index 207079e3..5109c95c 100644 --- a/compiler_tester/src/compiler_tester/arguments.rs +++ b/compiler_tester/src/compiler_tester/arguments.rs @@ -6,7 +6,7 @@ use std::path::PathBuf; use structopt::StructOpt; -use compiler_tester::workflow::Workflow; +use compiler_tester::Workflow; /// /// The compiler tester arguments. diff --git a/compiler_tester/src/lib.rs b/compiler_tester/src/lib.rs index 23173531..e2d075e4 100644 --- a/compiler_tester/src/lib.rs +++ b/compiler_tester/src/lib.rs @@ -10,11 +10,12 @@ pub(crate) mod summary; pub(crate) mod test; pub(crate) mod utils; pub(crate) mod vm; -pub mod workflow; +pub(crate) mod workflow; pub use self::filters::Filters; pub use self::llvm_options::LLVMOptions; pub use self::summary::Summary; +pub use self::workflow::Workflow; pub use crate::vm::eravm::deployers::native_deployer::NativeDeployer as EraVMNativeDeployer; pub use crate::vm::eravm::deployers::system_contract_deployer::SystemContractDeployer as EraVMSystemContractDeployer; pub use crate::vm::eravm::EraVM; @@ -27,7 +28,6 @@ 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; diff --git a/compiler_tester/src/workflow.rs b/compiler_tester/src/workflow.rs index bc86bcf5..862a2c3b 100644 --- a/compiler_tester/src/workflow.rs +++ b/compiler_tester/src/workflow.rs @@ -15,12 +15,9 @@ pub enum Workflow { BuildAndRun, } -// any error type implementing Display is acceptable. -type ParseError = &'static str; - impl FromStr for Workflow { - type Err = ParseError; - + type Err = &'static str; + fn from_str(day: &str) -> Result { match day { "build" => Ok(Workflow::BuildOnly), diff --git a/fuzzer/fuzz_targets/common.rs b/fuzzer/fuzz_targets/common.rs index eb9f04b5..1c1500fe 100644 --- a/fuzzer/fuzz_targets/common.rs +++ b/fuzzer/fuzz_targets/common.rs @@ -3,8 +3,8 @@ use std::{ sync::Arc, }; +use compiler_tester::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::{ @@ -174,7 +174,7 @@ pub fn build_and_run(test: EthereumTest) -> anyhow::Result { compiler_tester::Summary::new(true, false).wrap(), compiler_tester::Filters::new(vec![], vec![], vec![]), None, - Workflow::BuildAndRun + Workflow::BuildAndRun, )?; zkevm_tester::runners::compiler_tests::set_tracing_mode( zkevm_tester::runners::compiler_tests::VmTracingOptions::from_u64(0),