Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 17 additions & 36 deletions library/std/src/sys/pal/uefi/tests.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//! These tests are not run automatically right now. Please run these tests manually by copying them
//! to a separate project when modifying any related code.

use super::alloc::*;
use super::time::system_time_internal::{from_uefi, to_uefi};
use crate::io::{IoSlice, IoSliceMut};
use crate::ops::{Deref, DerefMut};
use crate::time::Duration;

const SECS_IN_MINUTE: u64 = 60;

const MAX_UEFI_TIME: Duration = from_uefi(r_efi::efi::Time {
const MAX_UEFI_TIME: Duration = from_uefi(&r_efi::efi::Time {
year: 9999,
month: 12,
day: 31,
Expand All @@ -20,27 +20,8 @@ const MAX_UEFI_TIME: Duration = from_uefi(r_efi::efi::Time {
daylight: 0,
pad1: 0,
pad2: 0,
});

#[test]
fn align() {
// UEFI ABI specifies that allocation alignment minimum is always 8. So this can be
// statically verified.
assert_eq!(POOL_ALIGNMENT, 8);

// Loop over allocation-request sizes from 0-256 and alignments from 1-128, and verify
// that in case of overalignment there is at least space for one additional pointer to
// store in the allocation.
for i in 0..256 {
for j in &[1, 2, 4, 8, 16, 32, 64, 128] {
if *j <= 8 {
assert_eq!(align_size(i, *j), i);
} else {
assert!(align_size(i, *j) > i + size_of::<*mut ()>());
}
}
}
}
})
.unwrap();

// UEFI Time cannot implement Eq due to uninitilaized pad1 and pad2
fn uefi_time_cmp(t1: r_efi::efi::Time, t2: r_efi::efi::Time) -> bool {
Expand Down Expand Up @@ -70,9 +51,9 @@ fn systemtime_start() {
daylight: 0,
pad2: 0,
};
assert_eq!(from_uefi(&t), Duration::new(0, 0));
assert!(uefi_time_cmp(t, to_uefi(&from_uefi(&t), -1440, 0).unwrap()));
assert!(to_uefi(&from_uefi(&t), 0, 0).is_err());
assert_eq!(from_uefi(&t).unwrap(), Duration::new(0, 0));
assert!(uefi_time_cmp(t, to_uefi(&from_uefi(&t).unwrap(), -1440, 0).unwrap()));
assert!(to_uefi(&from_uefi(&t).unwrap(), 0, 0).is_err());
}

#[test]
Expand All @@ -90,9 +71,9 @@ fn systemtime_utc_start() {
daylight: 0,
pad2: 0,
};
assert_eq!(from_uefi(&t), Duration::new(1440 * SECS_IN_MINUTE, 0));
assert!(uefi_time_cmp(t, to_uefi(&from_uefi(&t), 0, 0).unwrap()));
assert!(to_uefi(&from_uefi(&t), -1440, 0).is_ok());
assert_eq!(from_uefi(&t).unwrap(), Duration::new(1440 * SECS_IN_MINUTE, 0));
assert!(uefi_time_cmp(t, to_uefi(&from_uefi(&t).unwrap(), 0, 0).unwrap()));
assert!(to_uefi(&from_uefi(&t).unwrap(), -1440, 0).is_ok());
}

#[test]
Expand All @@ -110,8 +91,8 @@ fn systemtime_end() {
daylight: 0,
pad2: 0,
};
assert!(to_uefi(&from_uefi(&t), 1440, 0).is_ok());
assert!(to_uefi(&from_uefi(&t), 1439, 0).is_err());
assert!(to_uefi(&from_uefi(&t).unwrap(), 1440, 0).is_ok());
assert!(to_uefi(&from_uefi(&t).unwrap(), 1439, 0).is_err());
}

#[test]
Expand Down Expand Up @@ -139,17 +120,17 @@ fn min_time() {

#[test]
fn max_time() {
let inp = MAX_UEFI_TIME.0;
let inp = MAX_UEFI_TIME;
let new_tz = to_uefi(&inp, -1440, 0).err().unwrap();
assert_eq!(new_tz, 1440);
assert!(to_uefi(&inp, new_tz, 0).is_ok());

let inp = MAX_UEFI_TIME.0 - Duration::from_secs(1440 * SECS_IN_MINUTE);
let inp = MAX_UEFI_TIME - Duration::from_secs(1440 * SECS_IN_MINUTE);
let new_tz = to_uefi(&inp, -1440, 0).err().unwrap();
assert_eq!(new_tz, 0);
assert!(to_uefi(&inp, new_tz, 0).is_ok());

let inp = MAX_UEFI_TIME.0 - Duration::from_secs(1440 * SECS_IN_MINUTE + 10);
let inp = MAX_UEFI_TIME - Duration::from_secs(1440 * SECS_IN_MINUTE + 10);
let new_tz = to_uefi(&inp, -1440, 0).err().unwrap();
assert_eq!(new_tz, 0);
assert!(to_uefi(&inp, new_tz, 0).is_ok());
Expand Down Expand Up @@ -266,8 +247,8 @@ fn io_slice_mut_basic() {
let mut data_clone = [0, 1, 2, 3, 4];
let mut io_slice_mut = IoSliceMut::new(&mut data_clone);

assert_eq!(data, io_slice_mut.as_slice());
assert_eq!(data, io_slice_mut.as_mut_slice());
assert_eq!(data, io_slice_mut.deref());
assert_eq!(data, io_slice_mut.deref_mut());
Comment on lines +250 to +251
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clippy would probably tell you to do &*io_slice_mut and &mut *io_slice_mut so you don't need to import Deref/DerefMut, but it's not a problem of course


io_slice_mut.advance(2);
assert_eq!(&data[2..], io_slice_mut.into_slice());
Expand Down
Loading