[PATCH 2/3] testsuite: Update tests for 'xfmemopen' use
Maciej W. Rozycki
macro@orcam.me.uk
Sun Aug 24 20:22:32 GMT 2025
From: Maciej W. Rozycki <macro@redhat.com>
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.
---
elf/tst-audit18.c | 3 +--
elf/tst-audit19b.c | 3 +--
elf/tst-audit22.c | 3 +--
elf/tst-audit23.c | 6 ++----
elf/tst-audit25.h | 3 +--
elf/tst-pldd.c | 4 ++--
libio/tst-getdelim.c | 4 ++--
localedata/tst-bz12701-lc.c | 12 +++---------
localedata/tst-bz13988.c | 3 ++-
localedata/tst-scanf-width-digit.c | 5 ++---
localedata/tst-scanf-width-point.c | 5 ++---
misc/tst-mntent-escape.c | 9 ++-------
misc/tst-syslog.c | 4 +---
stdio-common/bug26.c | 4 +++-
stdio-common/tst-bz12701-c.c | 12 +++---------
stdio-common/tst-fgets.c | 4 +++-
16 files changed, 31 insertions(+), 53 deletions(-)
Index: glibc/elf/tst-audit18.c
===================================================================
--- glibc.orig/elf/tst-audit18.c
+++ glibc/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))
Index: glibc/elf/tst-audit19b.c
===================================================================
--- glibc.orig/elf/tst-audit19b.c
+++ glibc/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))
Index: glibc/elf/tst-audit22.c
===================================================================
--- glibc.orig/elf/tst-audit22.c
+++ glibc/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))
Index: glibc/elf/tst-audit23.c
===================================================================
--- glibc.orig/elf/tst-audit23.c
+++ glibc/elf/tst-audit23.c
@@ -91,8 +91,7 @@ do_one_test (int argc, char *argv[], boo
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[], boo
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;
Index: glibc/elf/tst-audit25.h
===================================================================
--- glibc.orig/elf/tst-audit25.h
+++ glibc/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;
Index: glibc/elf/tst-pldd.c
===================================================================
--- glibc.orig/elf/tst-pldd.c
+++ glibc/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);
Index: glibc/libio/tst-getdelim.c
===================================================================
--- glibc.orig/libio/tst-getdelim.c
+++ glibc/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);
Index: glibc/localedata/tst-bz12701-lc.c
===================================================================
--- glibc.orig/localedata/tst-bz12701-lc.c
+++ glibc/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);
Index: glibc/localedata/tst-bz13988.c
===================================================================
--- glibc.orig/localedata/tst-bz13988.c
+++ glibc/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. */
Index: glibc/localedata/tst-scanf-width-digit.c
===================================================================
--- glibc.orig/localedata/tst-scanf-width-digit.c
+++ glibc/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. */
Index: glibc/localedata/tst-scanf-width-point.c
===================================================================
--- glibc.orig/localedata/tst-scanf-width-point.c
+++ glibc/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. */
Index: glibc/misc/tst-mntent-escape.c
===================================================================
--- glibc.orig/misc/tst-mntent-escape.c
+++ glibc/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);
Index: glibc/misc/tst-syslog.c
===================================================================
--- glibc.orig/misc/tst-syslog.c
+++ glibc/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
Index: glibc/stdio-common/bug26.c
===================================================================
--- glibc.orig/stdio-common/bug26.c
+++ glibc/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);
Index: glibc/stdio-common/tst-bz12701-c.c
===================================================================
--- glibc.orig/stdio-common/tst-bz12701-c.c
+++ glibc/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);
Index: glibc/stdio-common/tst-fgets.c
===================================================================
--- glibc.orig/stdio-common/tst-fgets.c
+++ glibc/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");
More information about the Libc-alpha
mailing list