]> Savannah Git Hosting - gnulib.git/commitdiff
vasnwprintf tests: Add test of huge %ls arguments.
authorBruno Haible <bruno@clisp.org>
Thu, 20 Jun 2024 06:13:25 +0000 (08:13 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 20 Jun 2024 06:13:25 +0000 (08:13 +0200)
* tests/test-vasnwprintf-big.c (main): Add tests for wide string
arguments with > 2^31 wide characters.

ChangeLog
tests/test-vasnwprintf-big.c

index ea01cfe60d22f50b6b6a4324d1f08a907643781f..5fea7e958b3badbaba87f5964cdc1366f8f62dcd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2024-06-20  Bruno Haible  <bruno@clisp.org>
 
+       vasnwprintf tests: Add test of huge %ls arguments.
+       * tests/test-vasnwprintf-big.c (main): Add tests for wide string
+       arguments with > 2^31 wide characters.
+
        vasnwprintf: Support huge wide string arguments.
        * lib/vasnprintf.c: (VASNPRINTF): In 64-bit builds, handle the %ls
        directive ourselves.
index 30f123f15ff83ec1f8f8f09ea3ec919e332bc7c4..1c4411efca223c7a9535619a31630b477124e2ef 100644 (file)
@@ -55,14 +55,16 @@ main ()
   rl.rlim_cur = rl.rlim_max = 0;
   setrlimit (RLIMIT_CORE, &rl);
 # endif
-  /* The test below needs about 25 GiB of memory:
+  /* The test below needs about 40 GiB of memory:
        $ time /usr/bin/time -f "Max RSS: %M KiB" ./test-vasnwprintf-big
-       Max RSS: 26216204 KiB
-       real    4m22,540s
-       user    4m6,322s
-       sys     0m16,203s
-     5 GiB for the inputs and up to 20 GiB for temporary output buffers.  */
-  double needed = 25.0 * 1024 * 1024 * 1024;
+       Max RSS: 41944784 KiB
+       real    5m8,508s
+       user    4m38,035s
+       sys     0m30,456s
+     5 GiB for the inputs in the %s tests,
+     or 20 GiB for the inputs in the %ls tests,
+     and up to 20 GiB for temporary output buffers.  */
+  double needed = 40.0 * 1024 * 1024 * 1024;
   double avail = physmem_claimable (1.0);
   printf ("memory needed = %g MiB, available = %g MiB\n",
           needed / 1024 / 1024, avail / 1024 / 1024);
@@ -70,7 +72,7 @@ main ()
     {
       /* Note: The malloc() calls can fail, due to ulimit of RLIMIT_DATA.
          For example, on OpenBSD 7.5, the soft limit is 1.0 GiB or 1.5 GiB,
-         and you need "ulimit -d 26214400".  */
+         and you need "ulimit -d 42991616".  */
 
       /* Verify that asnwprintf() can return a string of size > 4 GiB.  */
       {
@@ -190,6 +192,79 @@ main ()
               }
           }
       }
+
+      /* Verify that asnwprintf() can take a wide string with an element count
+         > 2^31, < 2^32 as argument.  */
+      {
+        size_t n1 = 3 * (size_t) (INT_MAX / 2) + 10;
+        wchar_t *s1;
+
+        s1 = (wchar_t *) malloc ((n1 + 1) * sizeof (wchar_t));
+        if (s1 != NULL)
+          {
+            wmemset (s1, L'a', n1);
+            s1[n1] = L'\0';
+
+            size_t len;
+            wchar_t *s = asnwprintf (NULL, &len, L"x%lsy", s1);
+            if (s == NULL)
+              {
+                ASSERT (errno == ENOMEM);
+                skipped = true;
+              }
+            else
+              {
+                ASSERT (wcslen (s) == len);
+                ASSERT (len == n1 + 2);
+                size_t i;
+                for (i = 0; i <= len; i++)
+                  s[i] = (i == 0 ? 'x' :
+                          i <= n1 ? 'a' :
+                          i == n1 + 1 ? 'y' :
+                          '\0');
+                free (s);
+              }
+            free (s1);
+          }
+      }
+
+      /* Verify that asnwprintf() can take a wide string with an element count
+         > 2^32 as argument.  */
+      {
+        size_t n1 = 5 * (size_t) (INT_MAX / 2) + 10;
+        if (n1 > (size_t) INT_MAX)
+          {
+            wchar_t *s1;
+
+            s1 = (wchar_t *) malloc ((n1 + 1) * sizeof (wchar_t));
+            if (s1 != NULL)
+              {
+                wmemset (s1, L'a', n1);
+                s1[n1] = L'\0';
+
+                size_t len;
+                wchar_t *s = asnwprintf (NULL, &len, L"x%lsy", s1);
+                if (s == NULL)
+                  {
+                    ASSERT (errno == ENOMEM);
+                    skipped = true;
+                  }
+                else
+                  {
+                    ASSERT (wcslen (s) == len);
+                    ASSERT (len == n1 + 2);
+                    size_t i;
+                    for (i = 0; i <= len; i++)
+                      s[i] = (i == 0 ? 'x' :
+                              i <= n1 ? 'a' :
+                              i == n1 + 1 ? 'y' :
+                              '\0');
+                    free (s);
+                  }
+                free (s1);
+              }
+          }
+      }
     }
   else
     skipped = true;