test: add the HyperHDR mock server and the integration tests

The mock imitates FlatBuffersServerConnection and FlatBuffersParser (spec
3.2), including the priority handling, the idle timeout and the reject paths,
so the client can be tested against it over a real socket. It doubles as a
standalone example binary for end-to-end runs.
This commit is contained in:
2026-09-12 10:10:44 +03:00
parent 885ee7fa04
commit 1aa7d802eb
4 changed files with 963 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
//! Standalone HyperHDR flatbuffers server mock, the same code the integration tests use.
//!
//! cargo run --example mock_hyperhdr -- --listen 127.0.0.1:19400
use std::io::IsTerminal;
use std::time::Duration;
use clap::{Parser, ValueEnum};
use gamescope_hyperhdr::hyperhdr::mock::{Behavior, MockOptions, MockServer};
use tracing::info;
#[derive(Debug, Clone, Copy, ValueEnum)]
enum Mode {
Normal,
Reject,
NoRead,
ErrorReplies,
}
#[derive(Parser)]
#[command(about = "Imitation of HyperHDR's flatbuffers server")]
struct Opt {
/// Address to listen on
#[arg(long, default_value = "127.0.0.1:19400")]
listen: String,
/// Close connections after this many seconds without data (HyperHDR's `timeout`)
#[arg(long, default_value_t = 5)]
timeout_secs: u64,
/// How to treat connections
#[arg(long, value_enum, default_value_t = Mode::Normal)]
behavior: Mode,
}
fn main() -> anyhow::Result<()> {
let opt = Opt::parse();
tracing_subscriber::fmt()
.with_target(false)
.with_writer(std::io::stderr)
.with_ansi(std::io::stderr().is_terminal())
.init();
let server = MockServer::start(
opt.listen.as_str(),
MockOptions {
idle_timeout: Duration::from_secs(opt.timeout_secs),
record_events: false,
log_events: true,
},
)?;
server.set_behavior(match opt.behavior {
Mode::Normal => Behavior::Normal,
Mode::Reject => Behavior::Reject,
Mode::NoRead => Behavior::NoRead,
Mode::ErrorReplies => Behavior::ErrorReplies,
});
info!("listening on {} ({:?})", server.addr(), opt.behavior);
loop {
std::thread::park();
}
}