d8307d
commit f5e7e95921847bd83186bfe621fc2b48c4de5477
d8307d
Author: Florian Weimer <fweimer@redhat.com>
d8307d
Date:   Tue Oct 30 13:11:47 2018 +0100
d8307d
d8307d
    stdlib/test-bz22786: Avoid spurious test failures using alias mappings
d8307d
    
d8307d
    On systems without enough random-access memory, stdlib/test-bz22786
d8307d
    will go deeply into swap and time out, even with a substantial
d8307d
    TIMEOUTFACTOR.  This commit adds a facility to construct repeating
d8307d
    strings with alias mappings, so that the requirement for physical
d8307d
    memory, and uses it in stdlib/test-bz22786.
d8307d
d8307d
Adjusted here for conflicts due to the previous support/ backport in
d8307d
glibc-rh1638523-1.patch.
d8307d
d8307d
diff --git a/stdlib/test-bz22786.c b/stdlib/test-bz22786.c
d8307d
index 777bf9180f4b5022..bb1e04f2debe9042 100644
d8307d
--- a/stdlib/test-bz22786.c
d8307d
+++ b/stdlib/test-bz22786.c
d8307d
@@ -26,6 +26,7 @@
d8307d
 #include <unistd.h>
d8307d
 #include <sys/stat.h>
d8307d
 #include <sys/types.h>
d8307d
+#include <support/blob_repeat.h>
d8307d
 #include <support/check.h>
d8307d
 #include <support/support.h>
d8307d
 #include <support/temp_file.h>
d8307d
@@ -39,17 +40,12 @@ do_test (void)
d8307d
   const char *lnk = xasprintf ("%s/symlink", dir);
d8307d
   const size_t path_len = (size_t) INT_MAX + strlen (lnk) + 1;
d8307d
 
d8307d
-  DIAG_PUSH_NEEDS_COMMENT;
d8307d
-#if __GNUC_PREREQ (7, 0)
d8307d
-  /* GCC 7 warns about too-large allocations; here we need such
d8307d
-     allocation to succeed for the test to work.  */
d8307d
-  DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
d8307d
-#endif
d8307d
-  char *path = malloc (path_len);
d8307d
-  DIAG_POP_NEEDS_COMMENT;
d8307d
+  struct support_blob_repeat repeat
d8307d
+    = support_blob_repeat_allocate ("a", 1, path_len);
d8307d
+  char *path = repeat.start;
d8307d
   if (path == NULL)
d8307d
     {
d8307d
-      printf ("malloc (%zu): %m\n", path_len);
d8307d
+      printf ("Repeated allocation (%zu bytes): %m\n", path_len);
d8307d
       /* On 31-bit s390 the malloc will always fail as we do not have
d8307d
 	 so much memory, and we want to mark the test unsupported.
d8307d
 	 Likewise on systems with little physical memory the test will
d8307d
@@ -62,7 +58,6 @@ do_test (void)
d8307d
   /* Construct very long path = "/tmp/bz22786.XXXX/symlink/aaaa....."  */
d8307d
   char *p = mempcpy (path, lnk, strlen (lnk));
d8307d
   *(p++) = '/';
d8307d
-  memset (p, 'a', path_len - (p - path) - 2);
d8307d
   p[path_len - (p - path) - 1] = '\0';
d8307d
 
d8307d
   /* This call crashes before the fix for bz22786 on 32-bit platforms.  */
d8307d
@@ -76,6 +71,7 @@ do_test (void)
d8307d
 
d8307d
   /* Cleanup.  */
d8307d
   unlink (lnk);
d8307d
+  support_blob_repeat_free (&repeat);
d8307d
 
d8307d
   return 0;
d8307d
 }