Skip to content

Commit 85430df

Browse files
Rollup merge of #151555 - nicholasbishop:bishop-fix-just-uefi-test, r=Ayush1325,tgross35
Fix compilation of std/src/sys/pal/uefi/tests.rs Dropped the `align` test since the `POOL_ALIGNMENT` and `align_size` items it uses do not exist. The other changes are straightforward fixes for places where the test code drifted from the current API, since the tests are not yet built in CI for the UEFI target. CC @Ayush1325
2 parents b6b11f4 + 8995ff5 commit 85430df

1 file changed

Lines changed: 17 additions & 36 deletions

File tree

library/std/src/sys/pal/uefi/tests.rs

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//! These tests are not run automatically right now. Please run these tests manually by copying them
22
//! to a separate project when modifying any related code.
33
4-
use super::alloc::*;
54
use super::time::system_time_internal::{from_uefi, to_uefi};
65
use crate::io::{IoSlice, IoSliceMut};
6+
use crate::ops::{Deref, DerefMut};
77
use crate::time::Duration;
88

99
const SECS_IN_MINUTE: u64 = 60;
1010

11-
const MAX_UEFI_TIME: Duration = from_uefi(r_efi::efi::Time {
11+
const MAX_UEFI_TIME: Duration = from_uefi(&r_efi::efi::Time {
1212
year: 9999,
1313
month: 12,
1414
day: 31,
@@ -20,27 +20,8 @@ const MAX_UEFI_TIME: Duration = from_uefi(r_efi::efi::Time {
2020
daylight: 0,
2121
pad1: 0,
2222
pad2: 0,
23-
});
24-
25-
#[test]
26-
fn align() {
27-
// UEFI ABI specifies that allocation alignment minimum is always 8. So this can be
28-
// statically verified.
29-
assert_eq!(POOL_ALIGNMENT, 8);
30-
31-
// Loop over allocation-request sizes from 0-256 and alignments from 1-128, and verify
32-
// that in case of overalignment there is at least space for one additional pointer to
33-
// store in the allocation.
34-
for i in 0..256 {
35-
for j in &[1, 2, 4, 8, 16, 32, 64, 128] {
36-
if *j <= 8 {
37-
assert_eq!(align_size(i, *j), i);
38-
} else {
39-
assert!(align_size(i, *j) > i + size_of::<*mut ()>());
40-
}
41-
}
42-
}
43-
}
23+
})
24+
.unwrap();
4425

4526
// UEFI Time cannot implement Eq due to uninitilaized pad1 and pad2
4627
fn uefi_time_cmp(t1: r_efi::efi::Time, t2: r_efi::efi::Time) -> bool {
@@ -70,9 +51,9 @@ fn systemtime_start() {
7051
daylight: 0,
7152
pad2: 0,
7253
};
73-
assert_eq!(from_uefi(&t), Duration::new(0, 0));
74-
assert!(uefi_time_cmp(t, to_uefi(&from_uefi(&t), -1440, 0).unwrap()));
75-
assert!(to_uefi(&from_uefi(&t), 0, 0).is_err());
54+
assert_eq!(from_uefi(&t).unwrap(), Duration::new(0, 0));
55+
assert!(uefi_time_cmp(t, to_uefi(&from_uefi(&t).unwrap(), -1440, 0).unwrap()));
56+
assert!(to_uefi(&from_uefi(&t).unwrap(), 0, 0).is_err());
7657
}
7758

7859
#[test]
@@ -90,9 +71,9 @@ fn systemtime_utc_start() {
9071
daylight: 0,
9172
pad2: 0,
9273
};
93-
assert_eq!(from_uefi(&t), Duration::new(1440 * SECS_IN_MINUTE, 0));
94-
assert!(uefi_time_cmp(t, to_uefi(&from_uefi(&t), 0, 0).unwrap()));
95-
assert!(to_uefi(&from_uefi(&t), -1440, 0).is_ok());
74+
assert_eq!(from_uefi(&t).unwrap(), Duration::new(1440 * SECS_IN_MINUTE, 0));
75+
assert!(uefi_time_cmp(t, to_uefi(&from_uefi(&t).unwrap(), 0, 0).unwrap()));
76+
assert!(to_uefi(&from_uefi(&t).unwrap(), -1440, 0).is_ok());
9677
}
9778

9879
#[test]
@@ -110,8 +91,8 @@ fn systemtime_end() {
11091
daylight: 0,
11192
pad2: 0,
11293
};
113-
assert!(to_uefi(&from_uefi(&t), 1440, 0).is_ok());
114-
assert!(to_uefi(&from_uefi(&t), 1439, 0).is_err());
94+
assert!(to_uefi(&from_uefi(&t).unwrap(), 1440, 0).is_ok());
95+
assert!(to_uefi(&from_uefi(&t).unwrap(), 1439, 0).is_err());
11596
}
11697

11798
#[test]
@@ -139,17 +120,17 @@ fn min_time() {
139120

140121
#[test]
141122
fn max_time() {
142-
let inp = MAX_UEFI_TIME.0;
123+
let inp = MAX_UEFI_TIME;
143124
let new_tz = to_uefi(&inp, -1440, 0).err().unwrap();
144125
assert_eq!(new_tz, 1440);
145126
assert!(to_uefi(&inp, new_tz, 0).is_ok());
146127

147-
let inp = MAX_UEFI_TIME.0 - Duration::from_secs(1440 * SECS_IN_MINUTE);
128+
let inp = MAX_UEFI_TIME - Duration::from_secs(1440 * SECS_IN_MINUTE);
148129
let new_tz = to_uefi(&inp, -1440, 0).err().unwrap();
149130
assert_eq!(new_tz, 0);
150131
assert!(to_uefi(&inp, new_tz, 0).is_ok());
151132

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

269-
assert_eq!(data, io_slice_mut.as_slice());
270-
assert_eq!(data, io_slice_mut.as_mut_slice());
250+
assert_eq!(data, io_slice_mut.deref());
251+
assert_eq!(data, io_slice_mut.deref_mut());
271252

272253
io_slice_mut.advance(2);
273254
assert_eq!(&data[2..], io_slice_mut.into_slice());

0 commit comments

Comments
 (0)