impemented mock testing

This commit is contained in:
2026-02-26 17:11:42 +01:00
parent f76acd6256
commit 667d94af7a
21 changed files with 480 additions and 110 deletions

View File

@@ -3,7 +3,7 @@ use std::fs;
use regex::Regex;
use tracing::{info, debug};
use crate::sal::traits::PlatformSal;
use crate::sal::traits::{PlatformSal, EnvironmentCtx};
use crate::sal::dell_xps_9380::DellXps9380Sal;
use crate::sal::generic_linux::GenericLinuxSal;
use crate::sal::heuristic::schema::HardwareDb;
@@ -13,7 +13,7 @@ pub struct HeuristicEngine;
impl HeuristicEngine {
/// Loads the hardware database, probes the system, and builds the appropriate SAL.
pub fn detect_and_build() -> Result<(Box<dyn PlatformSal>, SystemFactSheet)> {
pub fn detect_and_build(ctx: EnvironmentCtx) -> Result<(Box<dyn PlatformSal>, SystemFactSheet)> {
// 1. Load Hardware DB
let db_path = "assets/hardware_db.toml";
let db_content = fs::read_to_string(db_path)
@@ -24,7 +24,7 @@ impl HeuristicEngine {
.context("Failed to parse hardware_db.toml")?;
// 2. Discover Facts
let facts = discover_facts(&db.discovery, &db.conflicts);
let facts = discover_facts(&ctx.sysfs_base, &db.discovery, &db.conflicts, db.benchmarking.clone());
info!("System Identity: {} {}", facts.vendor, facts.model);
// 3. Routing Logic
@@ -32,7 +32,7 @@ impl HeuristicEngine {
// --- Special Case: Dell XPS 13 9380 ---
if is_match(&facts.vendor, "(?i)Dell.*") && is_match(&facts.model, "(?i)XPS.*13.*9380.*") {
info!("Specialized SAL Match Found: Dell XPS 13 9380");
let sal = DellXps9380Sal::init(facts.clone()).map_err(|e| miette::miette!(e))?;
let sal = DellXps9380Sal::init(ctx, facts.clone()).map_err(|e| miette::miette!(e))?;
return Ok((Box::new(sal), facts));
}
@@ -47,7 +47,7 @@ impl HeuristicEngine {
return Err(miette::miette!("No RAPL power interface discovered. Generic fallback impossible."));
}
Ok((Box::new(GenericLinuxSal::new(facts.clone(), db)), facts))
Ok((Box::new(GenericLinuxSal::new(ctx, facts.clone(), db)), facts))
}
}