use devpath::*;
extern crate std;
fn decode(groups: &[&[u8]]) -> Result<Paths, Error> {
let mut bytes = Vec::new();
for group in groups {
bytes.extend_from_slice(group);
}
Paths::from_bytes(&bytes)
}
#[test]
fn acpi_root() {
let results = decode(&[
&[0x02, 0x01, 0x0c, 0x00], &[0xd0, 0x41, 0x03, 0x0a], &[0x00, 0x00, 0x00, 0x00], &[0x7f, 0xff, 0x04, 0x00], ])
.unwrap();
let expected = Path::from(vec![Node::Acpi(acpi::Acpi::Standard(
acpi::standard::Standard {
hid: 0x0a03_41d0,
uid: 0,
},
))]);
assert_eq!(results, expected.into());
}
#[test]
fn pci_device() {
let results = decode(&[
&[0x02, 0x01, 0x0c, 0x00], &[0xd0, 0x41, 0x03, 0x0a], &[0x00, 0x00, 0x00, 0x00], &[0x01, 0x01, 0x06, 0x00], &[0x00], &[0x01], &[0x7f, 0xff, 0x04, 0x00], ])
.unwrap();
let expected = Path::from(vec![
Node::Acpi(acpi::Acpi::Standard(acpi::standard::Standard {
hid: 0x0a03_41d0,
uid: 0,
})),
Node::Hardware(hw::Hardware::Pci(hw::pci::Pci {
device: 1,
function: 0,
})),
]);
assert_eq!(results, expected.into());
}
#[test]
fn usb_nodes() {
let results = decode(&[
&[0x02, 0x01, 0x0c, 0x00], &[0xd0, 0x41, 0x03, 0x0a], &[0x00, 0x00, 0x00, 0x00], &[0x01, 0x01, 0x06, 0x00], &[0x02], &[0x1f], &[0x03, 0x05, 0x06, 0x00], &[0x01], &[0x00], &[0x03, 0x05, 0x06, 0x00], &[0x03], &[0x00], &[0x7f, 0xff, 0x04, 0x00], ])
.unwrap();
let expected = Path::from(vec![
Node::Acpi(acpi::Acpi::Standard(acpi::standard::Standard {
hid: 0x0a03_41d0,
uid: 0,
})),
Node::Hardware(hw::Hardware::Pci(hw::pci::Pci {
device: 31,
function: 2,
})),
Node::Messaging(msg::Messaging::Usb(msg::usb::Usb {
port: 1,
interface: 0,
})),
Node::Messaging(msg::Messaging::Usb(msg::usb::Usb {
port: 3,
interface: 0,
})),
]);
assert_eq!(results, expected.into());
}
#[test]
fn usb_device() {
let results = decode(&[
&[0x02, 0x01, 0x0c, 0x00], &[0xd0, 0x41, 0x03, 0x0a], &[0x00, 0x00, 0x00, 0x00], &[0x01, 0x01, 0x06, 0x00], &[0x02], &[0x1f], &[0x03, 0x05, 0x06, 0x00], &[0x00], &[0x00], &[0x7f, 0xff, 0x04, 0x00], ])
.unwrap();
let expected = Path::from(vec![
Node::Acpi(acpi::Acpi::Standard(acpi::standard::Standard {
hid: 0x0a03_41d0,
uid: 0,
})),
Node::Hardware(hw::Hardware::Pci(hw::pci::Pci {
function: 2,
device: 31,
})),
Node::Messaging(msg::Messaging::Usb(msg::usb::Usb {
port: 0,
interface: 0,
})),
]);
assert_eq!(results, expected.into());
}
#[test]
fn fibre_channel_ex() {
let results = decode(&[
&[0x02, 0x01, 0x0c, 0x00], &[0xd0, 0x41, 0x03, 0x0a], &[0x00, 0x00, 0x00, 0x00], &[0x01, 0x01, 0x06, 0x00], &[0x00], &[0x1f], &[0x03, 0x15, 0x18, 0x00], &[0x00, 0x00, 0x00, 0x00], &[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00], &[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00], &[0x7f, 0xff, 0x04, 0x00], ])
.unwrap();
let expected = Path::from(vec![
Node::Acpi(acpi::Acpi::Standard(acpi::standard::Standard {
hid: 0x0a03_41d0,
uid: 0,
})),
Node::Hardware(hw::Hardware::Pci(hw::pci::Pci {
function: 0,
device: 31,
})),
Node::Messaging(msg::Messaging::FibreChannelEx(msg::fc::FibreChannelEx {
wwn: [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00],
lun: [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00],
})),
]);
assert_eq!(results, expected.into());
}
#[test]
fn scsi() {
let results = decode(&[
&[0x02, 0x01, 0x0c, 0x00], &[0xd0, 0x41, 0x03, 0x0a], &[0x00, 0x00, 0x00, 0x00], &[0x01, 0x01, 0x06, 0x00], &[0x00], &[0x01], &[0x03, 0x02, 0x08, 0x00], &[0x00, 0x00], &[0x00, 0x00], &[0x7f, 0xff, 0x04, 0x00], ])
.unwrap();
let expected = Path::from(vec![
Node::Acpi(acpi::Acpi::Standard(acpi::standard::Standard {
hid: 0x0a03_41d0,
uid: 0,
})),
Node::Hardware(hw::Hardware::Pci(hw::pci::Pci {
function: 0,
device: 1,
})),
Node::Messaging(msg::Messaging::Scsi(msg::scsi::Scsi { tid: 0, lun: 0 })),
]);
assert_eq!(results, expected.into());
}
#[test]
fn sata() {
let results = decode(&[
&[0x02, 0x01, 0x0c, 0x00], &[0xd0, 0x41, 0x03, 0x0a], &[0x00, 0x00, 0x00, 0x00], &[0x01, 0x01, 0x06, 0x00], &[0x00], &[0x01], &[0x03, 0x12, 0x0a, 0x00], &[0x00, 0x00], &[0xff, 0xff], &[0x00, 0x00], &[0x7f, 0xff, 0x04, 0x00], ])
.unwrap();
let expected = Path::from(vec![
Node::Acpi(acpi::Acpi::Standard(acpi::standard::Standard {
hid: 0x0a03_41d0,
uid: 0,
})),
Node::Hardware(hw::Hardware::Pci(hw::pci::Pci {
device: 1,
function: 0,
})),
Node::Messaging(msg::Messaging::Sata(msg::sata::Sata {
hba_port: 0,
pm_port: 0xFFFF,
lun: 0,
})),
]);
assert_eq!(results, expected.into());
}
#[test]
fn atapi() {
let results = decode(&[
&[0x02, 0x01, 0x0c, 0x00], &[0xd0, 0x41, 0x03, 0x0a], &[0x00, 0x00, 0x00, 0x00], &[0x01, 0x01, 0x06, 0x00], &[0x01], &[0x01], &[0x03, 0x01, 0x08, 0x00], &[0x00], &[0x00], &[0x00, 0x00], &[0x7f, 0xff, 0x04, 0x00], ])
.unwrap();
let expected = Path::from(vec![
Node::Acpi(acpi::Acpi::Standard(acpi::standard::Standard {
hid: 0x0a03_41d0,
uid: 0,
})),
Node::Hardware(hw::Hardware::Pci(hw::pci::Pci {
function: 1,
device: 1,
})),
Node::Messaging(msg::Messaging::Atapi(msg::atapi::Atapi {
primary: 0,
slave: 0,
lun: 0,
})),
]);
assert_eq!(results, expected.into());
}
#[test]
fn nvmeof_ipv4() {
let results = decode(&[
&[0x02, 0x01, 0x0c, 0x00], &[0xd0, 0x41, 0x03, 0x0a], &[0x00, 0x00, 0x00, 0x00], &[0x01, 0x01, 0x06, 0x00], &[0x00], &[0x19], &[0x03, 0x0b, 0x25, 0x00], &[0x00, 0x13, 0x20, 0xf5, 0xfa, 0x77], &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00], &[0x01], &[0x03, 0x0c, 0x1b, 0x00], &[0xc0, 0xa8, 0x00, 0x64], &[0xc0, 0xa8, 0x00, 0x01], &[0x00, 0x00], &[0xbc, 0x0c], &[0x06, 0x00], &[0x01], &[0x00, 0x00, 0x00, 0x00], &[0xff, 0xff, 0xff, 0x00], &[0x03, 0x22, 0x3d, 0x00], &[0x02], &[0x4e, 0xff, 0x7f, 0x8e, 0xd3, 0x53, 0x4e, 0x9b], &[0xa4, 0xec, 0xde, 0xea, 0x8e, 0xab, 0x84, 0xd7], &[
0x6e, 0x71, 0x6e, 0x2e, 0x31, 0x39, 0x39, 0x31, 0x2d, 0x30, 0x35, 0x2e, 0x6f, 0x72,
0x67, 0x2e, 0x75, 0x65, 0x66, 0x69, 0x3a, 0x6e, 0x76, 0x6d, 0x65, 0x6f, 0x66, 0x2d,
0x6e, 0x76, 0x6d, 0x65, 0x2d, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x00,
],
&[0x7f, 0xff, 0x04, 0x00], ])
.unwrap();
let expected = Path::from(vec![
Node::Acpi(acpi::Acpi::Standard(acpi::standard::Standard {
hid: 0x0a03_41d0,
uid: 0,
})),
Node::Hardware(hw::Hardware::Pci(hw::pci::Pci {
function: 0,
device: 25,
})),
Node::Messaging(msg::Messaging::MacAddress(msg::mac::MacAddress {
mac: [
0x00, 0x13, 0x20, 0xf5, 0xfa, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
],
if_type: msg::mac::InterfaceType::OTHER,
})),
Node::Messaging(msg::Messaging::Ipv4(msg::ipv4::Ipv4 {
local: std::net::SocketAddrV4::new(std::net::Ipv4Addr::new(192, 168, 0, 100), 0),
remote: std::net::SocketAddrV4::new(std::net::Ipv4Addr::new(192, 168, 0, 1), 3260),
protocol: msg::ipv4::Protocol::TCP,
static_ip: true,
gateway_ip: std::net::Ipv4Addr::UNSPECIFIED,
subnet_mask: std::net::Ipv4Addr::new(255, 255, 255, 0),
})),
Node::Messaging(msg::Messaging::NvmeOfNamespace(
msg::nvme_of::NvmeOfNamespace {
nid: msg::nvme_of::NamespaceId::Nguid([
0x4e, 0xff, 0x7f, 0x8e, 0xd3, 0x53, 0x4e, 0x9b, 0xa4, 0xec, 0xde, 0xea, 0x8e,
0xab, 0x84, 0xd7,
]),
nqn: "nqn.1991-05.org.uefi:nvmeof-nvme-target".to_string(),
},
)),
]);
assert_eq!(results, expected.into());
}
#[test]
fn memory_mapped() {
let results = decode(&[
&[0x02, 0x01, 0x0c, 0x00], &[0xd0, 0x41, 0x03, 0x0a], &[0x00, 0x00, 0x00, 0x00], &[0x01, 0x03, 0x18, 0x00], &[0x00, 0x00, 0x00, 0x00], &[0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00], &[0xff, 0xff, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00], &[0x7f, 0xff, 0x04, 0x00], ])
.unwrap();
let expected = Path::from(vec![
Node::Acpi(acpi::Acpi::Standard(acpi::standard::Standard {
hid: 0x0a03_41d0,
uid: 0,
})),
Node::Hardware(hw::Hardware::MemMap(hw::memmap::MemMap {
kind: hw::memmap::MemoryType::Reserved,
start: 0x3f00_0000,
end: 0x3f00_ffff,
})),
]);
assert_eq!(results, expected.into());
}
#[test]
fn uart() {
let results = decode(&[
&[0x02, 0x01, 0x0c, 0x00], &[0xd0, 0x41, 0x03, 0x0a], &[0x00, 0x00, 0x00, 0x00], &[0x01, 0x01, 0x06, 0x00], &[0x01], &[0x01], &[0x03, 0x0e, 0x13, 0x00], &[0x00, 0x00, 0x00, 0x00], &[0x00, 0xc2, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00], &[0x08], &[0x01], &[0x01], &[0x7f, 0xff, 0x04, 0x00], ])
.unwrap();
let expected = Path::from(vec![
Node::Acpi(acpi::Acpi::Standard(acpi::standard::Standard {
hid: 0x0a03_41d0,
uid: 0,
})),
Node::Hardware(hw::Hardware::Pci(hw::pci::Pci {
function: 1,
device: 1,
})),
Node::Messaging(msg::Messaging::Uart(msg::uart::Uart {
baud: 115_200,
data_bits: 8,
parity: 1, stop_bits: 1, })),
]);
assert_eq!(results, expected.into());
}
#[test]
fn controller() {
let results = decode(&[
&[0x02, 0x01, 0x0c, 0x00], &[0xd0, 0x41, 0x03, 0x0a], &[0x00, 0x00, 0x00, 0x00], &[0x01, 0x01, 0x06, 0x00], &[0x00], &[0x01], &[0x01, 0x05, 0x08, 0x00], &[0x00, 0x00, 0x00, 0x00], &[0x7f, 0xff, 0x04, 0x00], ])
.unwrap();
let expected = Path::from(vec![
Node::Acpi(acpi::Acpi::Standard(acpi::standard::Standard {
hid: 0x0a03_41d0,
uid: 0,
})),
Node::Hardware(hw::Hardware::Pci(hw::pci::Pci {
function: 0,
device: 1,
})),
Node::Hardware(hw::Hardware::Controller(hw::controller::Controller(0))),
]);
assert_eq!(results, expected.into());
}