xref: /drstd/src/std/sys/sgx/rwlock/tests.rs (revision 86982c5e9b2eaa583327251616ee822c36288824)
1 use super::*;
2 use crate::std::ptr;
3 
4 // Verify that the byte pattern libunwind uses to initialize an RwLock is
5 // equivalent to the value of RwLock::new(). If the value changes,
6 // `src/UnwindRustSgx.h` in libunwind needs to be changed too.
7 #[test]
8 fn test_c_rwlock_initializer() {
9     const C_RWLOCK_INIT: *mut () = ptr::null_mut();
10 
11     // For the test to work, we need the padding/unused bytes in RwLock to be
12     // initialized as 0. In practice, this is the case with statics.
13     static RUST_RWLOCK_INIT: RwLock = RwLock::new();
14 
15     unsafe {
16         // If the assertion fails, that not necessarily an issue with the value
17         // of C_RWLOCK_INIT. It might just be an issue with the way padding
18         // bytes are initialized in the test code.
19         assert_eq!(
20             crate::std::mem::transmute_copy::<_, *mut ()>(&RUST_RWLOCK_INIT),
21             C_RWLOCK_INIT
22         );
23     };
24 }
25