11 // Integration test suite runner.
13 int main(int argc, char **argv)
15 const char * const test_dirs[] = { "basic", "environ", "ps-environ", "chain-to" };
16 constexpr int num_tests = sizeof(test_dirs) / sizeof(test_dirs[0]);
22 bool aborted_run = false;
24 std::cout << "============== INTEGRATION TESTS =====================" << std::endl;
26 for (int i = 0; i < num_tests; i++) {
27 const char * test_dir = test_dirs[i];
29 std::string prog_path = "./run-test.sh";
30 char * const p_argv[2] = { const_cast<char *>(prog_path.c_str()), nullptr };
32 std::cout << test_dir << "... ";
34 // "Use posix_spawn", they said. "It will be easy", they said.
36 if (chdir(test_dir) != 0) {
37 std::cerr << "Couldn't chdir: " << test_dir << ": " << strerror(errno) << std::endl;
41 posix_spawn_file_actions_t p_actions;
42 posix_spawnattr_t p_attr;
44 if (posix_spawn_file_actions_init(&p_actions) != 0) {
46 std::cerr << "Error launching process: " << test_dir << "/run-test.sh: " << strerror(errno) << std::endl;
51 if (posix_spawnattr_init(&p_attr) != 0) {
53 std::cerr << "Error launching process: " << test_dir << "/run-test.sh: " << strerror(errno) << std::endl;
59 if (posix_spawn(&subproc_pid, prog_path.c_str(), &p_actions, &p_attr, p_argv, environ) != 0) {
61 std::cerr << "Failed to run run-test.sh in " << test_dir << std::endl;
66 if (waitpid(subproc_pid, &wstatus, 0) == -1) {
67 std::cout << "(unknown)" << std::endl;
68 std::cerr << "waitpid() failed" << std::endl;
73 if (WIFEXITED(wstatus)) {
74 if (WEXITSTATUS(wstatus) == 0) {
75 std::cout << "PASSED" << std::endl;
78 else if (WEXITSTATUS(wstatus) == 1) {
79 std::cout << "FAILED" << std::endl;
82 else if (WEXITSTATUS(wstatus) == 2) {
83 std::cout << "SKIPPED" << std::endl;
87 std::cout << "???" << std::endl;
91 std::cout << "*** terminated abnormally ***" << std::endl;
96 posix_spawnattr_destroy(&p_attr);
97 posix_spawn_file_actions_destroy(&p_actions);
101 std::cout << "======================================================" << std::endl;
104 std::cout << "Test run finished.\n"
105 "Passed: " << passed << "\n"
106 "Failed: " << failed;
111 "Skipped: " << skipped << std::endl;
114 std::cout << "Test run aborted." << std::endl;
117 return failed == 0 ? 0 : 1;