No test requires root. Linux x86-64 only. Tests must leave no stopped, zombie, or orphaned tracee behind.
just core configures with BUILD_TESTING=ON; ctest --test-dir build --output-on-failure runs build/core/tests/tinydbg_tests. The test binary
links a non-installed static tinydbg_internal core so it can exercise
internal C++ APIs; the installed libtinydbg.so hides the core's C++
implementation symbols (only the tdbg_* surface is exported) and is linked
by the Rust CLI.
- Portable unit tests: canonical/overflow address math, memory-range
validation,
/proc/<pid>/mapsparsing (paths with spaces, anonymous maps, vsyscall, malformed lines, empty input, deterministic random bytes), status results. - ABI tests: version/status strings, null and wrong-struct-size handling, wrong-thread rejection, create/destroy, spawn failure, a full spawn → continue → wait → exit cycle, and breakpoint/maps marshalling through the C boundary.
- Integration tests using fixtures:
- breakpoint by symbol → hit → register/RIP check → original byte restored
- data symbol read/write through target memory
- maps lookup for the executable mapping
- Capstone disassembly and instruction size
- single-step over the breakpoint (RIP advances by the original instruction length, not by the int3)
- continue to normal exit and reaping
- single-step without a breakpoint
- SIGUSR1 signal-delivery stop then re-delivery and clean exit
- SIGSEGV delivery then signaled exit
- runtime exec event, architecture re-check, and breakpoint-table clearing
- PIE symbol resolution explicitly unsupported
- target architecture probe accepts the x86-64 test process
- duplicate breakpoint errors and removal before continue
- attach → read registers → detach → target still alive
- second attach → destroy → target still alive (attached cleanup detaches)
- destroy while a spawned target is stopped → target gone and reaped
Cleanup assertions use kill(pid, 0), /proc/<pid>, and waitpid in the C++
tests. The test harness has a 120s CTest timeout.
Sanitizer build:
just test-sanitize
# or cmake -DTINYDBG_ENABLE_SANITIZERS=ON and ctestThe core library and C++ test binary are instrumented with AddressSanitizer/UBSan. Fixture processes are deliberately not instrumented: they are separate tracees and sanitizer runtimes interfere with signal and ptrace behavior.
tests/fixtures/ is built both by CMake into build/fixtures/ and by
tests/fixtures/build.sh. Compiler flags: -g -O0 -fno-omit-frame-pointer -no-pie (PIE fixture uses -fPIE -pie), -D_GNU_SOURCE, -Wall -Wextra.
| Fixture | Purpose |
|---|---|
hello |
normal exit, minimal target |
breakpoint_target |
main/tick symbols, g_buffer data symbol, known bytes |
signal_target |
SIGUSR1 delivery, handler, re-delivery, clean exit |
crash_target |
SIGSEGV delivery and signaled exit |
exec_target |
runtime exec, Exec event, breakpoint clearing |
pie_target |
ET_DYN / PIE unsupported symbol test |
longrun_target |
attach/detach, stop/cleanup and SIGINT tests; loops in pause |
Fixtures write their pid to TINYDBG_TEST_PIDFILE from an early constructor
when that environment variable is set. This lets the Rust tests verify that a
target is gone after the debugger exits. The long-running fixture calls
prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY) from a higher-priority constructor
so a same-user, non-parent debugger can attach in the attach test. This is an
explicit opt-in by the test target; it does not change system ptrace policy.
export TINYDBG_CORE_DIR="$PWD/build/install"
export TINYDBG_FIXTURES_DIR="$PWD/build/fixtures"
cargo test -p tinydbg-cliTINYDBG_FIXTURES_DIR must point at the CMake-built fixtures. just test
exports both variables. The test helper panics with a clear message if the
fixture directory is not configured; there are no silent skips for that.
Unit tests (inside the crate) cover:
- command grammar and aliases (
b,c,si [n],x/16xb,x/8g,disassemble [address] [count],info registers,info proc mappings,quit, errors for bad arguments) - hex/decimal address literals
- GDB-style
-exargument translation, including not rewriting program arguments after-- - a deterministic randomized parser robustness test (arbitrary Unicode and control characters must never panic)
- terminal escaping for control/bidi/invalid-UTF-8 text, signal names, address/permission formatting, and exit-code classification
Integration tests use assert_cmd and the real binary:
- breakpoint → continue → regs → memory → disassembly → step → maps, and target cleanup
- continue to normal exit, target reaped
- SIGSEGV crash: two continues, signaled-exit message, exit code 5
- SIGUSR1 redelivery and normal exit
- PIE symbol breakpoint rejects with a clear unsupported error
- detach leaves the target running and not in state
T - attach/detach through the CLI; if Yama still denies it, the test prints an explicit skip reason and does not silently pass
- SIGINT to a running batch CLI with a spawned target: CLI terminates, and the target disappears (PTRACE_O_EXITKILL)
- symbol-not-found and unknown-command errors stop the batch and still clean up
- batch output contains no ANSI escapes (
--no-colorand batch mode) - usage errors exit 2
- CLI's own unit tests for the parser and
-exrewriting
Output assertions use stable substrings only; addresses, pids, signals, and register values that vary are not snapshotted.
.github/workflows/ci.yml runs on Ubuntu x86-64 only:
- core: install CMake/Ninja/elfutils/Capstone (Ubuntu 24.04 ships Capstone 4.0.2; the stable API used here is compatible), build, run CTest.
- sanitizers: ASan/UBSan build and CTest with halt-on-error settings.
- bindings: install bindgen-cli 0.73.2, regenerate, and fail if the
checked-in
bindings.rsdiffers. - rust: build/install core,
cargo fmt --check, clippy with-D warnings, andcargo testwith the fixture environment. - lint: clang-format check, clang-tidy with compile commands.
- msrv: build/install core, then
cargo +1.85.0 check --workspace --all-targets. - audit:
cargo deny checkandcargo audit.
Tests run as the normal CI user; no root, no privileged containers. Attach tests that hit Yama print the reason and skip. If ptrace is completely unavailable, the spawned-target tests fail rather than pretending to pass.
Fixture sources are tiny, in-repo C programs with no external dependencies. No proprietary or downloaded binaries are committed. Any parser panic/abort found by fuzzing or randomized tests becomes a regression case.
A dedicated cargo-fuzz harness for the command grammar and maps parser is a
follow-up; stable CI exercises deterministic randomized inputs today and the
parsers never trust target-controlled text.
v0.1 does not include a checked-in benchmark harness. For performance-sensitive
changes, measure step/continue overhead, bulk memory reads, symbol lookup, and
disassembly of a known range with hyperfine or criterion, and report
before/after numbers. Do not gate correctness on unstable microbenchmarks.