impemented mock testing
This commit is contained in:
@@ -8,7 +8,7 @@ use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Mutex;
|
||||
|
||||
use crate::sal::traits::{PlatformSal, AuditStep, SafetyStatus};
|
||||
use crate::sal::traits::{PlatformSal, SafetyStatus};
|
||||
use crate::sal::heuristic::discovery::SystemFactSheet;
|
||||
use crate::load::Workload;
|
||||
use crate::mediator::{TelemetryState, UiCommand, BenchmarkPhase};
|
||||
@@ -94,6 +94,8 @@ impl BenchmarkOrchestrator {
|
||||
}
|
||||
|
||||
fn execute_benchmark(&mut self) -> Result<OptimizationResult> {
|
||||
let bench_cfg = self.facts.bench_config.clone().context("Benchmarking config missing in facts")?;
|
||||
|
||||
// Phase 1: Audit & Baseline
|
||||
self.phase = BenchmarkPhase::Auditing;
|
||||
for step in self.sal.audit() {
|
||||
@@ -107,13 +109,13 @@ impl BenchmarkOrchestrator {
|
||||
|
||||
// Baseline (Idle Calibration)
|
||||
self.phase = BenchmarkPhase::IdleCalibration;
|
||||
self.log("Phase 1: Recording Idle Baseline (10s)...")?;
|
||||
self.log(&format!("Phase 1: Recording Idle Baseline ({}s)...", bench_cfg.idle_duration_s))?;
|
||||
self.sal.set_fan_mode("auto")?; // Use auto for idle
|
||||
|
||||
let mut idle_temps = Vec::new();
|
||||
let start = Instant::now();
|
||||
let mut tick = 0;
|
||||
while start.elapsed() < Duration::from_secs(10) {
|
||||
while start.elapsed() < Duration::from_secs(bench_cfg.idle_duration_s) {
|
||||
self.check_abort()?;
|
||||
self.send_telemetry(tick)?;
|
||||
idle_temps.push(self.sal.get_temp().unwrap_or(0.0));
|
||||
@@ -128,19 +130,19 @@ impl BenchmarkOrchestrator {
|
||||
self.log("Phase 2: Starting Synthetic Stress Matrix.")?;
|
||||
self.sal.set_fan_mode("max")?; // Lock fans for consistent resistance
|
||||
|
||||
let power_steps = [15.0, 20.0, 25.0, 30.0, 35.0];
|
||||
for &pl in &power_steps {
|
||||
let steps = bench_cfg.power_steps_watts.clone();
|
||||
for &pl in &steps {
|
||||
self.log(&format!("Testing PL1 = {:.0}W...", pl))?;
|
||||
self.sal.set_sustained_power_limit(pl)?;
|
||||
self.sal.set_burst_power_limit(pl + 5.0)?;
|
||||
|
||||
self.workload.start(num_cpus::get(), 100)?;
|
||||
|
||||
// Wait for equilibrium: Hybrid approach (15s min, 45s max)
|
||||
// Wait for equilibrium
|
||||
let step_start = Instant::now();
|
||||
let mut step_temps = VecDeque::with_capacity(30); // Last 15s @ 500ms
|
||||
let mut step_temps = VecDeque::with_capacity(30);
|
||||
|
||||
while step_start.elapsed() < Duration::from_secs(45) {
|
||||
while step_start.elapsed() < Duration::from_secs(bench_cfg.stress_duration_max_s) {
|
||||
self.check_abort()?;
|
||||
|
||||
let t = self.sal.get_temp().unwrap_or(0.0);
|
||||
@@ -151,7 +153,7 @@ impl BenchmarkOrchestrator {
|
||||
tick += 1;
|
||||
|
||||
// Check for stability: Range < 0.5C over last 5s (10 ticks)
|
||||
if step_start.elapsed() > Duration::from_secs(15) && step_temps.len() == 10 {
|
||||
if step_start.elapsed() > Duration::from_secs(bench_cfg.stress_duration_min_s) && step_temps.len() == 10 {
|
||||
let min = step_temps.iter().fold(f32::MAX, |a, &b| a.min(b));
|
||||
let max = step_temps.iter().fold(f32::MIN, |a, &b| a.max(b));
|
||||
if (max - min) < 0.5 {
|
||||
@@ -179,8 +181,8 @@ impl BenchmarkOrchestrator {
|
||||
});
|
||||
|
||||
self.workload.stop()?;
|
||||
self.log(" Step complete. Cooling down for 5s...")?;
|
||||
thread::sleep(Duration::from_secs(5));
|
||||
self.log(&format!(" Step complete. Cooling down for {}s...", bench_cfg.cool_down_s))?;
|
||||
thread::sleep(Duration::from_secs(bench_cfg.cool_down_s));
|
||||
}
|
||||
|
||||
// Phase 4: Physical Modeling
|
||||
@@ -216,6 +218,7 @@ impl BenchmarkOrchestrator {
|
||||
let i8k_config = crate::engine::formatters::i8kmon::I8kmonConfig {
|
||||
t_ambient: self.profile.ambient_temp,
|
||||
t_max_fan: res.max_temp_c - 5.0,
|
||||
thermal_resistance_kw: res.thermal_resistance_kw,
|
||||
};
|
||||
crate::engine::formatters::i8kmon::I8kmonTranslator::save(i8k_path, &i8k_config)?;
|
||||
self.log(&format!("✓ Saved '{}'.", i8k_path.display()))?;
|
||||
@@ -229,6 +232,7 @@ impl BenchmarkOrchestrator {
|
||||
let abort = self.emergency_abort.clone();
|
||||
let reason_store = self.emergency_reason.clone();
|
||||
let sal = self.sal.clone();
|
||||
let tx = self.telemetry_tx.clone();
|
||||
|
||||
thread::spawn(move || {
|
||||
while !abort.load(Ordering::SeqCst) {
|
||||
@@ -239,7 +243,30 @@ impl BenchmarkOrchestrator {
|
||||
abort.store(true, Ordering::SeqCst);
|
||||
break;
|
||||
}
|
||||
Ok(SafetyStatus::Warning(_msg)) | Ok(SafetyStatus::Critical(_msg)) => {}
|
||||
Ok(SafetyStatus::Warning(msg)) | Ok(SafetyStatus::Critical(msg)) => {
|
||||
let state = TelemetryState {
|
||||
cpu_model: String::new(),
|
||||
total_ram_gb: 0,
|
||||
tick: 0,
|
||||
cpu_temp: 0.0,
|
||||
power_w: 0.0,
|
||||
current_freq: 0.0,
|
||||
fans: Vec::new(),
|
||||
governor: String::new(),
|
||||
pl1_limit: 0.0,
|
||||
pl2_limit: 0.0,
|
||||
fan_tier: String::new(),
|
||||
phase: BenchmarkPhase::StressTesting,
|
||||
history_watts: Vec::new(),
|
||||
history_temp: Vec::new(),
|
||||
history_mhz: Vec::new(),
|
||||
log_event: Some(format!("WATCHDOG: {}", msg)),
|
||||
metadata: std::collections::HashMap::new(),
|
||||
is_emergency: false,
|
||||
emergency_reason: None,
|
||||
};
|
||||
let _ = tx.send(state);
|
||||
}
|
||||
Ok(SafetyStatus::Nominal) => {}
|
||||
Err(e) => {
|
||||
*reason_store.lock().unwrap() = Some(format!("Watchdog Sensor Failure: {}", e));
|
||||
|
||||
Reference in New Issue
Block a user