From a397c95f8aea58533e72379d6e0de12683ecd0dc Mon Sep 17 00:00:00 2001 From: cvs2svn Date: Sat, 2 Aug 2025 06:16:35 +0000 Subject: This commit was manufactured by cvs2git to create tag 'tb_20250802'. --- src/regress/lib/libc/printf/Makefile | 13 -- src/regress/lib/libc/printf/fp.c | 225 ------------------ src/regress/lib/libc/printf/int.c | 376 ------------------------------ src/regress/lib/libc/printf/string.c | 435 ----------------------------------- 4 files changed, 1049 deletions(-) delete mode 100644 src/regress/lib/libc/printf/Makefile delete mode 100644 src/regress/lib/libc/printf/fp.c delete mode 100644 src/regress/lib/libc/printf/int.c delete mode 100644 src/regress/lib/libc/printf/string.c (limited to 'src/regress/lib/libc/printf') diff --git a/src/regress/lib/libc/printf/Makefile b/src/regress/lib/libc/printf/Makefile deleted file mode 100644 index 5125fc64da..0000000000 --- a/src/regress/lib/libc/printf/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# $OpenBSD: Makefile,v 1.3 2020/07/09 01:49:15 schwarze Exp $ - -PROGS = fp int string - -REGRESS_TARGETS = ${PROGS:S/^/run-regress-/} - -.for p in ${PROGS} -run-regress-${p}: ${p} - ./${p} -.PHONY: run-regress-${p} -.endfor - -.include diff --git a/src/regress/lib/libc/printf/fp.c b/src/regress/lib/libc/printf/fp.c deleted file mode 100644 index 299d05f55d..0000000000 --- a/src/regress/lib/libc/printf/fp.c +++ /dev/null @@ -1,225 +0,0 @@ -/* $OpenBSD: fp.c,v 1.2 2020/05/31 12:27:19 mortimer Exp $ */ -/*- - * Copyright (c) 2002, 2005 David Schultz - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * Test for printf() floating point formats. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define testfmt(result, fmt, ...) \ - _testfmt((result), __LINE__, #__VA_ARGS__, fmt, __VA_ARGS__) -void _testfmt(const char *, int, const char *, const char *, ...); -void smash_stack(void); - -int -main(int argc, char *argv[]) -{ - /* - * Basic tests of decimal output functionality. - */ - testfmt(" 1.000000E+00", "%13E", 1.0); - testfmt(" 1.000000", "%13f", 1.0); - testfmt(" 1", "%13G", 1.0); - testfmt(" 1.000000E+00", "%13LE", 1.0L); - testfmt(" 1.000000", "%13Lf", 1.0L); - testfmt(" 1", "%13LG", 1.0L); - - testfmt("2.718282", "%.*f", -2, 2.7182818); - - testfmt("1.234568e+06", "%e", 1234567.8); - testfmt("1234567.800000", "%f", 1234567.8); - testfmt("1.23457E+06", "%G", 1234567.8); - testfmt("1.234568e+06", "%Le", 1234567.8L); - testfmt("1234567.800000", "%Lf", 1234567.8L); - testfmt("1.23457E+06", "%LG", 1234567.8L); - -#if (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__) - testfmt("123456789.864210", "%Lf", 123456789.8642097531L); - testfmt("-1.23457E+08", "%LG", -123456789.8642097531L); - testfmt("123456789.8642097531", "%.10Lf", 123456789.8642097531L); - testfmt(" 3.141592653589793238e-4000", "%L27.18Le", - 3.14159265358979323846e-4000L); -#endif /* (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__) */ - - /* - * Infinities and NaNs - */ -#ifdef NAN - testfmt("nan", "%e", NAN); - testfmt("NAN", "%F", NAN); - testfmt("nan", "%g", NAN); - testfmt("NAN", "%LE", (long double)NAN); - testfmt(" nan", "%05e", NAN); -#endif /* NAN */ - - testfmt("INF", "%E", HUGE_VAL); - testfmt("-inf", "%f", -HUGE_VAL); - testfmt("+inf", "%+g", HUGE_VAL); - testfmt(" inf", "%4.2Le", HUGE_VALL); - testfmt("-inf", "%Lf", -HUGE_VALL); - testfmt(" inf", "%05e", HUGE_VAL); - testfmt(" -inf", "%05e", -HUGE_VAL); - - /* - * Padding - */ - testfmt("0.000000e+00", "%e", 0.0); - testfmt("0.000000", "%F", (double)0.0); - testfmt("0", "%G", 0.0); - testfmt(" 0", "%3.0Lg", 0.0L); - testfmt(" 0", "%5.0f", 0.001); - - /* - * Precision specifiers - */ - testfmt("1.0123e+00", "%.4e", 1.0123456789); - testfmt("1.0123", "%.4f", 1.0123456789); - testfmt("1.012", "%.4g", 1.0123456789); - testfmt("1.2346e-02", "%.4e", 0.0123456789); - testfmt("0.0123", "%.4f", 0.0123456789); - testfmt("0.01235", "%.4g", 0.0123456789); - - /* - * Signed conversions - */ - testfmt("+2.500000e-01", "%+e", 0.25); - testfmt("+0.000000", "%+F", 0.0); - testfmt("-1", "%+g", -1.0); - - testfmt("-1.000000e+00", "% e", -1.0); - testfmt("+1.000000", "% +f", 1.0); - testfmt(" 1", "% g", 1.0); - testfmt(" 0", "% g", 0.0); - - /* - * ``Alternate form'' - */ - testfmt("1.250e+00", "%#.3e", 1.25); - testfmt("123.000000", "%#f", 123.0); - testfmt(" 12345.", "%#7.5g", 12345.0); - testfmt(" 1.00000", "%#8g", 1.0); - testfmt("0.0", "%#.2g", 0.0); - - /* - * Padding and decimal point placement - */ - testfmt("03.2E+00", "%08.1E", 3.25); - testfmt("003.25", "%06.2F", 3.25); - testfmt("0003.25", "%07.4G", 3.25); - - testfmt("3.14159e-05", "%g", 3.14159e-5); - testfmt("0.000314159", "%g", 3.14159e-4); - testfmt("3.14159e+06", "%g", 3.14159e6); - testfmt("314159", "%g", 3.14159e5); - testfmt("314159.", "%#g", 3.14159e5); - - testfmt(" 9.000000e+03", "%13e", 9000.0); - testfmt(" 9000.000000", "%12f", 9000.0); - testfmt(" 9000", "%5g", 9000.0); - testfmt(" 900000.", "%#8g", 900000.0); - testfmt(" 9e+06", "%6g", 9000000.0); - testfmt(" 9.000000e-04", "%13e", 0.0009); - testfmt(" 0.000900", "%9f", 0.0009); - testfmt(" 0.0009", "%7g", 0.0009); - testfmt(" 9e-05", "%6g", 0.00009); - testfmt(" 9.00000e-05", "%#12g", 0.00009); - testfmt(" 9.e-05", "%#7.1g", 0.00009); - - testfmt(" 0.0", "%4.1f", 0.0); - testfmt("90.0", "%4.1f", 90.0); - testfmt(" 100", "%4.0f", 100.0); - testfmt("9.0e+01", "%4.1e", 90.0); - testfmt("1e+02", "%4.0e", 100.0); - - /* - * Hexadecimal floating point (%a, %A) tests. Some of these - * are only valid if the implementation converts to hex digits - * on nibble boundaries. - */ - testfmt("0x0p+0", "%a", 0x0.0p0); - testfmt("0X0.P+0", "%#LA", 0x0.0p0L); -#ifdef NAN - testfmt("inf", "%La", (long double)INFINITY); - testfmt("+INF", "%+A", INFINITY); - testfmt("nan", "%La", (long double)NAN); - testfmt("NAN", "%A", NAN); -#endif /* NAN */ - - testfmt(" 0x1.23p+0", "%10a", 0x1.23p0); - testfmt(" 0x1.23p-500", "%12a", 0x1.23p-500); - testfmt(" 0x1.2p+40", "%10.1a", 0x1.23p40); - testfmt(" 0X1.230000000000000000000000P-4", "%32.24A", 0x1.23p-4); - testfmt("0x1p-1074", "%a", 0x1p-1074); - testfmt("0x1.2345p-1024", "%a", 0x1.2345p-1024); - -#if LDBL_MANT_DIG == 113 - testfmt("-0x1.e7d7c7b7a7978777675747372717p-14344", "%La", - -0x1.e7d7c7b7a7978777675747372717p-14344L); -#elif LDBL_MANT_DIG == 64 - testfmt("-0x8.777675747372717p-16248", "%La", - -0x8.777675747372717p-16248L); -#endif - - return (0); -} - -void -smash_stack(void) -{ - static uint32_t junk = 0xdeadbeef; - uint32_t buf[512]; - int i; - - for (i = 0; i < sizeof(buf) / sizeof(buf[0]); i++) - buf[i] = junk; -} - -void -_testfmt(const char *result, int line, const char *argstr, const char *fmt,...) -{ - char s[100]; - va_list ap; - - va_start(ap, fmt); - smash_stack(); - vsnprintf(s, sizeof(s), fmt, ap); - if (strcmp(result, s) != 0) { - fprintf(stderr, - "%d: printf(\"%s\", %s) ==> [%s], expected [%s]\n", - line, fmt, argstr, s, result); - abort(); - } -} diff --git a/src/regress/lib/libc/printf/int.c b/src/regress/lib/libc/printf/int.c deleted file mode 100644 index 5a56c8d50e..0000000000 --- a/src/regress/lib/libc/printf/int.c +++ /dev/null @@ -1,376 +0,0 @@ -/* $OpenBSD: int.c,v 1.2 2020/07/14 16:40:04 kettenis Exp $ */ -/* - * Copyright (c) 2020 Ingo Schwarze - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Test the %c, %lc, %s, and %ls conversion specifiers with all their - * modifiers, in particular with the minus flag, width, and maxbytes. - * Also verify that other flags do nothing useful. - */ -#include -#include -#include -#include -#include -#include - -enum int_size { - S_CHAR, - S_SHORT, - S_INT, - S_LONG, - S_LL, - S_MAX, - S_PTR, - S_SIZE -}; - -void ti(const char *, enum int_size, long long, const char *); -void tu(const char *, enum int_size, unsigned long long, const char *); - -static int badret, badlen, badout; /* Error counters. */ -static int verbose; /* For debugging. */ - - -/* - * Print the signed integer i with the format fmt, - * check that the result matches what we want, - * and report and count the error on failure. - */ -void -ti(const char *fmt, enum int_size sz, long long i, const char *want) -{ - char buf[32]; - size_t len; - int irc, happy; - - happy = 1; - switch (sz) { - case S_CHAR: - irc = snprintf(buf, sizeof(buf), fmt, (signed char)i); - break; - case S_SHORT: - irc = snprintf(buf, sizeof(buf), fmt, (short)i); - break; - case S_INT: - irc = snprintf(buf, sizeof(buf), fmt, (int)i); - break; - case S_LONG: - irc = snprintf(buf, sizeof(buf), fmt, (long)i); - break; - case S_LL: - irc = snprintf(buf, sizeof(buf), fmt, (long long)i); - break; - case S_MAX: - irc = snprintf(buf, sizeof(buf), fmt, (intmax_t)i); - break; - case S_PTR: - irc = snprintf(buf, sizeof(buf), fmt, (ptrdiff_t)i); - break; - case S_SIZE: - irc = snprintf(buf, sizeof(buf), fmt, (ssize_t)i); - break; - default: - warnx("printf(\"%s\", %lld) unknown size code %d", - fmt, i, sz); - badret++; - return; - } - len = strlen(want); - if (irc < 0) { - warn("printf(\"%s\", %lld) returned %d", fmt, i, irc); - badret++; - return; - } - if ((unsigned long long)irc != len) { - warnx("printf(\"%s\", %lld) returned %d (expected %zu)", - fmt, i, irc, len); - badlen++; - happy = 0; - } - if (strcmp(buf, want) != 0) { - warnx("printf(\"%s\", %lld) wrote \"%s\" (expected \"%s\")", - fmt, i, buf, want); - badout++; - happy = 0; - } - if (verbose && happy) - warnx("printf(\"%s\", %lld) wrote \"%s\" length %d (OK)", - fmt, i, buf, irc); -} - -/* - * Print the unsigned integer i with the format fmt, - * check that the result matches what we want, - * and report and count the error on failure. - */ -void -tu(const char *fmt, enum int_size sz, unsigned long long i, const char *want) -{ - char buf[32]; - size_t len; - int irc, happy; - - happy = 1; - switch (sz) { - case S_CHAR: - irc = snprintf(buf, sizeof(buf), fmt, (unsigned char)i); - break; - case S_SHORT: - irc = snprintf(buf, sizeof(buf), fmt, (unsigned short)i); - break; - case S_INT: - irc = snprintf(buf, sizeof(buf), fmt, (unsigned int)i); - break; - case S_LONG: - irc = snprintf(buf, sizeof(buf), fmt, (unsigned long)i); - break; - case S_LL: - irc = snprintf(buf, sizeof(buf), fmt, (unsigned long long)i); - break; - case S_MAX: - irc = snprintf(buf, sizeof(buf), fmt, (uintmax_t)i); - break; - case S_SIZE: - irc = snprintf(buf, sizeof(buf), fmt, (size_t)i); - break; - default: - warnx("printf(\"%s\", %llu) unknown size code %d", - fmt, i, sz); - badret++; - return; - } - len = strlen(want); - if (irc < 0) { - warn("printf(\"%s\", %llu) returned %d", fmt, i, irc); - badret++; - return; - } - if ((unsigned long long)irc != len) { - warnx("printf(\"%s\", %llu) returned %d (expected %zu)", - fmt, i, irc, len); - badlen++; - happy = 0; - } - if (strcmp(buf, want) != 0) { - warnx("printf(\"%s\", %llu) wrote \"%s\" (expected \"%s\")", - fmt, i, buf, want); - badout++; - happy = 0; - } - if (verbose && happy) - warnx("printf(\"%s\", %llu) wrote \"%s\" length %d (OK)", - fmt, i, buf, irc); -} - -int -main(int argc, char *argv[]) -{ - int badarg, picky; - int ch; - - badarg = picky = 0; - while ((ch = getopt(argc, argv, "pv")) != -1) { - switch (ch) { - case 'p': - picky = 1; - break; - case 'v': - verbose = 1; - break; - default: - badarg = 1; - break; - } - } - argc -= optind; - argv += optind; - if (argc > 0) { - warnx("unexpected argument \"%s\"", *argv); - badarg = 1; - } - if (badarg) { - fputs("usage: int [-pv]\n", stderr); - return 1; - } - - /* - * Valid use cases of %d. - */ - - ti("<%d>", S_INT, 0, "<0>"); - ti("<%d>", S_INT, 1, "<1>"); - ti("<%d>", S_INT, -1, "<-1>"); - ti("<%d>", S_INT, 42, "<42>"); - ti("<%d>", S_INT, INT32_MAX, "<2147483647>"); - ti("<%d>", S_INT, INT32_MIN, "<-2147483648>"); - ti("<% d>", S_INT, 42, "< 42>"); - ti("<% d>", S_INT, -42, "<-42>"); - ti("<%+d>", S_INT, 42, "<+42>"); - ti("<%+d>", S_INT, -42, "<-42>"); - ti("<% +d>", S_INT, 42, "<+42>"); - ti("<% +d>", S_INT, -42, "<-42>"); - ti("<%-4d>", S_INT, 42, "<42 >"); - ti("<% -4d>", S_INT, 42, "< 42 >"); - ti("<%+-4d>", S_INT, 42, "<+42 >"); - ti("<%04d>", S_INT, 42, "<0042>"); - ti("<%-04d>", S_INT, 42, "<42 >"); - ti("<% 04d>", S_INT, 42, "< 042>"); - ti("<%+04d>", S_INT, 42, "<+042>"); - ti("<%4.3d>", S_INT, 42, "< 042>"); - ti("<% 5.3d>", S_INT, 42, "< 042>"); - ti("<%+5.3d>", S_INT, 42, "< +042>"); - ti("<%-4.3d>", S_INT, 42, "<042 >"); - ti("<%04.3d>", S_INT, 42, "< 042>"); - - ti("<%hhd>", S_CHAR, INT8_MIN, "<-128>"); - ti("<%hhd>", S_CHAR, -1, "<-1>"); - ti("<%hhd>", S_CHAR, 0, "<0>"); - ti("<%hhd>", S_CHAR, 1, "<1>"); - ti("<%hhd>", S_CHAR, INT8_MAX, "<127>"); - ti("<%+.4hhd>", S_CHAR, 42, "<+0042>"); - ti("<% 04hhd>", S_CHAR, 42, "< 042>"); - - ti("<%hd>", S_SHORT, INT16_MIN, "<-32768>"); - ti("<%hd>", S_SHORT, -1, "<-1>"); - ti("<%hd>", S_SHORT, 0, "<0>"); - ti("<%hd>", S_SHORT, 1, "<1>"); - ti("<%hd>", S_SHORT, INT16_MAX, "<32767>"); - - ti("<%hld>", S_LONG, INT32_MIN, "<-2147483648>"); - ti("<%hld>", S_LONG, -1, "<-1>"); - ti("<%hld>", S_LONG, 0, "<0>"); - ti("<%hld>", S_LONG, 1, "<1>"); - ti("<%hld>", S_LONG, INT32_MAX, "<2147483647>"); - - ti("<%hlld>", S_LL, INT64_MIN, "<-9223372036854775808>"); - ti("<%hlld>", S_LL, -1, "<-1>"); - ti("<%hlld>", S_LL, 0, "<0>"); - ti("<%hlld>", S_LL, 1, "<1>"); - ti("<%hlld>", S_LL, INT64_MAX, "<9223372036854775807>"); - ti("<%h-19lld>", S_LL, 123456789123456789LL, "<123456789123456789 >"); - - ti("<%hjd>", S_MAX, INT64_MIN, "<-9223372036854775808>"); - ti("<%hjd>", S_MAX, -1, "<-1>"); - ti("<%hjd>", S_MAX, 0, "<0>"); - ti("<%hjd>", S_MAX, 1, "<1>"); - ti("<%hjd>", S_MAX, INT64_MAX, "<9223372036854775807>"); - - ti("<%htd>", S_PTR, INT32_MIN, "<-2147483648>"); - ti("<%htd>", S_PTR, -1, "<-1>"); - ti("<%htd>", S_PTR, 0, "<0>"); - ti("<%htd>", S_PTR, 1, "<1>"); - ti("<%htd>", S_PTR, INT32_MAX, "<2147483647>"); - - ti("<%hzd>", S_SIZE, INT32_MIN, "<-2147483648>"); - ti("<%hzd>", S_SIZE, -1, "<-1>"); - ti("<%hzd>", S_SIZE, 0, "<0>"); - ti("<%hzd>", S_SIZE, 1, "<1>"); - ti("<%hzd>", S_SIZE, INT32_MAX, "<2147483647>"); - - /* - * Undefined behaviour of %d. - * Do not test by default to avoid noise. - * But provide the tests anyway to help track down - * unintended changes of behaviour when needed. - */ - - if (picky) { - ti("<%#d>", S_INT, 42, "<42>"); - ti("<%Ld>", S_INT, 42, "<42>"); - } - - /* - * Valid use cases of %u. - */ - - tu("<%u>", S_INT, 0, "<0>"); - tu("<%u>", S_INT, 1, "<1>"); - tu("<%u>", S_INT, 42, "<42>"); - tu("<%u>", S_INT, UINT32_MAX, "<4294967295>"); - tu("<%-4u>", S_INT, 42, "<42 >"); - tu("<%04u>", S_INT, 42, "<0042>"); - tu("<%-04u>", S_INT, 42, "<42 >"); - tu("<%4.3u>", S_INT, 42, "< 042>"); - tu("<%-4.3u>", S_INT, 42, "<042 >"); - tu("<%04.3u>", S_INT, 42, "< 042>"); - - tu("<%hhu>", S_CHAR, 0, "<0>"); - tu("<%hhu>", S_CHAR, UINT8_MAX, "<255>"); - tu("<%hhu>", S_CHAR, -1, "<255>"); - tu("<%-4hhu>", S_CHAR, 42, "<42 >"); - tu("<%04hhu>", S_CHAR, 42, "<0042>"); - - tu("<%hu>", S_SHORT, 0, "<0>"); - tu("<%hu>", S_SHORT, UINT16_MAX, "<65535>"); - tu("<%hlu>", S_LONG, 0, "<0>"); - tu("<%hlu>", S_LONG, UINT32_MAX, "<4294967295>"); - tu("<%hllu>", S_LL, 0, "<0>"); - tu("<%hllu>", S_LL, UINT64_MAX, "<18446744073709551615>"); - tu("<%h-19llu>", S_LL, 123456789123456789ULL, "<123456789123456789 >"); - tu("<%hju>", S_MAX, 0, "<0>"); - tu("<%hju>", S_MAX, UINT64_MAX, "<18446744073709551615>"); - tu("<%hzu>", S_SIZE, 0, "<0>"); - tu("<%hzu>", S_SIZE, UINT32_MAX, "<4294967295>"); - - tu("<%hho>", S_CHAR, 0, "<0>"); - tu("<%#hho>", S_CHAR, 0, "<0>"); - tu("<%hho>", S_CHAR, UINT8_MAX, "<377>"); - tu("<%#hho>", S_CHAR, UINT8_MAX, "<0377>"); - tu("<%hho>", S_CHAR, -1, "<377>"); - tu("<%#hho>", S_CHAR, -1, "<0377>"); - tu("<%-4hho>", S_CHAR, 42, "<52 >"); - tu("<%#-4hho>", S_CHAR, 42, "<052 >"); - tu("<%04hho>", S_CHAR, 42, "<0052>"); - tu("<%#04hho>", S_CHAR, 42, "<0052>"); - - tu("<%hx>", S_SHORT, 0, "<0>"); - tu("<%#hx>", S_SHORT, 0, "<0>"); - tu("<%hX>", S_SHORT, 0, "<0>"); - tu("<%#hX>", S_SHORT, 0, "<0>"); - tu("<%hx>", S_SHORT, 1, "<1>"); - tu("<%#hx>", S_SHORT, 1, "<0x1>"); - tu("<%hX>", S_SHORT, 1, "<1>"); - tu("<%#hX>", S_SHORT, 1, "<0X1>"); - tu("<%hx>", S_SHORT, 10, ""); - tu("<%#hx>", S_SHORT, 10, "<0xa>"); - tu("<%hX>", S_SHORT, 10, ""); - tu("<%#hX>", S_SHORT, 10, "<0XA>"); - tu("<%hx>", S_SHORT, UINT16_MAX, ""); - tu("<%#hx>", S_SHORT, UINT16_MAX, "<0xffff>"); - tu("<%hX>", S_SHORT, UINT16_MAX, ""); - tu("<%#hX>", S_SHORT, UINT16_MAX, "<0XFFFF>"); - - /* - * Undefined behaviour of %u. - */ - - if (picky) { - tu("<%#u>", S_INT, 42, "<42>"); - tu("<% u>", S_INT, 42, "<42>"); - tu("<%+u>", S_INT, 42, "<42>"); - tu("<%Lu>", S_INT, 42, "<42>"); - } - - /* - * Summarize the results. - */ - - if (badret + badlen + badout) - errx(1, "ERRORS: %d fail + %d mismatch (incl. %d bad length)", - badret, badout, badlen); - else if (verbose) - warnx("SUCCESS"); - return 0; -} diff --git a/src/regress/lib/libc/printf/string.c b/src/regress/lib/libc/printf/string.c deleted file mode 100644 index 6e65a371a4..0000000000 --- a/src/regress/lib/libc/printf/string.c +++ /dev/null @@ -1,435 +0,0 @@ -/* $OpenBSD: string.c,v 1.2 2020/07/14 16:40:04 kettenis Exp $ */ -/* - * Copyright (c) 2020 Ingo Schwarze - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Test the %c, %lc, %s, and %ls conversion specifiers with all their - * modifiers, in particular with the minus flag, width, and maxbytes. - * Also verify that other flags do nothing useful. - */ -#include -#include -#include -#include -#include -#include -#include -#include - -void tc(const char *, int, const char *); -void tlc(const char *, wint_t, const char *); -void tlc_expect_fail(const char *, wint_t); -void ts(const char *, const char *, const char *); -void tls(const char *, const wchar_t *, const char *); -void tls_expect_fail(const char *, const wchar_t *); - -static int badret, badlen, badout; /* Error counters. */ -static int verbose; /* For debugging. */ - - -/* - * Print the single-byte character c with the format fmt, - * check that the result matches what we want, - * and report and count the error on failure. - */ -void -tc(const char *fmt, int c, const char *want) -{ - char buf[32]; - size_t len; - int irc, happy; - - happy = 1; - irc = snprintf(buf, sizeof(buf), fmt, c); - len = strlen(want); - if (irc < 0) { - warn("printf(\"%s\", %d) returned %d", fmt, c, irc); - badret++; - return; - } - if ((unsigned long long)irc != len) { - warnx("printf(\"%s\", %d) returned %d (expected %zu)", - fmt, c, irc, len); - badlen++; - happy = 0; - } - if (strcmp(buf, want) != 0) { - warnx("printf(\"%s\", %d) wrote \"%s\" (expected \"%s\")", - fmt, c, buf, want); - badout++; - happy = 0; - } - if (verbose && happy) - warnx("printf(\"%s\", %d) wrote \"%s\" length %d (OK)", - fmt, c, buf, irc); -} - -/* - * Print the wide character wc with the format fmt, - * check that the result matches what we want, - * and report and count the error on failure. - */ -void -tlc(const char *fmt, wint_t wc, const char *want) -{ - char buf[32]; - const char *charset; - size_t len; - int irc, happy; - - happy = 1; - charset = MB_CUR_MAX > 1 ? "UTF-8" : "ASCII"; - irc = snprintf(buf, sizeof(buf), fmt, wc); - len = strlen(want); - if (irc < 0) { - warn("%s printf(\"%s\", U+%.4X) returned %d", - charset, fmt, (unsigned int)wc, irc); - badret++; - return; - } - if ((unsigned long long)irc != len) { - warnx("%s printf(\"%s\", U+%.4X) returned %d (expected %zu)", - charset, fmt, (unsigned int)wc, irc, len); - badlen++; - happy = 0; - } - if (strcmp(buf, want) != 0) { - warnx("%s printf(\"%s\", U+%.4X) " - "wrote \"%s\" (expected \"%s\")", - charset, fmt, (unsigned int)wc, buf, want); - badout++; - happy = 0; - } - if (verbose && happy) - warnx("%s printf(\"%s\", U+%.4X) wrote \"%s\" length %d (OK)", - charset, fmt, (unsigned int)wc, buf, irc); -} - -/* - * Try to print the invalid wide character wc with the format fmt, - * check that it fails as it should, and report and count if it doesn't. - */ -void -tlc_expect_fail(const char *fmt, wint_t wc) -{ - char buf[32]; - const char *charset; - int irc; - - errno = 0; - charset = MB_CUR_MAX > 1 ? "UTF-8" : "ASCII"; - irc = snprintf(buf, sizeof(buf), fmt, wc); - if (irc != -1) { - warn("%s printf(\"%s\", U+%.4X) returned %d", - charset, fmt, (unsigned int)wc, irc); - badret++; - } else if (errno != EILSEQ) { - warnx("%s printf(\"%s\", U+%.4X) errno %d (expected %d)", - charset, fmt, (unsigned int)wc, errno, EILSEQ); - badret++; - } else if (verbose) - warnx("%s printf(\"%s\", U+%.4X) returned %d errno %d (OK)", - charset, fmt, (unsigned int)wc, irc, errno); -} - -/* - * Print the string s with the format fmt, - * check that the result matches what we want, - * and report and count the error on failure. - */ -void -ts(const char *fmt, const char *s, const char *want) -{ - char buf[32]; - size_t len; - int irc, happy; - - happy = 1; - irc = snprintf(buf, sizeof(buf), fmt, s); - len = strlen(want); - if (irc < 0) { - warn("printf(\"%s\", \"%s\") returned %d", fmt, s, irc); - badret++; - return; - } - if ((unsigned long long)irc != len) { - warnx("printf(\"%s\", \"%s\") returned %d (expected %zu)", - fmt, s, irc, len); - badlen++; - happy = 0; - } - if (strcmp(buf, want) != 0) { - warnx("printf(\"%s\", \"%s\") wrote \"%s\" (expected \"%s\")", - fmt, s, buf, want); - badout++; - happy = 0; - } - if (verbose && happy) - warnx("printf(\"%s\", \"%s\") wrote \"%s\" length %d (OK)", - fmt, s, buf, irc); -} - -/* - * Print the wide character string ws with the format fmt, - * check that the result matches what we want, - * and report and count the error on failure. - */ -void -tls(const char *fmt, const wchar_t *ws, const char *want) -{ - char buf[32]; - const char *charset; - size_t len; - int irc, happy; - - happy = 1; - charset = MB_CUR_MAX > 1 ? "UTF-8" : "ASCII"; - irc = snprintf(buf, sizeof(buf), fmt, ws); - len = strlen(want); - if (irc < 0) { - warn("%s printf(\"%s\", \"%ls\") returned %d", - charset, fmt, ws, irc); - badret++; - return; - } - if ((unsigned long long)irc != len) { - warnx("%s printf(\"%s\", \"%ls\") returned %d (expected %zu)", - charset, fmt, ws, irc, len); - badlen++; - happy = 0; - } - if (strcmp(buf, want) != 0) { - warnx("%s printf(\"%s\", \"%ls\") " - "wrote \"%s\" (expected \"%s\")", - charset, fmt, ws, buf, want); - badout++; - happy = 0; - } - if (verbose && happy) - warnx("%s printf(\"%s\", \"%ls\") wrote \"%s\" length %d (OK)", - charset, fmt, ws, buf, irc); -} - -/* - * Try to print the invalid wide character string ws with the format fmt, - * check that it fails as it should, and report and count if it doesn't. - */ -void -tls_expect_fail(const char *fmt, const wchar_t *ws) -{ - char buf[32]; - const char *charset; - int irc; - - errno = 0; - charset = MB_CUR_MAX > 1 ? "UTF-8" : "ASCII"; - irc = snprintf(buf, sizeof(buf), fmt, ws); - if (irc != -1) { - warn("%s printf(\"%s\", U+%.4X, ...) returned %d", - charset, fmt, (unsigned int)*ws, irc); - badret++; - } else if (errno != EILSEQ) { - warnx("%s printf(\"%s\", U+%.4X, ...) errno %d (expected %d)", - charset, fmt, (unsigned int)*ws, errno, EILSEQ); - badret++; - } else if (verbose) - warnx("%s printf(\"%s\", U+%.4X, ...) " - "returned %d errno %d (OK)", - charset, fmt, (unsigned int)*ws, irc, errno); -} - -int -main(int argc, char *argv[]) -{ - const wchar_t ws[] = { 0x0421, 0x043e, 0x0444, 0x044f, 0 }; - const wchar_t wsbad[] = { 0x0391, 0xdeef, 0x3c9, 0 }; - int badarg, picky; - int ch; - - badarg = picky = 0; - while ((ch = getopt(argc, argv, "pv")) != -1) { - switch (ch) { - case 'p': - picky = 1; - break; - case 'v': - verbose = 1; - break; - default: - badarg = 1; - break; - } - } - argc -= optind; - argv += optind; - if (argc > 0) { - warnx("unexpected argument \"%s\"", *argv); - badarg = 1; - } - if (badarg) { - fputs("usage: string [-pv]\n", stderr); - return 1; - } - - /* - * Valid use cases of %c and %s. - */ - - tc("<%c>", '=', "<=>"); - tc("<%c>", '\t', "<\t>"); - tc("<%c>", 0xfe, "<\xfe>"); - tc("<%-c>", '=', "<=>"); - tc("<%2c>", '=', "< =>"); - tc("<%-2c>", '=', "<= >"); - - ts("<%s>", "text", ""); - ts("<%-s>", "text", ""); - ts("<%6s>", "text", "< text>"); - ts("<%-6s>", "text", ""); - ts("<%.2s>", "text", ""); - ts("<%4.2s>", "text", "< te>"); - ts("<%-4.2s>", "text", ""); - - /* - * Undefined behaviour of %c and %s. - * Do not test by default to avoid noise. - * But provide the tests anyway to help track down - * unintended changes of behaviour when needed. - */ - - if (picky) { - tc("<%#c>", '=', "<=>"); - tc("<% -3c>", '=', "<= >"); - tc("<%+-3c>", '=', "<= >"); - tc("<%03c>", '=', "<00=>"); - tc("<%-03c>", '=', "<= >"); - tc("<%3.2c>", '=', "< =>"); - tc("<%hc>", '=', "<=>"); - - ts("<%#s>", "text", ""); - ts("<% -6s>", "text", ""); - ts("<%+-6s>", "text", ""); - ts("<%06s>", "text", "<00text>"); - ts("<%-06s>", "text", ""); - ts("<%hs>", "text", ""); - } - - /* - * Valid use cases of %lc and %ls in the POSIX locale. - */ - - tlc("<%lc>", L'=', "<=>"); - tlc("<%lc>", L'\t', "<\t>"); - tlc_expect_fail("<%lc>", 0x03c0); - tlc("<%-lc>", L'=', "<=>"); - tlc("<%2lc>", L'=', "< =>"); - tlc("<%-2lc>", L'=', "<= >"); - - tls("<%ls>", L"text", ""); - tls_expect_fail("<%ls>", ws); - tls_expect_fail("<%ls>", wsbad); - tls("<%-ls>", L"text", ""); - tls("<%6ls>", L"text", "< text>"); - tls("<%-6ls>", L"text", ""); - tls("<%.2ls>", L"text", ""); - tls("<%4.2ls>", L"text", "< te>"); - tls("<%-4.2ls>", L"text", ""); - - /* - * Undefined behaviour of %lc and %ls in the POSIX locale. - */ - - if (picky) { - tlc("<%lc>", 0x00fe, "<\xfe>"); - tlc("<%#lc>", L'=', "<=>"); - tlc("<% -3lc>", L'=', "<= >"); - tlc("<%+-3lc>", L'=', "<= >"); - tlc("<%03lc>", L'=', "<00=>"); - tlc("<%-03lc>", L'=', "<= >"); - tlc("<%3.2lc>", L'=', "< =>"); - tc("<%llc>", '=', "<=>"); - - tls("<%#ls>", L"text", ""); - tls("<% -6ls>", L"text", ""); - tls("<%+-6ls>", L"text", ""); - tls("<%06ls>", L"text", "<00text>"); - tls("<%-06ls>", L"text", ""); - ts("<%lls>", "text", ""); - } - - /* - * Valid use cases of %lc and %ls in a UTF-8 locale. - */ - - if (setlocale(LC_CTYPE, "C.UTF-8") == NULL) - err(1, "setlocale"); - - tlc("<%lc>", L'=', "<=>"); - tlc("<%lc>", L'\t', "<\t>"); - tlc("<%lc>", 0x00fe, "<\xc3\xbe>"); - tlc("<%lc>", 0x03c0, "<\xcf\x80>"); - tlc_expect_fail("<%lc>", 0x123456); - tlc("<%-lc>", L'=', "<=>"); - tlc("<%-lc>", 0x03c0, "<\xcf\x80>"); - tlc("<%2lc>", L'=', "< =>"); - tlc("<%3lc>", 0x03c0, "< \xcf\x80>"); - tlc("<%-2lc>", L'=', "<= >"); - tlc("<%-3lc>", 0x03c0, "<\xcf\x80 >"); - - tls("<%ls>", ws, "<\xd0\xa1\xd0\xbe\xd1\x84\xd1\x8f>"); - tls_expect_fail("<%ls>", wsbad); - tls("<%-ls>", ws, "<\xd0\xa1\xd0\xbe\xd1\x84\xd1\x8f>"); - tls("<%9ls>", ws, "< \xd0\xa1\xd0\xbe\xd1\x84\xd1\x8f>"); - tls("<%-9ls>", ws, "<\xd0\xa1\xd0\xbe\xd1\x84\xd1\x8f >"); - tls("<%.4ls>", ws, "<\xd0\xa1\xd0\xbe>"); - tls("<%.3ls>", ws, "<\xd0\xa1>"); - tls("<%6.4ls>", ws, "< \xd0\xa1\xd0\xbe>"); - tls("<%3.3ls>", ws, "< \xd0\xa1>"); - tls("<%-6.4ls>", ws, "<\xd0\xa1\xd0\xbe >"); - tls("<%-3.3ls>", ws, "<\xd0\xa1 >"); - - /* - * Undefined behaviour of %lc and %ls in a UTF-8 locale. - */ - - if (picky) { - tlc("<%#lc>", 0x03c0, "<\xcf\x80>"); - tlc("<% -4lc>", 0x03c0, "<\xcf\x80 >"); - tlc("<%+-4lc>", 0x03c0, "<\xcf\x80 >"); - tlc("<%04lc>", 0x03c0, "<00\xcf\x80>"); - tlc("<%-04lc>", 0x03c0, "<\xcf\x80 >"); - tlc("<%4.5lc>", 0x03c0, "< \xcf\x80>"); - tlc("<%4.3lc>", 0x03c0, "< \xcf\x80>"); - tlc("<%4.1lc>", 0x03c0, "< \xcf\x80>"); - tc("<%llc>", 0xfe, "<\xfe>"); - - tls("<%#ls>", ws + 2, "<\xd1\x84\xd1\x8f>"); - tls("<% -6ls>", ws + 2, "<\xd1\x84\xd1\x8f >"); - tls("<%+-6ls>", ws + 2, "<\xd1\x84\xd1\x8f >"); - tls("<%06ls>", ws + 2, "<00\xd1\x84\xd1\x8f>"); - tls("<%-06ls>", ws + 2, "<\xd1\x84\xd1\x8f >"); - ts("<%lls>", "text", ""); - } - - /* - * Summarize the results. - */ - - if (badret + badlen + badout) - errx(1, "ERRORS: %d fail + %d mismatch (incl. %d bad length)", - badret, badout, badlen); - else if (verbose) - warnx("SUCCESS"); - return 0; -} -- cgit v1.2.3-55-g6feb