From 606f83436dcf68ccebd02a1d56ca340654a79ac8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 9 Sep 2020 21:06:11 +0200 Subject: [PATCH] test-js: Catch SIGINFO and dump the current test name + pass/fail/skip This is pretty handy if the JS tests take a long time to run and you wonder what they're doing. :^) --- Userland/test-js.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Userland/test-js.cpp b/Userland/test-js.cpp index 10c0810ec7..3a944aedac 100644 --- a/Userland/test-js.cpp +++ b/Userland/test-js.cpp @@ -44,6 +44,7 @@ #define TOP_LEVEL_TEST_NAME "__$$TOP_LEVEL$$__" static bool collect_on_every_allocation = false; +static String currently_running_test; enum class TestResult { Pass, @@ -105,15 +106,26 @@ private: class TestRunner { public: + static TestRunner* the() + { + return s_the; + } + TestRunner(String test_root, bool print_times) : m_test_root(move(test_root)) , m_print_times(print_times) { + ASSERT(!s_the); + s_the = this; } void run(); + const JSTestRunnerCounts& counts() const { return m_counts; } + private: + static TestRunner* s_the; + JSFileResult run_file_test(const String& test_path); void print_file_result(const JSFileResult& file_result) const; void print_test_results() const; @@ -127,6 +139,8 @@ private: RefPtr m_test_program; }; +TestRunner* TestRunner::s_the = nullptr; + TestRunnerGlobalObject::TestRunnerGlobalObject() { } @@ -256,6 +270,8 @@ static Optional get_test_results(JS::Interpreter& interpreter) JSFileResult TestRunner::run_file_test(const String& test_path) { + currently_running_test = test_path; + double start_time = get_time_in_ms(); auto interpreter = JS::Interpreter::create(); @@ -569,6 +585,15 @@ int main(int argc, char** argv) return 1; } +#ifdef SIGINFO + signal(SIGINFO, [](int) { + static char buffer[4096]; + auto& counts = TestRunner::the()->counts(); + int len = snprintf(buffer, sizeof(buffer), "Pass: %d, Fail: %d, Skip: %d\nCurrent test: %s\n", counts.tests_passed, counts.tests_failed, counts.tests_skipped, currently_running_test.characters()); + write(STDOUT_FILENO, buffer, len); + }); +#endif + Core::ArgsParser args_parser; args_parser.add_option(print_times, "Show duration of each test", "show-time", 't'); args_parser.add_option(collect_on_every_allocation, "Collect garbage after every allocation", "collect-often", 'g');