diff --git a/tests/general.rs b/tests/general.rs index 9a8ef14..2812711 100644 --- a/tests/general.rs +++ b/tests/general.rs @@ -89,3 +89,29 @@ fn open_flink() { drop(s2); } + +#[test] +fn share_data() { + let s1 = ShmemConf::new() + .size(core::mem::size_of::()) + .create() + .unwrap(); + + // Open with the unique os id + let os_id = s1.get_os_id().to_string(); + let s2 = ShmemConf::new().os_id(&os_id).open().unwrap(); + + let ptr1 = s1.as_ptr() as *mut u32; + let ptr2 = s2.as_ptr() as *mut u32; + + // Confirm that the two pointers are different + assert_ne!(ptr1, ptr2); + + // Write a value from s1 and read it from s2 + unsafe { + let shared_val = 0xBADC0FEE; + ptr1.write_volatile(shared_val); + let read_val = ptr2.read_volatile(); + assert_eq!(read_val, shared_val); + } +}