Mailing List Archive

leak testing modules [was: [Encode] 3.15 Released]
James E Keenan <jkeenan@pobox.com> wrote:
> On 10/8/21 11:50 AM, Dan Kogai wrote:
> > Porters,
> >
> > My apology for releasing 3.14 prematurely and releasing 3.15 to resolve it. In a way, this is what Encode 3.13 was supposed to be.
>
> Dan, just now I synched Encode 3.15 into blead ( cf927cc ). Can you double
> check that this distribution now appears in blead as it should be for our
> next development release on October 20 2021?

I'm not Dan, but Encode.xs being blob 3416df70fa9fd640 looks right to me :>

Does anybody here have suggestions on how to go about adding
leak tests to packages like Encode?

I see XS::APItest exists and exposes PL_sv_count; but I guess
it's only for Perl internals and not for stuff imported from CPAN?

It'd be nice to have regression testing guard against
introducing leaks for other core modules, too. Thanks.
Re: leak testing modules [was: [Encode] 3.15 Released] [ In reply to ]
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.

(Disclaimer: I wrote it)

It asserts that the refcount of a thing is what the test script claims
it to be (often 1). If it fails, it writes a heapdump file you can
analyse using Devel::MAT.

(Disclaimer: I wrote that too)

--
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
Re: leak testing modules [was: [Encode] 3.15 Released] [ In reply to ]
"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.
Re: leak testing modules [was: [Encode] 3.15 Released] [ In reply to ]
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.org