From 42509a63836af8e7864d59cec405411676116599 Mon Sep 17 00:00:00 2001 From: Noah <2+noah@noreply.gitea.bluefla.re> Date: Thu, 22 Oct 2026 10:49:04 -0600 Subject: [PATCH] Add a runnable self-check for the boot path alkane-os --self-check drives the whole chain without hardware: parse the example profile database, detect three BM1362 chains with a dead EEPROM, identify an APW12, boot the runtime, tick toward a power target and print the published hardware document. It fails loudly if the profile database does not parse, detection refuses, the tuner does not move, or the chain set is wrong, which makes it usable as a bench smoke test on a bare control board. profiles.example.json is a shape example, not validated hardware data: the envelopes are placeholders until real captures fill the database. --- profiles.example.json | 19 +++++++++ src/main.rs | 92 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 profiles.example.json diff --git a/profiles.example.json b/profiles.example.json new file mode 100644 index 0000000..6dc7f98 --- /dev/null +++ b/profiles.example.json @@ -0,0 +1,19 @@ +{ + "schema": 1, + "profiles": [ + { + "name": "s19jpro-bm1362-pic", + "chip": "bm1362", + "sensor": "pic", + "chains": 3, + "envelope": {"v_min_mv": 1100, "v_max_mv": 1500, "f_min_mhz": 300, "f_max_mhz": 700} + }, + { + "name": "s19kpro-bm1366-nopic", + "chip": "bm1366", + "sensor": "nopic", + "chains": 3, + "envelope": {"v_min_mv": 1100, "v_max_mv": 1500, "f_min_mhz": 300, "f_max_mhz": 700} + } + ] +} diff --git a/src/main.rs b/src/main.rs index 4f757b3..25ef8f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,16 @@ // SPDX-License-Identifier: MIT use alkane_os::app; +use alkane_os::detect::{ + ChipModel as DetectedChip, DetectionBackend, EepromState, Envelope, ProbeBudget, ProbeOutcome, + PsuCapability, SensorTopology, +}; use alkane_os::hal_wire::HalClient; use alkane_os::management::MiningStatus; use alkane_os::miner::{Bm1366Miner, ChipModel}; +use alkane_os::runtime::Tick; use alkane_os::stratum_client::{PoolConnection, PoolEvent}; use alkane_os::target_matrix; +use alkane_os::tuning::{PidConfig, TuningTarget}; use std::error::Error; use std::io; use std::net::SocketAddr; @@ -88,6 +94,84 @@ fn sim_mine(mut args: impl Iterator) -> Result<(), Box } } +/// A backend that answers without hardware, so the boot path can be exercised on any machine. +struct SelfCheckBackend; + +impl DetectionBackend for SelfCheckBackend { + type Error = (); + + fn probe(&mut self, _chain: u8, _attempt: u8) -> Result { + Ok(ProbeOutcome::Identified { + chip: DetectedChip::Bm1362, + chips: 126, + }) + } + + fn eeprom(&mut self, _chain: u8) -> Result { + Ok(EepromState::Absent) + } + + fn identify_psu(&mut self) -> Result, ()> { + Ok(Some(PsuCapability { + name: "APW12".into(), + envelope: Envelope { + v_min_mv: 1200, + v_max_mv: 1600, + f_min_mhz: 0, + f_max_mhz: 1000, + }, + max_dc_watts: 3600, + })) + } +} + +/// Run detection, the runtime loop and the API document against the self-check backend. +/// +/// This is the smoke test an image can run on a bench machine before any hashboard is attached: +/// it proves the profile database parses, detection produces a plan, the tuner moves within the +/// envelope and the published document is well formed. +fn self_check() -> Result<(), Box> { + let status = MiningStatus::new(); + let config = app::BootConfig { + profile_db_json: include_str!("../profiles.example.json").to_owned(), + chain_ports: vec![0, 1, 2], + sensor: SensorTopology::Pic, + budget: ProbeBudget::default(), + fan_zones: Vec::new(), + target: TuningTarget::PowerW(2_400.0), + pid: PidConfig::default(), + ceiling_mc: 95_000, + fault_policy: Default::default(), + }; + let mut backend = SelfCheckBackend; + let mut runtime = app::boot(&mut backend, &config, &status)?; + let start = runtime.operating_point().frequency_mhz; + for _ in 0..20 { + let power = 4.0 * f32::from(runtime.operating_point().frequency_mhz); + runtime.tick(&Tick { + power_w: Some(power), + hashrate_ths: None, + hottest_mc: Some(70_000), + ambient_mc: None, + dt_s: 1.0, + }); + } + let end = runtime.operating_point().frequency_mhz; + if end <= start { + return Err("self-check: frequency did not move toward the target".into()); + } + if runtime.active_chains().len() != 3 { + return Err("self-check: detection did not expose three chains".into()); + } + status.set_hardware(app::snapshot(&runtime, &app::target_label(&config.target))); + let document = status.hardware_document(); + if document["available"] != true { + return Err("self-check: hardware document is not available".into()); + } + println!("{}", serde_json::to_string_pretty(&document)?); + Ok(()) +} + fn main() { let mut args = std::env::args().skip(1); match args.next().as_deref() { @@ -101,6 +185,12 @@ fn main() { } } Some("--version") => println!("alkane-os {}", env!("CARGO_PKG_VERSION")), + Some("--self-check") => { + if let Err(error) = self_check() { + eprintln!("self-check failed: {error}"); + std::process::exit(1); + } + } Some("--mine-simulator") => { if let Err(error) = sim_mine(args) { eprintln!("simulator mining failed: {error}"); @@ -108,7 +198,7 @@ fn main() { } } _ => { - eprintln!("usage: alkane-os --list-targets | --version | --mine-simulator HAL_SOCKET POOL_ADDRESS WORKER BM1362|BM1366 [MAX_ACCEPTS]"); + eprintln!("usage: alkane-os --list-targets | --version | --self-check | --mine-simulator HAL_SOCKET POOL_ADDRESS WORKER BM1362|BM1366 [MAX_ACCEPTS]"); eprintln!( "env: ALKANE_API_LISTEN=ADDR ALKANE_WEB_LISTEN=ADDR ALKANE_POOL_PASSWORD=..." );