Fix import conflicts.

This commit is contained in:
jmmv 2011-03-31 16:44:17 +00:00
parent eb215e31ca
commit e7183a7993
4 changed files with 57 additions and 41 deletions

View File

@ -1,7 +1,7 @@
//
// Automated Testing Framework (atf)
//
// Copyright (c) 2007, 2008, 2009, 2010 The NetBSD Foundation, Inc.
// Copyright (c) 2007, 2008, 2009, 2010, 2011 The NetBSD Foundation, Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@ -99,6 +99,45 @@ public:
int main(void);
};
static void
dump_stacktrace(const atf::fs::path& tp, const atf::process::status& s,
const atf::fs::path& workdir, impl::atf_tps_writer& w)
{
PRE(s.signaled() && s.coredump());
w.stderr_tc("Test program crashed; attempting to get stack trace");
const atf::fs::path corename = workdir / (tp.leaf_name() + ".core");
if (!atf::fs::exists(corename)) {
w.stderr_tc("Expected file " + corename.str() + " not found");
return;
}
const atf::fs::path gdb(GDB);
const atf::fs::path gdbout = workdir / "gdb.out";
const atf::process::argv_array args(gdb.leaf_name().c_str(), "-batch",
"-q", "-ex", "bt", tp.c_str(),
corename.c_str(), NULL);
atf::process::status status = atf::process::exec(
gdb, args,
atf::process::stream_redirect_path(gdbout),
atf::process::stream_redirect_path(atf::fs::path("/dev/null")));
if (!status.exited() || status.exitstatus() != EXIT_SUCCESS) {
w.stderr_tc("Execution of " GDB " failed");
return;
}
std::ifstream input(gdbout.c_str());
if (input) {
std::string line;
while (std::getline(input, line).good())
w.stderr_tc(line);
input.close();
}
w.stderr_tc("Stack trace complete");
}
const char* atf_run::m_description =
"atf-run is a tool that runs tests programs and collects their "
"results.";
@ -370,8 +409,8 @@ atf_run::run_test_program(const atf::fs::path& tp,
if (user.first != -1 && user.second != -1) {
if (::chown(workdir.get_path().c_str(), user.first,
user.second) == -1) {
throw atf::system_error("chmod(" +
workdir.get_path().str() + ")", "chmod(2) failed",
throw atf::system_error("chown(" +
workdir.get_path().str() + ")", "chown(2) failed",
errno);
}
resfile = workdir.get_path() / "tcr";
@ -380,45 +419,17 @@ atf_run::run_test_program(const atf::fs::path& tp,
std::pair< std::string, const atf::process::status > s =
impl::run_test_case(tp, tcname, "body", tcmd, config,
resfile, workdir.get_path(), w);
if (s.second.signaled() && s.second.coredump())
dump_stacktrace(tp, s.second, 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 | grep -v ") +
std::string("'(no debugging symbols found)'");
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;

View File

@ -33,12 +33,14 @@ extern "C" {
#include <limits.h>
#include <signal.h>
#include <unistd.h>
}
#include <cerrno>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <ios>
#include <iostream>
#include <iterator>
#include <list>

View File

@ -27,7 +27,7 @@
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# The Atf_Check variable is set by atf-sh.
# The Atf_Check and Atf-Shell variables are set by atf-sh.
h_pass()
{
@ -36,7 +36,7 @@ h_pass()
echo "Running [atf-check $*] against [${cmd}]"
cat >script.sh <<EOF
#! $(atf-config -t atf_shell)
#! ${Atf_Shell}
${cmd}
EOF
chmod +x script.sh
@ -54,7 +54,7 @@ h_fail()
echo "Running [atf-check $*] against [${cmd}]"
cat >script.sh <<EOF
#! $(atf-config -t atf_shell)
#! ${Atf_Shell}
${cmd}
EOF
chmod +x script.sh

View File

@ -26,7 +26,7 @@
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd November 16, 2010
.Dd December 13, 2010
.Dt ATF-TEST-CASE 4
.Os
.Sh NAME
@ -274,8 +274,11 @@ Undefined.
The test program always creates a temporary directory
and switches to it before running the test case's body.
This way the test case is free to modify its current directory as it
wishes, and the test program will be able to clean it up later on in a
wishes, and the runtime engine will be able to clean it up later on in a
safe way, removing any traces of its execution from the system.
To do so, the runtime engine will perform a recursive removal of the work
directory without crossing mount points; if a mount point is found, the
file system will be unmounted (if possible).
.Ss File creation mode mask (umask)
Test cases are always executed with a file creation mode mask (umask) of
.Sq 0022 .