summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorDaniel Bertalan <dani@danielbertalan.dev>2023-05-30 11:16:31 +0200
committerAndreas Kling <kling@serenityos.org>2023-06-01 09:04:20 +0200
commite77ce26ff115ffe4a3bc17876c6fe8281b19cda7 (patch)
treede358e7c69b2b4825a2b93dfefcbe8d69fa1bc6a /Userland
parent427cf14d71056f526e41d5d564df91e8294c2eda (diff)
downloadserenity-e77ce26ff115ffe4a3bc17876c6fe8281b19cda7.zip
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.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Utilities/run-tests.cpp12
1 files changed, 10 insertions, 2 deletions
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<PosixExtended> exclude_regex, NonnullRefPtr<Core::ConfigFile> config, Regex<PosixExtended> 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<PosixExtended> exclude_regex, NonnullRefPtr<Core::ConfigFile> config, Regex<PosixExtended> 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<PosixExtended> m_skip_regex;
bool m_run_skipped_tests { false };
bool m_print_all_output { false };
+ bool m_unlink_coredumps { false };
};
Vector<DeprecatedString> 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<DeprecatedString> 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<int> 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<int> 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<int> 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;