Skip to content

Commit

Permalink
Add test to ensure data can be shared through shmem
Browse files Browse the repository at this point in the history
  • Loading branch information
elast0ny committed Mar 1, 2022
1 parent ba5d63e commit 8dfa117
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,29 @@ fn open_flink() {

drop(s2);
}

#[test]
fn share_data() {
let s1 = ShmemConf::new()
.size(core::mem::size_of::<u32>())
.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);
}
}

0 comments on commit 8dfa117

Please sign in to comment.