Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/atf/dist Partially pull up the following revisi...



details:   https://anonhg.NetBSD.org/src/rev/2ca80840bf1e
branches:  trunk
changeset: 757363:2ca80840bf1e
user:      jmmv <jmmv%NetBSD.org@localhost>
date:      Thu Aug 26 15:28:31 2010 +0000

description:
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 pooka@.

diffstat:

 external/bsd/atf/dist/atf-c++/io.cpp           |  18 +++++++++++++-----
 external/bsd/atf/dist/atf-c++/io.hpp           |   2 +-
 external/bsd/atf/dist/atf-c++/io_test.cpp      |   6 ++++--
 external/bsd/atf/dist/atf-run/test-program.cpp |  22 +++++++++++++++++++---
 4 files changed, 37 insertions(+), 11 deletions(-)

diffs (131 lines):

diff -r 09b5f02a1028 -r 2ca80840bf1e external/bsd/atf/dist/atf-c++/io.cpp
--- a/external/bsd/atf/dist/atf-c++/io.cpp      Thu Aug 26 15:07:16 2010 +0000
+++ b/external/bsd/atf/dist/atf-c++/io.cpp      Thu Aug 26 15:28:31 2010 +0000
@@ -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);
 
diff -r 09b5f02a1028 -r 2ca80840bf1e external/bsd/atf/dist/atf-c++/io.hpp
--- a/external/bsd/atf/dist/atf-c++/io.hpp      Thu Aug 26 15:07:16 2010 +0000
+++ b/external/bsd/atf/dist/atf-c++/io.hpp      Thu Aug 26 15:28:31 2010 +0000
@@ -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&);
 };
 
 // ------------------------------------------------------------------------
diff -r 09b5f02a1028 -r 2ca80840bf1e external/bsd/atf/dist/atf-c++/io_test.cpp
--- a/external/bsd/atf/dist/atf-c++/io_test.cpp Thu Aug 26 15:07:16 2010 +0000
+++ b/external/bsd/atf/dist/atf-c++/io_test.cpp Thu Aug 26 15:28:31 2010 +0000
@@ -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]);
diff -r 09b5f02a1028 -r 2ca80840bf1e external/bsd/atf/dist/atf-run/test-program.cpp
--- a/external/bsd/atf/dist/atf-run/test-program.cpp    Thu Aug 26 15:07:16 2010 +0000
+++ b/external/bsd/atf/dist/atf-run/test-program.cpp    Thu Aug 26 15:28:31 2010 +0000
@@ -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");
     }



Home | Main Index | Thread Index | Old Index