diff mbox series

libxml2: backport -timeout flag for testlimits

Message ID 20260113184532.3389502-1-tgamblin@baylibre.com
State New
Headers show
Series libxml2: backport -timeout flag for testlimits | expand

Commit Message

Trevor Gamblin Jan. 13, 2026, 6:45 p.m. UTC
[YOCTO #15912]

A commit was recently merged upstream to make the testlimits test's
timeout configurable. This test fails intermittently on the AB under
heavy load (particularly on qemuriscv64), so backport the change and
adjust the timeout from two seconds to five.

Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
---
 ...mits-optionally-accept-timeout-input.patch | 92 +++++++++++++++++++
 meta/recipes-core/libxml/libxml2/run-ptest    |  5 +-
 meta/recipes-core/libxml/libxml2_2.15.1.bb    |  1 +
 3 files changed, 97 insertions(+), 1 deletion(-)
 create mode 100644 meta/recipes-core/libxml/libxml2/0001-testlimits-optionally-accept-timeout-input.patch
diff mbox series

Patch

diff --git a/meta/recipes-core/libxml/libxml2/0001-testlimits-optionally-accept-timeout-input.patch b/meta/recipes-core/libxml/libxml2/0001-testlimits-optionally-accept-timeout-input.patch
new file mode 100644
index 0000000000..2f0899a0be
--- /dev/null
+++ b/meta/recipes-core/libxml/libxml2/0001-testlimits-optionally-accept-timeout-input.patch
@@ -0,0 +1,92 @@ 
+From b45e38edab72e4f09b24a5c9672df818f8df020c Mon Sep 17 00:00:00 2001
+From: Trevor Gamblin <tgamblin@baylibre.com>
+Date: Thu, 8 Jan 2026 15:30:47 -0500
+Subject: [PATCH] testlimits: optionally accept '-timeout' input
+
+Upstream-Status: Backport [https://gitlab.gnome.org/GNOME/libxml2/-/commit/b45e38edab72e4f09b24a5c9672df818f8df020c]
+Fixes: #1032
+
+The testlimits tests can use a lot of system resources, and thus they
+may fail when run on systems under heavy load, given that the default
+parsing timeout is set to two seconds. Retain this default value, but
+make the timeout length configurable with a new '-timeout' flag.
+
+Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
+---
+ testlimits.c | 33 ++++++++++++++++++++++++++-------
+ 1 file changed, 26 insertions(+), 7 deletions(-)
+
+diff --git a/testlimits.c b/testlimits.c
+index 695cbf48..87fcd1a1 100644
+--- a/testlimits.c
++++ b/testlimits.c
+@@ -35,9 +35,10 @@ static int tests_quiet = 0;
+  *									*
+  ************************************************************************/
+ 
+-/* maximum time for one parsing before declaring a timeout */
+-#define MAX_TIME 2 /* seconds */
++/* default maximum time for one parsing before declaring a timeout */
++#define DEFAULT_MAX_TIME 2 /* seconds */
+ 
++static int max_time = DEFAULT_MAX_TIME;
+ static clock_t t0;
+ static int timeout = 0;
+ 
+@@ -48,7 +49,7 @@ static void reset_timout(void) {
+ 
+ static int check_time(void) {
+     clock_t tnow = clock();
+-    if (((tnow - t0) / CLOCKS_PER_SEC) > MAX_TIME) {
++    if (((tnow - t0) / CLOCKS_PER_SEC) > max_time) {
+         timeout = 1;
+         return(0);
+     }
+@@ -1228,22 +1229,40 @@ runcrazy(void) {
+     return(ret);
+ }
+ 
+-
+ int
+ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
+     int i, a, ret = 0;
+     int subset = 0;
++    char *endptr;
++    long val;
+ 
+     fillFilling();
+     initializeLibxml2();
+ 
+     for (a = 1; a < argc;a++) {
+         if (!strcmp(argv[a], "-v"))
+-	    verbose = 1;
++            verbose = 1;
+         else if (!strcmp(argv[a], "-quiet"))
+-	    tests_quiet = 1;
++            tests_quiet = 1;
+         else if (!strcmp(argv[a], "-crazy"))
+-	    subset = 1;
++            subset = 1;
++        else if (!strcmp(argv[a], "-timeout")) {
++            if (a + 1 >= argc) {
++                fprintf(stderr, "Error: -timeout requires a value in seconds\n");
++                return 1;
++            }
++            val = strtol(argv[a + 1], &endptr, 10);
++            if (endptr == argv[a + 1] || *endptr != '\0') {
++                fprintf(stderr, "Error: -timeout value '%s' is not a valid number\n", argv[a + 1]);
++                return 1;
++            }
++            if (val <= 0 || val > INT_MAX) {
++                fprintf(stderr, "Error: -timeout must be a positive integer (got %s)\n", argv[a + 1]);
++                return 1;
++            }
++            max_time = (int)val;
++            a++;
++        }
+     }
+     if (subset == 0) {
+ 	for (i = 0; testDescriptions[i].func != NULL; i++) {
+-- 
+2.52.0
+
diff --git a/meta/recipes-core/libxml/libxml2/run-ptest b/meta/recipes-core/libxml/libxml2/run-ptest
index 868649240b..becf61398e 100755
--- a/meta/recipes-core/libxml/libxml2/run-ptest
+++ b/meta/recipes-core/libxml/libxml2/run-ptest
@@ -5,9 +5,12 @@  set -e
 export LC_ALL=en_US.UTF-8
 
 # testModule isn't that useful and hard-codes buildtree, so we don't run that
-TESTS="runtest runsuite testrecurse testchar testdict runxmlconf testapi testlimits testparser"
+TESTS="runtest runsuite testrecurse testchar testdict runxmlconf testapi testparser"
 
 for T in $TESTS; do
     echo Running $T
     ./$T && echo PASS: $T || echo FAIL: $T
 done
+
+echo Running testlimits with -timeout 5
+./testlimits -timeout 5 && echo PASS: testlimits || echo FAIL: testlimits
diff --git a/meta/recipes-core/libxml/libxml2_2.15.1.bb b/meta/recipes-core/libxml/libxml2_2.15.1.bb
index 905688e834..736aaea00e 100644
--- a/meta/recipes-core/libxml/libxml2_2.15.1.bb
+++ b/meta/recipes-core/libxml/libxml2_2.15.1.bb
@@ -18,6 +18,7 @@  SRC_URI += "http://www.w3.org/XML/Test/xmlts20130923.tar;subdir=${BP};name=testt
            file://run-ptest \
            file://install-tests.patch \
            file://0001-Revert-cmake-Fix-installation-directories-in-libxml2.patch \
+           file://0001-testlimits-optionally-accept-timeout-input.patch \
            "
 
 SRC_URI[archive.sha256sum] = "c008bac08fd5c7b4a87f7b8a71f283fa581d80d80ff8d2efd3b26224c39bc54c"