Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit aa1b362

Browse files
committed
uefi-raw: add unit test for typical high-level net API usage
1 parent 86830f3 commit aa1b362

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

‎uefi-raw/src/net.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,47 @@ mod tests {
394394
}
395395
}
396396

397+
/// Tests the expected flow of types in a higher-level UEFI API.
398+
#[test]
399+
fn test_uefi_flow() {
400+
fn efi_retrieve_efi_ip_addr(addr: &mut IpAddress, is_ipv6: bool) {
401+
// SAFETY: Alignment is guaranteed and memory is initialized.
402+
unsafe {
403+
addr.v4.0[0] = 42;
404+
addr.v4.0[1] = 42;
405+
addr.v4.0[2] = 42;
406+
addr.v4.0[3] = 42;
407+
}
408+
if is_ipv6 {
409+
unsafe {
410+
addr.v6.0[14] = 42;
411+
addr.v6.0[15] = 42;
412+
}
413+
}
414+
}
415+
416+
fn high_level_retrieve_ip(is_ipv6: bool) -> StdIpAddr {
417+
let mut efi_ip_addr = IpAddress::new_zeroed();
418+
efi_retrieve_efi_ip_addr(&mut efi_ip_addr, is_ipv6);
419+
unsafe { efi_ip_addr.into_std_ip_addr(is_ipv6) }
420+
}
421+
422+
let ipv4_addr = high_level_retrieve_ip(false);
423+
let ipv4_addr: StdIpv4Addr = match ipv4_addr {
424+
StdIpAddr::V4(ipv4_addr) => ipv4_addr,
425+
StdIpAddr::V6(_) => panic!("should not happen"),
426+
};
427+
assert_eq!(ipv4_addr.octets(), [42, 42, 42, 42]);
428+
429+
let ipv6_addr = high_level_retrieve_ip(true);
430+
let ipv6_addr: StdIpv6Addr = match ipv6_addr {
431+
StdIpAddr::V6(ipv6_addr) => ipv6_addr,
432+
StdIpAddr::V4(_) => panic!("should not happen"),
433+
};
434+
let expected = [42, 42, 42, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 42];
435+
assert_eq!(ipv6_addr.octets(), expected);
436+
}
437+
397438
#[test]
398439
fn test_efi_ip_address_abi() {
399440
#[repr(C, packed)]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /