]> git.lizzy.rs Git - rust.git/blob - library/std/src/sys/sgx/rwlock/tests.rs
05b36c633f8618e4a50e7a764ad1f11ab0b507a0
[rust.git] / library / std / src / sys / sgx / rwlock / tests.rs
1 use super::*;
2 use crate::mem::{self, MaybeUninit};
3 use core::array::FixedSizeArray;
4
5 // Verify that the bytes of initialized RWLock are the same as in
6 // libunwind. If they change, `src/UnwindRustSgx.h` in libunwind needs to
7 // be changed too.
8 #[test]
9 fn test_c_rwlock_initializer() {
10     #[rustfmt::skip]
11     const RWLOCK_INIT: &[u8] = &[
12         /* 0x00 */ 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
13         /* 0x10 */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
14         /* 0x20 */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
15         /* 0x30 */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
16         /* 0x40 */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
17         /* 0x50 */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
18         /* 0x60 */ 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
19         /* 0x70 */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
20         /* 0x80 */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
21     ];
22
23     #[inline(never)]
24     fn zero_stack() {
25         test::black_box(MaybeUninit::<[RWLock; 16]>::zeroed());
26     }
27
28     #[inline(never)]
29     unsafe fn rwlock_new(init: &mut MaybeUninit<RWLock>) {
30         init.write(RWLock::new());
31     }
32
33     unsafe {
34         // try hard to make sure that the padding/unused bytes in RWLock
35         // get initialized as 0. If the assertion below fails, that might
36         // just be an issue with the test code and not with the value of
37         // RWLOCK_INIT.
38         zero_stack();
39         let mut init = MaybeUninit::<RWLock>::zeroed();
40         rwlock_new(&mut init);
41         assert_eq!(mem::transmute::<_, [u8; 144]>(init.assume_init()).as_slice(), RWLOCK_INIT)
42     };
43 }