From 290f2654e1fcbcc3dfaca1cda4e004361da28b55 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 16 Feb 2024 11:05:24 +0100 Subject: [PATCH] feat: Add manual testing of bindings with Valgrind (cherry picked from commit 12fed067bf230d3258db172afe648ec690ba584c) --- doc/hacking/test-ffi.md | 25 +++++++++++++++++++++++++ flake.nix | 5 +++++ 2 files changed, 30 insertions(+) create mode 100644 doc/hacking/test-ffi.md diff --git a/doc/hacking/test-ffi.md b/doc/hacking/test-ffi.md new file mode 100644 index 0000000..2ae260e --- /dev/null +++ b/doc/hacking/test-ffi.md @@ -0,0 +1,25 @@ + +# 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 ` +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`: a leak in the rust test framework + +When in doubt, compare the log to a run with your new test case commented out. diff --git a/flake.nix b/flake.nix index d4728d0..35d15f4 100644 --- a/flake.nix +++ b/flake.nix @@ -55,6 +55,11 @@ pkgs.rustfmt pkgs.pkg-config pkgs.clang-tools # clangd + pkgs.valgrind + # TODO: set up cargo-valgrind in shell and build + # currently both this and `cargo install cargo-valgrind` + # produce a binary that says ENOENT. + # pkgs.cargo-valgrind ]; shellHook = '' ${config.pre-commit.installationScript}