mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-24 22:10:13 +00:00
Refactor strtod tests
This patch changes strtod* tests to use strfrom* functions.
This commit is contained in:
parent
6962682ffe
commit
bf5eea32ac
@ -1,3 +1,11 @@
|
|||||||
|
2016-10-25 Rajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com>
|
||||||
|
|
||||||
|
* stdlib/bug-strtod.c: Refactor based on GEN_TEST_STRTOD_FOREACH.
|
||||||
|
* stdlib/bug-strtod2.c: Likewise.
|
||||||
|
* stdlib/tst-strtod-round-skeleton.c: Likewise.
|
||||||
|
* stdlib/tst-strtod6.c: Likewise.
|
||||||
|
* stdlib/tst-strtod.h (GEN_TEST_STRTOD_FOREACH): Use strfrom.
|
||||||
|
|
||||||
2016-10-25 Gabriel F. T. Gomes <gftg@linux.vnet.ibm.com>
|
2016-10-25 Gabriel F. T. Gomes <gftg@linux.vnet.ibm.com>
|
||||||
|
|
||||||
* NEWS: Mention the addition of strfromd, strfromf, and strfroml.
|
* NEWS: Mention the addition of strfromd, strfromf, and strfroml.
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include "tst-strtod.h"
|
#include "tst-strtod.h"
|
||||||
|
|
||||||
#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF) \
|
#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
|
||||||
static int \
|
static int \
|
||||||
test_strto ## FSUF (void) \
|
test_strto ## FSUF (void) \
|
||||||
{ \
|
{ \
|
||||||
@ -45,8 +45,8 @@ test_strto ## FSUF (void) \
|
|||||||
{ \
|
{ \
|
||||||
char fstr[FSTRLENMAX]; \
|
char fstr[FSTRLENMAX]; \
|
||||||
char fcntstr[FSTRLENMAX]; \
|
char fcntstr[FSTRLENMAX]; \
|
||||||
FTOSTR (fstr, sizeof (fstr), "%" FTOSTRM "g", f); \
|
FTOSTR (fstr, sizeof (fstr), "%g", f); \
|
||||||
FTOSTR (fcntstr, sizeof (fstr), "%" FTOSTRM "g", (FTYPE) cnt); \
|
FTOSTR (fcntstr, sizeof (fstr), "%g", (FTYPE) cnt); \
|
||||||
printf ("strto" #FSUF "(\"%s\") " \
|
printf ("strto" #FSUF "(\"%s\") " \
|
||||||
"failed for cnt == %d (%s instead of %s)\n", \
|
"failed for cnt == %d (%s instead of %s)\n", \
|
||||||
buf, cnt, fstr, fcntstr); \
|
buf, cnt, fstr, fcntstr); \
|
||||||
|
@ -12,7 +12,7 @@ static const char *tests[] =
|
|||||||
};
|
};
|
||||||
#define ntests (sizeof (tests) / sizeof (tests[0]))
|
#define ntests (sizeof (tests) / sizeof (tests[0]))
|
||||||
|
|
||||||
#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF) \
|
#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
|
||||||
static int \
|
static int \
|
||||||
test_strto ## FSUF (void) \
|
test_strto ## FSUF (void) \
|
||||||
{ \
|
{ \
|
||||||
|
@ -58,11 +58,11 @@
|
|||||||
|
|
||||||
/* Generator to create an FTYPE member variabled named FSUF
|
/* Generator to create an FTYPE member variabled named FSUF
|
||||||
used to populate struct member variables. */
|
used to populate struct member variables. */
|
||||||
#define FTYPE_MEMBER(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF) \
|
#define FTYPE_MEMBER(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
|
||||||
FTYPE FSUF;
|
FTYPE FSUF;
|
||||||
|
|
||||||
/* Likewise, but each member is of type bool. */
|
/* Likewise, but each member is of type bool. */
|
||||||
#define BOOL_MEMBER(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF) \
|
#define BOOL_MEMBER(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
|
||||||
bool FSUF;
|
bool FSUF;
|
||||||
|
|
||||||
#define STRUCT_FOREACH_FLOAT_FTYPE GEN_TEST_STRTOD_FOREACH (FTYPE_MEMBER)
|
#define STRUCT_FOREACH_FLOAT_FTYPE GEN_TEST_STRTOD_FOREACH (FTYPE_MEMBER)
|
||||||
@ -96,13 +96,13 @@
|
|||||||
/* long double is special, and handled above. */
|
/* long double is special, and handled above. */
|
||||||
|
|
||||||
/* Selector for expected result field of a given type. */
|
/* Selector for expected result field of a given type. */
|
||||||
#define _ENTRY(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF, ...) \
|
#define _ENTRY(FSUF, FTYPE, FTOSTR, LSUF, CSUF, ...) \
|
||||||
CONCAT (CHOOSE_ ## FSUF (__VA_ARGS__), LSUF),
|
CONCAT (CHOOSE_ ## FSUF (__VA_ARGS__), LSUF),
|
||||||
#define ENTRY(...) \
|
#define ENTRY(...) \
|
||||||
GEN_TEST_STRTOD_FOREACH (_ENTRY, __VA_ARGS__)
|
GEN_TEST_STRTOD_FOREACH (_ENTRY, __VA_ARGS__)
|
||||||
|
|
||||||
/* Selector for boolean exact tag of expected results. */
|
/* Selector for boolean exact tag of expected results. */
|
||||||
#define _XNTRY(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF, ...) \
|
#define _XNTRY(FSUF, FTYPE, FTOSTR, LSUF, CSUF, ...) \
|
||||||
CHOOSE_ ## FSUF (__VA_ARGS__),
|
CHOOSE_ ## FSUF (__VA_ARGS__),
|
||||||
#define XNTRY(...) \
|
#define XNTRY(...) \
|
||||||
GEN_TEST_STRTOD_FOREACH (_XNTRY, __VA_ARGS__)
|
GEN_TEST_STRTOD_FOREACH (_XNTRY, __VA_ARGS__)
|
||||||
@ -157,21 +157,19 @@ struct test {
|
|||||||
#define STR(x) STRX (x)
|
#define STR(x) STRX (x)
|
||||||
#define FNPFXS STR (FNPFX)
|
#define FNPFXS STR (FNPFX)
|
||||||
|
|
||||||
#define GEN_ONE_TEST(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF) \
|
#define GEN_ONE_TEST(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
|
||||||
{ \
|
{ \
|
||||||
FTYPE f = STRTO (FSUF) (s, NULL); \
|
FTYPE f = STRTO (FSUF) (s, NULL); \
|
||||||
if (f != expected->FSUF \
|
if (f != expected->FSUF \
|
||||||
|| (copysign ## CSUF) (1.0 ## LSUF, f) \
|
|| (copysign ## CSUF) (1.0 ## LSUF, f) \
|
||||||
!= (copysign ## CSUF) (1.0 ## LSUF, expected->FSUF)) \
|
!= (copysign ## CSUF) (1.0 ## LSUF, expected->FSUF)) \
|
||||||
{ \
|
{ \
|
||||||
CHAR efstr[FSTRLENMAX]; \
|
char efstr[FSTRLENMAX]; \
|
||||||
CHAR fstr[FSTRLENMAX]; \
|
char fstr[FSTRLENMAX]; \
|
||||||
FTOSTR (efstr, FSTRLENMAX, L_("%") L_(FTOSTRM) L_("a"), \
|
FTOSTR (efstr, FSTRLENMAX, "%a", expected->FSUF); \
|
||||||
expected->FSUF); \
|
FTOSTR (fstr, FSTRLENMAX, "%a", f); \
|
||||||
FTOSTR (fstr, FSTRLENMAX, L_("%") L_(FTOSTRM) L_("a"), f);\
|
printf (FNPFXS "to" #FSUF " (" STRM ") returned %s not " \
|
||||||
printf (FNPFXS "to" #FSUF " (" STRM ") returned " STRM \
|
"%s (%s)\n", s, fstr, efstr, mode_name); \
|
||||||
" not " STRM " (%s)\n", \
|
|
||||||
s, fstr, efstr, mode_name); \
|
|
||||||
if (ROUNDING_TESTS (FTYPE, rnd_mode) || exact->FSUF) \
|
if (ROUNDING_TESTS (FTYPE, rnd_mode) || exact->FSUF) \
|
||||||
result = 1; \
|
result = 1; \
|
||||||
else \
|
else \
|
||||||
|
@ -23,14 +23,13 @@
|
|||||||
|
|
||||||
/* Splat n variants of the same test for the various strtod functions. */
|
/* Splat n variants of the same test for the various strtod functions. */
|
||||||
#define GEN_TEST_STRTOD_FOREACH(mfunc, ...) \
|
#define GEN_TEST_STRTOD_FOREACH(mfunc, ...) \
|
||||||
mfunc ( f, float, snprintf, "", f, f, ##__VA_ARGS__) \
|
mfunc ( f, float, strfromf, f, f, ##__VA_ARGS__) \
|
||||||
mfunc ( d, double, snprintf, "", , , ##__VA_ARGS__) \
|
mfunc ( d, double, strfromd, , , ##__VA_ARGS__) \
|
||||||
mfunc ( ld, long double, snprintf, "L", L, l, ##__VA_ARGS__)
|
mfunc ( ld, long double, strfroml, L, l, ##__VA_ARGS__)
|
||||||
/* The arguments to the generated macros are:
|
/* The arguments to the generated macros are:
|
||||||
FSUF - Function suffix
|
FSUF - Function suffix
|
||||||
FTYPE - float type
|
FTYPE - float type
|
||||||
FTOSTR - float to string func
|
FTOSTR - float to string func
|
||||||
FTOSTRM - Optional modifier for FTOSTR format
|
|
||||||
LSUF - Literal suffix
|
LSUF - Literal suffix
|
||||||
CSUF - C standardish suffix for many of the math functions
|
CSUF - C standardish suffix for many of the math functions
|
||||||
*/
|
*/
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "tst-strtod.h"
|
#include "tst-strtod.h"
|
||||||
|
|
||||||
#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF) \
|
#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
|
||||||
static int \
|
static int \
|
||||||
test_strto ## FSUF (const char str[]) \
|
test_strto ## FSUF (const char str[]) \
|
||||||
{ \
|
{ \
|
||||||
|
Loading…
Reference in New Issue
Block a user