use std::collections::HashMap;
use std::fs;
use std::path::Path;
use crate::testing::performance::{PerformanceTestRunner, Result, TestConfig};
pub fn create_standard_test_config(name: &str, iterations: usize) -> TestConfig {
TestConfig {
name: name.to_string(),
iterations,
warmup_iterations: iterations / 10,
duration_limit_secs: 3600, parameters: HashMap::new(),
}
}
pub fn run_comprehensive_test_suite(output_dir: &Path) -> Result<()> {
let mut runner = PerformanceTestRunner::new();
runner.add_config(create_standard_test_config("performance_test", 10000));
runner.add_config(create_standard_test_config("all", 1000));
runner.run_all_tests()?;
let report = runner.generate_report_markdown();
fs::create_dir_all(output_dir)?;
let report_path = output_dir.join("performance_report.md");
fs::write(&report_path, report).map_err(|e| {
crate::testing::performance::PerfTestError::TestError(format!(
"Failed to write report: {e}"
))
})?;
println!("Performance report written to: {}", report_path.display());
Ok(())
}
pub fn run_targeted_test(test_name: &str, iterations: usize, output_dir: &Path) -> Result<()> {
let mut runner = PerformanceTestRunner::new();
runner.add_config(create_standard_test_config(test_name, iterations));
match test_name {
"performance_test" => {
println!("Running performance test: {test_name}");
}
_ => {
return Err(
crate::testing::performance::PerfTestError::ConfigurationError(format!(
"Unknown test name: {test_name}"
)),
);
}
}
runner.run_test(test_name)?;
let report = runner.generate_report_markdown();
fs::create_dir_all(output_dir)?;
let report_path = output_dir.join(format!("{test_name}_report.md"));
fs::write(&report_path, report).map_err(|e| {
crate::testing::performance::PerfTestError::TestError(format!(
"Failed to write report: {e}"
))
})?;
println!("Performance report written to: {}", report_path.display());
Ok(())
}