]> git.proxmox.com Git - mirror_qemu.git/commit
test-cutils: Add coverage of qemu_strtod
authorEric Blake <eblake@redhat.com>
Mon, 22 May 2023 19:04:31 +0000 (14:04 -0500)
committerEric Blake <eblake@redhat.com>
Fri, 2 Jun 2023 17:29:27 +0000 (12:29 -0500)
commit759573d05b808344f7047f893d2dd095884dfa4d
treed3304e5a7c942e090b90512e79952c1aa51ba3ae
parent52d606aa5b6859bf13b026aa82f53f8506aa6abe
test-cutils: Add coverage of qemu_strtod

It's hard to tweak code for consistency if I can't prove what will or
won't break from those tweaks.  Time to add unit tests for
qemu_strtod() and qemu_strtod_finite().

Among other things, I wrote a check whether we have C99 semantics for
strtod("0x1") (which MUST parse hex numbers) rather than C89 (which
must stop parsing at 'x').  These days, I suspect that is okay; but if
it fails CI checks, knowing the difference will help us decide what we
want to do about it.  Note that C2x, while not final at the time of
this patch, has been considering whether to make strtol("0b1") parse
as 1 with no slop instead of the C17 parse of 0 with slop "b1"; that
decision may also bleed over to strtod().  But for now, I didn't think
it worth adding unit tests on that front (to strtol or strtod) as
things may still change.

Likewise, there are plenty more corner cases of strtod proper that I
don't explicitly test here, but there are enough unit tests added here
that it covers all the branches reached in our wrappers.  In
particular, it demonstrates the difference on when *value is left
uninitialized, which an upcoming patch will normalize.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
Message-Id: <20230522190441.64278-10-eblake@redhat.com>
tests/unit/test-cutils.c