Fil-C on Nix

Filnix wiki

mbrock/filnix

ports/tpm2.nix

TPM2's mocks must retain pointers, including Fil-C capabilities.

λpkgs, final
let
4inherit import./. inherit pkgs lib pkgs;
for arg use patch
10cmocka=
final.cmocka.overrideAttrs
λold
11version=
"2.0.2"
12src=
pkgs.fetchurl
13url=
"https://cmocka.org/files/2.0/cmocka-2.0.2.tar.xz"
14hash=
"sha256-OfkvNmvfPxoCr02nW0pcUt9sn35zbH1l3hMoP58O9BY="

The old uintptr_t compatibility patch is no longer needed in 2.x.

18doCheck=
true

Nixpkgs drops the TCTI unit tests under Clang, whose mocks it cannot make work there. The pointer-preserving mocks below make them pass.

22dropTctiTests=
sed -i '/TESTS_UNIT / {
/test\/unit\/tcti-swtpm/d;
/test\/unit\/tcti-mssim/d;
/test\/unit\/tcti-device/d
}' Makefile-test.am
used by keepTctiTests
29keepTctiTests=
postPatch: assert pkgs.lib.hasInfixdropTctiTests postPatch; builtins.replaceStringsdropTctiTests "" postPatch
uses dropTctiTests used by tpm2-tss
in
38tpm2-tss=
38tpm2-tss
arginherit cmocka;
useimport../toolchain/test-wrap.nix inherit pkgs;
patch../patches/tpm2-test-environment.patch
patch../patches/tpm2-spi-pointers.patch
use
λold
44postPatch=
+
cp ${../toolchain/cmocka-pointer-mocks.h} test/cmocka-pointer-mocks.h
# Since 4.2 every test includes cmocka through this helper.
substituteInPlace test/helper/cmocka_all.h \
--replace-fail '#include <cmocka.h>' '#include "../cmocka-pointer-mocks.h"'
substituteInPlace test/unit/esys-vendor.c \
--replace-fail 'will_return_uint_always(tcti_fake_recv, (uintptr_t) __func__)' \
'will_return_ptr_always(tcti_fake_recv, __func__)' \
--replace-fail '(const char *)mock_type(uintptr_t)' 'mock_ptr_type(const char *)'
# Preserve calls to the functions these tests interpose. The compiler
# adapter restores their descriptor names after Fil-C's lowering.
substituteInPlace Makefile-test.am \
--replace-fail 'TESTS_CFLAGS = ' \
'TESTS_CFLAGS = -Dmalloc=filnix_wrap_malloc -Dfree=filnix_wrap_free '