11 // Integration test suite runner.
13 int main(int argc, char **argv)
15 const char * const test_dirs[] = { "basic", "environ", "ps-environ", "chain-to", "force-stop", "restart",
16 "check-basic", "check-cycle", "reload1", "reload2" };
17 constexpr int num_tests = sizeof(test_dirs) / sizeof(test_dirs[0]);
23 bool aborted_run = false;
25 std::cout << "============== INTEGRATION TESTS =====================" << std::endl;
27 for (int i = 0; i < num_tests; i++) {
28 const char * test_dir = test_dirs[i];
30 std::string prog_path = "./run-test.sh";
31 char * const p_argv[2] = { const_cast<char *>(prog_path.c_str()), nullptr };
33 std::cout << test_dir << "... ";
35 // "Use posix_spawn", they said. "It will be easy", they said.
37 if (chdir(test_dir) != 0) {
38 std::cerr << "Couldn't chdir: " << test_dir << ": " << strerror(errno) << std::endl;
42 posix_spawn_file_actions_t p_actions;
43 posix_spawnattr_t p_attr;
45 if (posix_spawn_file_actions_init(&p_actions) != 0) {
47 std::cerr << "Error launching process: " << test_dir << "/run-test.sh: " << strerror(errno) << std::endl;
52 if (posix_spawnattr_init(&p_attr) != 0) {
54 std::cerr << "Error launching process: " << test_dir << "/run-test.sh: " << strerror(errno) << std::endl;
60 if (posix_spawn(&subproc_pid, prog_path.c_str(), &p_actions, &p_attr, p_argv, environ) != 0) {
62 std::cerr << "Failed to run run-test.sh in " << test_dir << std::endl;
67 if (waitpid(subproc_pid, &wstatus, 0) == -1) {
68 std::cout << "(unknown)" << std::endl;
69 std::cerr << "waitpid() failed" << std::endl;
74 if (WIFEXITED(wstatus)) {
75 if (WEXITSTATUS(wstatus) == 0) {
76 std::cout << "PASSED" << std::endl;
79 else if (WEXITSTATUS(wstatus) == 1) {
80 std::cout << "FAILED" << std::endl;
83 else if (WEXITSTATUS(wstatus) == 2) {
84 std::cout << "SKIPPED" << std::endl;
88 std::cout << "???" << std::endl;
92 std::cout << "*** terminated abnormally ***" << std::endl;
97 posix_spawnattr_destroy(&p_attr);
98 posix_spawn_file_actions_destroy(&p_actions);
102 std::cout << "======================================================" << std::endl;
105 std::cout << "Test run finished.\n"
106 "Passed: " << passed << "\n"
107 "Failed: " << failed;
112 "Skipped: " << skipped << std::endl;
115 std::cout << "Test run aborted." << std::endl;
118 return failed == 0 ? 0 : 1;