]> git.lizzy.rs Git - rust.git/blob - library/std/src/sys/sgx/rwlock/tests.rs
Improve SGX RWLock initializer test
[rust.git] / library / std / src / sys / sgx / rwlock / tests.rs
1 use super::*;
2
3 // Verify that the byte pattern libunwind uses to initialize an RWLock is
4 // equivalent to the value of RWLock::new(). If the value changes,
5 // `src/UnwindRustSgx.h` in libunwind needs to be changed too.
6 #[test]
7 fn test_c_rwlock_initializer() {
8     #[rustfmt::skip]
9     const C_RWLOCK_INIT: &[u8] = &[
10         /* 0x00 */ 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
11         /* 0x10 */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
12         /* 0x20 */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
13         /* 0x30 */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
14         /* 0x40 */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
15         /* 0x50 */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
16         /* 0x60 */ 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
17         /* 0x70 */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
18         /* 0x80 */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
19     ];
20
21     // For the test to work, we need the padding/unused bytes in RWLock to be
22     // initialized as 0. In practice, this is the case with statics.
23     static RUST_RWLOCK_INIT: RWLock = RWLock::new();
24
25     unsafe {
26         // If the assertion fails, that not necessarily an issue with the value
27         // of C_RWLOCK_INIT. It might just be an issue with the way padding
28         // bytes are initialized in the test code.
29         assert_eq!(&crate::mem::transmute_copy::<_, [u8; 144]>(&RUST_RWLOCK_INIT), C_RWLOCK_INIT);
30     };
31 }