FDS/OS 1.0
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
// Test-only static ARM client. Never installed in a production image.
|
||||
use clap::Parser;
|
||||
use std::{
|
||||
io::{Read, Write},
|
||||
os::unix::net::UnixStream,
|
||||
process::{Command, ExitCode},
|
||||
time::Duration,
|
||||
};
|
||||
#[derive(Parser)]
|
||||
#[command(about = "Exercise the cartridge socket with slow, oversize, or a JSON request")]
|
||||
struct Cli {
|
||||
mode: String,
|
||||
}
|
||||
fn main() -> ExitCode {
|
||||
let mode = Cli::parse().mode;
|
||||
let socket = "/run/fds/control.sock";
|
||||
let result = (|| -> std::io::Result<()> {
|
||||
let mut stream = UnixStream::connect(socket)?;
|
||||
stream.set_read_timeout(Some(Duration::from_secs(8)))?;
|
||||
if mode == "slow" {
|
||||
stream.write_all(b"{")?;
|
||||
assert!(Command::new("fds").arg("bays").status()?.success());
|
||||
println!("FDS_SLOW_CLIENT_OK");
|
||||
} else if mode == "oversize" {
|
||||
let _ = stream.write_all(&vec![b'x'; 65537]);
|
||||
let mut bytes = Vec::new();
|
||||
let read = stream.read_to_end(&mut bytes);
|
||||
assert!(bytes.is_empty());
|
||||
assert!(
|
||||
read.is_ok() || read.unwrap_err().kind() == std::io::ErrorKind::ConnectionReset
|
||||
);
|
||||
println!("FDS_OVERSIZE_OK");
|
||||
} else {
|
||||
stream.write_all(mode.as_bytes())?;
|
||||
stream.write_all(b"\n")?;
|
||||
let mut text = String::new();
|
||||
stream.take(65537).read_to_string(&mut text)?;
|
||||
if text.is_empty() {
|
||||
return Err(std::io::Error::other("peer rejected"));
|
||||
}
|
||||
println!("{text}");
|
||||
}
|
||||
Ok(())
|
||||
})();
|
||||
match result {
|
||||
Ok(()) => ExitCode::SUCCESS,
|
||||
Err(e) => {
|
||||
eprintln!("test-client: {e}");
|
||||
ExitCode::FAILURE
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user