Skip to content

Commit

Permalink
feat: add fast eval mode for the testing tool (#1353)
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy authored May 23, 2024
1 parent f90939f commit 15ba412
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion kclvm/runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub mod runner;
#[cfg(test)]
pub mod tests;

const KCL_FAST_EVAL_ENV_VAR: &str = "KCL_FAST_EVAL";
pub const KCL_FAST_EVAL_ENV_VAR: &str = "KCL_FAST_EVAL";

/// After the kcl program passed through kclvm-parser in the compiler frontend,
/// KCL needs to resolve ast, generate corresponding LLVM IR, dynamic link library or
Expand Down
36 changes: 27 additions & 9 deletions kclvm/tools/src/testing/suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ use kclvm_driver::{get_kcl_files, get_pkg_list};
use kclvm_parser::{parse_file_force_errors, ParseSessionRef};
#[cfg(feature = "llvm")]
use kclvm_runner::build_program;
#[cfg(not(feature = "llvm"))]
use kclvm_runner::exec_program;
#[cfg(feature = "llvm")]
use kclvm_runner::runner::ProgramRunner;
use kclvm_runner::ExecProgramArgs;
use kclvm_runner::{Artifact, ExecProgramArgs, KCL_FAST_EVAL_ENV_VAR};
use std::time::Instant;

/// File suffix for test files.
Expand Down Expand Up @@ -62,20 +61,39 @@ impl TestRun for TestSuite {
disable_yaml_result: true,
..opts.exec_args.clone()
};
// Build the program.
#[cfg(feature = "llvm")]
let artifact = build_program::<String>(ParseSessionRef::default(), &args, None)?;
let is_fast_eval_mode = std::env::var(KCL_FAST_EVAL_ENV_VAR).is_ok();
// Build the program
let artifact: Option<Artifact> = if is_fast_eval_mode {
None
} else {
#[cfg(feature = "llvm")]
let artifact = Some(build_program::<String>(
ParseSessionRef::default(),
&args,
None,
)?);
#[cfg(not(feature = "llvm"))]
let artifact = None;
artifact
};
// Test every case in the suite.
for (name, _) in &self.cases {
args.args = vec![ast::CmdArgSpec {
name: TEST_CASE_RUN_OPTION.into(),
value: format!("{:?}", name),
}];
let start = Instant::now();
#[cfg(feature = "llvm")]
let exec_result = artifact.run(&args)?;
#[cfg(not(feature = "llvm"))]
let exec_result = exec_program(ParseSessionRef::default(), &args)?;
// Check if is the fast eval mode.
let exec_result = if let Some(_artifact) = &artifact {
#[cfg(feature = "llvm")]
let exec_result = _artifact.run(&args)?;
#[cfg(not(feature = "llvm"))]
let exec_result = exec_program(ParseSessionRef::default(), &args)?;
exec_result
} else {
args.fast_eval = true;
exec_program(ParseSessionRef::default(), &args)?
};
// Check if there was an error.
let error = if exec_result.err_message.is_empty() {
None
Expand Down

0 comments on commit 15ba412

Please sign in to comment.