timbunce / devel-nytprof

Devel::NYTProf is a powerful feature-rich source code profiler for Perl. (Mostly in maintenance mode, so PRs are much more likely to be acted upon than Issues.)
http://blog.timbunce.org/tag/nytprof/
67 stars 50 forks source link

t/30-util.t: fmt_float error on certain Windows/Strawberry Perl builds #170

Closed jkeenan closed 3 years ago

jkeenan commented 3 years ago

In certain smoke-testing reports for Devel-NYTProf-6.08 on Windows, a new unit test failure is being observed.

Typical report: http://www.cpantesters.org/cpan/report/eae60049-6bf4-1014-9867-b4129abe8bb7

Failure:

#   Failed test 'fmt_float, applied to 0.00004'
#   at t/30-util.t line 129.
#          got: '4.0e-05'
#     expected: '4.0e-5'
# Looks like you failed 1 test of 67.
t/30-util.t .............. 
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/67 subtests

Relevant code in t/30-util.t:

128 my $val = '0.00004';
129 is(fmt_float($val), '4.0e-5', "fmt_float, applied to $val");

Tester's perl -V data:

  Platform:
    osname=MSWin32
    osvers=5.1.2600
    archname=MSWin32-x86-multi-thread-64int
    uname='Win32 strawberry-perl 5.28.2.1 #1 Mon Apr 22 21:59:01 2019 i386'
    config_args='undef'
    hint=recommended
    useposix=true
    d_sigaction=undef
    useithreads=define
    usemultiplicity=define
    use64bitint=define
    use64bitall=undef
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='gcc'
    ccflags =' -s -O2 -DWIN32 -D__USE_MINGW_ANSI_STDIO -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -fwrapv -fno-strict-aliasing -mms-bitfields'
    optimize='-s -O2'
    cppflags='-DWIN32'
    ccversion=''
    gccversion='7.1.0'
    gccosandvers=''
    intsize=4
    longsize=4
    ptrsize=4
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=12
    longdblkind=3
    ivtype='long long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='long long'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='g++'
    ldflags ='-s -L"C:\STRAWB~1\perl\lib\CORE" -L"C:\STRAWB~1\c\lib"'
    libpth=C:\STRAWB~1\c\lib C:\STRAWB~1\c\i686-w64-mingw32\lib C:\STRAWB~1\c\lib\gcc\i686-w64-mingw32\7.1.0
    libs= -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
    perllibs= -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
    libc=
    so=dll
    useshrplib=true
    libperl=libperl528.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs
    dlext=xs.dll
    d_dlsymun=undef
    ccdlflags=' '
    cccdlflags=' '
    lddlflags='-mdll -s -L"C:\STRAWB~1\perl\lib\CORE" -L"C:\STRAWB~1\c\lib"'

Characteristics of this binary (from libperl): 
  Compile-time options:
    HAS_TIMES
    HAVE_INTERP_INTERN
    MULTIPLICITY
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_IMPLICIT_CONTEXT
    PERL_IMPLICIT_SYS
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    USE_64_BIT_INT
    USE_ITHREADS
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
  Built under MSWin32
  Compiled at Apr 22 2019 22:09:26
  %ENV:
    PERL5_CPANPLUS_IS_RUNNING="224"
    PERL5_CPAN_IS_RUNNING="224"
    PERL5_CPAN_IS_RUNNING_IN_RECURSION="1496,224"
    PERL_CR_SMOKER_CURRENT="Devel-NYTProf-6.08"
    PERL_CR_SMOKER_RUNONCE="1"
    PERL_EXTUTILS_AUTOINSTALL="--defaultdeps"
    PERL_MM_USE_DEFAULT="1"
    PERL_USE_UNSAFE_INC="1"
  @INC:
    C:/Strawberry282/perl/site/lib
    C:/Strawberry282/perl/vendor/lib
    C:/Strawberry282/perl/lib
    .

The failure was observed on earlier versions of perl reported by the same tester.

This test was added by me in 13d789c4 which was part of the 6.08 release to CPAN. The failure was not observed on any of the AppVeyor test runs on Strawberry Perl/Windows during development. There are certain differences in the perl configuration between the tester and my Appveyor:

$ diff chorny-perl-V.txt appveyor-perl-V.txt > chorny-vs-appveyor.diff
3,5c3,5
<   osvers=5.1.2600
<   archname=MSWin32-x86-multi-thread-64int
<   uname='Win32 strawberry-perl 5.28.2.1 #1 Mon Apr 22 21:59:01 2019 i386'
---
>   osvers=10.0.19042.746
>   archname=MSWin32-x64-multi-thread
>   uname='Win32 strawberry-perl 5.32.1.1 #1 Sun Jan 24 15:00:15 2021 x64'
20c20
<   ccflags =' -s -O2 -DWIN32 -D__USE_MINGW_ANSI_STDIO -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -fwrapv -fno-strict-aliasing -mms-bitfields'
---
>   ccflags =' -DWIN32 -DWIN64 -D__USE_MINGW_ANSI_STDIO -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -fwrapv -fno-strict-aliasing -mms-bitfields'
24c24
<   gccversion='7.1.0'
---
>   gccversion='8.3.0'
28c28
<   ptrsize=4
---
>   ptrsize=8
35c35
<   longdblsize=12
---
>   longdblsize=16
48c48
<   libpth=C:\STRAWB~1\c\lib C:\STRAWB~1\c\i686-w64-mingw32\lib C:\STRAWB~1\c\lib\gcc\i686-w64-mingw32\7.1.0
---
>   libpth=C:\STRAWB~1\c\lib C:\STRAWB~1\c\x86_64-w64-mingw32\lib C:\STRAWB~1\c\lib\gcc\x86_64-w64-mingw32\8.3.0
54c54
<   libperl=libperl528.a
---
>   libperl=libperl532.a
89c89
< Compiled at Apr 22 2019 22:09:26
---
> Compiled at Jan 24 2021 15:05:42
91,97c91
<   PERL5_CPANPLUS_IS_RUNNING="224"
<   PERL5_CPAN_IS_RUNNING="224"
<   PERL5_CPAN_IS_RUNNING_IN_RECURSION="1496,224"
<   PERL_CR_SMOKER_CURRENT="Devel-NYTProf-6.08"
<   PERL_CR_SMOKER_RUNONCE="1"
<   PERL_EXTUTILS_AUTOINSTALL="--defaultdeps"
<   PERL_MM_USE_DEFAULT="1"
---
>   PERL5LIB="C:\projects\devel-nytprof\blib\lib;C:\projects\devel-nytprof\blib\arch"
100,102c94,98
<   C:/Strawberry282/perl/site/lib
<   C:/Strawberry282/perl/vendor/lib
<   C:/Strawberry282/perl/lib
---
>   C:\projects\devel-nytprof\blib\lib
>   C:\projects\devel-nytprof\blib\arch
>   C:/strawberry/perl/site/lib
>   C:/strawberry/perl/vendor/lib
>   C:/strawberry/perl/lib

However, I cannot yet determine whether these differences are explanatory.

The problematic code can be extracted to the following:

$ cat fmt_float-bug.pl 
my $val = '0.00004';
my $expected = '4.0e-5';
my $rv = fmt_float($val);

print <<EOF;
Test value:     $val
Expected:       $expected
Got:            $rv
EOF

sub fmt_float {
    my ($val, $precision) = @_;
    $precision ||= 5;
    if ($val < 10 ** -($precision - 1) and $val > 0) {
        $val = sprintf("%." . ($precision - 4) . "e", $val);
        $val =~ s/e-0/e-/;   ##### <--
    }
    elsif ($val != int($val)) {
        $val = sprintf("%.${precision}f", $val);
    }
    return $val;
}

... where most testers are getting 4.0e-5 but this tester is getting 4.0e-05, i.e., the statement at ##### is either not being reached or not running correctly.

Needs investigation.

Thank you very much. Jim Keenan

jkeenan commented 3 years ago

@chorny, do you have any insight into this problem?

Thank you very much. Jim Keenan

jkeenan commented 3 years ago

Pending feedback from @chorny, I have TODO-ed the errant test in commit 3b361cec80.

shawnlaffan commented 3 years ago

On my windows machine with Strawberry Perl 5.28.0 I get

perl -E"my $x = sprintf '%.1e', 1e-5; say $x; $x=~s/e-0/e-/; say $x"
1.0e-005
1.0e-05

If I modify the regexp to capture multiple zeroes using s/e-0+/e-/ then it works as desired.

perl -E"my $x = sprintf '%.1e', 1e-5; say $x; $x=~s/e-0+/e-/; say $x"
1.0e-005
1.0e-5
jkeenan commented 3 years ago

If I modify the regexp to capture multiple zeroes using s/e-0+/e-/ then it works as desired.

perl -E"my $x = sprintf '%.1e', 1e-5; say $x; $x=~s/e-0+/e-/; say $x"
1.0e-005
1.0e-5

Good insight! Can you try out this pull request?

https://github.com/timbunce/devel-nytprof/pull/173

And thanks for continuing to follow this repository! Jim Keenan

shawnlaffan commented 3 years ago

t/30-util.t passes for me under that PR, whereas it failed when testing 6.08 from CPAN.

jkeenan commented 3 years ago

On 4/28/21 6:12 PM, shawnlaffan wrote:

t/30-util.t passes for me under that PR, whereas it failed when testing 6.08 from CPAN.

Thanks! I will merge the p.r. to master soon. jimk

jkeenan commented 3 years ago

On 4/28/21 6:12 PM, shawnlaffan wrote: t/30-util.t passes for me under that PR, whereas it failed when testing 6.08 from CPAN. Thanks! I will merge the p.r. to master soon. jimk

Branch has been merged to master in merge commit 6b9a3df7b0ece3ae7451524ff912c51fa81efca4. Ticket will be kept open until we can observe results of next CPAN release.

Thank you very much. Jim Keenan

jkeenan commented 3 years ago

This should be closable now that v6.09 has been released.

jkeenan commented 3 years ago

This should be closable now that v6.09 has been released.

No Win32 test failures for v6.10 are attributable to t/30-util.t. Closing ticket.

Thank you very much. Jim Keenan