Skip to content

Commit 8dfa117

Browse files
committed
Add test to ensure data can be shared through shmem
1 parent ba5d63e commit 8dfa117

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/general.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,29 @@ fn open_flink() {
8989

9090
drop(s2);
9191
}
92+
93+
#[test]
94+
fn 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+
}

0 commit comments

Comments
 (0)