* Gabriel F. T. Gomes:
> /* Splat n variants of the same test for the various strtod functions. */
> #define GEN_TEST_STRTOD_FOREACH(mfunc, ...) \
> - mfunc ( f, float, snprintf, "", f, f, ##__VA_ARGS__) \
> - mfunc ( d, double, snprintf, "", , , ##__VA_ARGS__) \
> - mfunc ( ld, long double, snprintf, "L", L, l, ##__VA_ARGS__)
> + mfunc ( f, float, strfromf, f, f, ##__VA_ARGS__) \
> + mfunc ( d, double, strfromd, , , ##__VA_ARGS__) \
> + mfunc ( ld, long double, strfroml, L, l, ##__VA_ARGS__)
Will this lose test coverage for snprintf?
On 09/23/2016 02:02 AM, Florian Weimer wrote:
> * Gabriel F. T. Gomes:
>
>> /* Splat n variants of the same test for the various strtod functions. */
>> #define GEN_TEST_STRTOD_FOREACH(mfunc, ...) \
>> - mfunc ( f, float, snprintf, "", f, f, ##__VA_ARGS__) \
>> - mfunc ( d, double, snprintf, "", , , ##__VA_ARGS__) \
>> - mfunc ( ld, long double, snprintf, "L", L, l, ##__VA_ARGS__)
>> + mfunc ( f, float, strfromf, f, f, ##__VA_ARGS__) \
>> + mfunc ( d, double, strfromd, , , ##__VA_ARGS__) \
>> + mfunc ( ld, long double, strfroml, L, l, ##__VA_ARGS__)
> Will this lose test coverage for snprintf?
No. stdlib/tst-strtod.h(with snprintf) file is created few months back with
the purpose of refactoring strtod tests and snprintf was not used by
the strtod tests before refactoring too. So changing this to strfrom
should not affect. Also snprintf is still used in math/test-*.h
which adds test coverage.
>
>
@@ -23,7 +23,7 @@
#include "tst-strtod.h"
-#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF) \
+#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
static int \
test_strto ## FSUF (void) \
{ \
@@ -45,8 +45,8 @@ test_strto ## FSUF (void) \
{ \
char fstr[FSTRLENMAX]; \
char fcntstr[FSTRLENMAX]; \
- FTOSTR (fstr, sizeof (fstr), "%" FTOSTRM "g", f); \
- FTOSTR (fcntstr, sizeof (fstr), "%" FTOSTRM "g", (FTYPE) cnt); \
+ FTOSTR (fstr, sizeof (fstr), "%g", f); \
+ FTOSTR (fcntstr, sizeof (fstr), "%g", (FTYPE) cnt); \
printf ("strto" #FSUF "(\"%s\") " \
"failed for cnt == %d (%s instead of %s)\n", \
buf, cnt, fstr, fcntstr); \
@@ -12,7 +12,7 @@ static const char *tests[] =
};
#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 \
test_strto ## FSUF (void) \
{ \
@@ -58,11 +58,11 @@
/* Generator to create an FTYPE member variabled named FSUF
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;
/* 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;
#define STRUCT_FOREACH_FLOAT_FTYPE GEN_TEST_STRTOD_FOREACH (FTYPE_MEMBER)
@@ -96,13 +96,13 @@
/* long double is special, and handled above. */
/* 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),
#define ENTRY(...) \
GEN_TEST_STRTOD_FOREACH (_ENTRY, __VA_ARGS__)
/* 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__),
#define XNTRY(...) \
GEN_TEST_STRTOD_FOREACH (_XNTRY, __VA_ARGS__)
@@ -157,21 +157,19 @@ struct test {
#define STR(x) STRX (x)
#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); \
if (f != expected->FSUF \
|| (copysign ## CSUF) (1.0 ## LSUF, f) \
!= (copysign ## CSUF) (1.0 ## LSUF, expected->FSUF)) \
{ \
- CHAR efstr[FSTRLENMAX]; \
- CHAR fstr[FSTRLENMAX]; \
- FTOSTR (efstr, FSTRLENMAX, L_("%") L_(FTOSTRM) L_("a"), \
- expected->FSUF); \
- FTOSTR (fstr, FSTRLENMAX, L_("%") L_(FTOSTRM) L_("a"), f);\
- printf (FNPFXS "to" #FSUF " (" STRM ") returned " STRM \
- " not " STRM " (%s)\n", \
- s, fstr, efstr, mode_name); \
+ char efstr[FSTRLENMAX]; \
+ char fstr[FSTRLENMAX]; \
+ FTOSTR (efstr, FSTRLENMAX, "%a", expected->FSUF); \
+ FTOSTR (fstr, FSTRLENMAX, "%a", f); \
+ printf (FNPFXS "to" #FSUF " (" STRM ") returned %s not " \
+ "%s (%s)\n", s, fstr, efstr, mode_name); \
if (ROUNDING_TESTS (FTYPE, rnd_mode) || exact->FSUF) \
result = 1; \
else \
@@ -23,14 +23,13 @@
/* Splat n variants of the same test for the various strtod functions. */
#define GEN_TEST_STRTOD_FOREACH(mfunc, ...) \
- mfunc ( f, float, snprintf, "", f, f, ##__VA_ARGS__) \
- mfunc ( d, double, snprintf, "", , , ##__VA_ARGS__) \
- mfunc ( ld, long double, snprintf, "L", L, l, ##__VA_ARGS__)
+ mfunc ( f, float, strfromf, f, f, ##__VA_ARGS__) \
+ mfunc ( d, double, strfromd, , , ##__VA_ARGS__) \
+ mfunc ( ld, long double, strfroml, L, l, ##__VA_ARGS__)
/* The arguments to the generated macros are:
FSUF - Function suffix
FTYPE - float type
FTOSTR - float to string func
- FTOSTRM - Optional modifier for FTOSTR format
LSUF - Literal suffix
CSUF - C standardish suffix for many of the math functions
*/
@@ -5,7 +5,7 @@
#include "tst-strtod.h"
-#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF) \
+#define TEST_STRTOD(FSUF, FTYPE, FTOSTR, LSUF, CSUF) \
static int \
test_strto ## FSUF (const char str[]) \
{ \