English
Workspace: tests, Clippy, layers, features, MIPS
All commands are run from the repository root, through the runner; CARGO_TARGET_DIR, if set, must be exported (see environment).
Rust tests
sh
python3 tests/run.py -- cargo test -p <crate> [--test <target>] # while working
python3 tests/run.py -- cargo test --workspace # the final run- Unit tests —
#[cfg(test)] mod testsinsrc/; integration tests — the crate'stests/*.rs. Module tests bring up a real kernel instance with their own module list (ours_testkit::config,ours_kernel::Instance) — see testkit. - Test data (certificates,
.srs, subscription fixtures) — in the crate'stests/data/, the path throughenv!("CARGO_MANIFEST_DIR"). A sharedtarget/bakes this path into the test binary: after a working tree is removed its artifacts need cleaning (cargo clean -p <crate>). #[ignore]with a reason — tests that need the network (crates/http/tests/network.rs), thetlskernel module and kTLS key updates (modules/system/tls/tests,modules/protocols/vless,modules/protocols/http), and cost measurements (bench_cost.rsinlibs/net-infoandmodules/routing/router). Run with-- --ignored(and--exact <name>for one).- The auto-nft and TUN
netnstests are ignored by default; see the netns tests. - Cargo unifies the features of all workspace members, so
cargo test --workspacechecks their union; individual combinations —tests/features.py. - The binary's tests (
app/ours/src/modules.rs) compareLISTwith the workspace modules andrequireswith the crates' dependencies — see how-to: a module. The integration tests inapp/ours/tests/run the built binary, for example:check.rs(checkdoes not touch the cache, checkslog.level),handover.rs(two reloads in a row hand over listening sockets),mixed.rs(SOCKS and HTTP on one port),users.rs(changing users without rebuilding the inbound),docs.rs(every complete configuration indocs/usageandexamples/passescheck).
The netns tests
crates/auto-nft/tests/netns.rs and modules/protocols/tun/tests/netns.rs change netfilter, links and routes, so they run only in their own network namespace, serially and with OURS_NETNS_TESTS=1:
sh
cargo test -p ours-auto-nft --test netns --no-run # or -p ours-mod-tun
unshare -rn sh -c 'ip link set lo up && OURS_NETNS_TESTS=1 "$1" --ignored --test-threads 1' sh /path/to/test-binaryUse the executable path printed by Cargo.
Clippy
sh
python3 tests/run.py -- cargo clippy --workspace --all-targets -- -D warningsThe level clippy::all = warn is set in [workspace.lints.clippy]; -D warnings turns warnings into errors. The workspace forbids unsafe_code; the crates that need it (ours-alloc, ours-sys, ours-ktls-sys, ours-tun-sys and the allocs tool) allow it and require a // SAFETY: comment on every unsafe block (undocumented_unsafe_blocks = "deny").
Layers: tests/layers.py
sh
python3 tests/layers.pyUsing cargo metadata --no-deps it checks (in detail — Layers):
- the
libs/libraries do not depend on any workspace crate outsidelibs/(including dev); ours-apidepends only onlibs/and the externalarc-swap,tokio,tracing;ours-kernel— only onours-api,ours-config,ours-runtimeandlibs/;ours-runtime— only onours-apiandlibs/;- only
app/crates depend (as a normal dependency) onours-kernel; - modules are exactly the
ours-mod-*crates undermodules/; ours-configbuilds onours-apiandlibs/only, andours-apidoes not depend on it;ours-configis used by modules,app/,ours-kernel,ours-native-configand the shared crates listed inCONFIG_READERS(the list may only shrink);- the
ours-singbox-convertcrate (the sing-box configuration model) does not exist.
Violations go to stderr as layer violation: …, exit code 1.
Extra things in the index: tests/tracked.py
sh
python3 tests/tracked.pyFails if git tracks something .gitignore keeps out of the index: __pycache__/, *.pyc, logs, target/, local assistant settings (CLAUDE.md, .claude/). Catches git add -f and a clone where the ignore rules were lost. Violations go to stderr as tracked but should not be: …, exit code 1.
Feature sets: tests/features.py
sh
python3 tests/run.py -- python3 tests/features.py [--clippy]cargo hack check -p ours --each-feature(needscargo-hack) — every feature of the binary separately.- The minimal build (
--no-default-features) must not pull inrustls,ring,quinn,h3,h3-quinn,tokio-rustls,ours-mod-dns,ours-mod-router,ours-mod-group,ours-srs. - For every feature from
default— adefaultbuild without it ("default minus one").
With --clippy, clippy -- -D warnings instead of check in every combination. Wrong [features] (a module without what it requires) are caught at compilation thanks to the const assert in app/ours/src/modules.rs.
The MIPS build
The target is routers on MT7621 (mipsel, 32 bits, no 64-bit atomics). It is checked by cargo check of the binary for that target:
sh
CC_mipsel_unknown_linux_musl=clang CFLAGS_mipsel_unknown_linux_musl=--target=mipsel-linux-musl \
cargo +nightly check -Z build-std=std,panic_abort --target mipsel-unknown-linux-musl -p oursmipsel-unknown-linux-muslis tier 3, there is no prebuilt std: hence nightly and-Z build-std.CC_…/CFLAGS_…— the dependencies' C code (cryptography) is built by clang for this target.- It catches what is not visible on x86_64: 64-bit atomics (use
ours-atomic64), a 32-bitusize,libcdifferences on musl/MIPS.