]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
testsuite: Update tests for 'xfmemopen' use
authorMaciej W. Rozycki <macro@redhat.com>
Fri, 5 Sep 2025 10:53:31 +0000 (11:53 +0100)
committerMaciej W. Rozycki <macro@redhat.com>
Fri, 5 Sep 2025 10:53:31 +0000 (11:53 +0100)
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>
16 files changed:
elf/tst-audit18.c
elf/tst-audit19b.c
elf/tst-audit22.c
elf/tst-audit23.c
elf/tst-audit25.h
elf/tst-pldd.c
libio/tst-getdelim.c
localedata/tst-bz12701-lc.c
localedata/tst-bz13988.c
localedata/tst-scanf-width-digit.c
localedata/tst-scanf-width-point.c
misc/tst-mntent-escape.c
misc/tst-syslog.c
stdio-common/bug26.c
stdio-common/tst-bz12701-c.c
stdio-common/tst-fgets.c

index 0b06999ec84606ed0f1ad15525fc629eaeec78d2..7d71a7ff18bbf288f0462f1748964a5487d20349 100644 (file)
@@ -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 aefdddc9eba8143b246146ab655645207af84ab0..b3097c82f1aab49ee19d41f323fb43778316fedf 100644 (file)
@@ -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 5e8020455a956193bb42aa869848f9090cf9803d..e5cc8a3077eb2e866fe04752ff326d81643eb45c 100644 (file)
@@ -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 aef52de215eacf7981a0af5498ccddab0499195b..0a26a2d4dfeed6d465b1216a69fa9c5473106e2e 100644 (file)
@@ -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;
index c14b6a5a227a298aabe423c333d2e28358357ac9..b9cd11de6b772f83da10ca7c92bc0eac6dd9dbb4 100644 (file)
@@ -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 8c1e33b7cee6d9f980972f19590e62a290f2a4cf..3326ff918ffa562ee99ac9c8a30c7eb94a78c3e6 100644 (file)
@@ -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 e1ec26753d2511c338450bdbdb53209a25d91d23..829b12caf39a790dabd3185e511947e8a22bf5c8 100644 (file)
@@ -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 fcc9f29a1412532bea2e484e3ad45c3dd2f1deec..686843ae6ba584f3e7300b43aa8c1eb35294e111 100644 (file)
@@ -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 8d6f399bbc96c328f3a5813ddbbd90a42aa2d743..43ab593b317ad3052479fba512c2d347d545ba83 100644 (file)
@@ -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 e52edfe7050acb1517cb1694243f94546b0aeeda..f9883a1c82940eb879f124f0f854834bc46737db 100644 (file)
@@ -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 090c9e02168f73dc2b5c32e2c408938190320bc4..9469527d2cc524cfa7fcad55ad940d3dc18df62c 100644 (file)
@@ -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 75363d39d52e59d96ae9205d4e86acf9ef0c2ce6..13996cac9f5adec5833b03c45f0c12952d084268 100644 (file)
@@ -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 97aae0d50c4d3058c0e830878f64153374403dd4..56454f4840581e539bd4a832992e9fa0ae3dab72 100644 (file)
@@ -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 74a00d04d0997f20bbcfd6c704db253d19ea75c8..ea0367e95f74909ebdfcda390a2f6aab52ea751a 100644 (file)
@@ -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 ffb4330bfb6af5f2da5f667a03fb5154cbcd77ef..742111aa33a674ae0d6dfd063cb45abc025c35e3 100644 (file)
@@ -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 912b7068ebf10cd8a83a6536666131f0b9305297..4545c2998b5d9ded668cbb15ad6b70f00b1eece2 100644 (file)
@@ -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");