headless-browser: Allow overriding the test timeout with a CLI parameter

Also bump the test timeout when running ctest to 120 seconds,
to accommodate the slow GCC CI.

(cherry picked from commit be03002780d3b7d2e3e0e38c2139361aa5fb718a)
This commit is contained in:
Andreas Kling authored and Nico Weber committed 2026-09-17 10:39:03 -04:00
1 parent 313c89a9ea
commit 8b55754eab
2 files changed
+13 -13

No files matched your search

+1 -1
View File
@@ -214,7 +214,7 @@ include(CTest)
if (BUILD_TESTING)
add_test(
NAME LibWeb
COMMAND $<TARGET_FILE:headless-browser> --run-tests ${SERENITY_SOURCE_DIR}/Tests/LibWeb --dump-failed-ref-tests
COMMAND $<TARGET_FILE:headless-browser> --run-tests ${SERENITY_SOURCE_DIR}/Tests/LibWeb --dump-failed-ref-tests --per-test-timeout 120
)
add_test(
NAME WPT
+12 -12
View File
@@ -59,8 +59,6 @@
# include <Ladybird/Utilities.h>
#endif
constexpr int DEFAULT_TIMEOUT_MS = 60'000;
static StringView s_current_test_path;
class HeadlessWebContentView final : public WebView::ViewImplementation {
@@ -248,7 +246,7 @@ static StringView test_result_to_string(TestResult result)
VERIFY_NOT_REACHED();
}
static ErrorOr<TestResult> run_dump_test(HeadlessWebContentView& view, StringView input_path, StringView expectation_path, TestMode mode, int timeout_in_milliseconds = DEFAULT_TIMEOUT_MS)
static ErrorOr<TestResult> run_dump_test(HeadlessWebContentView& view, StringView input_path, StringView expectation_path, TestMode mode, int timeout_in_milliseconds)
{
Core::EventLoop loop;
bool did_timeout = false;
@@ -348,7 +346,7 @@ static ErrorOr<TestResult> run_dump_test(HeadlessWebContentView& view, StringVie
return TestResult::Fail;
}
static ErrorOr<TestResult> run_ref_test(HeadlessWebContentView& view, StringView input_path, bool dump_failed_ref_tests, int timeout_in_milliseconds = DEFAULT_TIMEOUT_MS)
static ErrorOr<TestResult> run_ref_test(HeadlessWebContentView& view, StringView input_path, bool dump_failed_ref_tests, int timeout_in_milliseconds)
{
Core::EventLoop loop;
bool did_timeout = false;
@@ -407,7 +405,7 @@ static ErrorOr<TestResult> run_ref_test(HeadlessWebContentView& view, StringView
return TestResult::Fail;
}
static ErrorOr<TestResult> run_test(HeadlessWebContentView& view, StringView input_path, StringView expectation_path, TestMode mode, bool dump_failed_ref_tests)
static ErrorOr<TestResult> run_test(HeadlessWebContentView& view, StringView input_path, StringView expectation_path, TestMode mode, bool dump_failed_ref_tests, int per_test_timeout_in_seconds)
{
// Clear the current document.
// FIXME: Implement a debug-request to do this more thoroughly.
@@ -463,9 +461,9 @@ static ErrorOr<TestResult> run_test(HeadlessWebContentView& view, StringView inp
switch (mode) {
case TestMode::Text:
case TestMode::Layout:
return run_dump_test(view, input_path, expectation_path, mode);
return run_dump_test(view, input_path, expectation_path, mode, per_test_timeout_in_seconds * 1000);
case TestMode::Ref:
return run_ref_test(view, input_path, dump_failed_ref_tests);
return run_ref_test(view, input_path, dump_failed_ref_tests, per_test_timeout_in_seconds * 1000);
default:
VERIFY_NOT_REACHED();
}
@@ -540,7 +538,7 @@ static ErrorOr<void> collect_ref_tests(Vector<Test>& tests, StringView path)
return {};
}
static ErrorOr<int> run_tests(HeadlessWebContentView& view, StringView test_root_path, StringView test_glob, bool dump_failed_ref_tests, bool dump_gc_graph)
static ErrorOr<int> run_tests(HeadlessWebContentView& view, StringView test_root_path, StringView test_glob, bool dump_failed_ref_tests, bool dump_gc_graph, int per_test_timeout_in_seconds)
{
view.clear_content_filters();
@@ -585,7 +583,7 @@ static ErrorOr<int> run_tests(HeadlessWebContentView& view, StringView test_root
continue;
}
test.result = TRY(run_test(view, test.input_path, test.expectation_path, test.mode, dump_failed_ref_tests));
test.result = TRY(run_test(view, test.input_path, test.expectation_path, test.mode, dump_failed_ref_tests, per_test_timeout_in_seconds));
switch (*test.result) {
case TestResult::Pass:
++pass_count;
@@ -644,6 +642,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
StringView test_root_path;
ByteString test_glob;
Vector<ByteString> certificates;
int per_test_timeout_in_seconds { 30 };
#if !defined(AK_OS_SERENITY)
platform_init();
@@ -663,6 +662,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.add_option(web_driver_ipc_path, "Path to the WebDriver IPC socket", "webdriver-ipc-path", 0, "path");
args_parser.add_option(is_layout_test_mode, "Enable layout test mode", "layout-test-mode");
args_parser.add_option(certificates, "Path to a certificate file", "certificate", 'C', "certificate");
args_parser.add_option(per_test_timeout_in_seconds, "Per-test timeout (default: 30)", "per-test-timeout", 't', "seconds");
args_parser.add_positional_argument(raw_url, "URL to open", "url", Core::ArgsParser::Required::No);
args_parser.parse(arguments);
@@ -689,7 +689,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (!test_root_path.is_empty()) {
test_glob = ByteString::formatted("*{}*", test_glob);
return run_tests(*view, test_root_path, test_glob, dump_failed_ref_tests, dump_gc_graph);
return run_tests(*view, test_root_path, test_glob, dump_failed_ref_tests, dump_gc_graph, per_test_timeout_in_seconds);
}
auto url = WebView::sanitize_url(raw_url);
@@ -699,12 +699,12 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}
if (dump_layout_tree) {
TRY(run_dump_test(*view, raw_url, ""sv, TestMode::Layout));
TRY(run_dump_test(*view, raw_url, ""sv, TestMode::Layout, per_test_timeout_in_seconds));
return 0;
}
if (dump_text) {
TRY(run_dump_test(*view, raw_url, ""sv, TestMode::Text));
TRY(run_dump_test(*view, raw_url, ""sv, TestMode::Text, per_test_timeout_in_seconds));
return 0;
}