Module Name:    src
Committed By:   pooka
Date:           Wed Mar  2 16:47:04 UTC 2011

Modified Files:
        src/external/bsd/atf/dist/atf-run: atf-run.cpp

Log Message:
In case we get a coredump from a test, autorun gdb to produce a
stacktrace (or whatever gdb can give us, which unfortunately is
usually not that much).


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/external/bsd/atf/dist/atf-run/atf-run.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-run/atf-run.cpp
diff -u src/external/bsd/atf/dist/atf-run/atf-run.cpp:1.7 src/external/bsd/atf/dist/atf-run/atf-run.cpp:1.8
--- src/external/bsd/atf/dist/atf-run/atf-run.cpp:1.7	Sun Nov  7 17:45:22 2010
+++ src/external/bsd/atf/dist/atf-run/atf-run.cpp	Wed Mar  2 16:47:04 2011
@@ -380,15 +380,44 @@
                 std::pair< std::string, const atf::process::status > s =
                     impl::run_test_case(tp, tcname, "body", tcmd, config,
                                             resfile, workdir.get_path(), w);
-                if (has_cleanup)
-                    (void)impl::run_test_case(tp, tcname, "cleanup", tcmd,
-                            config, resfile, workdir.get_path(), w);
 
                 // TODO: Force deletion of workdir.
 
                 impl::test_case_result tcr = get_test_case_result(s.first,
                     s.second, resfile);
 
+		/* if we have a core, scope out stacktrace */
+		size_t slashpos = tp.str().rfind("/");
+		std::string corename = workdir.get_path().str()
+		    + std::string("/") + tp.str().substr(slashpos+1)
+		    + std::string(".core");
+		if (s.second.signaled() && s.second.coredump() &&
+		    access(corename.c_str(), F_OK) == 0) {
+			std::string gdbcmd;
+			char buf[256];
+			char *p;
+
+			gdbcmd = std::string("gdb -batch -q -ex bt ") +
+			    tp.str() + std::string(" ") + corename +
+			    std::string(" 2> /dev/null");
+			FILE *gdbstrm = popen(gdbcmd.c_str(), "r");
+			if (gdbstrm) {
+				w.stderr_tc(std::string("test program crashed, "
+				    "autolisting stacktrace:"));
+				while (fgets(buf, sizeof(buf), gdbstrm)) {
+					if ((p = strchr(buf, '\n')) != NULL)
+						*p = '\0';
+					w.stderr_tc(std::string(buf));
+				}
+				pclose(gdbstrm);
+				w.stderr_tc(std::string("stacktrace complete"));
+			}
+		}
+
+                if (has_cleanup)
+                    (void)impl::run_test_case(tp, tcname, "cleanup", tcmd,
+                            config, resfile, workdir.get_path(), w);
+
                 w.end_tc(tcr.state(), tcr.reason());
                 if (tcr.state() == "failed")
                     errcode = EXIT_FAILURE;

Reply via email to