]> Savannah Git Hosting - gnulib.git/commitdiff
vasnprintf, u*-asnprintf tests: Add test of huge %ls arguments.
authorBruno Haible <bruno@clisp.org>
Thu, 20 Jun 2024 01:24:18 +0000 (03:24 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 20 Jun 2024 01:24:18 +0000 (03:24 +0200)
* tests/test-vasnprintf-big.c: Include <wchar.h>.
(main): Add tests for wide string arguments with > 2^31 wide characters.
* tests/unistdio/test-u8-asnprintf-big.c: Include <wchar.h>.
(main): Add tests for wide string arguments with > 2^31 wide characters.
* tests/unistdio/test-ulc-asnprintf-big.c: Include <wchar.h>.
(main): Add tests for wide string arguments with > 2^31 wide characters.

ChangeLog
tests/test-vasnprintf-big.c
tests/unistdio/test-u8-asnprintf-big.c
tests/unistdio/test-ulc-asnprintf-big.c

index 4b9485f6c7a74a219bde352e762b1e433d764631..1c156b791ec47362b85a2270375b8d704bd2bee9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2024-06-19  Bruno Haible  <bruno@clisp.org>
 
+       vasnprintf, u*-asnprintf tests: Add test of huge %ls arguments.
+       * tests/test-vasnprintf-big.c: Include <wchar.h>.
+       (main): Add tests for wide string arguments with > 2^31 wide characters.
+       * tests/unistdio/test-u8-asnprintf-big.c: Include <wchar.h>.
+       (main): Add tests for wide string arguments with > 2^31 wide characters.
+       * tests/unistdio/test-ulc-asnprintf-big.c: Include <wchar.h>.
+       (main): Add tests for wide string arguments with > 2^31 wide characters.
+
        vasnprintf, u*-vasnprintf: Support huge wide string arguments.
        * lib/vasnprintf.c: (VASNPRINTF): In 64-bit builds, handle the %ls
        directive ourselves.
index 65b4dc3f7c64466670541762cb7da96b103919fa..eae1d2704d820da7114ebff3a2a754cf694ba582 100644 (file)
@@ -31,6 +31,7 @@
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
+#include <wchar.h>
 
 #if HAVE_SETRLIMIT
 # include <sys/types.h>
@@ -54,14 +55,16 @@ main ()
   rl.rlim_cur = rl.rlim_max = 0;
   setrlimit (RLIMIT_CORE, &rl);
 # endif
-  /* The test below needs about 10 GiB of memory:
+  /* The test below needs about 25 GiB of memory:
        $ time /usr/bin/time -f "Max RSS: %M KiB" ./test-vasnprintf-big
-       Max RSS: 10487464 KiB
-       real    0m34,417s
-       user    0m26,175s
-       sys     0m8,240s
-     5 GiB for the inputs and up to 5 GiB for temporary output buffers.  */
-  double needed = 10.0 * 1024 * 1024 * 1024;
+       Max RSS: 26216128 KiB
+       real    3m54,169s
+       user    3m33,309s
+       sys     0m20,819s
+     5 GiB for the inputs in the %s tests,
+     or 20 GiB for the inputs in the %ls tests,
+     and up to 5 GiB for temporary output buffers.  */
+  double needed = 25.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);
@@ -69,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 15728640".  */
+         and you need "ulimit -d 27262976".  */
 
       /* Verify that asnprintf() can return a string of size > 4 GiB.  */
       {
@@ -189,6 +192,79 @@ main ()
               }
           }
       }
+
+      /* Verify that asnprintf() 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;
+            char *s = asnprintf (NULL, &len, "x%lsy", s1);
+            if (s == NULL)
+              {
+                ASSERT (errno == ENOMEM);
+                skipped = true;
+              }
+            else
+              {
+                ASSERT (strlen (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 asnprintf() 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;
+                char *s = asnprintf (NULL, &len, "x%lsy", s1);
+                if (s == NULL)
+                  {
+                    ASSERT (errno == ENOMEM);
+                    skipped = true;
+                  }
+                else
+                  {
+                    ASSERT (strlen (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;
index 6b7cced5ce05c2bfe123c7e8fa0d947430b06f0b..1a5b46d09886284dc64b7dbe2a01658d196c2bee 100644 (file)
@@ -32,6 +32,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistr.h>
+#include <wchar.h>
 
 #if HAVE_SETRLIMIT
 # include <sys/types.h>
@@ -55,14 +56,16 @@ main ()
   rl.rlim_cur = rl.rlim_max = 0;
   setrlimit (RLIMIT_CORE, &rl);
 # endif
-  /* The test below needs about 15 GiB of memory:
+  /* The test below needs about 30 GiB of memory:
        $ time /usr/bin/time -f "Max RSS: %M KiB" ./test-u8-asnprintf-big
-       Max RSS: 15730356 KiB
-       real    0m58,011s
-       user    0m46,403s
-       sys     0m11,604s
-     5 GiB for the inputs and up to 10 GiB for temporary output buffers.  */
-  double needed = 15.0 * 1024 * 1024 * 1024;
+       Max RSS: 31459148 KiB
+       real    6m57,851s
+       user    6m28,413s
+       sys     0m29,382s
+     5 GiB for the inputs in the %s tests,
+     or 20 GiB for the inputs in the %ls tests,
+     and up to 10 GiB for temporary output buffers.  */
+  double needed = 30.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 +73,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 15728640".  */
+         and you need "ulimit -d 32505856".  */
 
       /* Verify that u8_asnprintf() can return a string of size > 4 GiB.  */
       {
@@ -190,6 +193,79 @@ main ()
               }
           }
       }
+
+      /* Verify that u8_asnprintf() 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;
+            uint8_t *s = u8_asnprintf (NULL, &len, "x%lsy", s1);
+            if (s == NULL)
+              {
+                ASSERT (errno == ENOMEM);
+                skipped = true;
+              }
+            else
+              {
+                ASSERT (u8_strlen (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 u8_asnprintf() 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;
+                uint8_t *s = u8_asnprintf (NULL, &len, "x%lsy", s1);
+                if (s == NULL)
+                  {
+                    ASSERT (errno == ENOMEM);
+                    skipped = true;
+                  }
+                else
+                  {
+                    ASSERT (u8_strlen (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;
index 8ef733d962f1732c54d17448d1918517aea411f3..fcb879968434303d5aec4bd22e5d9fd5e0168f51 100644 (file)
@@ -31,6 +31,7 @@
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
+#include <wchar.h>
 
 #if HAVE_SETRLIMIT
 # include <sys/types.h>
@@ -54,14 +55,17 @@ main ()
   rl.rlim_cur = rl.rlim_max = 0;
   setrlimit (RLIMIT_CORE, &rl);
 # endif
-  /* The test below needs about 15 GiB of memory:
+  /* The test below needs about 25 GiB of memory:
        $ time /usr/bin/time -f "Max RSS: %M KiB" ./test-ulc-asnprintf-big
-       Max RSS: 15730376 KiB
-       real    1m13,702s
-       user    1m0,184s
-       sys     0m13,512s
-     5 GiB for the inputs and up to 10 GiB for temporary output buffers.  */
-  double needed = 15.0 * 1024 * 1024 * 1024;
+       Max RSS: 26216192 KiB
+       real    4m34,682s
+       user    4m8,592s
+       sys     0m26,063s
+     - In the %s tests:
+       5 GiB for the inputs and up to 10 GiB for temporary output buffers.
+     - In the %ls tests:
+       20 GiB for the inputs and up to 5 GiB for temporary output buffers.  */
+  double needed = 25.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);
@@ -69,7 +73,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 15728640".  */
+         and you need "ulimit -d 27262976".  */
 
       /* Verify that ulc_asnprintf() can return a string of size > 4 GiB.  */
       {
@@ -243,6 +247,79 @@ main ()
               }
           }
       }
+
+      /* Verify that ulc_asnprintf() 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;
+            char *s = ulc_asnprintf (NULL, &len, "x%lsy", s1);
+            if (s == NULL)
+              {
+                ASSERT (errno == ENOMEM);
+                skipped = true;
+              }
+            else
+              {
+                ASSERT (strlen (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 ulc_asnprintf() 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;
+                char *s = ulc_asnprintf (NULL, &len, "x%lsy", s1);
+                if (s == NULL)
+                  {
+                    ASSERT (errno == ENOMEM);
+                    skipped = true;
+                  }
+                else
+                  {
+                    ASSERT (strlen (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;