Skip to content

Commit 173106a

Browse files
committed
Add IPC test and fix clippy failures.
1 parent fda4134 commit 173106a

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717

1818
steps:
1919
- name: Checkout Sources
20-
uses: actions/checkout@v3
20+
uses: actions/checkout@v4
2121

2222
- name: Install Rust Toolchain
2323
uses: actions-rs/[email protected]

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ win-sys = "0.3"
4141
raw_sync = "0.1"
4242
clap = {version = "4", features = ["derive"]}
4343
env_logger = "0"
44+
45+
[[test]]
46+
name = "ipc"
47+
harness = false

examples/mutex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn increment_value(shmem_flink: &str, thread_num: usize) {
5757
let is_init: &mut AtomicU8;
5858

5959
unsafe {
60-
is_init = &mut *(raw_ptr as *mut u8 as *mut AtomicU8);
60+
is_init = &mut *(raw_ptr as *mut AtomicU8);
6161
raw_ptr = raw_ptr.add(8);
6262
};
6363

src/windows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Drop for MapData {
7373
{
7474
Ok(_) => {
7575
// 2. Rename file to prevent further use
76-
base_path.push(&format!(
76+
base_path.push(format!(
7777
"{}_deleted",
7878
self.unique_id.trim_start_matches('/')
7979
));

tests/ipc.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use shared_memory::ShmemConf;
2+
use std::{env, process::Command};
3+
4+
fn main() {
5+
let args: Vec<String> = env::args().collect();
6+
match args.len() {
7+
1 => {
8+
let mut s = ShmemConf::new().size(1024).create().unwrap();
9+
let bytes = unsafe { s.as_slice_mut() };
10+
bytes[0..4].copy_from_slice(b"Ping");
11+
let mut child = Command::new(args[0].as_str())
12+
.arg(s.get_os_id())
13+
.spawn()
14+
.unwrap();
15+
assert_eq!(child.wait().unwrap().code(), Some(0));
16+
let bytes = unsafe { s.as_slice() };
17+
assert_eq!(&bytes[0..4], b"PONG");
18+
}
19+
2 => {
20+
let mut s = ShmemConf::new().os_id(args[1].as_str()).open().unwrap();
21+
let bytes = unsafe { s.as_slice_mut() };
22+
assert_eq!(&bytes[0..4], b"Ping");
23+
bytes[0..4].copy_from_slice(b"PONG");
24+
}
25+
_ => {
26+
panic!("Invalid arguments");
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)