Module Name:    src
Committed By:   jmmv
Date:           Thu Aug 26 15:28:31 UTC 2010

Modified Files:
        src/external/bsd/atf/dist/atf-c++: io.cpp io.hpp io_test.cpp
        src/external/bsd/atf/dist/atf-run: test-program.cpp

Log Message:
Partially pull up the following revisions that address ticket #53:

    996f9c26e07a86607f373c8f0243d57329c11543
    ef98529abaf16e40a2e684496bf3da8f9ff0d09c

These prevent atf-run from stalling/crashing when a subprocess of a test
case stays around after the test case itself exits.

Reported, and verified working, by po...@.


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.3 -r1.2 src/external/bsd/atf/dist/atf-c++/io.cpp
cvs rdiff -u -r1.1.1.2 -r1.2 src/external/bsd/atf/dist/atf-c++/io.hpp
cvs rdiff -u -r1.1.1.1 -r1.2 src/external/bsd/atf/dist/atf-c++/io_test.cpp
cvs rdiff -u -r1.3 -r1.4 src/external/bsd/atf/dist/atf-run/test-program.cpp

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/bsd/atf/dist/atf-c++/io.cpp
diff -u src/external/bsd/atf/dist/atf-c++/io.cpp:1.1.1.3 src/external/bsd/atf/dist/atf-c++/io.cpp:1.2
--- src/external/bsd/atf/dist/atf-c++/io.cpp:1.1.1.3	Sat Jul  3 08:04:50 2010
+++ src/external/bsd/atf/dist/atf-c++/io.cpp	Thu Aug 26 15:28:31 2010
@@ -368,7 +368,8 @@
 }
 
 void
-impl::std_muxer::read(unbuffered_istream& out, unbuffered_istream& err)
+impl::std_muxer::read(unbuffered_istream& out, unbuffered_istream& err,
+                      const bool& terminate)
 {
     struct pollfd fds[2];
     fds[0].fd = out.get_fh().get();
@@ -379,8 +380,15 @@
     do {
         fds[0].revents = 0;
         fds[1].revents = 0;
-        if (::poll(fds, 2, -1) == -1)
-            break;
+
+        int ret;
+        while ((ret = ::poll(fds, 2, 250)) <= 0) {
+            if (terminate || ret == -1) {
+                fds[0].events = 0;
+                fds[1].events = 0;
+                break;
+            }
+        }
 
         if (fds[0].revents & POLLIN) {
             std::string line;
@@ -388,7 +396,7 @@
                 got_stdout_line(line);
             else
                 fds[0].events &= ~POLLIN;
-        } else if (fds[0].revents & POLLHUP)
+        } else if (fds[0].revents & POLLERR || fds[0].revents & POLLHUP)
             fds[0].events &= ~POLLIN;
 
         if (fds[1].revents & POLLIN) {
@@ -397,7 +405,7 @@
                 got_stderr_line(line);
             else
                 fds[1].events &= ~POLLIN;
-        } else if (fds[1].revents & POLLHUP)
+        } else if (fds[1].revents & POLLERR || fds[1].revents & POLLHUP)
             fds[1].events &= ~POLLIN;
     } while (fds[0].events & POLLIN || fds[1].events & POLLIN);
 

Index: src/external/bsd/atf/dist/atf-c++/io.hpp
diff -u src/external/bsd/atf/dist/atf-c++/io.hpp:1.1.1.2 src/external/bsd/atf/dist/atf-c++/io.hpp:1.2
--- src/external/bsd/atf/dist/atf-c++/io.hpp:1.1.1.2	Sat May  8 08:05:21 2010
+++ src/external/bsd/atf/dist/atf-c++/io.hpp	Thu Aug 26 15:28:31 2010
@@ -578,7 +578,7 @@
     std_muxer(void);
     virtual ~std_muxer(void);
 
-    void read(unbuffered_istream&, unbuffered_istream&);
+    void read(unbuffered_istream&, unbuffered_istream&, const bool&);
 };
 
 // ------------------------------------------------------------------------

Index: src/external/bsd/atf/dist/atf-c++/io_test.cpp
diff -u src/external/bsd/atf/dist/atf-c++/io_test.cpp:1.1.1.1 src/external/bsd/atf/dist/atf-c++/io_test.cpp:1.2
--- src/external/bsd/atf/dist/atf-c++/io_test.cpp:1.1.1.1	Sat Jul  3 08:04:51 2010
+++ src/external/bsd/atf/dist/atf-c++/io_test.cpp	Thu Aug 26 15:28:31 2010
@@ -502,7 +502,8 @@
     atf::io::unbuffered_istream errs(errfh);
 
     test_std_muxer m;
-    m.read(outs, errs);
+    bool terminate = false;
+    m.read(outs, errs, terminate);
     ATF_CHECK(m.m_eof);
     ATF_CHECK(m.m_stdout_lines.empty());
     ATF_CHECK(m.m_stderr_lines.empty());
@@ -530,7 +531,8 @@
     atf::io::unbuffered_istream errs(errfh);
 
     test_std_muxer m;
-    m.read(outs, errs);
+    bool terminate = false;
+    m.read(outs, errs, terminate);
     ATF_CHECK(m.m_eof);
     ATF_CHECK_EQUAL(3, m.m_stdout_lines.size());
     ATF_CHECK_EQUAL("stdout line 1", m.m_stdout_lines[0]);

Index: src/external/bsd/atf/dist/atf-run/test-program.cpp
diff -u src/external/bsd/atf/dist/atf-run/test-program.cpp:1.3 src/external/bsd/atf/dist/atf-run/test-program.cpp:1.4
--- src/external/bsd/atf/dist/atf-run/test-program.cpp:1.3	Sat Jul  3 08:11:26 2010
+++ src/external/bsd/atf/dist/atf-run/test-program.cpp	Thu Aug 26 15:28:31 2010
@@ -646,6 +646,18 @@
     return detail::parse_test_case_result(line);
 }
 
+namespace {
+
+static bool sigchld_received;
+
+static void
+sigchld_handler(const int signo)
+{
+    sigchld_received = true;
+}
+
+} // anonymous namespace
+
 std::pair< std::string, atf::process::status >
 impl::run_test_case(const atf::fs::path& executable,
                     const std::string& test_case_name,
@@ -683,8 +695,11 @@
     // Process the test case's output and multiplex it into our output
     // stream as we read it.
     try {
+        atf::signals::signal_programmer sigchld(SIGCHLD, sigchld_handler);
+
         output_muxer muxer(writer);
-        muxer.read(outin, errin);
+        sigchld_received = false;
+        muxer.read(outin, errin, sigchld_received);
         outin.close();
         errin.close();
     } catch (...) {
@@ -697,8 +712,9 @@
     std::string reason;
 
     if (timeout_timer.fired()) {
-        INV(status.signaled());
-        INV(status.termsig() == SIGKILL);
+        // Don't assume the child process has been signaled due to the timeout
+        // expiration as older versions did.  The child process may have exited
+        // but we may have timed out due to a subchild process getting stuck.
         reason = "Test case timed out after " + atf::text::to_string(timeout) +
             " " + (timeout == 1 ? "second" : "seconds");
     }

Reply via email to