about summary refs log tree commit diff
path: root/support/tst-support_blob_repeat.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2020-05-12 19:01:49 +0200
committerFlorian Weimer <fweimer@redhat.com>2020-05-12 19:02:44 +0200
commit0e28cfff9dfdb71352151054e0d38816856182d5 (patch)
tree38396de261b09ec133cc138a18f4b73217914ba2 /support/tst-support_blob_repeat.c
parent4cab20fa49b3ea3e3454fdc4f13bf3828d8efd19 (diff)
downloadglibc-0e28cfff9dfdb71352151054e0d38816856182d5.tar.gz
glibc-0e28cfff9dfdb71352151054e0d38816856182d5.tar.xz
glibc-0e28cfff9dfdb71352151054e0d38816856182d5.zip
support: Add support_blob_repeat_allocate_shared
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'support/tst-support_blob_repeat.c')
-rw-r--r--support/tst-support_blob_repeat.c45
1 files changed, 32 insertions, 13 deletions
diff --git a/support/tst-support_blob_repeat.c b/support/tst-support_blob_repeat.c
index a0eb9d2b89..b61d6b249a 100644
--- a/support/tst-support_blob_repeat.c
+++ b/support/tst-support_blob_repeat.c
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <stdio.h>
+#include <string.h>
 #include <support/blob_repeat.h>
 #include <support/check.h>
 
@@ -63,21 +64,39 @@ do_test (void)
     }
   support_blob_repeat_free (&repeat);
 
-  repeat = support_blob_repeat_allocate ("012345678", 9, 10 * 1000 * 1000);
-  if (repeat.start == NULL)
-    puts ("warning: not enough memory for large mapping");
-  else
+  for (int do_shared = 0; do_shared < 2; ++do_shared)
     {
-      unsigned char *p = repeat.start;
-      for (int i = 0; i < 10 * 1000 * 1000; ++i)
-        for (int j = 0; j <= 8; ++j)
-          if (p[i * 9 + j] != '0' + j)
-            {
-              printf ("error: element %d index %d\n", i, j);
-              TEST_COMPARE (p[i * 9 + j], '0' + j);
-            }
+      if (do_shared)
+        repeat = support_blob_repeat_allocate_shared ("012345678", 9,
+                                                      10 * 1000 * 1000);
+      else
+        repeat = support_blob_repeat_allocate ("012345678", 9,
+                                               10 * 1000 * 1000);
+      if (repeat.start == NULL)
+        puts ("warning: not enough memory for large mapping");
+      else
+        {
+          unsigned char *p = repeat.start;
+          for (int i = 0; i < 10 * 1000 * 1000; ++i)
+            for (int j = 0; j <= 8; ++j)
+              if (p[i * 9 + j] != '0' + j)
+                {
+                  printf ("error: element %d index %d\n", i, j);
+                  TEST_COMPARE (p[i * 9 + j], '0' + j);
+                }
+
+          enum { total_size = 9 * 10 * 1000 * 1000 };
+          p[total_size - 1] = '\0';
+          asm ("" ::: "memory");
+          if (do_shared)
+            /* The write is repeated in multiple places earlier in the
+               string due to page sharing.  */
+            TEST_VERIFY (strlen (repeat.start) < total_size - 1);
+          else
+            TEST_COMPARE (strlen (repeat.start), total_size - 1);
+        }
+      support_blob_repeat_free (&repeat);
     }
-  support_blob_repeat_free (&repeat);
 
   return 0;
 }