From patchwork Mon Aug 15 22:29:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. Murphy" X-Patchwork-Id: 659435 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sCqtm0B2dz9t2D for ; Tue, 16 Aug 2016 08:30:07 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=dxYrEbvQ; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:subject:to:cc:date:mime-version :content-type:content-transfer-encoding:message-id; q=dns; s= default; b=OmjpaB32LU/ldtEjJfAuNa+vIq0z46mgsuQ1ej8a+Tf4tpqw8dpRN P1OXPpZfcl27zeArnmEHfH4WNZaS0zOF1qQf9CY6nJqJCNkqPhzLQ+BdFrUAvK5M RalotoyK4tQMY9Lrra6CbtwpRm1krSytpP4BbXfS1bI2m+Wu/PYEy8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:subject:to:cc:date:mime-version :content-type:content-transfer-encoding:message-id; s=default; bh=41x/8mvlIdyPGYzkjBWXWY0sZAk=; b=dxYrEbvQThPsmRMBxGksdNqU83nb 5zGfIsb51Y3On4cL8aLMWQq0h/l4KMGNmXKMPsatxvh5axlDm1QKy/K4kSvNLcVe QoxCbVYDvbfVVvlx2QKlSohSAeM/VuhJPvud+R6s0m6ywfzXHvrcoLXwJcH2U55k 1BNR1zQSW6xyY40= Received: (qmail 27178 invoked by alias); 15 Aug 2016 22:30:01 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 27160 invoked by uid 89); 15 Aug 2016 22:30:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.8 required=5.0 tests=AWL, BAYES_50, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=fd, rounded, Nonstandard, populate X-HELO: mx0a-001b2d01.pphosted.com X-IBM-Helo: d03dlp03.boulder.ibm.com X-IBM-MailFrom: murphyp@linux.vnet.ibm.com From: "Paul E. Murphy" Subject: [PATCHv2] Add tst-wcstod-round To: "libc-alpha@sourceware.org" Cc: "Carlos O'Donell" , Joseph Myers Date: Mon, 15 Aug 2016 17:29:44 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16081522-0012-0000-0000-00001066D66B X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00005600; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000181; SDB=6.00745145; UDB=6.00351143; IPR=6.00517696; BA=6.00004662; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00012342; XFM=3.00000011; UTC=2016-08-15 22:29:47 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16081522-0013-0000-0000-00004492D3D1 Message-Id: <70ef8ff5-9819-c96f-ed01-2e1a2a6040ad@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-08-15_10:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1608150251 Continuing the discussion from https://sourceware.org/ml/libc-alpha/2016-08/msg00198.html Changes: * Rename tst-strtod-round.c to tst-strtod-round-skeleton.c and do not provide default macro definitions, but do add a comment describing their expected behavior. * Replace tst-strtod-round.c with a shim providing char versions of requires macros. ---8<--- This extends tst-strtod-round with a few trivial changes to also test the wide character variants of strto* using similar macros to other shared tests. * stdlib/tst-strtod-round-skeleton.c: Refactored from tst-strtod-round.c. (L_): New macro to apply literal modifier. (FNPFX): New macro to select str or wcs prefix. (CHAR): New macro to choose wchar_t or char. (STRM): New macro to choose printf for tested character type. (STRTO): New macro to choose appropriate string -> real function. (FNPFXS): Stringitized version of FNPFX. (STR): Support for above macro. (STRX): Likewise. (TEST): Update with above macros. (test): Likewise. (GEN_ONE_TEST): Likewise. (test_in_one_mode): Likewise. * stdlib/tst-strtod-round.c: New file. * wcsmbs/tst-wcstod-round.c: New file. * wcsmbs/Makefile: (tests): Add tst-wcstod-round (tst-wcstod-round): Add libm depencency for fesetround. --- ...-strtod-round.c => tst-strtod-round-skeleton.c} | 40 +++- stdlib/tst-strtod-round.c | 206 +-------------------- wcsmbs/Makefile | 3 + wcsmbs/tst-wcstod-round.c | 31 ++++ 4 files changed, 71 insertions(+), 209 deletions(-) copy stdlib/{tst-strtod-round.c => tst-strtod-round-skeleton.c} (86%) create mode 100644 wcsmbs/tst-wcstod-round.c diff --git a/stdlib/tst-strtod-round.c b/stdlib/tst-strtod-round-skeleton.c similarity index 86% copy from stdlib/tst-strtod-round.c copy to stdlib/tst-strtod-round-skeleton.c index 509f96a..f74b744 100644 --- a/stdlib/tst-strtod-round.c +++ b/stdlib/tst-strtod-round-skeleton.c @@ -31,9 +31,23 @@ #include "tst-strtod.h" +/* Non-standard macro's expected to be externally defined: + + L_(str): Pastes the appropriate modifier to a string literal str. + + FNPFX: Expands to the correct prefix for the strtod equivalent + of type CHAR. (e.g str or wcs). + + CHAR: Expands to the string type being tested (e.g wchar_t or char). + + STRM: Expands to a string literal suitable for printing CHAR* via + printf (e.g "%s" or "%Ls"). */ + #define _CONCAT(a, b) a ## b #define CONCAT(a, b) _CONCAT (a, b) +#define STRTO(x) CONCAT (CONCAT (FNPFX, to), x) + #if LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024 /* This is a stupid hack for IBM long double. This test ignores inexact values for long double due to the limitations of the @@ -110,7 +124,7 @@ ld106x, ld106d, ld106n, ld106z, ld106u, \ ld113x, ld113d, ld113n, ld113z, ld113u) \ { \ - s, \ + L_ (s), \ { XNTRY (fx, dx, ld64ix, ld64mx, ld106x, ld113x) }, \ { \ { ENTRY (fn, dn, ld64in, ld64mn, ld106n, ld113n) }, \ @@ -131,7 +145,7 @@ struct test_results }; struct test { - const char *s; + const CHAR *s; struct test_exactness exact; struct test_results r[4]; }; @@ -139,19 +153,25 @@ struct test { /* Include the generated test data. */ #include "tst-strtod-round-data.h" +#define STRX(x) #x +#define STR(x) STRX (x) +#define FNPFXS STR (FNPFX) + #define GEN_ONE_TEST(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF) \ { \ - FTYPE f = strto ## FSUF (s, NULL); \ + 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, "%" FTOSTRM "a", expected->FSUF); \ - FTOSTR (fstr, FSTRLENMAX, "%" FTOSTRM "a", f); \ - printf ("strto" #FSUF " (%s) returned %s not %s" \ - " (%s)\n", s, fstr, efstr, mode_name); \ + 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); \ if (ROUNDING_TESTS (FTYPE, rnd_mode) || exact->FSUF) \ result = 1; \ else \ @@ -160,7 +180,7 @@ struct test { } static int -test_in_one_mode (const char *s, const struct test_results *expected, +test_in_one_mode (const CHAR *s, const struct test_results *expected, const struct test_exactness *exact, const char *mode_name, int rnd_mode) { diff --git a/stdlib/tst-strtod-round.c b/stdlib/tst-strtod-round.c index 509f96a..ae5d6f8 100644 --- a/stdlib/tst-strtod-round.c +++ b/stdlib/tst-strtod-round.c @@ -1,6 +1,5 @@ -/* Test for correct rounding of results of strtod and related - functions. - Copyright (C) 2012-2016 Free Software Foundation, Inc. +/* char shim for tst-strtod-round-skeleton.c. + Copyright (C) 2016 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -17,200 +16,9 @@ License along with the GNU C Library; if not, see . */ -/* Defining _LIBC_TEST ensures long double math functions are - declared in the headers. */ -#define _LIBC_TEST 1 -#include -#include -#include -#include -#include -#include -#include -#include +#define L_(str) str +#define FNPFX str +#define CHAR char +#define STRM "%s" -#include "tst-strtod.h" - -#define _CONCAT(a, b) a ## b -#define CONCAT(a, b) _CONCAT (a, b) - -#if LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024 -/* This is a stupid hack for IBM long double. This test ignores - inexact values for long double due to the limitations of the - format. This ensures rounding tests are ignored. */ -# undef ROUNDING_TESTS_long_double -# define ROUNDING_TESTS_long_double(x) 0 -#endif - -/* Generator to create an FTYPE member variabled named FSUF - used to populate struct member variables. */ -#define FTYPE_MEMBER(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF) \ - FTYPE FSUF; - -/* Likewise, but each member is of type bool. */ -#define BOOL_MEMBER(FSUF, FTYPE, FTOSTR, FTOSTRM, LSUF, CSUF) \ - bool FSUF; - -#define STRUCT_FOREACH_FLOAT_FTYPE GEN_TEST_STRTOD_FOREACH (FTYPE_MEMBER) -#define STRUCT_FOREACH_FLOAT_BOOL GEN_TEST_STRTOD_FOREACH (BOOL_MEMBER) - -/* Define the long double choose (CHOOSE_ld) macro - to select the appropriate generated long double - value from the generated test data. */ -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -/* This is for the long double == double format. */ -# define CHOOSE_ld(f,d,...) d -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 && LDBL_MIN_EXP == -16381 -/* This is for the Intel extended float format. */ -# define CHOOSE_ld(f,d,ld64i,...) ld64i -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 && LDBL_MIN_EXP == -16382 -/* This is for the Motorola extended float format. */ -# define CHOOSE_ld(f,d,ld64i,ld64m,...) ld64m -#elif LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024 -/* This is for the IBM extended double format. */ -# define CHOOSE_ld(f,d,ld64i,ld64m,ld106,...) ld106 -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -/* This is for the IEEE binary128 format. */ -# define CHOOSE_ld(f,d,ld64i,ld64m,ld106,ld113,...) ld113 -#else -# error "unknown long double format" -#endif - -/* Add type specific choosing macros below. */ -#define CHOOSE_f(f,...) f -#define CHOOSE_d(f,d,...) d -/* long double is special, and handled above. */ - -/* Selector for expected result field of a given type. */ -#define _ENTRY(FSUF, FTYPE, FTOSTR, FTOSTRM, 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, ...) \ - CHOOSE_ ## FSUF (__VA_ARGS__), -#define XNTRY(...) \ - GEN_TEST_STRTOD_FOREACH (_XNTRY, __VA_ARGS__) - -/* This is hacky way around the seemingly unavoidable macro - expansion of the INFINITY or HUGE_VAL like macros in the - above. It is assumed the compiler will implicitly convert - the infinity correctly. */ -#define INF INFINITY + 0.0 - -/* This macro is used in conjunction with the output from the - gen-tst-strtod-round utility to select the appropriately - rounded long double value for a given format. */ -#define TEST(s, \ - fx, fd, fn, fz, fu, \ - dx, dd, dn, dz, du, \ - ld64ix, ld64id, ld64in, ld64iz, ld64iu, \ - ld64mx, ld64md, ld64mn, ld64mz, ld64mu, \ - ld106x, ld106d, ld106n, ld106z, ld106u, \ - ld113x, ld113d, ld113n, ld113z, ld113u) \ - { \ - s, \ - { XNTRY (fx, dx, ld64ix, ld64mx, ld106x, ld113x) }, \ - { \ - { ENTRY (fn, dn, ld64in, ld64mn, ld106n, ld113n) }, \ - { ENTRY (fd, dd, ld64id, ld64md, ld106d, ld113d) }, \ - { ENTRY (fz, dz, ld64iz, ld64mz, ld106z, ld113z) }, \ - { ENTRY (fu, du, ld64iu, ld64mu, ld106u, ld113u) } \ - } \ - } - -struct test_exactness - { - STRUCT_FOREACH_FLOAT_BOOL - }; - -struct test_results - { - STRUCT_FOREACH_FLOAT_FTYPE - }; - -struct test { - const char *s; - struct test_exactness exact; - struct test_results r[4]; -}; - -/* Include the generated test data. */ -#include "tst-strtod-round-data.h" - -#define GEN_ONE_TEST(FSUF, FTYPE, FTOSTR, FTOSTRM, 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, "%" FTOSTRM "a", expected->FSUF); \ - FTOSTR (fstr, FSTRLENMAX, "%" FTOSTRM "a", f); \ - printf ("strto" #FSUF " (%s) returned %s not %s" \ - " (%s)\n", s, fstr, efstr, mode_name); \ - if (ROUNDING_TESTS (FTYPE, rnd_mode) || exact->FSUF) \ - result = 1; \ - else \ - printf ("ignoring this inexact result\n"); \ - } \ -} - -static int -test_in_one_mode (const char *s, const struct test_results *expected, - const struct test_exactness *exact, const char *mode_name, - int rnd_mode) -{ - int result = 0; - GEN_TEST_STRTOD_FOREACH (GEN_ONE_TEST) - return result; -} - -static const struct fetestmodes - { - const char *mode_name; - int rnd_mode; - int rnd_i; /* Corresponding index into r array of struct test. */ - } modes[] = { - { "default rounding mode", FE_TONEAREST, 0 }, -#ifdef FE_DOWNWARD - { "FE_DOWNWARD", FE_DOWNWARD, 1 }, -#endif -#ifdef FE_TOWARDZERO - { "FE_TOWARDZERO", FE_TOWARDZERO, 2 }, -#endif -#ifdef FE_UPWARD - { "FE_UPWARD", FE_UPWARD, 3 }, -#endif - {} -}; - -static int -do_test (void) -{ - int save_round_mode __attribute__ ((unused)) = fegetround (); - int result = 0; - for (size_t i = 0; i < sizeof (tests) / sizeof (tests[0]); i++) - { - result |= test_in_one_mode (tests[i].s, &tests[i].r[modes[0].rnd_i], - &tests[i].exact, modes[0].mode_name, - modes[0].rnd_mode); - for (const struct fetestmodes *m = &modes[1]; m->mode_name != NULL; m++) - { - if (!fesetround (m->rnd_mode)) - { - result |= test_in_one_mode (tests[i].s, &tests[i].r[m->rnd_i], - &tests[i].exact, m->mode_name, - m->rnd_mode); - fesetround (save_round_mode); - } - } - } - return result; -} - -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" +#include diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile index 8b599f7..9384a10 100644 --- a/wcsmbs/Makefile +++ b/wcsmbs/Makefile @@ -49,6 +49,7 @@ strop-tests := wcscmp wcsncmp wmemcmp wcslen wcschr wcsrchr wcscpy wcsnlen \ tests := tst-wcstof wcsmbs-tst1 tst-wcsnlen tst-btowc tst-mbrtowc \ tst-wcrtomb tst-wcpncpy tst-mbsrtowcs tst-wchar-h tst-mbrtowc2 \ tst-c16c32-1 wcsatcliff tst-wcstol-locale tst-wcstod-nan-locale \ + tst-wcstod-round \ $(addprefix test-,$(strop-tests)) include ../Rules @@ -68,6 +69,8 @@ $(objpfx)tst-wcstol-locale.out: $(gen-locales) $(objpfx)tst-wcstod-nan-locale.out: $(gen-locales) endif +$(objpfx)tst-wcstod-round: $(libm) + CFLAGS-wcwidth.c = -I../wctype CFLAGS-wcswidth.c = -I../wctype diff --git a/wcsmbs/tst-wcstod-round.c b/wcsmbs/tst-wcstod-round.c new file mode 100644 index 0000000..38ddaea --- /dev/null +++ b/wcsmbs/tst-wcstod-round.c @@ -0,0 +1,31 @@ +/* wide character shim for tst-strtod-round-skeleton.c. + Copyright (C) 2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +/* Include stdio.h early to avoid issues with the snprintf + redefinition below. */ +#include + +#define L_(str) L ## str +#define FNPFX wcs +#define CHAR wchar_t +#define STRM "%ls" +#define snprintf swprintf + +#include