From 7c85964684c395296af92fcee701275a6f6b6222 Mon Sep 17 00:00:00 2001 From: Igor Zhirkov Date: Tue, 23 Apr 2024 15:44:47 +0200 Subject: [PATCH] feat: compiling tests without executing them (#13) Co-authored-by: Oleksandr Zarudnyi --- .../src/compiler_tester/arguments.rs | 6 ++++ compiler_tester/src/compiler_tester/main.rs | 8 ++++-- compiler_tester/src/lib.rs | 14 ++++++++-- compiler_tester/src/workflow.rs | 28 +++++++++++++++++++ fuzzer/fuzz_targets/common.rs | 2 ++ 5 files changed, 54 insertions(+), 4 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 b42bb078..5109c95c 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; + /// /// The compiler tester arguments. /// @@ -103,6 +105,10 @@ pub struct Arguments { /// Sets the `debug logging` option in LLVM. #[structopt(long = "llvm-debug-logging")] pub llvm_debug_logging: 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 5dbd45cd..9d8d6535 100644 --- a/compiler_tester/src/compiler_tester/main.rs +++ b/compiler_tester/src/compiler_tester/main.rs @@ -92,8 +92,12 @@ 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 compiler_tester = compiler_tester::CompilerTester::new( + summary.clone(), + filters, + debug_config.clone(), + arguments.workflow, + )?; let binary_download_config_paths = vec![ arguments diff --git a/compiler_tester/src/lib.rs b/compiler_tester/src/lib.rs index cb58ea9a..e2d075e4 100644 --- a/compiler_tester/src/lib.rs +++ b/compiler_tester/src/lib.rs @@ -10,10 +10,12 @@ pub(crate) mod summary; pub(crate) mod test; pub(crate) mod utils; pub(crate) mod vm; +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; @@ -63,6 +65,8 @@ pub struct CompilerTester { pub filters: Filters, /// The debug config. pub debug_config: Option, + /// Actions to perform. + pub workflow: Workflow, } impl CompilerTester { @@ -98,11 +102,13 @@ impl CompilerTester { summary: Arc>, filters: Filters, debug_config: Option, + workflow: Workflow, ) -> anyhow::Result { Ok(Self { summary, filters, debug_config, + workflow, }) } @@ -131,7 +137,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 +168,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/compiler_tester/src/workflow.rs b/compiler_tester/src/workflow.rs new file mode 100644 index 00000000..862a2c3b --- /dev/null +++ b/compiler_tester/src/workflow.rs @@ -0,0 +1,28 @@ +//! +//! The compiler tester workflows. +//! + +use std::str::FromStr; + +/// +/// 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, +} + +impl FromStr for Workflow { + type Err = &'static str; + + 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 bb2463f0..1c1500fe 100644 --- a/fuzzer/fuzz_targets/common.rs +++ b/fuzzer/fuzz_targets/common.rs @@ -3,6 +3,7 @@ use std::{ sync::Arc, }; +use compiler_tester::Workflow; use compiler_tester::{Buildable, EthereumTest, Mode, SolidityCompiler, SolidityMode, Summary}; pub use solidity_adapter::{ test::function_call::parser::{ @@ -173,6 +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, )?; zkevm_tester::runners::compiler_tests::set_tracing_mode( zkevm_tester::runners::compiler_tests::VmTracingOptions::from_u64(0),