From cf8c1d9f841888f8a644b3a9dce6eacac407368e Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Wed, 11 Feb 2026 15:19:45 +0200 Subject: [PATCH] feat(runner): add TOML matrix benchmark config support --- .gitignore | 2 ++ runner/src/args.rs | 4 ++-- runner/src/config.rs | 25 ++++++++++++++----------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 3015405..0ec61f2 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ target/ # MSVC Windows builds of rustc generate these, which store debugging information *.pdb + +benchmarks.toml diff --git a/runner/src/args.rs b/runner/src/args.rs index f641f65..e1eb1aa 100644 --- a/runner/src/args.rs +++ b/runner/src/args.rs @@ -11,8 +11,8 @@ pub struct Args { pub mode: KeyExchangeMode, /// Server address to connect to. - #[arg(long)] - pub server: SocketAddr, + #[arg(long, required_unless_present = "config")] + pub server: Option, /// Payload size in bytes to request from server. #[arg(long, default_value = "1024")] diff --git a/runner/src/config.rs b/runner/src/config.rs index 35acc62..24bf6cd 100644 --- a/runner/src/config.rs +++ b/runner/src/config.rs @@ -1,4 +1,6 @@ -use miette::{Context, IntoDiagnostic}; +use crate::args::Args; +use common::KeyExchangeMode; +use miette::{Context, IntoDiagnostic, miette}; use serde::Deserialize; use std::{fs::read_to_string, net::SocketAddr, path::PathBuf}; @@ -25,10 +27,12 @@ pub fn load_from_file(path: &PathBuf) -> miette::Result { let content = read_to_string(path) .into_diagnostic() .context(format!("failed to read config file: {}", path.display()))?; - let config: Config = toml::from_str(&content).into_diagnostic().context(format!( - "failed to parse TOML config from file {}", - path.display() - ))?; + let config = toml::from_str::(&content) + .into_diagnostic() + .context(format!( + "failed to parse TOML config from file {}", + path.display() + ))?; Ok(config) } @@ -36,16 +40,17 @@ pub fn load_from_file(path: &PathBuf) -> miette::Result { /// /// # Errors /// Never returns an error, but returns Result for consistency. -pub fn load_from_cli(args: &crate::args::Args) -> miette::Result { - let mode = args.mode.to_string(); +pub fn load_from_cli(args: &Args) -> miette::Result { Ok(Config { benchmarks: vec![BenchmarkConfig { - mode, + mode: args.mode.to_string(), payload: args.payload_bytes, iters: args.iters, warmup: args.warmup, concurrency: args.concurrency, - server: args.server, + server: args + .server + .ok_or_else(|| miette!("--server is required when not using --config"))?, }], }) } @@ -60,5 +65,3 @@ impl Config { .unwrap_or(KeyExchangeMode::X25519) } } - -use common::KeyExchangeMode;