MCPcopy Create free account
hub / github.com/elast0ny/shared_memory / share_data

Function share_data

tests/general.rs:94–117  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

92
93#[test]
94fn share_data() {
95 let s1 = ShmemConf::new()
96 .size(core::mem::size_of::<u32>())
97 .create()
98 .unwrap();
99
100 // Open with the unique os id
101 let os_id = s1.get_os_id().to_string();
102 let s2 = ShmemConf::new().os_id(&os_id).open().unwrap();
103
104 let ptr1 = s1.as_ptr() as *mut u32;
105 let ptr2 = s2.as_ptr() as *mut u32;
106
107 // Confirm that the two pointers are different
108 assert_ne!(ptr1, ptr2);
109
110 // Write a value from s1 and read it from s2
111 unsafe {
112 let shared_val = 0xBADC0FEE;
113 ptr1.write_volatile(shared_val);
114 let read_val = ptr2.read_volatile();
115 assert_eq!(read_val, shared_val);
116 }
117}

Callers

nothing calls this directly

Calls 6

createMethod · 0.80
sizeMethod · 0.80
get_os_idMethod · 0.80
openMethod · 0.80
os_idMethod · 0.80
as_ptrMethod · 0.80

Tested by

no test coverage detected