From 8b55754eab866056f96f5bdce2b2cd164f2272e8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 26 Oct 2024 18:22:18 +0200 Subject: [PATCH] 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) --- Ladybird/CMakeLists.txt | 2 +- Userland/Utilities/headless-browser.cpp | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Ladybird/CMakeLists.txt b/Ladybird/CMakeLists.txt index 1096c3f9352..448f792b6b5 100644 --- a/Ladybird/CMakeLists.txt +++ b/Ladybird/CMakeLists.txt @@ -214,7 +214,7 @@ include(CTest) if (BUILD_TESTING) add_test( NAME LibWeb - COMMAND $ --run-tests ${SERENITY_SOURCE_DIR}/Tests/LibWeb --dump-failed-ref-tests + COMMAND $ --run-tests ${SERENITY_SOURCE_DIR}/Tests/LibWeb --dump-failed-ref-tests --per-test-timeout 120 ) add_test( NAME WPT diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp index 778bf8026b0..7c02ddeaa02 100644 --- a/Userland/Utilities/headless-browser.cpp +++ b/Userland/Utilities/headless-browser.cpp @@ -59,8 +59,6 @@ # include #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 run_dump_test(HeadlessWebContentView& view, StringView input_path, StringView expectation_path, TestMode mode, int timeout_in_milliseconds = DEFAULT_TIMEOUT_MS) +static ErrorOr 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 run_dump_test(HeadlessWebContentView& view, StringVie return TestResult::Fail; } -static ErrorOr run_ref_test(HeadlessWebContentView& view, StringView input_path, bool dump_failed_ref_tests, int timeout_in_milliseconds = DEFAULT_TIMEOUT_MS) +static ErrorOr 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 run_ref_test(HeadlessWebContentView& view, StringView return TestResult::Fail; } -static ErrorOr run_test(HeadlessWebContentView& view, StringView input_path, StringView expectation_path, TestMode mode, bool dump_failed_ref_tests) +static ErrorOr 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 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 collect_ref_tests(Vector& tests, StringView path) return {}; } -static ErrorOr run_tests(HeadlessWebContentView& view, StringView test_root_path, StringView test_glob, bool dump_failed_ref_tests, bool dump_gc_graph) +static ErrorOr 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 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 serenity_main(Main::Arguments arguments) StringView test_root_path; ByteString test_glob; Vector certificates; + int per_test_timeout_in_seconds { 30 }; #if !defined(AK_OS_SERENITY) platform_init(); @@ -663,6 +662,7 @@ ErrorOr 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 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 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; }