test262-runner: Use names for the different exit codes

These are not used by test-test262 but can be used to quickly
distinguish the type of problem if the runner fails when running
manually.
This commit is contained in:
davidot 2022-09-28 17:03:07 +02:00 committed by Andrew Kaster
parent 1f54259922
commit 340a2a96a4
Notes: sideshowbarker 2024-07-17 06:00:39 +09:00

View file

@ -566,6 +566,11 @@ extern "C" __attribute__((__noreturn__)) void __assert_fail(char const* assertio
} }
#endif #endif
constexpr int exit_wrong_arguments = 2;
constexpr int exit_stdout_setup_failed = 1;
constexpr int exit_setup_input_failure = 7;
constexpr int exit_read_file_failure = 3;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
int timeout = 10; int timeout = 10;
@ -585,7 +590,7 @@ int main(int argc, char** argv)
#ifndef AK_OS_MACOS #ifndef AK_OS_MACOS
if (disable_core_dumping && prctl(PR_SET_DUMPABLE, 0, 0) < 0) { if (disable_core_dumping && prctl(PR_SET_DUMPABLE, 0, 0) < 0) {
perror("prctl(PR_SET_DUMPABLE)"); perror("prctl(PR_SET_DUMPABLE)");
return 2; return exit_wrong_arguments;
} }
#endif #endif
@ -597,7 +602,7 @@ int main(int argc, char** argv)
if (timeout <= 0) { if (timeout <= 0) {
warnln("timeout must be at least 1"); warnln("timeout must be at least 1");
return 2; return exit_wrong_arguments;
} }
AK::set_debug_enabled(enable_debug_printing); AK::set_debug_enabled(enable_debug_printing);
@ -609,19 +614,19 @@ int main(int argc, char** argv)
auto saved_stdout = dup(STDOUT_FILENO); auto saved_stdout = dup(STDOUT_FILENO);
if (saved_stdout < 0) { if (saved_stdout < 0) {
perror("dup"); perror("dup");
return 1; return exit_stdout_setup_failed;
} }
saved_stdout_fd = fdopen(saved_stdout, "w"); saved_stdout_fd = fdopen(saved_stdout, "w");
if (!saved_stdout_fd) { if (!saved_stdout_fd) {
perror("fdopen"); perror("fdopen");
return 1; return exit_stdout_setup_failed;
} }
int stdout_pipe[2]; int stdout_pipe[2];
if (pipe(stdout_pipe) < 0) { if (pipe(stdout_pipe) < 0) {
perror("pipe"); perror("pipe");
return 1; return exit_stdout_setup_failed;
} }
auto flags = fcntl(stdout_pipe[0], F_GETFL); auto flags = fcntl(stdout_pipe[0], F_GETFL);
@ -634,12 +639,12 @@ int main(int argc, char** argv)
if (dup2(stdout_pipe[1], STDOUT_FILENO) < 0) { if (dup2(stdout_pipe[1], STDOUT_FILENO) < 0) {
perror("dup2"); perror("dup2");
return 1; return exit_stdout_setup_failed;
} }
if (close(stdout_pipe[1]) < 0) { if (close(stdout_pipe[1]) < 0) {
perror("close"); perror("close");
return 1; return exit_stdout_setup_failed;
} }
auto collect_output = [&] { auto collect_output = [&] {
@ -665,12 +670,12 @@ int main(int argc, char** argv)
auto standard_input_or_error = Core::Stream::File::standard_input(); auto standard_input_or_error = Core::Stream::File::standard_input();
if (standard_input_or_error.is_error()) if (standard_input_or_error.is_error())
return 7; return exit_setup_input_failure;
Array<u8, 1024> input_buffer {}; Array<u8, 1024> input_buffer {};
auto buffered_standard_input_or_error = Core::Stream::BufferedFile::create(standard_input_or_error.release_value()); auto buffered_standard_input_or_error = Core::Stream::BufferedFile::create(standard_input_or_error.release_value());
if (buffered_standard_input_or_error.is_error()) if (buffered_standard_input_or_error.is_error())
return 7; return exit_setup_input_failure;
auto& buffered_input_stream = buffered_standard_input_or_error.value(); auto& buffered_input_stream = buffered_standard_input_or_error.value();
@ -687,7 +692,7 @@ int main(int argc, char** argv)
if (s_automatic_harness_detection_mode) { if (s_automatic_harness_detection_mode) {
if (!extract_harness_directory(path)) if (!extract_harness_directory(path))
return 4; return exit_read_file_failure;
s_automatic_harness_detection_mode = false; s_automatic_harness_detection_mode = false;
VERIFY(!s_harness_file_directory.is_empty()); VERIFY(!s_harness_file_directory.is_empty());
} }
@ -695,7 +700,7 @@ int main(int argc, char** argv)
auto file_or_error = Core::Stream::File::open(path, Core::Stream::OpenMode::Read); auto file_or_error = Core::Stream::File::open(path, Core::Stream::OpenMode::Read);
if (file_or_error.is_error()) { if (file_or_error.is_error()) {
warnln("Could not open file: {}", path); warnln("Could not open file: {}", path);
return 3; return exit_read_file_failure;
} }
auto& file = file_or_error.value(); auto& file = file_or_error.value();
@ -709,7 +714,7 @@ int main(int argc, char** argv)
auto contents_or_error = file->read_all(); auto contents_or_error = file->read_all();
if (contents_or_error.is_error()) { if (contents_or_error.is_error()) {
warnln("Could not read contents of file: {}", path); warnln("Could not read contents of file: {}", path);
return 3; return exit_read_file_failure;
} }
auto& contents = contents_or_error.value(); auto& contents = contents_or_error.value();
StringBuilder builder { contents.size() + strict_length }; StringBuilder builder { contents.size() + strict_length };