Truly independent web browser
test-web: Fail a run in which a WebWorker process crashes
Andreas Kling628e6abe4d8d
diff --git a/Tests/LibWeb/test-web/TestRunCapture.cpp b/Tests/LibWeb/test-web/TestRunCapture.cppindex 96c646fd4f7..223973fb255 100644--- a/Tests/LibWeb/test-web/TestRunCapture.cpp+++ b/Tests/LibWeb/test-web/TestRunCapture.cpp@@ -9,10 +9,12 @@#include "TestWeb.h"#include "TestWebView.h"+#include <AK/GenericShorthands.h>#include <AK/LexicalPath.h>#include <LibCore/System.h>#if !defined(AK_OS_WINDOWS)+# include <signal.h># include <sys/wait.h>#endif@@ -20,6 +22,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 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);@@ -50,6 +53,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;m_previous_on_process_exited(move(process), exit_status);};@@ -139,6 +144,24 @@ static ByteString format_exit_status(Optional<int> exit_status)#endif}+bool exit_status_is_crash(Optional<int> exit_status)+{+#if defined(AK_OS_WINDOWS)+ (void)exit_status;+ return false;+#else+ if (!exit_status.has_value())+ return false;++ // NB: A crash handler ends the process with a status of 128 plus the signal.+ if (WIFEXITED(*exit_status))+ return WEXITSTATUS(*exit_status) >= 128;++ // NB: The UI process kills a worker that does not exit in time, so being killed is no crash.+ return WIFSIGNALED(*exit_status) && !first_is_one_of(WTERMSIG(*exit_status), SIGKILL, SIGTERM);+#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.hindex b84ca56f939..31c3bfd51b7 100644--- a/Tests/LibWeb/test-web/TestRunCapture.h+++ b/Tests/LibWeb/test-web/TestRunCapture.h@@ -34,6 +34,9 @@ public:void write_test_output(TestWebView const&);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; }+TestRunCapture(TestRunCapture const&) = delete;TestRunCapture& operator=(TestRunCapture const&) = delete;@@ -80,6 +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 };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.cppindex f01ba7ec265..bb5ce365fce 100644--- a/Tests/LibWeb/test-web/main.cpp+++ b/Tests/LibWeb/test-web/main.cpp@@ -1494,7 +1494,11 @@ static ErrorOr<int> run_tests(Core::AnonymousBuffer const& theme, Web::DevicePixoutln("Results: file://{}/index.html", app.results_directory);}- return display.fail_count + display.timeout_count + display.crashed_count + tests_remaining;+ 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);++ return display.fail_count + display.timeout_count + display.crashed_count + tests_remaining + crashed_worker_process_count;}static void handle_signal(int signal)