On Tue, 12 Oct 2021 00:42:16 +0000, Eric Wong <p5p@yhbt.net> wrote: > "Paul \"LeoNerd\" Evans" <leonerd@leonerd.org.uk> wrote: > > On Mon, 11 Oct 2021 20:43:09 +0000 > > Eric Wong <p5p@yhbt.net> wrote: > > > > > Does anybody here have suggestions on how to go about adding > > > leak tests to packages like Encode? > > > > I usually use Test::Refcount. > > Thanks for the response, but can that check for allocations made > (and lost) from inside XS? > > The leaks which got fixed in Encode was created by newSV() and > the SV not being mortalized; so it got lost on croak and AFAIK > that can't be tested by pure Perl. Something like valgrind > could notice that leak, as would (AFAIK) PL_sv_count. > > Adding valgrind to a test suite seems heavy-handed; so I wonder > if XS::APITests::sv_count should be moved to Devel::Peek or > similar. For my XS modules I use --8<--- export PERL_DESTRUCT_LEVEL=2 PERL_DL_NONLAZY=1 valgrind \ --suppressions=sandbox/perl.supp \ --leak-check=yes \ --leak-resolution=high \ --show-reachable=yes \ --num-callers=50 \ --log-fd=3 \ perl \ -MPerl::Destruct::Level=level,2 \ "$@" \ 3>valgrind.log -->8--- Where sandbox/perl.supp is a symlink to .../bleadperl/t/perl.supp Another approach would be --8<--- export PERL_DESTRUCT_LEVEL=2 PERL_DL_NONLAZY=1 prove --exec "perl -Iblib/lib -Iblib/arch -MTest::Valgrind" $@ -->8--- And a third might be --8<--- perl -MTest::LeakTrace::Script=-verbose t/foo.t -->8--- -- H.Merijn Brand https://tux.nl Perl Monger http://amsterdam.pm.org/ using perl5.00307 .. 5.33 porting perl5 on HP-UX, AIX, and Linux https://tux.nl/email.html http://qa.perl.org https://www.test-smoke.orgThread Previous | Thread Next