From e77ce26ff115ffe4a3bc17876c6fe8281b19cda7 Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Tue, 30 May 2023 11:16:31 +0200 Subject: [PATCH] run-tests: Unlink coredumps in self-test mode This ensures that the RAM does not fill up with already processed coredumps when many tests crash (as is the case on AArch64). We only do this in self-test mode so as to avoid racing CrashDaemon. --- Base/home/anon/Tests/run-tests-and-shutdown.sh | 2 +- Userland/Utilities/run-tests.cpp | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Base/home/anon/Tests/run-tests-and-shutdown.sh b/Base/home/anon/Tests/run-tests-and-shutdown.sh index 4edea6bfeb..f31fe5f038 100755 --- a/Base/home/anon/Tests/run-tests-and-shutdown.sh +++ b/Base/home/anon/Tests/run-tests-and-shutdown.sh @@ -5,7 +5,7 @@ echo "==== Running Tests on SerenityOS ====" export LLVM_PROFILE_FILE="$HOME/profiles/%p-profile.profraw" -run-tests --show-progress=false +run-tests --show-progress=false --unlink-coredumps fail_count=$? unset LLVM_PROFILE_FILE diff --git a/Userland/Utilities/run-tests.cpp b/Userland/Utilities/run-tests.cpp index 645a5c3598..d753fec3e3 100644 --- a/Userland/Utilities/run-tests.cpp +++ b/Userland/Utilities/run-tests.cpp @@ -37,13 +37,14 @@ DeprecatedString g_currently_running_test; class TestRunner : public ::Test::TestRunner { public: - TestRunner(DeprecatedString test_root, Regex exclude_regex, NonnullRefPtr config, Regex skip_regex, bool run_skipped_tests, bool print_progress, bool print_json, bool print_all_output, bool print_times = true) + TestRunner(DeprecatedString test_root, Regex exclude_regex, NonnullRefPtr config, Regex skip_regex, bool run_skipped_tests, bool print_progress, bool print_json, bool print_all_output, bool unlink_coredumps, bool print_times = true) : ::Test::TestRunner(move(test_root), print_times, print_progress, print_json) , m_exclude_regex(move(exclude_regex)) , m_config(move(config)) , m_skip_regex(move(skip_regex)) , m_run_skipped_tests(run_skipped_tests) , m_print_all_output(print_all_output) + , m_unlink_coredumps(unlink_coredumps) { if (!run_skipped_tests) { m_skip_directories = m_config->read_entry("Global", "SkipDirectories", "").split(' '); @@ -70,6 +71,7 @@ protected: Regex m_skip_regex; bool m_run_skipped_tests { false }; bool m_print_all_output { false }; + bool m_unlink_coredumps { false }; }; Vector TestRunner::get_test_paths() const @@ -142,6 +144,7 @@ void TestRunner::do_run_single_test(DeprecatedString const& test_path, size_t cu print_modifiers({ Test::CLEAR }); if (test_result.result == Test::Result::Crashed) { auto pid_search_string = DeprecatedString::formatted("_{}_", test_result.child_pid); + Optional coredump_path; Core::DirIterator iterator("/tmp/coredump"sv); if (!iterator.has_error()) { while (iterator.has_next()) { @@ -149,6 +152,7 @@ void TestRunner::do_run_single_test(DeprecatedString const& test_path, size_t cu if (!path.contains(pid_search_string)) continue; + coredump_path = path; auto reader = Coredump::Reader::create(path); if (!reader) break; @@ -165,6 +169,8 @@ void TestRunner::do_run_single_test(DeprecatedString const& test_path, size_t cu break; } } + if (m_unlink_coredumps && coredump_path.has_value()) + (void)Core::System::unlink(coredump_path.value()); } } else { print_modifiers({ Test::BG_GREEN, Test::FG_BLACK, Test::FG_BOLD }); @@ -315,6 +321,7 @@ ErrorOr serenity_main(Main::Arguments arguments) bool print_all_output = false; bool run_benchmarks = false; bool run_skipped_tests = false; + bool unlink_coredumps = false; StringView specified_test_root; DeprecatedString test_glob; DeprecatedString exclude_pattern; @@ -340,6 +347,7 @@ ErrorOr serenity_main(Main::Arguments arguments) args_parser.add_option(print_all_output, "Show all test output", "verbose", 'v'); args_parser.add_option(run_benchmarks, "Run benchmarks as well", "benchmarks", 'b'); args_parser.add_option(run_skipped_tests, "Run all matching tests, even those marked as 'skip'", "all", 'a'); + args_parser.add_option(unlink_coredumps, "Unlink coredumps after printing backtraces", "unlink-coredumps", 0); args_parser.add_option(test_glob, "Only run tests matching the given glob", "filter", 'f', "glob"); args_parser.add_option(exclude_pattern, "Regular expression to use to exclude paths from being considered tests", "exclude-pattern", 'e', "pattern"); args_parser.add_option(config_file, "Configuration file to use", "config-file", 'c', "filename"); @@ -406,7 +414,7 @@ ErrorOr serenity_main(Main::Arguments arguments) return 1; } - TestRunner test_runner(test_root, move(exclude_regex), move(config), move(skip_regex), run_skipped_tests, print_progress, print_json, print_all_output); + TestRunner test_runner(test_root, move(exclude_regex), move(config), move(skip_regex), run_skipped_tests, print_progress, print_json, print_all_output, unlink_coredumps); test_runner.run(test_glob); return test_runner.counts().tests_failed;