Initial import: ICE-NET research docs and Rust workspace (v0.4)
Some checks failed
rust-ci / checks (push) Has been cancelled
Some checks failed
rust-ci / checks (push) Has been cancelled
- Rust workspace: 7 library crates, icenetd CLI, icenet-city (Slint GUI) - Sim: fix false Delivered after a route cut, derive traffic class from payload size, per-link airtime slots (link capacity, queueing) - Docs: single docs/STATUS.md for all figures, remove v0.2/egui leftovers, drop unimplemented seed claims, uncheck store-and-forward - License: LGPL-3.0-or-later (LICENSE, LICENSES/GPL-3.0.txt)
This commit is contained in:
commit
2e61688eb3
141 changed files with 13993 additions and 0 deletions
156
workspace/apps/icenetd/tests/cli.rs
Normal file
156
workspace/apps/icenetd/tests/cli.rs
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
//! End-to-end route/send/sim/wire tests against the real `icenetd` binary.
|
||||
mod common;
|
||||
|
||||
use common::{run, stderr, stdout, temp};
|
||||
|
||||
#[test]
|
||||
fn help_lists_all_commands() {
|
||||
let output = run(&["help"]);
|
||||
assert!(output.status.success());
|
||||
let text = stdout(&output);
|
||||
for command in [
|
||||
"route",
|
||||
"send",
|
||||
"sim",
|
||||
"policy",
|
||||
"wire-encode",
|
||||
"wire-decode",
|
||||
] {
|
||||
assert!(text.contains(command), "missing {command} in help");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bulk_route_avoids_slow_radio() {
|
||||
let output = run(&[
|
||||
"route", "--from", "1", "--to", "3", "--class", "bulk", "--size", "5000000",
|
||||
]);
|
||||
assert!(output.status.success(), "stderr: {}", stderr(&output));
|
||||
assert!(stdout(&output).contains("1-4-5-3"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bulk_route_reports_no_route_without_fast_links() {
|
||||
let output = run(&[
|
||||
"route",
|
||||
"--from",
|
||||
"1",
|
||||
"--to",
|
||||
"3",
|
||||
"--class",
|
||||
"bulk",
|
||||
"--size",
|
||||
"5000000",
|
||||
"--disable",
|
||||
"2,3,4",
|
||||
]);
|
||||
assert!(output.status.success());
|
||||
assert!(stdout(&output).contains("NO_ROUTE"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn text_route_may_use_slow_radio() {
|
||||
let output = run(&[
|
||||
"route",
|
||||
"--from",
|
||||
"1",
|
||||
"--to",
|
||||
"3",
|
||||
"--class",
|
||||
"text",
|
||||
"--size",
|
||||
"128",
|
||||
"--disable",
|
||||
"2,3,4",
|
||||
]);
|
||||
assert!(output.status.success());
|
||||
assert!(stdout(&output).contains("1-2-3"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_reports_delivered_message() {
|
||||
let output = run(&[
|
||||
"send", "--from", "1", "--to", "3", "--class", "text", "--size", "128", "--ticks", "1000",
|
||||
]);
|
||||
assert!(output.status.success());
|
||||
assert!(stdout(&output).contains("status=Delivered"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_reports_expired_message() {
|
||||
let output = run(&[
|
||||
"send",
|
||||
"--from",
|
||||
"1",
|
||||
"--to",
|
||||
"3",
|
||||
"--class",
|
||||
"bulk",
|
||||
"--size",
|
||||
"5000000",
|
||||
"--disable",
|
||||
"2,3,4",
|
||||
"--ttl",
|
||||
"1000",
|
||||
"--ticks",
|
||||
"2000",
|
||||
]);
|
||||
assert!(output.status.success(), "stderr: {}", stderr(&output));
|
||||
assert!(stdout(&output).contains("status=Expired"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sim_writes_csv_and_json_exports() {
|
||||
let csv = temp("metrics.csv");
|
||||
let json = temp("scenario.json");
|
||||
let output = run(&[
|
||||
"sim",
|
||||
"--csv",
|
||||
csv.to_str().expect("utf8 path"),
|
||||
"--json",
|
||||
json.to_str().expect("utf8 path"),
|
||||
]);
|
||||
assert!(output.status.success(), "stderr: {}", stderr(&output));
|
||||
assert!(stdout(&output).contains("expired=1"));
|
||||
let csv_body = std::fs::read_to_string(&csv).expect("csv export");
|
||||
assert!(csv_body.starts_with("id,from,to,class,bytes,status,"));
|
||||
let json_body = std::fs::read_to_string(&json).expect("json export");
|
||||
assert!(json_body.contains("\"messages\""));
|
||||
let _ = std::fs::remove_file(csv);
|
||||
let _ = std::fs::remove_file(json);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wire_encoder_and_decoder_round_trip() {
|
||||
let encoded = run(&[
|
||||
"wire-encode",
|
||||
"--service",
|
||||
"7",
|
||||
"--class",
|
||||
"text",
|
||||
"--text",
|
||||
"hello",
|
||||
]);
|
||||
assert!(encoded.status.success(), "stderr: {}", stderr(&encoded));
|
||||
let text = stdout(&encoded);
|
||||
let hex = text
|
||||
.lines()
|
||||
.find_map(|line| line.strip_prefix("frame: "))
|
||||
.expect("frame hex line")
|
||||
.to_owned();
|
||||
let decoded = run(&["wire-decode", "--hex", &hex]);
|
||||
assert!(decoded.status.success(), "stderr: {}", stderr(&decoded));
|
||||
let text = stdout(&decoded);
|
||||
assert!(text.contains("class: Text"));
|
||||
assert!(text.contains("service: 7"));
|
||||
assert!(text.contains("payload: hello"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wire_decode_escapes_control_bytes() {
|
||||
let output = run(&["wire-decode", "--hex", "494e0101000000000000000700020102"]);
|
||||
assert!(output.status.success(), "stderr: {}", stderr(&output));
|
||||
let text = stdout(&output);
|
||||
assert!(text.contains("payload_hex: 0102"));
|
||||
assert!(!text.contains('\u{1}'));
|
||||
}
|
||||
23
workspace/apps/icenetd/tests/common/mod.rs
Normal file
23
workspace/apps/icenetd/tests/common/mod.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
//! Shared helpers for CLI integration tests.
|
||||
#![allow(dead_code)]
|
||||
use std::path::PathBuf;
|
||||
use std::process::{Command, Output};
|
||||
|
||||
pub fn run(args: &[&str]) -> Output {
|
||||
Command::new(env!("CARGO_BIN_EXE_icenetd"))
|
||||
.args(args)
|
||||
.output()
|
||||
.expect("icenetd must start")
|
||||
}
|
||||
|
||||
pub fn stdout(output: &Output) -> String {
|
||||
String::from_utf8_lossy(&output.stdout).into_owned()
|
||||
}
|
||||
|
||||
pub fn stderr(output: &Output) -> String {
|
||||
String::from_utf8_lossy(&output.stderr).into_owned()
|
||||
}
|
||||
|
||||
pub fn temp(name: &str) -> PathBuf {
|
||||
std::env::temp_dir().join(format!("icenetd-{}-{name}", std::process::id()))
|
||||
}
|
||||
104
workspace/apps/icenetd/tests/policy.rs
Normal file
104
workspace/apps/icenetd/tests/policy.rs
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
//! Policy, usage and exit-code tests against the real `icenetd` binary.
|
||||
mod common;
|
||||
|
||||
use common::{run, stderr, stdout};
|
||||
|
||||
#[test]
|
||||
fn policy_reports_acl_and_authentication_reasons() {
|
||||
let permit = run(&["policy", "--service", "77777", "--size", "5"]);
|
||||
assert!(permit.status.success());
|
||||
assert!(stdout(&permit).contains("Permit"));
|
||||
|
||||
let denied = run(&[
|
||||
"policy",
|
||||
"--service",
|
||||
"77777",
|
||||
"--size",
|
||||
"5",
|
||||
"--allow",
|
||||
"1",
|
||||
]);
|
||||
assert!(denied.status.success());
|
||||
assert!(stdout(&denied).contains("service_denied"));
|
||||
|
||||
let anonymous = run(&[
|
||||
"policy",
|
||||
"--service",
|
||||
"77777",
|
||||
"--size",
|
||||
"5",
|
||||
"--unauthenticated",
|
||||
]);
|
||||
assert!(anonymous.status.success());
|
||||
assert!(stdout(&anonymous).contains("unauthenticated"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn policy_reports_rate_and_queue_reasons() {
|
||||
let queue = run(&[
|
||||
"policy",
|
||||
"--service",
|
||||
"77777",
|
||||
"--size",
|
||||
"5",
|
||||
"--queue",
|
||||
"2",
|
||||
"--max-queue",
|
||||
"2",
|
||||
]);
|
||||
assert!(queue.status.success());
|
||||
assert!(stdout(&queue).contains("queue_full"));
|
||||
|
||||
let rate = run(&[
|
||||
"policy",
|
||||
"--service",
|
||||
"77777",
|
||||
"--size",
|
||||
"5",
|
||||
"--rate",
|
||||
"1",
|
||||
"--burst",
|
||||
"0",
|
||||
]);
|
||||
assert!(rate.status.success());
|
||||
assert!(stdout(&rate).contains("rate_limited"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help_and_version_flags_work_without_a_command() {
|
||||
let help = run(&["--help"]);
|
||||
assert!(help.status.success());
|
||||
assert!(stdout(&help).contains("USAGE"));
|
||||
let version = run(&["--version"]);
|
||||
assert!(version.status.success());
|
||||
assert!(stdout(&version).contains("icenetd"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_values_are_usage_errors_with_exit_two() {
|
||||
let cases: Vec<Vec<&str>> = vec![
|
||||
vec!["route", "--from", "1"],
|
||||
vec!["route", "--from", "1", "--to", "3", "--class", "Bulk"],
|
||||
vec!["route", "--from", "1", "--to", "3", "--disable", "99"],
|
||||
vec!["route", "--from", "1", "--to", "3", "--csv", "x.csv"],
|
||||
vec!["send", "--from", "1", "--to", "3", "--ttl", "0"],
|
||||
vec!["sim", "--disable", "0"],
|
||||
vec!["route", "--from", "1", "--from", "3", "--to", "2"],
|
||||
];
|
||||
for case in cases {
|
||||
let output = run(&case);
|
||||
assert_eq!(
|
||||
output.status.code(),
|
||||
Some(2),
|
||||
"case {case:?} stderr: {}",
|
||||
stderr(&output)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_option_is_a_usage_error() {
|
||||
let output = run(&["route", "--bogus", "1"]);
|
||||
assert_eq!(output.status.code(), Some(2));
|
||||
assert!(stderr(&output).contains("unknown option"));
|
||||
}
|
||||
75
workspace/apps/icenetd/tests/udp_cli.rs
Normal file
75
workspace/apps/icenetd/tests/udp_cli.rs
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
//! Process-to-process UDP tests for `icenetd send-udp` and `icenetd serve`.
|
||||
mod common;
|
||||
|
||||
use std::io::{BufRead, BufReader, Read};
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
use common::{run, stderr, stdout};
|
||||
|
||||
#[test]
|
||||
fn serve_and_send_udp_exchange_a_frame() {
|
||||
let mut server = Command::new(env!("CARGO_BIN_EXE_icenetd"))
|
||||
.args([
|
||||
"serve",
|
||||
"--bind",
|
||||
"127.0.0.1:0",
|
||||
"--count",
|
||||
"1",
|
||||
"--timeout",
|
||||
"5000",
|
||||
])
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.expect("serve starts");
|
||||
|
||||
let stdout_pipe = server.stdout.take().expect("server stdout");
|
||||
let mut reader = BufReader::new(stdout_pipe);
|
||||
let mut first_line = String::new();
|
||||
reader.read_line(&mut first_line).expect("listening line");
|
||||
let address = first_line
|
||||
.trim()
|
||||
.strip_prefix("listening: ")
|
||||
.expect("listening address")
|
||||
.to_owned();
|
||||
|
||||
let sent = run(&[
|
||||
"send-udp",
|
||||
"--to",
|
||||
&address,
|
||||
"--service",
|
||||
"77777",
|
||||
"--class",
|
||||
"text",
|
||||
"--text",
|
||||
"hello-udp",
|
||||
]);
|
||||
assert!(sent.status.success(), "stderr: {}", stderr(&sent));
|
||||
assert!(stdout(&sent).contains("sent:"));
|
||||
|
||||
let mut received = String::new();
|
||||
reader.read_to_string(&mut received).expect("server output");
|
||||
let status = server.wait().expect("server exits");
|
||||
assert!(status.success(), "server stderr: {received}");
|
||||
assert!(
|
||||
received.contains("service=77777 class=Text bytes=9 payload=hello-udp"),
|
||||
"received: {received}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serve_times_out_when_no_frames_arrive() {
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_icenetd"))
|
||||
.args(["serve", "--bind", "127.0.0.1:0", "--timeout", "200"])
|
||||
.output()
|
||||
.expect("serve starts");
|
||||
assert_eq!(output.status.code(), Some(1));
|
||||
assert!(stderr(&output).contains("timeout after"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_udp_rejects_invalid_addresses() {
|
||||
let output = run(&["send-udp", "--to", "not-an-address", "--text", "hello"]);
|
||||
assert_eq!(output.status.code(), Some(2));
|
||||
assert!(stderr(&output).contains("invalid socket address"));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue