diff options
author | Maciej W. Rozycki <macro@redhat.com> | 2025-09-05 11:53:31 +0100 |
---|---|---|
committer | Maciej W. Rozycki <macro@redhat.com> | 2025-09-05 11:53:31 +0100 |
commit | 2d47b01de020c2e07f25e4b8904419b707920ec4 (patch) | |
tree | 06aecaaeac19dc6eb4e01066bd0af68c2bfc231a | |
parent | fe709cc24578ecfd2ff5b07e10e3829fcb55075b (diff) | |
download | glibc-2d47b01de020c2e07f25e4b8904419b707920ec4.zip glibc-2d47b01de020c2e07f25e4b8904419b707920ec4.tar.gz glibc-2d47b01de020c2e07f25e4b8904419b707920ec4.tar.bz2 |
testsuite: Update tests for 'xfmemopen' use
Convert tests to use 'xfmemopen' rather than open-coding error checks
with 'fmemopen' or plain missing them, where 'fmemopen' itself is not
the scope of testing. Leave 'fmemopen' tests alone.
Reviewed-by: Florian Weimer <fweimer@redhat.com>
-rw-r--r-- | elf/tst-audit18.c | 3 | ||||
-rw-r--r-- | elf/tst-audit19b.c | 3 | ||||
-rw-r--r-- | elf/tst-audit22.c | 3 | ||||
-rw-r--r-- | elf/tst-audit23.c | 6 | ||||
-rw-r--r-- | elf/tst-audit25.h | 3 | ||||
-rw-r--r-- | elf/tst-pldd.c | 4 | ||||
-rw-r--r-- | libio/tst-getdelim.c | 4 | ||||
-rw-r--r-- | localedata/tst-bz12701-lc.c | 12 | ||||
-rw-r--r-- | localedata/tst-bz13988.c | 3 | ||||
-rw-r--r-- | localedata/tst-scanf-width-digit.c | 5 | ||||
-rw-r--r-- | localedata/tst-scanf-width-point.c | 5 | ||||
-rw-r--r-- | misc/tst-mntent-escape.c | 9 | ||||
-rw-r--r-- | misc/tst-syslog.c | 4 | ||||
-rw-r--r-- | stdio-common/bug26.c | 4 | ||||
-rw-r--r-- | stdio-common/tst-bz12701-c.c | 12 | ||||
-rw-r--r-- | stdio-common/tst-fgets.c | 4 |
16 files changed, 31 insertions, 53 deletions
diff --git a/elf/tst-audit18.c b/elf/tst-audit18.c index 0b06999..7d71a7f 100644 --- a/elf/tst-audit18.c +++ b/elf/tst-audit18.c @@ -103,8 +103,7 @@ do_test (int argc, char *argv[]) /* Some hooks are called more than once but the test only check if any is called at least once. */ - FILE *out = fmemopen (result.err.buffer, result.err.length, "r"); - TEST_VERIFY (out != NULL); + FILE *out = xfmemopen (result.err.buffer, result.err.length, "r"); char *buffer = NULL; size_t buffer_length = 0; while (xgetline (&buffer, &buffer_length, out)) diff --git a/elf/tst-audit19b.c b/elf/tst-audit19b.c index aefdddc..b3097c8 100644 --- a/elf/tst-audit19b.c +++ b/elf/tst-audit19b.c @@ -74,8 +74,7 @@ do_test (int argc, char *argv[]) bool find_symbind = false; - FILE *out = fmemopen (result.err.buffer, result.err.length, "r"); - TEST_VERIFY (out != NULL); + FILE *out = xfmemopen (result.err.buffer, result.err.length, "r"); char *buffer = NULL; size_t buffer_length = 0; while (xgetline (&buffer, &buffer_length, out)) diff --git a/elf/tst-audit22.c b/elf/tst-audit22.c index 5e80204..e5cc8a3 100644 --- a/elf/tst-audit22.c +++ b/elf/tst-audit22.c @@ -95,8 +95,7 @@ do_test (int argc, char *argv[]) bool vdso_audit_found = false; uintptr_t vdso_audit = 0; - FILE *out = fmemopen (result.err.buffer, result.err.length, "r"); - TEST_VERIFY (out != NULL); + FILE *out = xfmemopen (result.err.buffer, result.err.length, "r"); char *buffer = NULL; size_t buffer_length = 0; while (xgetline (&buffer, &buffer_length, out)) diff --git a/elf/tst-audit23.c b/elf/tst-audit23.c index aef52de..0a26a2d 100644 --- a/elf/tst-audit23.c +++ b/elf/tst-audit23.c @@ -91,8 +91,7 @@ do_one_test (int argc, char *argv[], bool pass_dlclose_flag) support_capture_subprocess_check (&result, "tst-audit22", 0, sc_allow_stderr); { - FILE *fp = fmemopen (result.err.buffer, result.err.length, "r"); - TEST_VERIFY (fp != NULL); + FILE *fp = xfmemopen (result.err.buffer, result.err.length, "r"); unsigned int line = 0; char *buffer = NULL; size_t buffer_length = 0; @@ -132,8 +131,7 @@ do_one_test (int argc, char *argv[], bool pass_dlclose_flag) uintptr_t last_act_cookie = -1; bool seen_first_objclose = false; - FILE *out = fmemopen (result.err.buffer, result.err.length, "r"); - TEST_VERIFY (out != NULL); + FILE *out = xfmemopen (result.err.buffer, result.err.length, "r"); char *buffer = NULL; size_t buffer_length = 0; unsigned int line = 0; diff --git a/elf/tst-audit25.h b/elf/tst-audit25.h index c14b6a5..b9cd11d 100644 --- a/elf/tst-audit25.h +++ b/elf/tst-audit25.h @@ -19,8 +19,7 @@ static void compare_output (void *buffer, size_t length, const char *ref[], size_t reflen) { - FILE *in = fmemopen (buffer, length, "r"); - TEST_VERIFY_EXIT (in != NULL); + FILE *in = xfmemopen (buffer, length, "r"); char *line = NULL; size_t linelen = 0; diff --git a/elf/tst-pldd.c b/elf/tst-pldd.c index 8c1e33b..3326ff9 100644 --- a/elf/tst-pldd.c +++ b/elf/tst-pldd.c @@ -31,6 +31,7 @@ #include <support/check.h> #include <support/support.h> #include <support/xptrace.h> +#include <support/xstdio.h> #include <support/xunistd.h> #include <sys/mman.h> #include <errno.h> @@ -113,8 +114,7 @@ do_test (void) #define STRINPUT(size) XSTRINPUT(size) #define XSTRINPUT(size) "%" # size "s" - FILE *out = fmemopen (pldd.out.buffer, pldd.out.length, "r"); - TEST_VERIFY (out != NULL); + FILE *out = xfmemopen (pldd.out.buffer, pldd.out.length, "r"); /* First line is in the form of <pid>: <full path of executable> */ TEST_COMPARE (fscanf (out, "%u: " STRINPUT (BUFFERLEN), &pid, buffer), 2); diff --git a/libio/tst-getdelim.c b/libio/tst-getdelim.c index e1ec267..829b12c 100644 --- a/libio/tst-getdelim.c +++ b/libio/tst-getdelim.c @@ -26,6 +26,7 @@ #include <support/check.h> #include <support/support.h> #include <support/test-driver.h> +#include <support/xstdio.h> static int do_test (void) @@ -41,8 +42,7 @@ do_test (void) char *lineptr = NULL; size_t linelen = 0; char membuf[] = "abc\0d\nef\0"; - FILE *memstream = fmemopen (membuf, sizeof (membuf), "r"); - TEST_VERIFY_EXIT (memstream != NULL); + FILE *memstream = xfmemopen (membuf, sizeof (membuf), "r"); TEST_VERIFY (getdelim (&lineptr, &linelen, '\0', memstream) != -1); TEST_COMPARE_BLOB (lineptr, 4, "abc\0", 4); TEST_VERIFY (getdelim (&lineptr, &linelen, '\0', memstream) != -1); diff --git a/localedata/tst-bz12701-lc.c b/localedata/tst-bz12701-lc.c index fcc9f29..686843a 100644 --- a/localedata/tst-bz12701-lc.c +++ b/localedata/tst-bz12701-lc.c @@ -84,9 +84,7 @@ do_test (void) memcpy (ntfi.buffer, s, sizeof (s)); ic = i = 0; - f = fmemopen (b, sizeof (s), "r"); - if (f == NULL) - FAIL_EXIT1 ("fmemopen: %m"); + f = xfmemopen (b, sizeof (s), "r"); c = e - 1; TEST_VERIFY_EXIT (ftell (f) == i); @@ -168,9 +166,7 @@ do_test (void) xfclose (f); ic = i = 0; - f = fmemopen (b, 3, "r"); - if (f == NULL) - FAIL_EXIT1 ("fmemopen: %m"); + f = xfmemopen (b, 3, "r"); c = e - 2; TEST_VERIFY_EXIT (ftell (f) == i); @@ -192,9 +188,7 @@ do_test (void) xfclose (f); ic = i = 0; - f = fmemopen (b, 3, "r"); - if (f == NULL) - FAIL_EXIT1 ("fmemopen: %m"); + f = xfmemopen (b, 3, "r"); c = e - 1; TEST_VERIFY_EXIT (ftell (f) == i); diff --git a/localedata/tst-bz13988.c b/localedata/tst-bz13988.c index 8d6f399..43ab593 100644 --- a/localedata/tst-bz13988.c +++ b/localedata/tst-bz13988.c @@ -22,6 +22,7 @@ #include <libc-diag.h> #include <support/check.h> +#include <support/xstdio.h> #define PD "\xd9\xab" @@ -32,7 +33,7 @@ do_test (void) FAIL_EXIT1 ("setlocale (LC_ALL, \"fa_IR.UTF-8\")"); char s[] = "+" PD "e"; - FILE *f = fmemopen (s, strlen (s), "r"); + FILE *f = xfmemopen (s, strlen (s), "r"); /* Avoid: "warning: 'I' flag used with '%f' gnu_scanf format [-Wformat=]"; cf. GCC PR c/119514. */ diff --git a/localedata/tst-scanf-width-digit.c b/localedata/tst-scanf-width-digit.c index e52edfe..f9883a1 100644 --- a/localedata/tst-scanf-width-digit.c +++ b/localedata/tst-scanf-width-digit.c @@ -22,6 +22,7 @@ #include <libc-diag.h> #include <support/check.h> +#include <support/xstdio.h> #define P1 "\xdb\xb1" #define P2 "\xdb\xb2" @@ -33,9 +34,7 @@ do_test (void) FAIL_EXIT1 ("setlocale (LC_ALL, \"fa_IR.UTF-8\")"); char s[] = P1 P2; - FILE *f = fmemopen (s, strlen (s), "r"); - if (f == NULL) - FAIL_EXIT1 ("fmemopen: %m"); + FILE *f = xfmemopen (s, strlen (s), "r"); /* Avoid: "warning: 'I' flag used with '%f' gnu_scanf format [-Wformat=]"; cf. GCC PR c/119514. */ diff --git a/localedata/tst-scanf-width-point.c b/localedata/tst-scanf-width-point.c index 090c9e0..9469527 100644 --- a/localedata/tst-scanf-width-point.c +++ b/localedata/tst-scanf-width-point.c @@ -22,6 +22,7 @@ #include <libc-diag.h> #include <support/check.h> +#include <support/xstdio.h> #define PD "\xd9\xab" @@ -32,9 +33,7 @@ do_test (void) FAIL_EXIT1 ("setlocale (LC_ALL, \"ps_AF.UTF-8\")"); char s[] = "1" PD; - FILE *f = fmemopen (s, strlen (s), "r"); - if (f == NULL) - FAIL_EXIT1 ("fmemopen: %m"); + FILE *f = xfmemopen (s, strlen (s), "r"); /* This should succeed parsing a floating-point number, and leave '\xd9', '\xab' in the input. */ diff --git a/misc/tst-mntent-escape.c b/misc/tst-mntent-escape.c index 75363d3..13996ca 100644 --- a/misc/tst-mntent-escape.c +++ b/misc/tst-mntent-escape.c @@ -21,6 +21,7 @@ #include <stdio.h> #include <string.h> #include <support/check.h> +#include <support/xstdio.h> struct const_mntent { @@ -54,13 +55,7 @@ do_test (void) { char buf[128]; struct mntent *ret, curtest; - FILE *fp = fmemopen (buf, sizeof (buf), "w+"); - - if (fp == NULL) - { - printf ("Failed to open file\n"); - return 1; - } + FILE *fp = xfmemopen (buf, sizeof (buf), "w+"); curtest.mnt_fsname = strdupa (tests[i].mnt_fsname); curtest.mnt_dir = strdupa (tests[i].mnt_dir); diff --git a/misc/tst-syslog.c b/misc/tst-syslog.c index 97aae0d..56454f4 100644 --- a/misc/tst-syslog.c +++ b/misc/tst-syslog.c @@ -520,9 +520,7 @@ check_syslog_perror (bool large) : send_openlog_callback, &(int){LOG_PERROR}); - FILE *mfp = fmemopen (result.err.buffer, result.err.length, "r"); - if (mfp == NULL) - FAIL_EXIT1 ("fmemopen: %m"); + FILE *mfp = xfmemopen (result.err.buffer, result.err.length, "r"); if (large) check_syslog_console_read_large (mfp); else diff --git a/stdio-common/bug26.c b/stdio-common/bug26.c index 74a00d0..ea0367e 100644 --- a/stdio-common/bug26.c +++ b/stdio-common/bug26.c @@ -18,6 +18,8 @@ #include <stdio.h> #include <string.h> +#include <support/xstdio.h> + int main (void) { @@ -27,7 +29,7 @@ main (void) double d; char s[] = "+.e"; - f = fmemopen (s, strlen (s), "r"); + f = xfmemopen (s, strlen (s), "r"); /* This should fail to parse a floating-point number, and leave 'e' in the input. */ lost |= (fscanf (f, "%lf", &d) != 0); diff --git a/stdio-common/tst-bz12701-c.c b/stdio-common/tst-bz12701-c.c index ffb4330..742111a 100644 --- a/stdio-common/tst-bz12701-c.c +++ b/stdio-common/tst-bz12701-c.c @@ -45,9 +45,7 @@ do_test (void) memcpy (ntfi.buffer, s, sizeof (s)); i = 0; - f = fmemopen (b, sizeof (s), "r"); - if (f == NULL) - FAIL_EXIT1 ("fmemopen: %m"); + f = xfmemopen (b, sizeof (s), "r"); c = e - 1; TEST_VERIFY_EXIT (ftell (f) == i); @@ -114,9 +112,7 @@ do_test (void) xfclose (f); i = 0; - f = fmemopen (b, 3, "r"); - if (f == NULL) - FAIL_EXIT1 ("fmemopen: %m"); + f = xfmemopen (b, 3, "r"); c = e - 1; TEST_VERIFY_EXIT (ftell (f) == i); @@ -144,9 +140,7 @@ do_test (void) xfclose (f); i = 0; - f = fmemopen (b, 3, "r"); - if (f == NULL) - FAIL_EXIT1 ("fmemopen: %m"); + f = xfmemopen (b, 3, "r"); c = e - 2; TEST_VERIFY_EXIT (ftell (f) == i); diff --git a/stdio-common/tst-fgets.c b/stdio-common/tst-fgets.c index 912b706..4545c29 100644 --- a/stdio-common/tst-fgets.c +++ b/stdio-common/tst-fgets.c @@ -2,10 +2,12 @@ https://sourceware.org/bugzilla/show_bug.cgi?id=713. */ #include <stdio.h> +#include <support/xstdio.h> + static int do_test (void) { - FILE *fp = fmemopen ((char *) "hello", 5, "r"); + FILE *fp = xfmemopen ((char *) "hello", 5, "r"); char buf[2]; char *bp = fgets (buf, sizeof (buf), fp); printf ("fgets: %s\n", bp == buf ? "OK" : "ERROR"); |