From 54afb19745e83b1c56c42433f7d913a25f9fbd87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Mon, 9 Sep 2024 14:40:23 +0200 Subject: [PATCH] Make the timeout test more resilient Since we don't keep timers sorted by deadline but by insertion order, the test is flaky in slow environments (GHA seemingly). Increase the timeouts to give it a bigger chance of success. ASan / UBSan builds are notoriously slow, so skip the test in those. --- CMakeLists.txt | 3 +++ qjs.c | 3 +++ tests/test_std.js | 10 ++++++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c4219ab..5988d74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,6 +128,9 @@ add_link_options( ) elseif(CONFIG_UBSAN) message(STATUS "Building with UBSan") +add_compile_definitions( + __UBSAN__=1 +) add_compile_options( -fsanitize=undefined -fno-sanitize-recover=all diff --git a/qjs.c b/qjs.c index 3ab74ab..654be95 100644 --- a/qjs.c +++ b/qjs.c @@ -140,6 +140,9 @@ static const JSCFunctionListEntry navigator_obj[] = { static const JSCFunctionListEntry global_obj[] = { JS_CFUNC_DEF("gc", 0, js_gc), JS_OBJECT_DEF("navigator", navigator_obj, countof(navigator_obj), JS_PROP_C_W_E), +#if defined(__ASAN__) || defined(__UBSAN__) + JS_PROP_INT32_DEF("__running_with_sanitizer__", 1, JS_PROP_C_W_E ), +#endif }; /* also used to initialize the worker context */ diff --git a/tests/test_std.js b/tests/test_std.js index f722064..44a81cf 100644 --- a/tests/test_std.js +++ b/tests/test_std.js @@ -277,11 +277,13 @@ function test_timeout() function test_timeout_order() { + if (globalThis.__running_with_sanitizer__) return; + var s = ""; - os.setTimeout(a, 1); - os.setTimeout(b, 2); - os.setTimeout(d, 5); - function a() { s += "a"; os.setTimeout(c, 0); } + os.setTimeout(a, 100); + os.setTimeout(b, 200); + os.setTimeout(d, 500); + function a() { s += "a"; os.setTimeout(c, 200); } function b() { s += "b"; } function c() { s += "c"; } function d() { assert(s === "abc"); } // not "acb"