Skip to content

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 tests in src/; integration tests — the crate's tests/*.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's tests/data/, the path through env!("CARGO_MANIFEST_DIR"). A shared target/ 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), the tls kernel module and kTLS key updates (modules/system/tls/tests, modules/protocols/vless, modules/protocols/http), and cost measurements (bench_cost.rs in libs/net-info and modules/routing/router). Run with -- --ignored (and --exact <name> for one).
  • The auto-nft and TUN netns tests are ignored by default; see the netns tests.
  • Cargo unifies the features of all workspace members, so cargo test --workspace checks their union; individual combinations — tests/features.py.
  • The binary's tests (app/ours/src/modules.rs) compare LIST with the workspace modules and requires with the crates' dependencies — see how-to: a module. The integration tests in app/ours/tests/ run the built binary, for example: check.rs (check does not touch the cache, checks log.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 in docs/usage and examples/ passes check).

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-binary

Use the executable path printed by Cargo.

Clippy ​

sh
python3 tests/run.py -- cargo clippy --workspace --all-targets -- -D warnings

The 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.py

Using cargo metadata --no-deps it checks (in detail — Layers):

  • the libs/ libraries do not depend on any workspace crate outside libs/ (including dev);
  • ours-api depends only on libs/ and the external arc-swap, tokio, tracing;
  • ours-kernel — only on ours-api, ours-config, ours-runtime and libs/; ours-runtime — only on ours-api and libs/;
  • only app/ crates depend (as a normal dependency) on ours-kernel;
  • modules are exactly the ours-mod-* crates under modules/;
  • ours-config builds on ours-api and libs/ only, and ours-api does not depend on it;
  • ours-config is used by modules, app/, ours-kernel, ours-native-config and the shared crates listed in CONFIG_READERS (the list may only shrink);
  • the ours-singbox-convert crate (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.py

Fails 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]
  1. cargo hack check -p ours --each-feature (needs cargo-hack) — every feature of the binary separately.
  2. The minimal build (--no-default-features) must not pull in rustls, ring, quinn, h3, h3-quinn, tokio-rustls, ours-mod-dns, ours-mod-router, ours-mod-group, ours-srs.
  3. For every feature from default — a default build 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 ours
  • mipsel-unknown-linux-musl is 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-bit usize, libc differences on musl/MIPS.

GPL-3.0-or-later