Skip to content

Truly independent web browser

test-web: Fail the run if a worker thread crashes

Andreas Kling35b043648025
diff --git a/Tests/LibWeb/test-web/TestRunCapture.cpp b/Tests/LibWeb/test-web/TestRunCapture.cpp
index 223973fb255..cc92de652e2 100644
--- a/Tests/LibWeb/test-web/TestRunCapture.cpp
+++ b/Tests/LibWeb/test-web/TestRunCapture.cpp
@@ -12,6 +12,7 @@
#include <AK/GenericShorthands.h>
#include <AK/LexicalPath.h>
#include <LibCore/System.h>
+#include <LibWebCommon/WebView/Utilities.h>
#if !defined(AK_OS_WINDOWS)
# include <signal.h>
@@ -23,6 +24,7 @@ namespace TestWeb {
static ByteString format_elapsed_time(UnixDateTime run_start_time);
static ByteString format_exit_status(Optional<int> exit_status);
static bool exit_status_is_crash(Optional<int> exit_status);
+static bool is_crash_of_worker(WebView::ProcessType, Optional<int> exit_status);
static void setup_capture_notifier(RefPtr<Core::Notifier>& notifier, Core::File& file, bool drain_available, Function<void(StringView)> on_output);
static bool drain_capture_output(Core::File& file, bool drain_available, Function<void(StringView)> const& on_output);
@@ -53,8 +55,8 @@ TestRunCapture::TestRunCapture()
{ process.type(), process.pid() },
m_stderr_capture.original_fd.value_or(STDERR_FILENO),
ByteString::formatted("test-web: process exited: {}\n", format_exit_status(exit_status)));
- if (process.type() == WebView::ProcessType::WebWorker && exit_status_is_crash(exit_status))
- ++m_crashed_worker_process_count;
+ if (is_crash_of_worker(process.type(), exit_status))
+ ++m_crashed_worker_count;
m_previous_on_process_exited(move(process), exit_status);
};
@@ -162,6 +164,20 @@ bool exit_status_is_crash(Optional<int> exit_status)
#endif
}
+// NB: A dedicated worker runs on a thread of a WebContent process that can go down between tests, or be the process of
+// a remote frame, where no test would notice.
+bool is_crash_of_worker(WebView::ProcessType type, Optional<int> exit_status)
+{
+ if (type == WebView::ProcessType::WebWorker)
+ return exit_status_is_crash(exit_status);
+#if defined(AK_OS_WINDOWS)
+ return false;
+#else
+ return type == WebView::ProcessType::WebContent && exit_status.has_value() && WIFEXITED(*exit_status)
+ && WEXITSTATUS(*exit_status) > WebView::worker_thread_crash_exit_status;
+#endif
+}
+
void TestRunCapture::setup_output_capture_for_view(TestWebView& view, ViewOutputCapture& view_capture)
{
auto process = Application::the().find_process(view.web_content_pid());
diff --git a/Tests/LibWeb/test-web/TestRunCapture.h b/Tests/LibWeb/test-web/TestRunCapture.h
index 31c3bfd51b7..c0b8a559995 100644
--- a/Tests/LibWeb/test-web/TestRunCapture.h
+++ b/Tests/LibWeb/test-web/TestRunCapture.h
@@ -35,7 +35,7 @@ public:
bool write_helper_process_output();
// A worker's process goes away when no test is looking at it any more, so the run as a whole fails if one crashes.
- size_t crashed_worker_process_count() const { return m_crashed_worker_process_count; }
+ size_t crashed_worker_count() const { return m_crashed_worker_count; }
TestRunCapture(TestRunCapture const&) = delete;
TestRunCapture& operator=(TestRunCapture const&) = delete;
@@ -83,7 +83,7 @@ private:
HashMap<TestWebView const*, NonnullOwnPtr<ViewOutputCapture>> m_test_output_captures;
HashMap<pid_t, NonnullOwnPtr<HelperOutputCapture>> m_helper_output_captures;
CaptureFile m_helper_output;
- size_t m_crashed_worker_process_count { 0 };
+ size_t m_crashed_worker_count { 0 };
Optional<HelperOutputSource> m_last_helper_source;
UnixDateTime m_run_started_at;
BrowserStderrCapture m_stderr_capture;
diff --git a/Tests/LibWeb/test-web/main.cpp b/Tests/LibWeb/test-web/main.cpp
index bb5ce365fce..40dfb13d6c3 100644
--- a/Tests/LibWeb/test-web/main.cpp
+++ b/Tests/LibWeb/test-web/main.cpp
@@ -1494,11 +1494,11 @@ static ErrorOr<int> run_tests(Core::AnonymousBuffer const& theme, Web::DevicePix
outln("Results: file://{}/index.html", app.results_directory);
}
- auto crashed_worker_process_count = test_run_capture.crashed_worker_process_count();
- if (crashed_worker_process_count > 0)
- warnln("test-web: {} WebWorker process(es) crashed, see the helper process logs", crashed_worker_process_count);
+ auto crashed_worker_count = test_run_capture.crashed_worker_count();
+ if (crashed_worker_count > 0)
+ warnln("test-web: {} worker(s) crashed, see the helper process logs", crashed_worker_count);
- return display.fail_count + display.timeout_count + display.crashed_count + tests_remaining + crashed_worker_process_count;
+ return display.fail_count + display.timeout_count + display.crashed_count + tests_remaining + crashed_worker_count;
}
static void handle_signal(int signal)