nixide/doc/hacking/test-ffi.md
Robert Hensing 290f2654e1 feat: Add manual testing of bindings with Valgrind
(cherry picked from commit 12fed067bf230d3258db172afe648ec690ba584c)
2025-09-30 18:45:54 +02:00

882 B

Testing FFI code

If cargo-valgrind is broken, you may run valgrind manually.

  1. cd rust; cargo test -v
  2. find the relevant test suite executable in the log
    • example: /home/user/src/nix-bindings-rust/rust/target/debug/deps/nix_util-036ec381a9e3fd6d
  3. valgrind --leak-check=full <paste the test exe>
  4. check that
    • definitely lost: 0 bytes in 0 blocks

Paranoid check

Although normal valgrind tends to catch things, you may choose to enable --show-leak-kinds=all. This will print a few false positive.

Acceptable leaks are those involving (and this may be Linux-specific)

  • call_init: static initializers
    • nix::GlobalConfig::Register::Register
    • _GLOBAL__sub_I_logging.cc
    • ...
  • new<test::test_main::{closure_env#0}>: a leak in the rust test framework

When in doubt, compare the log to a run with your new test case commented out.