Three more patches in this series:
1) Fix a small mistake that caused gcc warnings.
2) I measured the amount of RAM that the tests need:
$ /usr/bin/time -f "Max RSS: %M KiB" ./test-...printf-big
This is consistent with what I see by watching the process through "top".
3) vasnwprintf tests: Add test of %s directive with large arguments.
This test passes without modifications to lib/vasnprintf.c. The
corresponding code is in lines 3141..3628.
2024-06-19 Bruno Haible <[email protected]>
vasnwprintf tests: Add test of %s directive with large arguments.
* tests/test-vasnwprintf-big.c: New file, based on
tests/test-vasnprintf-big.c.
* modules/vasnwprintf-extra-tests: New file.
* modules/vasnwprintf-tests (Depends-on): Depend on it.
2024-06-19 Bruno Haible <[email protected]>
vasnprintf, u*-asnprintf tests: Adjust memory need.
* tests/test-vasnprintf-big.c (main): Require 10, not 12, GiB of RAM.
* tests/unistdio/test-u8-asnprintf-big.c (main): Require 15 GiB of RAM.
* tests/unistdio/test-ulc-asnprintf-big.c (main): Likewise.
2024-06-19 Bruno Haible <[email protected]>
u8-asnprintf tests: Fix mistake.
* tests/unistdio/test-u8-asnprintf-big.c: Include <unistr.h>.
(main): Use u8_strlen instead of strlen.
* modules/unistdio/u8-asnprintf-extra-tests (Depends-on): Add
unistr/u8-strlen.
>From c97a622affb78e78a3beddeb0f7fa9e23e718ee9 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Thu, 20 Jun 2024 01:27:12 +0200
Subject: [PATCH 1/3] u8-asnprintf tests: Fix mistake.
* tests/unistdio/test-u8-asnprintf-big.c: Include <unistr.h>.
(main): Use u8_strlen instead of strlen.
* modules/unistdio/u8-asnprintf-extra-tests (Depends-on): Add
unistr/u8-strlen.
---
ChangeLog | 8 ++++++++
modules/unistdio/u8-asnprintf-extra-tests | 1 +
tests/unistdio/test-u8-asnprintf-big.c | 7 ++++---
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 7b780206b9..04002a54a8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-06-19 Bruno Haible <[email protected]>
+
+ u8-asnprintf tests: Fix mistake.
+ * tests/unistdio/test-u8-asnprintf-big.c: Include <unistr.h>.
+ (main): Use u8_strlen instead of strlen.
+ * modules/unistdio/u8-asnprintf-extra-tests (Depends-on): Add
+ unistr/u8-strlen.
+
2024-06-19 Collin Funk <[email protected]>
filemode tests: Fix comment.
diff --git a/modules/unistdio/u8-asnprintf-extra-tests b/modules/unistdio/u8-asnprintf-extra-tests
index c4f7a18e19..ac223b2b63 100644
--- a/modules/unistdio/u8-asnprintf-extra-tests
+++ b/modules/unistdio/u8-asnprintf-extra-tests
@@ -9,6 +9,7 @@ Depends-on:
stdbool
stdint
physmem
+unistr/u8-strlen
configure.ac:
AC_CHECK_FUNCS_ONCE([setrlimit])
diff --git a/tests/unistdio/test-u8-asnprintf-big.c b/tests/unistdio/test-u8-asnprintf-big.c
index 25a5880c0a..55eb933639 100644
--- a/tests/unistdio/test-u8-asnprintf-big.c
+++ b/tests/unistdio/test-u8-asnprintf-big.c
@@ -31,6 +31,7 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
+#include <unistr.h>
#if HAVE_SETRLIMIT
# include <sys/types.h>
@@ -94,7 +95,7 @@ main ()
}
else
{
- ASSERT (strlen (s) == len);
+ ASSERT (u8_strlen (s) == len);
ASSERT (len == n1 + n2 + 3);
size_t i;
for (i = 0; i <= len; i++)
@@ -133,7 +134,7 @@ main ()
}
else
{
- ASSERT (strlen (s) == len);
+ ASSERT (u8_strlen (s) == len);
ASSERT (len == n1 + 2);
size_t i;
for (i = 0; i <= len; i++)
@@ -170,7 +171,7 @@ main ()
}
else
{
- ASSERT (strlen (s) == len);
+ ASSERT (u8_strlen (s) == len);
ASSERT (len == n1 + 2);
size_t i;
for (i = 0; i <= len; i++)
--
2.34.1
>From 335ca665041ed16f3da008e34f17c1f7140f7173 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Thu, 20 Jun 2024 01:28:33 +0200
Subject: [PATCH 2/3] vasnprintf, u*-asnprintf tests: Adjust memory need.
* tests/test-vasnprintf-big.c (main): Require 10, not 12, GiB of RAM.
* tests/unistdio/test-u8-asnprintf-big.c (main): Require 15 GiB of RAM.
* tests/unistdio/test-ulc-asnprintf-big.c (main): Likewise.
---
ChangeLog | 7 +++++++
tests/test-vasnprintf-big.c | 11 ++++++++---
tests/unistdio/test-u8-asnprintf-big.c | 11 ++++++++---
tests/unistdio/test-ulc-asnprintf-big.c | 11 ++++++++---
4 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 04002a54a8..2218550af3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-06-19 Bruno Haible <[email protected]>
+
+ vasnprintf, u*-asnprintf tests: Adjust memory need.
+ * tests/test-vasnprintf-big.c (main): Require 10, not 12, GiB of RAM.
+ * tests/unistdio/test-u8-asnprintf-big.c (main): Require 15 GiB of RAM.
+ * tests/unistdio/test-ulc-asnprintf-big.c (main): Likewise.
+
2024-06-19 Bruno Haible <[email protected]>
u8-asnprintf tests: Fix mistake.
diff --git a/tests/test-vasnprintf-big.c b/tests/test-vasnprintf-big.c
index e4bb28c95c..65b4dc3f7c 100644
--- a/tests/test-vasnprintf-big.c
+++ b/tests/test-vasnprintf-big.c
@@ -54,9 +54,14 @@ main ()
rl.rlim_cur = rl.rlim_max = 0;
setrlimit (RLIMIT_CORE, &rl);
# endif
- /* The test below needs about 12 GiB of memory:
- 3 GiB for the inputs and up to 9 GiB for temporary output buffers. */
- double needed = 12.0 * 1024 * 1024 * 1024;
+ /* The test below needs about 10 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;
double avail = physmem_claimable (1.0);
printf ("memory needed = %g MiB, available = %g MiB\n",
needed / 1024 / 1024, avail / 1024 / 1024);
diff --git a/tests/unistdio/test-u8-asnprintf-big.c b/tests/unistdio/test-u8-asnprintf-big.c
index 55eb933639..6b7cced5ce 100644
--- a/tests/unistdio/test-u8-asnprintf-big.c
+++ b/tests/unistdio/test-u8-asnprintf-big.c
@@ -55,9 +55,14 @@ main ()
rl.rlim_cur = rl.rlim_max = 0;
setrlimit (RLIMIT_CORE, &rl);
# endif
- /* The test below needs about 12 GiB of memory:
- 3 GiB for the inputs and up to 9 GiB for temporary output buffers. */
- double needed = 12.0 * 1024 * 1024 * 1024;
+ /* The test below needs about 15 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;
double avail = physmem_claimable (1.0);
printf ("memory needed = %g MiB, available = %g MiB\n",
needed / 1024 / 1024, avail / 1024 / 1024);
diff --git a/tests/unistdio/test-ulc-asnprintf-big.c b/tests/unistdio/test-ulc-asnprintf-big.c
index b73ff302be..8ef733d962 100644
--- a/tests/unistdio/test-ulc-asnprintf-big.c
+++ b/tests/unistdio/test-ulc-asnprintf-big.c
@@ -54,9 +54,14 @@ main ()
rl.rlim_cur = rl.rlim_max = 0;
setrlimit (RLIMIT_CORE, &rl);
# endif
- /* The test below needs about 12 GiB of memory:
- 3 GiB for the inputs and up to 9 GiB for temporary output buffers. */
- double needed = 12.0 * 1024 * 1024 * 1024;
+ /* The test below needs about 15 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;
double avail = physmem_claimable (1.0);
printf ("memory needed = %g MiB, available = %g MiB\n",
needed / 1024 / 1024, avail / 1024 / 1024);
--
2.34.1
>From 9bc7bceef85fc2524fadb558389d8d5bba1bd5d9 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Thu, 20 Jun 2024 01:31:21 +0200
Subject: [PATCH 3/3] vasnwprintf tests: Add test of %s directive with large
arguments.
* tests/test-vasnwprintf-big.c: New file, based on
tests/test-vasnprintf-big.c.
* modules/vasnwprintf-extra-tests: New file.
* modules/vasnwprintf-tests (Depends-on): Depend on it.
---
ChangeLog | 8 ++
modules/vasnwprintf-extra-tests | 18 +++
modules/vasnwprintf-tests | 1 +
tests/test-vasnwprintf-big.c | 206 ++++++++++++++++++++++++++++++++
4 files changed, 233 insertions(+)
create mode 100644 modules/vasnwprintf-extra-tests
create mode 100644 tests/test-vasnwprintf-big.c
diff --git a/ChangeLog b/ChangeLog
index 2218550af3..5b465a7eb7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-06-19 Bruno Haible <[email protected]>
+
+ vasnwprintf tests: Add test of %s directive with large arguments.
+ * tests/test-vasnwprintf-big.c: New file, based on
+ tests/test-vasnprintf-big.c.
+ * modules/vasnwprintf-extra-tests: New file.
+ * modules/vasnwprintf-tests (Depends-on): Depend on it.
+
2024-06-19 Bruno Haible <[email protected]>
vasnprintf, u*-asnprintf tests: Adjust memory need.
diff --git a/modules/vasnwprintf-extra-tests b/modules/vasnwprintf-extra-tests
new file mode 100644
index 0000000000..325bc8fa98
--- /dev/null
+++ b/modules/vasnwprintf-extra-tests
@@ -0,0 +1,18 @@
+Status:
+longrunning-test
+
+Files:
+tests/test-vasnwprintf-big.c
+tests/macros.h
+
+Depends-on:
+stdbool
+stdint
+physmem
+
+configure.ac:
+AC_CHECK_FUNCS_ONCE([setrlimit])
+
+Makefile.am:
+TESTS += test-vasnwprintf-big
+check_PROGRAMS += test-vasnwprintf-big
diff --git a/modules/vasnwprintf-tests b/modules/vasnwprintf-tests
index 5eb8a67d0c..77969fe346 100644
--- a/modules/vasnwprintf-tests
+++ b/modules/vasnwprintf-tests
@@ -6,6 +6,7 @@ Depends-on:
wcscmp
wmemcmp
wmemcpy
+vasnwprintf-extra-tests
configure.ac:
diff --git a/tests/test-vasnwprintf-big.c b/tests/test-vasnwprintf-big.c
new file mode 100644
index 0000000000..30f123f15f
--- /dev/null
+++ b/tests/test-vasnwprintf-big.c
@@ -0,0 +1,206 @@
+/* Test of [v]asnwprintf() with big results.
+ Copyright (C) 2024 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <[email protected]>, 2024. */
+
+#include <config.h>
+
+#include "vasnwprintf.h"
+
+#include "physmem.h"
+
+/* Get INT_MAX. */
+#include <limits.h>
+
+/* Get PTRDIFF_MAX. */
+#include <stdint.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <wchar.h>
+
+#if HAVE_SETRLIMIT
+# include <sys/types.h>
+# include <sys/time.h>
+# include <sys/resource.h>
+#endif
+
+#include "macros.h"
+
+int
+main ()
+{
+#if PTRDIFF_MAX == INT_MAX
+ fputs ("Skipping test: ptrdiff_t is not 64-bits wide\n", stderr);
+ return 77;
+#else
+ bool skipped = false;
+ /* Disable core files that would be huge. */
+# if HAVE_SETRLIMIT && defined RLIMIT_CORE
+ struct rlimit rl;
+ rl.rlim_cur = rl.rlim_max = 0;
+ setrlimit (RLIMIT_CORE, &rl);
+# endif
+ /* The test below needs about 25 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;
+ double avail = physmem_claimable (1.0);
+ printf ("memory needed = %g MiB, available = %g MiB\n",
+ needed / 1024 / 1024, avail / 1024 / 1024);
+ if (avail >= needed)
+ {
+ /* 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". */
+
+ /* Verify that asnwprintf() can return a string of size > 4 GiB. */
+ {
+ size_t n1 = 3 * (INT_MAX / 4) + 10;
+ size_t n2 = 3 * (INT_MAX / 4) + 20;
+ char *s1;
+ char *s2;
+
+ s1 = (char *) malloc (n1 + 1);
+ if (s1 != NULL)
+ {
+ memset (s1, 'a', n1);
+ s1[n1] = '\0';
+
+ s2 = (char *) malloc (n2 + 1);
+ if (s2 != NULL)
+ {
+ memset (s2, 'b', n2);
+ s1[n1] = '\0';
+
+ size_t len;
+ wchar_t *s = asnwprintf (NULL, &len, L"x%sy%sz", s1, s2);
+ if (s == NULL)
+ {
+ ASSERT (errno == ENOMEM);
+ skipped = true;
+ }
+ else
+ {
+ ASSERT (wcslen (s) == len);
+ ASSERT (len == n1 + n2 + 3);
+ size_t i;
+ for (i = 0; i <= len; i++)
+ s[i] = (i == 0 ? 'x' :
+ i <= n1 ? 'a' :
+ i == n1 + 1 ? 'y' :
+ i <= n1 + n2 + 1 ? 'b' :
+ i == n1 + n2 + 2 ? 'z' :
+ '\0');
+ free (s);
+ }
+ free (s2);
+ }
+ free (s1);
+ }
+ }
+
+ /* Verify that asnwprintf() can take a string of size > 2 GiB, < 4 GiB
+ as argument. */
+ {
+ size_t n1 = 3 * (size_t) (INT_MAX / 2) + 10;
+ char *s1;
+
+ s1 = (char *) malloc (n1 + 1);
+ if (s1 != NULL)
+ {
+ memset (s1, 'a', n1);
+ s1[n1] = '\0';
+
+ size_t len;
+ wchar_t *s = asnwprintf (NULL, &len, L"x%sy", 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 string of size > 4 GiB
+ as argument. */
+ {
+ size_t n1 = 5 * (size_t) (INT_MAX / 2) + 10;
+ if (n1 > (size_t) INT_MAX)
+ {
+ char *s1;
+
+ s1 = (char *) malloc (n1 + 1);
+ if (s1 != NULL)
+ {
+ memset (s1, 'a', n1);
+ s1[n1] = '\0';
+
+ size_t len;
+ wchar_t *s = asnwprintf (NULL, &len, L"x%sy", 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;
+
+ if (test_exit_status != EXIT_SUCCESS)
+ return test_exit_status;
+ if (skipped)
+ {
+ fputs ("Skipping test: not enough memory available\n", stderr);
+ return 77;
+ }
+ return 0;
+#endif
+}
--
2.34.1