Skip to content

Commit 8afe314

Browse files
committed
test(fspy_test_bin): read_verify / read_verify_threads actions
read_verify opens the file, reads it, and asserts the content is non-empty — used by the seccomp blocking-callback test to prove the ADDFD-installed descriptor in the target is usable. read_verify_threads runs the same from four concurrent threads to exercise the callback path under concurrency.
1 parent 01cd08c commit 8afe314

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

crates/fspy_test_bin/src/main.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,37 @@ fn main() {
4040
"stat" => {
4141
let _ = std::fs::metadata(path);
4242
}
43+
"read_verify" => {
44+
// Open and read the file, then drop it (closing it). Used by the
45+
// seccomp blocking-callback test: under seccomp the supervisor
46+
// opens the file itself and installs the descriptor into this
47+
// process via `ADDFD`, so a successful non-empty read proves the
48+
// installed descriptor works.
49+
use std::io::Read as _;
50+
let mut file = File::open(path).expect("read_verify: open failed");
51+
let mut content = Vec::new();
52+
file.read_to_end(&mut content).expect("read_verify: read failed");
53+
assert!(!content.is_empty(), "read_verify: file content was empty");
54+
}
55+
"read_verify_threads" => {
56+
// Like `read_verify`, but from several threads concurrently, so the
57+
// seccomp blocking-callback path is exercised under concurrency.
58+
use std::io::Read as _;
59+
let handles: Vec<_> = (0..4)
60+
.map(|_| {
61+
let path = path.to_owned();
62+
std::thread::spawn(move || {
63+
let mut file = File::open(&path).expect("open failed");
64+
let mut content = Vec::new();
65+
file.read_to_end(&mut content).expect("read failed");
66+
assert!(!content.is_empty(), "file content was empty");
67+
})
68+
})
69+
.collect();
70+
for handle in handles {
71+
handle.join().expect("worker thread panicked");
72+
}
73+
}
4374
"execve" => {
4475
let _ = std::process::Command::new(path).spawn();
4576
}

0 commit comments

Comments
 (0)