Wed May 8 18:19:57 2024 UTC (24d)
tests/lib/libc/stdio/t_printf: Add a couple simple %La tests.

PR lib/56937: printf(3) long double %a formatting is broken


(riastradh)
diff -r1.10 -r1.11 src/tests/lib/libc/stdio/t_printf.c

cvs diff -r1.10 -r1.11 src/tests/lib/libc/stdio/t_printf.c (expand / switch to unified diff)

--- src/tests/lib/libc/stdio/t_printf.c 2023/04/04 19:39:38 1.10
+++ src/tests/lib/libc/stdio/t_printf.c 2024/05/08 18:19:57 1.11
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: t_printf.c,v 1.10 2023/04/04 19:39:38 he Exp $ */ 1/* $NetBSD: t_printf.c,v 1.11 2024/05/08 18:19:57 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -18,34 +18,36 @@ @@ -18,34 +18,36 @@
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/types.h> 29#include <sys/types.h>
30#include <sys/resource.h> 30#include <sys/resource.h>
 31
31#include <atf-c.h> 32#include <atf-c.h>
 33#include <errno.h>
 34#include <float.h>
32#include <math.h> 35#include <math.h>
33#include <stdio.h> 
34#include <stdint.h> 36#include <stdint.h>
 37#include <stdio.h>
 38#include <stdlib.h>
35#include <string.h> 39#include <string.h>
36#include <time.h> 40#include <time.h>
37#include <stdlib.h> 
38#include <errno.h> 
39 41
40ATF_TC(snprintf_c99); 42ATF_TC(snprintf_c99);
41ATF_TC_HEAD(snprintf_c99, tc) 43ATF_TC_HEAD(snprintf_c99, tc)
42{ 44{
43 45
44 atf_tc_set_md_var(tc, "descr", 46 atf_tc_set_md_var(tc, "descr",
45 "Test printf(3) C99 conformance (PR lib/22019)"); 47 "Test printf(3) C99 conformance (PR lib/22019)");
46} 48}
47 49
48ATF_TC_BODY(snprintf_c99, tc) 50ATF_TC_BODY(snprintf_c99, tc)
49{ 51{
50 char s[4]; 52 char s[4];
51 53
@@ -181,27 +183,66 @@ ATF_TC_BODY(sprintf_zeropad, tc) @@ -181,27 +183,66 @@ ATF_TC_BODY(sprintf_zeropad, tc)
181} 183}
182 184
183ATF_TC(snprintf_double_a); 185ATF_TC(snprintf_double_a);
184ATF_TC_HEAD(snprintf_double_a, tc) 186ATF_TC_HEAD(snprintf_double_a, tc)
185{ 187{
186 atf_tc_set_md_var(tc, "descr", "Test printf a format"); 188 atf_tc_set_md_var(tc, "descr", "Test printf a format");
187} 189}
188 190
189ATF_TC_BODY(snprintf_double_a, tc) 191ATF_TC_BODY(snprintf_double_a, tc)
190{ 192{
191 char buf[1000]; 193 char buf[1000];
192 194
193 snprintf(buf, sizeof buf, "%.3a", (double)10.6); 195 snprintf(buf, sizeof buf, "%.3a", (double)10.6);
194 ATF_REQUIRE_STREQ("0x1.533p+3", buf); 196 ATF_CHECK_MSG((strcmp(buf, "0x1.533p+3") == 0 ||
 197 strcmp(buf, "0x2.a66p+2") == 0 ||
 198 strcmp(buf, "0x5.4ccp+1") == 0 ||
 199 strcmp(buf, "0xa.998p+0") == 0),
 200 "buf=%s", buf);
 201
 202 snprintf(buf, sizeof buf, "%a", (double)0.125);
 203 ATF_CHECK_MSG((strcmp(buf, "0x1p-3") == 0 ||
 204 strcmp(buf, "0x2p-4") == 0 ||
 205 strcmp(buf, "0x4p-5") == 0 ||
 206 strcmp(buf, "0x8p-6") == 0),
 207 "buf=%s", buf);
 208}
 209
 210ATF_TC(snprintf_long_double_a);
 211ATF_TC_HEAD(snprintf_long_double_a, tc)
 212{
 213 atf_tc_set_md_var(tc, "descr", "Test printf La format");
 214}
 215
 216ATF_TC_BODY(snprintf_long_double_a, tc)
 217{
 218 char buf[1000];
 219
 220 atf_tc_expect_fail("PR lib/56937:"
 221 " printf(3) long double %%a formatting is broken");
 222
 223 snprintf(buf, sizeof buf, "%.3La", 10.6L);
 224 ATF_CHECK_MSG((strcmp(buf, "0x1.533p+3") == 0 ||
 225 strcmp(buf, "0x2.a66p+2") == 0 ||
 226 strcmp(buf, "0x5.4ccp+1") == 0 ||
 227 strcmp(buf, "0xa.998p+0") == 0),
 228 "buf=%s", buf);
 229
 230 snprintf(buf, sizeof buf, "%La", 0.125L);
 231 ATF_CHECK_MSG((strcmp(buf, "0x1p-3") == 0 ||
 232 strcmp(buf, "0x2p-4") == 0 ||
 233 strcmp(buf, "0x4p-5") == 0 ||
 234 strcmp(buf, "0x8p-6") == 0),
 235 "buf=%s", buf);
195} 236}
196 237
197/* is "long double" and "double" different? */ 238/* is "long double" and "double" different? */
198#if (__LDBL_MANT_DIG__ != __DBL_MANT_DIG__) || \ 239#if (__LDBL_MANT_DIG__ != __DBL_MANT_DIG__) || \
199 (__LDBL_MAX_EXP__ != __DBL_MAX_EXP__) 240 (__LDBL_MAX_EXP__ != __DBL_MAX_EXP__)
200#define WIDE_DOUBLE 241#define WIDE_DOUBLE
201#endif 242#endif
202 243
203#ifndef WIDE_DOUBLE 244#ifndef WIDE_DOUBLE
204ATF_TC(pr57250_fix); 245ATF_TC(pr57250_fix);
205ATF_TC_HEAD(pr57250_fix, tc) 246ATF_TC_HEAD(pr57250_fix, tc)
206{ 247{
207 atf_tc_set_md_var(tc, "descr", "Test for PR57250"); 248 atf_tc_set_md_var(tc, "descr", "Test for PR57250");
@@ -225,19 +266,20 @@ ATF_TC_BODY(pr57250_fix, tc) @@ -225,19 +266,20 @@ ATF_TC_BODY(pr57250_fix, tc)
225 266
226 267
227ATF_TP_ADD_TCS(tp) 268ATF_TP_ADD_TCS(tp)
228{ 269{
229 270
230 ATF_TP_ADD_TC(tp, snprintf_c99); 271 ATF_TP_ADD_TC(tp, snprintf_c99);
231 ATF_TP_ADD_TC(tp, snprintf_dotzero); 272 ATF_TP_ADD_TC(tp, snprintf_dotzero);
232 ATF_TP_ADD_TC(tp, snprintf_posarg); 273 ATF_TP_ADD_TC(tp, snprintf_posarg);
233 ATF_TP_ADD_TC(tp, snprintf_posarg_width); 274 ATF_TP_ADD_TC(tp, snprintf_posarg_width);
234 ATF_TP_ADD_TC(tp, snprintf_posarg_error); 275 ATF_TP_ADD_TC(tp, snprintf_posarg_error);
235 ATF_TP_ADD_TC(tp, snprintf_float); 276 ATF_TP_ADD_TC(tp, snprintf_float);
236 ATF_TP_ADD_TC(tp, sprintf_zeropad); 277 ATF_TP_ADD_TC(tp, sprintf_zeropad);
237 ATF_TP_ADD_TC(tp, snprintf_double_a); 278 ATF_TP_ADD_TC(tp, snprintf_double_a);
 279 ATF_TP_ADD_TC(tp, snprintf_long_double_a);
238#ifndef WIDE_DOUBLE 280#ifndef WIDE_DOUBLE
239 ATF_TP_ADD_TC(tp, pr57250_fix); 281 ATF_TP_ADD_TC(tp, pr57250_fix);
240#endif 282#endif
241 283
242 return atf_no_error(); 284 return atf_no_error();
243} 285}