style(v0.4): rustfmt thermal/protocol/coprocessor/service/integration

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Alexander <akotenev2003@gmail.com>
This commit is contained in:
2026-06-25 15:44:10 +03:00
parent a050f57241
commit 50fdaab25b
4 changed files with 62 additions and 17 deletions
+6 -2
View File
@@ -42,7 +42,9 @@ impl SocToMcu {
pub fn from_wire(t: u8, p: &[u8]) -> Option<Self> {
match t {
wire::HEARTBEAT => Some(SocToMcu::Heartbeat),
wire::SHUTDOWN_IMMINENT => Some(SocToMcu::ShutdownImminent { budget: *p.first()? }),
wire::SHUTDOWN_IMMINENT => Some(SocToMcu::ShutdownImminent {
budget: *p.first()?,
}),
wire::SAFE_TO_CUT => Some(SocToMcu::SafeToCut),
_ => None,
}
@@ -68,7 +70,9 @@ impl McuToSoc {
pub fn from_wire(t: u8, p: &[u8]) -> Option<Self> {
match t {
wire::ACK => Some(McuToSoc::Ack),
wire::ACC => Some(McuToSoc::Acc { on: *p.first()? != 0 }),
wire::ACC => Some(McuToSoc::Acc {
on: *p.first()? != 0,
}),
wire::VOLTAGE => Some(McuToSoc::Voltage {
mv: u16::from_be_bytes([*p.first()?, *p.get(1)?]),
}),
+3 -1
View File
@@ -303,7 +303,9 @@ impl PowerMock {
/// Тишина линка: SoC-сторона деградирует (лог, не self-cut — red-line). MCU-политика cut-vs-hold — B §12/HW.
async fn mcu_link_loss(&self) {
tracing::warn!("coprocessor: MCU link loss — SoC деградирует (cut-vs-hold политика — HW/§12)");
tracing::warn!(
"coprocessor: MCU link loss — SoC деградирует (cut-vs-hold политика — HW/§12)"
);
}
}
+44 -11
View File
@@ -230,28 +230,61 @@ mod policy_tests {
#[test]
fn rises_by_entry_thresholds() {
assert_eq!(ThermalPolicy::next(ThermalLevel::Normal, 70), ThermalLevel::Normal);
assert_eq!(ThermalPolicy::next(ThermalLevel::Normal, 75), ThermalLevel::Warn);
assert_eq!(ThermalPolicy::next(ThermalLevel::Warn, 85), ThermalLevel::Throttle(1));
assert_eq!(ThermalPolicy::next(ThermalLevel::Throttle(1), 95), ThermalLevel::Critical);
assert_eq!(
ThermalPolicy::next(ThermalLevel::Normal, 70),
ThermalLevel::Normal
);
assert_eq!(
ThermalPolicy::next(ThermalLevel::Normal, 75),
ThermalLevel::Warn
);
assert_eq!(
ThermalPolicy::next(ThermalLevel::Warn, 85),
ThermalLevel::Throttle(1)
);
assert_eq!(
ThermalPolicy::next(ThermalLevel::Throttle(1), 95),
ThermalLevel::Critical
);
// прыжок вверх через банды
assert_eq!(ThermalPolicy::next(ThermalLevel::Normal, 99), ThermalLevel::Critical);
assert_eq!(
ThermalPolicy::next(ThermalLevel::Normal, 99),
ThermalLevel::Critical
);
}
#[test]
fn hysteresis_holds_until_below_exit() {
// critical держится до < 90 (955)
assert_eq!(ThermalPolicy::next(ThermalLevel::Critical, 92), ThermalLevel::Critical);
assert_eq!(ThermalPolicy::next(ThermalLevel::Critical, 89), ThermalLevel::Throttle(1));
assert_eq!(
ThermalPolicy::next(ThermalLevel::Critical, 92),
ThermalLevel::Critical
);
assert_eq!(
ThermalPolicy::next(ThermalLevel::Critical, 89),
ThermalLevel::Throttle(1)
);
// warn держится до < 70
assert_eq!(ThermalPolicy::next(ThermalLevel::Warn, 73), ThermalLevel::Warn);
assert_eq!(ThermalPolicy::next(ThermalLevel::Warn, 69), ThermalLevel::Normal);
assert_eq!(
ThermalPolicy::next(ThermalLevel::Warn, 73),
ThermalLevel::Warn
);
assert_eq!(
ThermalPolicy::next(ThermalLevel::Warn, 69),
ThermalLevel::Normal
);
}
#[test]
fn no_oscillation_at_boundary() {
// на 84 (чуть ниже entry throttle=85): зависит от prev (Schmitt), не дёргается
assert_eq!(ThermalPolicy::next(ThermalLevel::Throttle(1), 84), ThermalLevel::Throttle(1));
assert_eq!(ThermalPolicy::next(ThermalLevel::Warn, 84), ThermalLevel::Warn);
assert_eq!(
ThermalPolicy::next(ThermalLevel::Throttle(1), 84),
ThermalLevel::Throttle(1)
);
assert_eq!(
ThermalPolicy::next(ThermalLevel::Warn, 84),
ThermalLevel::Warn
);
}
}
@@ -13,7 +13,10 @@ use std::sync::Arc;
#[ignore = "нужна session-шина: just test-integration"]
async fn power_state_and_fake_acc() {
let svc = PowerService::new();
let mock = svc.mock(Arc::new(MockTempSource::new(20)), Arc::new(MockCoprocessor::new()));
let mock = svc.mock(
Arc::new(MockTempSource::new(20)),
Arc::new(MockCoprocessor::new()),
);
// сервер: Power1 + dev.PowerMock1 на одном пути (владеет ru.shturman.Power)
let server = zbus::Connection::session().await.unwrap();
@@ -56,7 +59,10 @@ async fn power_state_and_fake_acc() {
#[ignore = "нужна session-шина: just test-integration"]
async fn shutdown_imminent_then_abort() {
let svc = PowerService::new();
let mock = svc.mock(Arc::new(MockTempSource::new(20)), Arc::new(MockCoprocessor::new()));
let mock = svc.mock(
Arc::new(MockTempSource::new(20)),
Arc::new(MockCoprocessor::new()),
);
let server = zbus::Connection::session().await.unwrap();
server
.object_server()
@@ -193,7 +199,7 @@ async fn mcu_failsafe_cuts_on_hang() {
// дать coproc-циклу послать ≥1 heartbeat (иначе last_heartbeat=0 и guard не даст cut)
tokio::time::sleep(std::time::Duration::from_millis(1300)).await;
copro.hang(); // SoC завис → heartbeat не освежает таймер
// ждём, пока coproc-цикл (HEARTBEAT=1с) накопит > FAILSAFE_MISS окон и сделает FailsafeCut
// ждём, пока coproc-цикл (HEARTBEAT=1с) накопит > FAILSAFE_MISS окон и сделает FailsafeCut
for _ in 0..10 {
tokio::time::sleep(std::time::Duration::from_millis(700)).await;
if power.power_state().await.unwrap() == PowerState::Off {