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