From 72aa8b40fe307a3471eb3bb04a6fa9408cbb74d8 Mon Sep 17 00:00:00 2001 From: David Peter Date: Sun, 29 Dec 2024 13:40:05 +0100 Subject: [PATCH] Basic scheduler test --- src/benchmark/scheduler.rs | 65 ++++++++++++++++++++++++++++++++++++++ src/options.rs | 1 + 2 files changed, 66 insertions(+) diff --git a/src/benchmark/scheduler.rs b/src/benchmark/scheduler.rs index a88cda7..824788e 100644 --- a/src/benchmark/scheduler.rs +++ b/src/benchmark/scheduler.rs @@ -162,3 +162,68 @@ impl<'a> Scheduler<'a> { .write_results(&self.results, self.options.sort_order_exports, false) } } + +#[cfg(test)] +fn generate_results(args: &[&'static str]) -> Result> { + use crate::cli::get_cli_arguments; + + let args = ["hyperfine", "--debug-mode", "--style=none"] + .iter() + .chain(args.into_iter()); + let cli_arguments = get_cli_arguments(args); + let mut options = Options::from_cli_arguments(&cli_arguments)?; + + assert_eq!(options.executor_kind, ExecutorKind::Mock(None)); + + let commands = Commands::from_cli_arguments(&cli_arguments)?; + let export_manager = ExportManager::from_cli_arguments(&cli_arguments, options.time_unit)?; + + options.validate_against_command_list(&commands)?; + + let mut scheduler = Scheduler::new(&commands, &options, &export_manager); + + scheduler.run_benchmarks()?; + Ok(scheduler.results) +} + +#[test] +fn scheduler_basic() -> Result<()> { + insta::assert_yaml_snapshot!(generate_results(&["--runs=2", "sleep 0.123", "sleep 0.456"])?, @r#" + - command: sleep 0.123 + mean: 0.123 + stddev: 0 + median: 0.123 + user: 0 + system: 0 + min: 0.123 + max: 0.123 + times: + - 0.123 + - 0.123 + memory_usage_byte: + - 0 + - 0 + exit_codes: + - 0 + - 0 + - command: sleep 0.456 + mean: 0.456 + stddev: 0 + median: 0.456 + user: 0 + system: 0 + min: 0.456 + max: 0.456 + times: + - 0.456 + - 0.456 + memory_usage_byte: + - 0 + - 0 + exit_codes: + - 0 + - 0 + "#); + + Ok(()) +} diff --git a/src/options.rs b/src/options.rs index c9b0e44..c4cffc3 100644 --- a/src/options.rs +++ b/src/options.rs @@ -178,6 +178,7 @@ impl CommandOutputPolicy { } } +#[derive(Debug, PartialEq)] pub enum ExecutorKind { Raw, Shell(Shell),