Files
2026-09-21 22:29:23 +08:00

56 lines
1.5 KiB
Rust

// Test-only workload: sustained dirty writes plus a child that ignores TERM.
use clap::{Parser, ValueEnum};
use std::{
fs::{self, File},
io::{Seek, SeekFrom, Write},
process::Command,
};
unsafe extern "C" {
fn signal(number: i32, handler: usize) -> usize;
}
#[derive(Parser)]
#[command(about = "Write disposable DATA stress output")]
struct Cli {
role: Option<Role>,
}
#[derive(Clone, ValueEnum)]
enum Role {
Child,
}
fn main() {
let cli = Cli::parse();
unsafe {
signal(15, 1);
}
if matches!(cli.role, Some(Role::Child)) {
loop {
std::thread::park();
}
}
fs::write(
"/data/process-status",
fs::read("/proc/self/status").unwrap(),
)
.unwrap();
let child = Command::new(std::env::current_exe().unwrap())
.arg("child")
.spawn()
.unwrap();
fs::write("/data/child-pid", child.id().to_string()).unwrap();
let mut file = File::create("/data/stress.bin").unwrap();
let buffer: Vec<u8> = (0..1024 * 1024).map(|i| (i % 256) as u8).collect();
let mut blocks = 0_u64;
loop {
if blocks % 64 == 0 {
file.seek(SeekFrom::Start(0)).unwrap();
}
if let Err(error) = file.write_all(&buffer) {
eprintln!("write fault: {error}");
return;
}
blocks += 1;
fs::write("/data/progress.next", blocks.to_string()).unwrap();
fs::rename("/data/progress.next", "/data/progress").unwrap();
}
}