#![cfg(test)]
use serial_test::serial;
use luwen::api::{chip::HlCommsInterface, ChipImpl};
mod test_utils;
#[serial]
mod tests {
use super::*;
use test_utils::hardware_available;
#[test]
#[cfg_attr(
not(all(feature = "test_hardware", feature = "test_wormhole")),
ignore = "Requires real wormhole hardware"
)]
fn wormhole_detect_test() {
assert!(hardware_available(), "Test requires hardware");
let partial_chips = luwen::pci::detect_chips_fallible().unwrap();
assert!(!partial_chips.is_empty(), "Should find at least one chip");
let mut found_wh = false;
for chip in partial_chips {
if let Some(upgraded_chip) = chip.try_upgrade() {
if let Some(wh) = upgraded_chip.as_wh() {
found_wh = true;
let status = chip.status();
let eth_status = chip.eth_safe();
let is_remote = wh.is_remote;
if chip.arc_alive() {
let telemetry = wh.get_telemetry().unwrap();
println!("Wormhole board ID: {:X}", telemetry.board_id_low);
}
println!(
"Wormhole Chip: {:?}, Remote: {}, Status: {:?}, Ethernet: {:?}",
upgraded_chip.get_arch(),
is_remote,
status,
eth_status
);
break;
}
}
}
assert!(found_wh, "Test failed: No Wormhole chip found");
}
#[test]
#[cfg_attr(
not(all(feature = "test_hardware", feature = "test_blackhole")),
ignore = "Requires real blackhole hardware"
)]
fn blackhole_detect_test() {
assert!(hardware_available(), "Test requires hardware");
let partial_chips = luwen::pci::detect_chips_fallible().unwrap();
assert!(!partial_chips.is_empty(), "Should find at least one chip");
let mut found_bh = false;
for chip in partial_chips {
if let Some(upgraded_chip) = chip.try_upgrade() {
if let Some(bh) = upgraded_chip.as_bh() {
found_bh = true;
let status = chip.status();
let eth_status = chip.eth_safe();
let telemetry = bh.get_telemetry().unwrap();
println!("Blackhole telemetry: {telemetry:?}");
let result = bh
.arc_msg(luwen::api::chip::ArcMsgOptions {
msg: luwen::api::ArcMsg::Raw {
msg: 0x90,
arg0: 106,
arg1: 0,
},
..Default::default()
})
.unwrap();
println!("ARC message result: {result:?}");
let scratch_value = bh.axi_sread32("arc_ss.reset_unit.SCRATCH_RAM[0]").unwrap();
println!("Blackhole scratch value: {scratch_value:x}");
println!(
"Blackhole Chip: {:?}, Status: {:?}, Ethernet: {:?}",
upgraded_chip.get_arch(),
status,
eth_status
);
break;
}
}
}
assert!(found_bh, "Test failed: No Blackhole chip found");
}
#[test]
#[ignore = "Requires hardware"]
fn blackhole_test_enumerate_output() {
assert!(hardware_available(), "Test requires hardware");
let partial_chips = luwen::pci::detect_chips_fallible().unwrap();
assert!(!partial_chips.is_empty(), "Should find at least one chip");
let mut found_bh = false;
for chip in partial_chips {
if let Some(upgraded_chip) = chip.try_upgrade() {
if let Some(_bh) = upgraded_chip.as_bh() {
found_bh = true;
let mut output = [0u32; 32];
for (index, o) in output.iter_mut().enumerate() {
*o = u32::try_from(index).unwrap_or(0);
}
println!("Successfully created test data of length {}", output.len());
assert_eq!(output[0], 0);
assert_eq!(output[10], 10);
break;
}
}
}
assert!(found_bh, "Test failed: No Blackhole chip found");
}
}