#include #include #include #include #include #include #include #include Result luna_main(int argc, char** argv) { StringView test_dir; os::ArgumentParser parser; parser.add_description("Run the system test suite."); parser.add_system_program_info("run-tests"_sv); parser.add_positional_argument(test_dir, "test-dir", "/bin/tests"_sv); parser.parse(argc, argv); auto dir = TRY(os::Directory::open(test_dir)); auto files = TRY(dir->list_names(os::Directory::Filter::Hidden)); for (const auto& program : files) { auto command = TRY(String::format("%s/%s"_sv, test_dir.chars(), program.chars())); StringView args[] = { command.view() }; auto pid = TRY(os::Process::spawn(args[0], Slice { args, 1 }, false)); int status; TRY(os::Process::wait(pid, &status)); if (WEXITSTATUS(status) != 0) { os::Process::kill(1, SIGQUIT); // Tell init to report a failed test run. return WEXITSTATUS(status); } } os::println("All tests passed."); os::Process::kill(1, SIGTERM); // Tell init to report a successful test run. return 0; }