head	1.13;
access;
symbols
	perseant-exfatfs-base-20250801:1.13
	perseant-exfatfs-base-20240630:1.13
	perseant-exfatfs:1.13.0.18
	perseant-exfatfs-base:1.13
	cjep_sun2x:1.13.0.16
	cjep_sun2x-base:1.13
	cjep_staticlib_x-base1:1.13
	cjep_staticlib_x:1.13.0.14
	cjep_staticlib_x-base:1.13
	phil-wifi-20200421:1.13
	phil-wifi-20200411:1.13
	phil-wifi-20200406:1.13
	pgoyette-compat-merge-20190127:1.13
	pgoyette-compat-20190127:1.13
	pgoyette-compat-20190118:1.13
	pgoyette-compat-1226:1.13
	pgoyette-compat-1126:1.13
	pgoyette-compat-1020:1.13
	pgoyette-compat-0930:1.13
	pgoyette-compat-0906:1.13
	pgoyette-compat-0728:1.13
	pgoyette-compat-0625:1.13
	pgoyette-compat-0521:1.13
	pgoyette-compat-0502:1.13
	pgoyette-compat-0422:1.13
	pgoyette-compat-0415:1.13
	pgoyette-compat-0407:1.13
	pgoyette-compat-0330:1.13
	pgoyette-compat-0322:1.13
	pgoyette-compat-0315:1.13
	pgoyette-compat:1.13.0.12
	pgoyette-compat-base:1.13
	perseant-stdc-iso10646:1.13.0.10
	perseant-stdc-iso10646-base:1.13
	prg-localcount2-base3:1.13
	prg-localcount2-base2:1.13
	prg-localcount2-base1:1.13
	prg-localcount2:1.13.0.8
	prg-localcount2-base:1.13
	pgoyette-localcount-20170426:1.13
	bouyer-socketcan-base1:1.13
	pgoyette-localcount-20170320:1.13
	bouyer-socketcan:1.13.0.6
	bouyer-socketcan-base:1.13
	pgoyette-localcount-20170107:1.13
	pgoyette-localcount-20161104:1.13
	localcount-20160914:1.13
	pgoyette-localcount-20160806:1.13
	pgoyette-localcount-20160726:1.13
	pgoyette-localcount:1.13.0.4
	pgoyette-localcount-base:1.13
	netbsd-6-0-6-RELEASE:1.12
	netbsd-6-1-5-RELEASE:1.12
	yamt-pagecache-base9:1.13
	yamt-pagecache-tag8:1.10.2.1
	netbsd-6-1-4-RELEASE:1.12
	netbsd-6-0-5-RELEASE:1.12
	tls-earlyentropy:1.13.0.2
	tls-earlyentropy-base:1.13
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.13
	riastradh-drm2-base3:1.13
	netbsd-6-1-3-RELEASE:1.12
	netbsd-6-0-4-RELEASE:1.12
	netbsd-6-1-2-RELEASE:1.12
	netbsd-6-0-3-RELEASE:1.12
	netbsd-6-1-1-RELEASE:1.12
	riastradh-drm2-base2:1.12
	riastradh-drm2-base1:1.12
	riastradh-drm2:1.12.0.10
	riastradh-drm2-base:1.12
	netbsd-6-1:1.12.0.16
	netbsd-6-0-2-RELEASE:1.12
	netbsd-6-1-RELEASE:1.12
	khorben-n900:1.12.0.14
	netbsd-6-1-RC4:1.12
	netbsd-6-1-RC3:1.12
	agc-symver:1.12.0.12
	agc-symver-base:1.12
	netbsd-6-1-RC2:1.12
	netbsd-6-1-RC1:1.12
	atf-0-17:1.1.1.8
	yamt-pagecache-base8:1.12
	netbsd-6-0-1-RELEASE:1.12
	yamt-pagecache-base7:1.12
	matt-nb6-plus-nbase:1.12
	yamt-pagecache-base6:1.12
	netbsd-6-0:1.12.0.8
	netbsd-6-0-RELEASE:1.12
	netbsd-6-0-RC2:1.12
	tls-maxphys:1.12.0.6
	tls-maxphys-base:1.13
	matt-nb6-plus:1.12.0.4
	matt-nb6-plus-base:1.12
	netbsd-6-0-RC1:1.12
	atf-0-16:1.1.1.8
	yamt-pagecache-base5:1.12
	yamt-pagecache-base4:1.12
	netbsd-6:1.12.0.2
	netbsd-6-base:1.12
	atf-0-15:1.1.1.8
	yamt-pagecache-base3:1.10
	yamt-pagecache-base2:1.10
	yamt-pagecache:1.10.0.2
	yamt-pagecache-base:1.10
	atf-0-14:1.1.1.7
	cherry-xenmp:1.8.0.2
	cherry-xenmp-base:1.8
	atf-0-13:1.1.1.6
	bouyer-quota2-nbase:1.7
	bouyer-quota2:1.7.0.2
	bouyer-quota2-base:1.7
	matt-mips64-premerge-20101231:1.7
	atf-0-12:1.1.1.5
	atf-0-11:1.1.1.4
	atf-0-10:1.1.1.3
	atf-0-9:1.1.1.2
	atf-0-8:1.1.1.1
	TNF:1.1.1;
locks; strict;
comment	@// @;


1.13
date	2014.02.08.19.13.44;	author jmmv;	state dead;
branches;
next	1.12;
commitid	V1QGpoY6GYJZzkox;

1.12
date	2012.01.16.22.41.30;	author jmmv;	state Exp;
branches
	1.12.6.1;
next	1.11;

1.11
date	2011.11.16.17.46.16;	author christos;	state Exp;
branches;
next	1.10;

1.10
date	2011.06.15.08.48.36;	author jmmv;	state Exp;
branches
	1.10.2.1;
next	1.9;

1.9
date	2011.06.14.15.26.21;	author jmmv;	state Exp;
branches;
next	1.8;

1.8
date	2011.03.17.19.45.36;	author jmmv;	state Exp;
branches
	1.8.2.1;
next	1.7;

1.7
date	2010.11.16.17.55.56;	author jmmv;	state Exp;
branches;
next	1.6;

1.6
date	2010.11.07.17.45.22;	author jmmv;	state Exp;
branches;
next	1.5;

1.5
date	2010.10.20.09.17.24;	author jmmv;	state Exp;
branches;
next	1.4;

1.4
date	2010.08.26.15.28.31;	author jmmv;	state Exp;
branches;
next	1.3;

1.3
date	2010.07.03.08.11.26;	author jmmv;	state Exp;
branches;
next	1.2;

1.2
date	2010.06.10.15.27.02;	author jmmv;	state Exp;
branches;
next	1.1;

1.1
date	2010.05.08.08.05.23;	author jmmv;	state Exp;
branches
	1.1.1.1;
next	;

1.12.6.1
date	2014.08.19.23.45.53;	author tls;	state dead;
branches;
next	;
commitid	jTnpym9Qu0o4R1Nx;

1.10.2.1
date	2012.04.17.00.03.03;	author yamt;	state Exp;
branches;
next	1.10.2.2;

1.10.2.2
date	2014.05.22.15.40.12;	author yamt;	state dead;
branches;
next	;
commitid	TzMwNuE6CLSD5yBx;

1.8.2.1
date	2011.06.23.14.18.28;	author cherry;	state Exp;
branches;
next	;

1.1.1.1
date	2010.05.08.08.05.23;	author jmmv;	state Exp;
branches;
next	1.1.1.2;

1.1.1.2
date	2010.06.04.08.23.45;	author jmmv;	state Exp;
branches;
next	1.1.1.3;

1.1.1.3
date	2010.07.03.08.04.53;	author jmmv;	state Exp;
branches;
next	1.1.1.4;

1.1.1.4
date	2010.10.20.09.14.23;	author jmmv;	state Exp;
branches;
next	1.1.1.5;

1.1.1.5
date	2010.11.07.17.43.27;	author jmmv;	state Exp;
branches;
next	1.1.1.6;

1.1.1.6
date	2011.03.31.16.41.12;	author jmmv;	state Exp;
branches;
next	1.1.1.7;

1.1.1.7
date	2011.06.14.15.23.25;	author jmmv;	state Exp;
branches;
next	1.1.1.8;

1.1.1.8
date	2012.01.16.22.36.50;	author jmmv;	state Exp;
branches;
next	;


desc
@@


1.13
log
@Merge atf-0.19.
@
text
@//
// Automated Testing Framework (atf)
//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

extern "C" {
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>

#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
}

#include <cerrno>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>

#include "atf-c/defs.h"

#include "atf-c++/detail/env.hpp"
#include "atf-c++/detail/parser.hpp"
#include "atf-c++/detail/process.hpp"
#include "atf-c++/detail/sanity.hpp"
#include "atf-c++/detail/text.hpp"

#include "config.hpp"
#include "fs.hpp"
#include "io.hpp"
#include "requirements.hpp"
#include "signals.hpp"
#include "test-program.hpp"
#include "timer.hpp"
#include "user.hpp"

namespace impl = atf::atf_run;
namespace detail = atf::atf_run::detail;

namespace {

static void
check_stream(std::ostream& os)
{
    // If we receive a signal while writing to the stream, the bad bit gets set.
    // Things seem to behave fine afterwards if we clear such error condition.
    // However, I'm not sure if it's safe to query errno at this point.
    if (os.bad()) {
        if (errno == EINTR)
            os.clear();
        else
            throw std::runtime_error("Failed");
    }
}

namespace atf_tp {

static const atf::parser::token_type eof_type = 0;
static const atf::parser::token_type nl_type = 1;
static const atf::parser::token_type text_type = 2;
static const atf::parser::token_type colon_type = 3;
static const atf::parser::token_type dblquote_type = 4;

class tokenizer : public atf::parser::tokenizer< std::istream > {
public:
    tokenizer(std::istream& is, size_t curline) :
        atf::parser::tokenizer< std::istream >
            (is, true, eof_type, nl_type, text_type, curline)
    {
        add_delim(':', colon_type);
        add_quote('"', dblquote_type);
    }
};

} // namespace atf_tp

class metadata_reader : public detail::atf_tp_reader {
    impl::test_cases_map m_tcs;

    void got_tc(const std::string& ident, const atf::tests::vars_map& props)
    {
        if (m_tcs.find(ident) != m_tcs.end())
            throw(std::runtime_error("Duplicate test case " + ident +
                                     " in test program"));
        m_tcs[ident] = props;

        if (m_tcs[ident].find("has.cleanup") == m_tcs[ident].end())
            m_tcs[ident].insert(std::make_pair("has.cleanup", "false"));

        if (m_tcs[ident].find("timeout") == m_tcs[ident].end())
            m_tcs[ident].insert(std::make_pair("timeout", "300"));
    }

public:
    metadata_reader(std::istream& is) :
        detail::atf_tp_reader(is)
    {
    }

    const impl::test_cases_map&
    get_tcs(void)
        const
    {
        return m_tcs;
    }
};

struct get_metadata_params {
    const atf::fs::path& executable;
    const atf::tests::vars_map& config;

    get_metadata_params(const atf::fs::path& p_executable,
                        const atf::tests::vars_map& p_config) :
        executable(p_executable),
        config(p_config)
    {
    }
};

struct test_case_params {
    const atf::fs::path& executable;
    const std::string& test_case_name;
    const std::string& test_case_part;
    const atf::tests::vars_map& metadata;
    const atf::tests::vars_map& config;
    const atf::fs::path& resfile;
    const atf::fs::path& workdir;

    test_case_params(const atf::fs::path& p_executable,
                     const std::string& p_test_case_name,
                     const std::string& p_test_case_part,
                     const atf::tests::vars_map& p_metadata,
                     const atf::tests::vars_map& p_config,
                     const atf::fs::path& p_resfile,
                     const atf::fs::path& p_workdir) :
        executable(p_executable),
        test_case_name(p_test_case_name),
        test_case_part(p_test_case_part),
        metadata(p_metadata),
        config(p_config),
        resfile(p_resfile),
        workdir(p_workdir)
    {
    }
};

static
std::string
generate_timestamp(void)
{
    struct timeval tv;
    if (gettimeofday(&tv, NULL) == -1)
        return "0.0";

    char buf[32];
    const int len = snprintf(buf, sizeof(buf), "%ld.%ld",
                             static_cast< long >(tv.tv_sec),
                             static_cast< long >(tv.tv_usec));
    if (len >= static_cast< int >(sizeof(buf)) || len < 0)
        return "0.0";
    else
        return buf;
}

static
void
append_to_vector(std::vector< std::string >& v1,
                 const std::vector< std::string >& v2)
{
    std::copy(v2.begin(), v2.end(),
              std::back_insert_iterator< std::vector< std::string > >(v1));
}

static
char**
vector_to_argv(const std::vector< std::string >& v)
{
    char** argv = new char*[v.size() + 1];
    for (std::vector< std::string >::size_type i = 0; i < v.size(); i++) {
        argv[i] = strdup(v[i].c_str());
    }
    argv[v.size()] = NULL;
    return argv;
}

static
void
exec_or_exit(const atf::fs::path& executable,
             const std::vector< std::string >& argv)
{
    // This leaks memory in case of a failure, but it is OK.  Exiting will
    // do the necessary cleanup.
    char* const* native_argv = vector_to_argv(argv);

    ::execv(executable.c_str(), native_argv);

    const std::string message = "Failed to execute '" + executable.str() +
        "': " + std::strerror(errno) + "\n";
    if (::write(STDERR_FILENO, message.c_str(), message.length()) == -1)
        std::abort();
    std::exit(EXIT_FAILURE);
}

static
std::vector< std::string >
config_to_args(const atf::tests::vars_map& config)
{
    std::vector< std::string > args;

    for (atf::tests::vars_map::const_iterator iter = config.begin();
         iter != config.end(); iter++)
        args.push_back("-v" + (*iter).first + "=" + (*iter).second);

    return args;
}

static
void
silence_stdin(void)
{
    ::close(STDIN_FILENO);
    int fd = ::open("/dev/null", O_RDONLY);
    if (fd == -1)
        throw std::runtime_error("Could not open /dev/null");
    INV(fd == STDIN_FILENO);
}

static
void
prepare_child(const atf::fs::path& workdir)
{
    const int ret = ::setpgid(::getpid(), 0);
    INV(ret != -1);

    ::umask(S_IWGRP | S_IWOTH);

    for (int i = 1; i <= impl::last_signo; i++)
        impl::reset(i);

    atf::env::set("HOME", workdir.str());
    atf::env::unset("LANG");
    atf::env::unset("LC_ALL");
    atf::env::unset("LC_COLLATE");
    atf::env::unset("LC_CTYPE");
    atf::env::unset("LC_MESSAGES");
    atf::env::unset("LC_MONETARY");
    atf::env::unset("LC_NUMERIC");
    atf::env::unset("LC_TIME");
    atf::env::set("TZ", "UTC");

    atf::env::set("__RUNNING_INSIDE_ATF_RUN", "internal-yes-value");

    impl::change_directory(workdir);

    silence_stdin();
}

static
void
get_metadata_child(void* raw_params)
{
    const get_metadata_params* params =
        static_cast< const get_metadata_params* >(raw_params);

    std::vector< std::string > argv;
    argv.push_back(params->executable.leaf_name());
    argv.push_back("-l");
    argv.push_back("-s" + params->executable.branch_path().str());
    append_to_vector(argv, config_to_args(params->config));

    exec_or_exit(params->executable, argv);
}

void
run_test_case_child(void* raw_params)
{
    const test_case_params* params =
        static_cast< const test_case_params* >(raw_params);

    const std::pair< int, int > user = impl::get_required_user(
        params->metadata, params->config);
    if (user.first != -1 && user.second != -1)
        impl::drop_privileges(user);

    // The input 'tp' parameter may be relative and become invalid once
    // we change the current working directory.
    const atf::fs::path absolute_executable = params->executable.to_absolute();

    // Prepare the test program's arguments.  We use dynamic memory and
    // do not care to release it.  We are going to die anyway very soon,
    // either due to exec(2) or to exit(3).
    std::vector< std::string > argv;
    argv.push_back(absolute_executable.leaf_name());
    argv.push_back("-r" + params->resfile.str());
    argv.push_back("-s" + absolute_executable.branch_path().str());
    append_to_vector(argv, config_to_args(params->config));
    argv.push_back(params->test_case_name + ":" + params->test_case_part);

    prepare_child(params->workdir);
    exec_or_exit(absolute_executable, argv);
}

static void
tokenize_result(const std::string& line, std::string& out_state,
                std::string& out_arg, std::string& out_reason)
{
    const std::string::size_type pos = line.find_first_of(":(");
    if (pos == std::string::npos) {
        out_state = line;
        out_arg = "";
        out_reason = "";
    } else if (line[pos] == ':') {
        out_state = line.substr(0, pos);
        out_arg = "";
        out_reason = atf::text::trim(line.substr(pos + 1));
    } else if (line[pos] == '(') {
        const std::string::size_type pos2 = line.find("):", pos);
        if (pos2 == std::string::npos)
            throw std::runtime_error("Invalid test case result '" + line +
                "': unclosed optional argument");
        out_state = line.substr(0, pos);
        out_arg = line.substr(pos + 1, pos2 - pos - 1);
        out_reason = atf::text::trim(line.substr(pos2 + 2));
    } else
        UNREACHABLE;
}

static impl::test_case_result
handle_result(const std::string& state, const std::string& arg,
              const std::string& reason)
{
    PRE(state == "passed");

    if (!arg.empty() || !reason.empty())
        throw std::runtime_error("The test case result '" + state + "' cannot "
            "be accompanied by a reason nor an expected value");

    return impl::test_case_result(state, -1, reason);
}

static impl::test_case_result
handle_result_with_reason(const std::string& state, const std::string& arg,
                          const std::string& reason)
{
    PRE(state == "expected_death" || state == "expected_failure" ||
        state == "expected_timeout" || state == "failed" || state == "skipped");

    if (!arg.empty() || reason.empty())
        throw std::runtime_error("The test case result '" + state + "' must "
            "be accompanied by a reason but not by an expected value");

    return impl::test_case_result(state, -1, reason);
}

static impl::test_case_result
handle_result_with_reason_and_arg(const std::string& state,
                                  const std::string& arg,
                                  const std::string& reason)
{
    PRE(state == "expected_exit" || state == "expected_signal");

    if (reason.empty())
        throw std::runtime_error("The test case result '" + state + "' must "
            "be accompanied by a reason");

    int value;
    if (arg.empty()) {
        value = -1;
    } else {
        try {
            value = atf::text::to_type< int >(arg);
        } catch (const std::runtime_error&) {
            throw std::runtime_error("The value '" + arg + "' passed to the '" +
                state + "' state must be an integer");
        }
    }

    return impl::test_case_result(state, value, reason);
}

} // anonymous namespace

detail::atf_tp_reader::atf_tp_reader(std::istream& is) :
    m_is(is)
{
}

detail::atf_tp_reader::~atf_tp_reader(void)
{
}

void
detail::atf_tp_reader::got_tc(
    const std::string& ident ATF_DEFS_ATTRIBUTE_UNUSED,
    const std::map< std::string, std::string >& md ATF_DEFS_ATTRIBUTE_UNUSED)
{
}

void
detail::atf_tp_reader::got_eof(void)
{
}

void
detail::atf_tp_reader::validate_and_insert(const std::string& name,
    const std::string& value, const size_t lineno,
    std::map< std::string, std::string >& md)
{
    using atf::parser::parse_error;

    if (value.empty())
        throw parse_error(lineno, "The value for '" + name +"' cannot be "
                          "empty");

    const std::string ident_regex = "^[_A-Za-z0-9]+$";
    const std::string integer_regex = "^[0-9]+$";

    if (name == "descr") {
        // Any non-empty value is valid.
    } else if (name == "has.cleanup") {
        try {
            (void)atf::text::to_bool(value);
        } catch (const std::runtime_error&) {
            throw parse_error(lineno, "The has.cleanup property requires a"
                              " boolean value");
        }
    } else if (name == "ident") {
        if (!atf::text::match(value, ident_regex))
            throw parse_error(lineno, "The identifier must match " +
                              ident_regex + "; was '" + value + "'");
    } else if (name == "require.arch") {
    } else if (name == "require.config") {
    } else if (name == "require.files") {
    } else if (name == "require.machine") {
    } else if (name == "require.memory") {
        try {
            (void)atf::text::to_bytes(value);
        } catch (const std::runtime_error&) {
            throw parse_error(lineno, "The require.memory property requires an "
                              "integer value representing an amount of bytes");
        }
    } else if (name == "require.progs") {
    } else if (name == "require.user") {
    } else if (name == "timeout") {
        if (!atf::text::match(value, integer_regex))
            throw parse_error(lineno, "The timeout property requires an integer"
                              " value");
    } else if (name == "use.fs") {
        // Deprecated; ignore it.
    } else if (name.size() > 2 && name[0] == 'X' && name[1] == '-') {
        // Any non-empty value is valid.
    } else {
        throw parse_error(lineno, "Unknown property '" + name + "'");
    }

    md.insert(std::make_pair(name, value));
}

void
detail::atf_tp_reader::read(void)
{
    using atf::parser::parse_error;
    using namespace atf_tp;

    std::pair< size_t, atf::parser::headers_map > hml =
        atf::parser::read_headers(m_is, 1);
    atf::parser::validate_content_type(hml.second,
        "application/X-atf-tp", 1);

    tokenizer tkz(m_is, hml.first);
    atf::parser::parser< tokenizer > p(tkz);

    try {
        atf::parser::token t = p.expect(text_type, "property name");
        if (t.text() != "ident")
            throw parse_error(t.lineno(), "First property of a test case "
                              "must be 'ident'");

        std::map< std::string, std::string > props;
        do {
            const std::string name = t.text();
            t = p.expect(colon_type, "`:'");
            const std::string value = atf::text::trim(p.rest_of_line());
            t = p.expect(nl_type, "new line");
            validate_and_insert(name, value, t.lineno(), props);

            t = p.expect(eof_type, nl_type, text_type, "property name, new "
                         "line or eof");
            if (t.type() == nl_type || t.type() == eof_type) {
                const std::map< std::string, std::string >::const_iterator
                    iter = props.find("ident");
                if (iter == props.end())
                    throw parse_error(t.lineno(), "Test case definition did "
                                      "not define an 'ident' property");
                ATF_PARSER_CALLBACK(p, got_tc((*iter).second, props));
                props.clear();

                if (t.type() == nl_type) {
                    t = p.expect(text_type, "property name");
                    if (t.text() != "ident")
                        throw parse_error(t.lineno(), "First property of a "
                                          "test case must be 'ident'");
                }
            }
        } while (t.type() != eof_type);
        ATF_PARSER_CALLBACK(p, got_eof());
    } catch (const parse_error& pe) {
        p.add_error(pe);
        p.reset(nl_type);
    }
}

impl::test_case_result
detail::parse_test_case_result(const std::string& line)
{
    std::string state, arg, reason;
    tokenize_result(line, state, arg, reason);

    if (state == "expected_death")
        return handle_result_with_reason(state, arg, reason);
    else if (state.compare(0, 13, "expected_exit") == 0)
        return handle_result_with_reason_and_arg(state, arg, reason);
    else if (state.compare(0, 16, "expected_failure") == 0)
        return handle_result_with_reason(state, arg, reason);
    else if (state.compare(0, 15, "expected_signal") == 0)
        return handle_result_with_reason_and_arg(state, arg, reason);
    else if (state.compare(0, 16, "expected_timeout") == 0)
        return handle_result_with_reason(state, arg, reason);
    else if (state == "failed")
        return handle_result_with_reason(state, arg, reason);
    else if (state == "passed")
        return handle_result(state, arg, reason);
    else if (state == "skipped")
        return handle_result_with_reason(state, arg, reason);
    else
        throw std::runtime_error("Unknown test case result type in: " + line);
}

impl::atf_tps_writer::atf_tps_writer(std::ostream& os) :
    m_os(os)
{
    atf::parser::headers_map hm;
    atf::parser::attrs_map ct_attrs;
    ct_attrs["version"] = "3";
    hm["Content-Type"] =
        atf::parser::header_entry("Content-Type", "application/X-atf-tps",
                                  ct_attrs);
    atf::parser::write_headers(hm, m_os);
}

void
impl::atf_tps_writer::info(const std::string& what, const std::string& val)
{
    m_os << "info: " << what << ", " << val << "\n";
    m_os.flush();
}

void
impl::atf_tps_writer::ntps(size_t p_ntps)
{
    m_os << "tps-count: " << p_ntps << "\n";
    m_os.flush();
}

void
impl::atf_tps_writer::start_tp(const std::string& tp, size_t ntcs)
{
    m_tpname = tp;
    m_os << "tp-start: " << generate_timestamp() << ", " << tp << ", "
         << ntcs << "\n";
    m_os.flush();
}

void
impl::atf_tps_writer::end_tp(const std::string& reason)
{
    PRE(reason.find('\n') == std::string::npos);
    if (reason.empty())
        m_os << "tp-end: " << generate_timestamp() << ", " << m_tpname << "\n";
    else
        m_os << "tp-end: " << generate_timestamp() << ", " << m_tpname
             << ", " << reason << "\n";
    m_os.flush();
}

void
impl::atf_tps_writer::start_tc(const std::string& tcname)
{
    m_tcname = tcname;
    m_os << "tc-start: " << generate_timestamp() << ", " << tcname << "\n";
    m_os.flush();
}

void
impl::atf_tps_writer::stdout_tc(const std::string& line)
{
    m_os << "tc-so:" << line << "\n";
    check_stream(m_os);
    m_os.flush();
    check_stream(m_os);
}

void
impl::atf_tps_writer::stderr_tc(const std::string& line)
{
    m_os << "tc-se:" << line << "\n";
    check_stream(m_os);
    m_os.flush();
    check_stream(m_os);
}

void
impl::atf_tps_writer::end_tc(const std::string& state,
                             const std::string& reason)
{
    std::string str =  ", " + m_tcname + ", " + state;
    if (!reason.empty())
        str += ", " + reason;
    m_os << "tc-end: " << generate_timestamp() << str << "\n";
    m_os.flush();
}

impl::metadata
impl::get_metadata(const atf::fs::path& executable,
                   const atf::tests::vars_map& config)
{
    get_metadata_params params(executable, config);
    atf::process::child child =
        atf::process::fork(get_metadata_child,
                           atf::process::stream_capture(),
                           atf::process::stream_inherit(),
                           static_cast< void * >(&params));

    impl::pistream outin(child.stdout_fd());

    metadata_reader parser(outin);
    parser.read();

    const atf::process::status status = child.wait();
    if (!status.exited() || status.exitstatus() != EXIT_SUCCESS)
        throw atf::parser::format_error("Test program returned failure "
                                        "exit status for test case list");

    return metadata(parser.get_tcs());
}

impl::test_case_result
impl::read_test_case_result(const atf::fs::path& results_path)
{
    std::ifstream results_file(results_path.c_str());
    if (!results_file)
        throw std::runtime_error("Failed to open " + results_path.str());

    std::string line, extra_line;
    std::getline(results_file, line);
    if (!results_file.good())
        throw std::runtime_error("Results file is empty");

    while (std::getline(results_file, extra_line).good())
        line += "<<NEWLINE UNEXPECTED>>" + extra_line;

    results_file.close();

    return detail::parse_test_case_result(line);
}

namespace {

static volatile bool terminate_poll;

static void
sigchld_handler(const int signo ATF_DEFS_ATTRIBUTE_UNUSED)
{
    terminate_poll = true;
}

class child_muxer : public impl::muxer {
    impl::atf_tps_writer& m_writer;

    void
    line_callback(const size_t index, const std::string& line)
    {
        switch (index) {
        case 0: m_writer.stdout_tc(line); break;
        case 1: m_writer.stderr_tc(line); break;
        default: UNREACHABLE;
        }
    }

public:
    child_muxer(const int* fds, const size_t nfds,
                impl::atf_tps_writer& writer) :
        muxer(fds, nfds),
        m_writer(writer)
    {
    }
};

} // anonymous namespace

std::pair< std::string, atf::process::status >
impl::run_test_case(const atf::fs::path& executable,
                    const std::string& test_case_name,
                    const std::string& test_case_part,
                    const atf::tests::vars_map& metadata,
                    const atf::tests::vars_map& config,
                    const atf::fs::path& resfile,
                    const atf::fs::path& workdir,
                    atf_tps_writer& writer)
{
    // TODO: Capture termination signals and deliver them to the subprocess
    // instead.  Or maybe do something else; think about it.

    test_case_params params(executable, test_case_name, test_case_part,
                            metadata, config, resfile, workdir);
    atf::process::child child =
        atf::process::fork(run_test_case_child,
                           atf::process::stream_capture(),
                           atf::process::stream_capture(),
                           static_cast< void * >(&params));

    terminate_poll = false;

    const atf::tests::vars_map::const_iterator iter = metadata.find("timeout");
    INV(iter != metadata.end());
    const unsigned int timeout =
        atf::text::to_type< unsigned int >((*iter).second);
    const pid_t child_pid = child.pid();

    // Get the input stream of stdout and stderr.
    impl::file_handle outfh = child.stdout_fd();
    impl::file_handle errfh = child.stderr_fd();

    bool timed_out = false;

    // Process the test case's output and multiplex it into our output
    // stream as we read it.
    int fds[2] = {outfh.get(), errfh.get()};
    child_muxer mux(fds, 2, writer);
    try {
        child_timer timeout_timer(timeout, child_pid, terminate_poll);
        signal_programmer sigchld(SIGCHLD, sigchld_handler);
        mux.mux(terminate_poll);
        timed_out = timeout_timer.fired();
    } catch (...) {
        UNREACHABLE;
    }

    ::killpg(child_pid, SIGKILL);
    mux.flush();
    atf::process::status status = child.wait();

    std::string reason;

    if (timed_out) {
        // 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");
    }

    return std::make_pair(reason, status);
}
@


1.12
log
@Resolve conflicts after the import of atf 0.15.
@
text
@@


1.12.6.1
log
@Rebase to HEAD as of a few days ago.
@
text
@@


1.11
log
@PR/45619: jmmv: Allow atf tests to request a minimum amount of memory
@
text
@d4 1
a4 1
// Copyright (c) 2007, 2008, 2009, 2010, 2011 The NetBSD Foundation, Inc.
d33 1
d46 2
d174 18
d419 3
a421 2
detail::atf_tp_reader::got_tc(const std::string& ident,
                              const std::map< std::string, std::string >& md)
a442 1
    const std::string memory_regex = "^[0-9]+[KMGT]$";
d461 7
a469 6
    } else if (name == "require.memory") {
        if (!atf::text::match(value, integer_regex) &&
	    !atf::text::match(value, memory_regex))
            throw parse_error(lineno, "The require.memory property requires"
			      " an integer value or a string of the form"
			      " <number>[KMGT]");
d570 1
a570 1
    ct_attrs["version"] = "2";
d595 2
a596 1
    m_os << "tp-start: " << tp << ", " << ntcs << "\n";
d605 1
a605 1
        m_os << "tp-end: " << m_tpname << "\n";
d607 2
a608 1
        m_os << "tp-end: " << m_tpname << ", " << reason << "\n";
d616 1
a616 1
    m_os << "tc-start: " << tcname << "\n";
d642 1
a642 1
    std::string str = "tc-end: " + m_tcname + ", " + state;
d645 1
a645 1
    m_os << str << "\n";
d698 1
a698 1
sigchld_handler(const int signo)
@


1.10
log
@Pull up part of revision f621bc0489ac3e4ef364f840a852a6a5290e8e12:

-----
Only silence stdin for test programs

atf-check is expected to accept data in its stdin, and a previous change
broke this behavior.
-----

This should fix a few tests that broke during the 0.14 import.  In
particularly, the tests in libc/stdlib and libc/ssp that redirect stuff
to atf_check.
@
text
@d421 1
d442 6
@


1.10.2.1
log
@sync with head
@
text
@d4 1
a4 1
// Copyright (c) 2007 The NetBSD Foundation, Inc.
a32 1
#include <sys/time.h>
a44 2
#include "atf-c/defs.h"

a170 18
std::string
generate_timestamp(void)
{
    struct timeval tv;
    if (gettimeofday(&tv, NULL) == -1)
        return "0.0";

    char buf[32];
    const int len = snprintf(buf, sizeof(buf), "%ld.%ld",
                             static_cast< long >(tv.tv_sec),
                             static_cast< long >(tv.tv_usec));
    if (len >= static_cast< int >(sizeof(buf)) || len < 0)
        return "0.0";
    else
        return buf;
}

static
d398 2
a399 3
detail::atf_tp_reader::got_tc(
    const std::string& ident ATF_DEFS_ATTRIBUTE_UNUSED,
    const std::map< std::string, std::string >& md ATF_DEFS_ATTRIBUTE_UNUSED)
a438 7
    } else if (name == "require.memory") {
        try {
            (void)atf::text::to_bytes(value);
        } catch (const std::runtime_error&) {
            throw parse_error(lineno, "The require.memory property requires an "
                              "integer value representing an amount of bytes");
        }
d541 1
a541 1
    ct_attrs["version"] = "3";
d566 1
a566 2
    m_os << "tp-start: " << generate_timestamp() << ", " << tp << ", "
         << ntcs << "\n";
d575 1
a575 1
        m_os << "tp-end: " << generate_timestamp() << ", " << m_tpname << "\n";
d577 1
a577 2
        m_os << "tp-end: " << generate_timestamp() << ", " << m_tpname
             << ", " << reason << "\n";
d585 1
a585 1
    m_os << "tc-start: " << generate_timestamp() << ", " << tcname << "\n";
d611 1
a611 1
    std::string str =  ", " + m_tcname + ", " + state;
d614 1
a614 1
    m_os << "tc-end: " << generate_timestamp() << str << "\n";
d667 1
a667 1
sigchld_handler(const int signo ATF_DEFS_ATTRIBUTE_UNUSED)
@


1.10.2.2
log
@sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs.  ("Protocol error: too many arguments")
@
text
@@


1.9
log
@Post-import merge of atf-0.14.
@
text
@d34 1
d224 11
d259 2
@


1.8
log
@Pull up revision 3dd2481ec97b2fde76521939b6451d03ce989745 from upstream:

Really kill subprocesses of a test case before waiting for its completion

Before waiting for any leftover output of the test case after it terminates,
we must ensure that all of its subprocess are really, really dead.  Otherwise,
these subprocesses may be sharing the stdout of the test case, in which case
our wait will block (potentially indefinitely).

This finally (well, hopefully) fixes some random lockups exposed by the
NetBSD test suite.  Reported by Antti Kantee after
tests/fs/vfs/t_full:p2k_ffs_fillfs was exposing this problem in a pretty
reproducible manner.
@
text
@d242 3
a244 1
    atf::env::unset("TZ");
d423 1
@


1.8.2.1
log
@Catchup with rmind-uvmplock merge.
@
text
@a33 1
#include <fcntl.h>
a222 11
silence_stdin(void)
{
    ::close(STDIN_FILENO);
    int fd = ::open("/dev/null", O_RDONLY);
    if (fd == -1)
        throw std::runtime_error("Could not open /dev/null");
    INV(fd == STDIN_FILENO);
}

static
void
d242 1
a242 3
    atf::env::set("TZ", "UTC");

    atf::env::set("__RUNNING_INSIDE_ATF_RUN", "internal-yes-value");
a244 2

    silence_stdin();
a420 1
    } else if (name == "require.files") {
@


1.7
log
@Pull up 702fa99a25c1b27e4c501e4a504f36b74106ea97 from upstream

This reverts the default timeout for test cases back to 300 seconds.
The change in the release was quite blind because it did not anticipate
many existing tests to be slow enough to overflow the modified timeout
(30 seconds), specially in anita.

My plan to really fix this is to let test cases specify their sizes in
a declarative way instead of specifying timeouts in seconds (the timeout
being defined by atf-run on a size basis), so I'm not going to bother to
go over all existing tests trying to figure out which ones need a higher
timeout for now.  It is just easier to revert.
@
text
@d4 1
a4 1
// Copyright (c) 2007, 2008, 2009, 2010 The NetBSD Foundation, Inc.
d727 1
a727 1
    ::killpg(child_pid, SIGTERM);
a729 1
    ::killpg(child_pid, SIGKILL);
@


1.6
log
@Help merge of atf-0.12.
@
text
@d113 1
a113 1
            m_tcs[ident].insert(std::make_pair("timeout", "30"));
@


1.5
log
@Resolve import conflicts.
@
text
@d53 1
d57 1
d113 1
a113 4
            m_tcs[ident].insert(std::make_pair("timeout", "300"));

        if (m_tcs[ident].find("use.fs") == m_tcs[ident].end())
            m_tcs[ident].insert(std::make_pair("use.fs", "false"));
d269 5
d429 1
a429 6
        try {
            (void)atf::text::to_bool(value);
        } catch (const std::runtime_error&) {
            throw parse_error(lineno, "The use.fs property requires a boolean"
                              " value");
        }
@


1.4
log
@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@@.
@
text
@d42 1
d44 5
a48 6
#include "atf-c++/env.hpp"
#include "atf-c++/parser.hpp"
#include "atf-c++/process.hpp"
#include "atf-c++/sanity.hpp"
#include "atf-c++/signals.hpp"
#include "atf-c++/text.hpp"
d52 2
d62 14
a130 22
class output_muxer : public atf::io::std_muxer {
    impl::atf_tps_writer& m_writer;

    void
    got_stdout_line(const std::string& line)
    {
        m_writer.stdout_tc(line);
    }

    void
    got_stderr_line(const std::string& line)
    {
        m_writer.stderr_tc(line);
    }

public:
    output_muxer(impl::atf_tps_writer& writer) :
        m_writer(writer)
    {
    }
};

d231 2
a232 2
    for (int i = 1; i <= atf::signals::last_signo; i++)
        atf::signals::reset(i);
d357 1
a357 1
        } catch (const std::runtime_error& e) {
d407 1
a407 1
        } catch (const std::runtime_error& e) {
d427 1
a427 1
        } catch (const std::runtime_error& e) {
d535 1
a535 1
    m_os << "info: " << what << ", " << val << std::endl;
d542 1
a542 1
    m_os << "tps-count: " << p_ntps << std::endl;
d550 1
a550 1
    m_os << "tp-start: " << tp << ", " << ntcs << std::endl;
d559 1
a559 1
        m_os << "tp-end: " << m_tpname << std::endl;
d561 1
a561 1
        m_os << "tp-end: " << m_tpname << ", " << reason << std::endl;
d569 1
a569 1
    m_os << "tc-start: " << tcname << std::endl;
d576 2
a577 1
    m_os << "tc-so:" << line << std::endl;
d579 1
d585 2
a586 1
    m_os << "tc-se:" << line << std::endl;
d588 1
d598 1
a598 1
    m_os << str << std::endl;
d613 1
a613 2
    atf::io::file_handle outfh = child.stdout_fd();
    atf::io::pistream outin(outfh);
d648 1
a648 1
static bool sigchld_received;
d653 1
a653 1
    sigchld_received = true;
d656 22
d701 2
a707 1
    child_timer timeout_timer(timeout, child_pid);
d710 4
a713 4
    atf::io::file_handle outfh = child.stdout_fd();
    atf::io::unbuffered_istream outin(outfh);
    atf::io::file_handle errfh = child.stderr_fd();
    atf::io::unbuffered_istream errin(errfh);
d717 2
d720 4
a723 7
        atf::signals::signal_programmer sigchld(SIGCHLD, sigchld_handler);

        output_muxer muxer(writer);
        sigchld_received = false;
        muxer.read(outin, errin, sigchld_received);
        outin.close();
        errin.close();
d728 2
d735 1
a735 1
    if (timeout_timer.fired()) {
@


1.3
log
@Fix merge conflicts for atf 0.10.
@
text
@d649 12
d698 2
d701 2
a702 1
        muxer.read(outin, errin);
d715 3
a717 2
        INV(status.signaled());
        INV(status.termsig() == SIGKILL);
@


1.2
log
@Pull up revision 2f7a426c0f4149d59a7f3717ebedd6c55998e8bc from upstream:

----------
Fix detection of crashed test cases

Prevent cross-test-case contamination that occured when a first test case
passed and the second crashed.  The second could pick up the result of the
first test case and not be reported as failed.

Similarly, change the way timed out test cases are reported back to the
caller.  The creation of a temporary results file was just a really stupid
way of passing information around and introduced false positives if the
test case creates a results file before timing out.

Fixes ticket #35.
----------

Problem originally reported by pooka@@.
@
text
@d44 1
a44 1
#include "atf-c++/formats.hpp"
d51 1
d56 1
d60 22
a81 1
class metadata_reader : public atf::formats::atf_tp_reader {
d91 3
d103 1
a103 1
        atf::formats::atf_tp_reader(is)
d116 1
a116 1
    atf::formats::atf_tps_writer& m_writer;
d131 1
a131 1
    output_muxer(atf::formats::atf_tps_writer& writer) :
d251 1
a251 1
    atf::fs::change_directory(workdir);
d294 78
d374 230
d623 2
a624 2
        throw atf::formats::format_error("Test program returned failure "
                                         "exit status for test case list");
d629 20
d657 1
a657 1
                    atf::formats::atf_tps_writer& writer)
@


1.1
log
@Initial revision
@
text
@d70 3
a189 17
void
create_timeout_resfile(const atf::fs::path& path, const unsigned int timeout)
{
    std::ofstream os(path.c_str());
    if (!os)
        throw std::runtime_error("Failed to create " + path.str());

    const std::string reason = "Test case timed out after " +
        atf::text::to_string(timeout) + " " +
        (timeout == 1 ? "second" : "seconds");

    atf::formats::atf_tcr_writer writer(os);
    writer.result("failed");
    writer.reason(reason);
}

static
d295 1
a295 1
atf::process::status
d343 2
d348 2
a349 1
        create_timeout_resfile(resfile, timeout);
d352 1
a352 1
    return status;
@


1.1.1.1
log
@Import atf 0.8.  Changes in this release:

* Test programs no longer run several test cases in a row. The execution
  of a test program now requires a test case name, and that single test
  case is executed. To execute several test cases, use the atf-run
  utility as usual.

* Test programs no longer fork a subprocess to isolate the execution of
  test cases. They run the test case code in-process, and a crash of the
  test case will result in a crash of the test program. This is to ease
  debugging of faulty test cases.

* Test programs no longer isolate their test cases. This means that they
  will not create temporary directories nor sanitize the environment any
  more. Yes: running a test case that depends on system state by hand
  will most likely yield different results depending on where (machine,
  directory, user environment, etc.) it is run. Isolation has been moved
  to atf-run.

* Test programs no longer print a cryptic format (application/X-atf-tcs)
  on a special file channel. They can now print whatever they want on
  the screen. Because test programs can now only run one test case every
  time, providing controlled output is not necessary any more.

* Test programs no longer write their status into a special file
  descriptor. Instead, they create a file with the results, which is
  later parsed by atf-run. This changes the semantics of the -r flag.

* atf-run has been adjusted to perform the test case isolation. As a
  result, there is now a single canonical place that implements the
  isolation of test caes. In previous releases, the three language
  bindings (C, C++ and shell) had to be kept in sync with each other
  (read: not a nice thing to do at all). As a side effect of this
  change, writing bindings for other languages will be much, much easier
  from now on.

* atf-run forks test programs on a test case basis, instead of on a test
  program basis as it did before. This is to provide the test case
  isolation that was before implemented by the test programs themselves.

* Removed the atf-exec tool. This was used to implement test case
  isolation in atf-sh, but it is now unnecessary.

* It is now optional to define the descr meta-data property. It has been
  proven to be mostly useless, because test cases often carry a
  descriptive name of their own.
@
text
@@


1.1.1.2
log
@Import atf 0.9:

* Added atf-sh, an interpreter to process test programs written using
  the shell API. This is not really a shell interpreter by itself
  though: it is just a wrapper around the system shell that eases the
  loading of the necessary ATF libraries.

* Removed atf-compile in favour of atf-sh.

* Added the use.fs metadata property to test case, which is used to
  specify which test cases require file system access. This is to
  highlight dependencies on external resources more clearly and to speed
  up the execution of test suites by skipping the creation of many
  unnecessary work directories.

* Fixed test programs to get a sane default value for their source
  directory. This means that it should not be necessary any more to pass
  -s when running test programs that do not live in the current
  directory.

* Defining test case headers became optional. This is trivial to achieve
  in shell-based tests but a bit ugly in C and C++. In C, use the new
  ATF_TC_WITHOUT_HEAD macro to define the test case, and in C++ use
  ATF_TEST_CASE_WITHOUT_HEAD.
@
text
@a69 3

        if (m_tcs[ident].find("use.fs") == m_tcs[ident].end())
            m_tcs[ident].insert(std::make_pair("use.fs", "false"));
@


1.1.1.3
log
@Import atf 0.10:

Miscellaneous features

* Added expected failures support to test cases and atf-run.  These
  include, for example, expected clean exits, expected reception of fatal
  signals, expected timeouts and expected errors in condition checks.
  These statuses can be used to denote test cases that are known to fail
  due to a bug in the code they are testing.  atf-report reports these
  tests separately but they do not count towards the failed test cases
  amount.

* Added the ATF_CHECK_ERRNO and ATF_REQUIRE_ERRNO to the C library to
  allow easy checking of call failures that update errno.

* Added the has.cleanup meta-data property to test caes that specifies
  whether the test case has a cleanup routine or not; its value is
  automatically set.  This property is read by atf-run to know if it has to
  run the cleanup routine; skipping this run for every test case
  significantly speeds up the run time of test suites.

* Reversed the order of the ATF_CHECK_THROW macro in the C++ binding to
  take the expected exception as the first argument and the statement to
  execute as the second argument.

Changes in atf-check

* Changed atf-check to support negating the status and output checks by
  prefixing them with not- and added support to specify multiple checkers
  for stdout and stderr, not only one.

* Added the match output checker to atf-check to look for regular
  expressions in the stdout and stderr of commands.

* Modified the exit checks in atf-check to support checking for the
  reception of signals.

Code simplifications and cleanups

* Removed usage messages from test programs to simplify the
  implementation of every binding by a significant amount.  They just now
  refer the user to the appropriate manual page and do not attempt to wrap
  lines on terminal boundaries.  Test programs are not supposed to be run
  by users directly so this minor interface regression is not important.

* Removed the atf-format internal utility, which is unused after the
  change documented above.

* Removed the atf-cleanup internal utility.  It has been unused since the
  test case isolation was moved to atf-run in 0.8

* Splitted the Makefile.am into smaller files for easier maintenance and
  dropped the use of M4.  Only affects users building from the repository
  sources.

* Intermixed tests with the source files in the source tree to provide
  them more visibility and easier access.  The tests directory is gone from
  the source tree and tests are now suffixed by _test, not prefixed by t_.

* Simplifications to the atf-c library: removed the io, tcr and ui
  modules as they had become unnecessary after all simplifications
  introduced since the 0.8 release.

* Removed the application/X-atf-tcr format introduced in 0.8 release.
  Tests now print a much simplified format that is easy to parse and nicer
  to read by end users.  As a side effect, the default for test cases is
  now to print their results to stdout unless otherwise stated by providing
  the -r flag.

* Removed XML distribution documents and replaced them with plain-text
  documents.  They provided little value and introduced a lot of complexity
  to the build system.

* Simplified the output of atf-version by not attempting to print a
  revision number when building form a distfile.  Makes the build system
  easier to maintain.
@
text
@d44 1
a44 1
#include "atf-c++/parser.hpp"
a50 1
#include "fs.hpp"
a54 1
namespace detail = atf::atf_run::detail;
d58 1
a58 22
namespace atf_tp {

static const atf::parser::token_type eof_type = 0;
static const atf::parser::token_type nl_type = 1;
static const atf::parser::token_type text_type = 2;
static const atf::parser::token_type colon_type = 3;
static const atf::parser::token_type dblquote_type = 4;

class tokenizer : public atf::parser::tokenizer< std::istream > {
public:
    tokenizer(std::istream& is, size_t curline) :
        atf::parser::tokenizer< std::istream >
            (is, true, eof_type, nl_type, text_type, curline)
    {
        add_delim(':', colon_type);
        add_quote('"', dblquote_type);
    }
};

} // namespace atf_tp

class metadata_reader : public detail::atf_tp_reader {
a67 3
        if (m_tcs[ident].find("has.cleanup") == m_tcs[ident].end())
            m_tcs[ident].insert(std::make_pair("has.cleanup", "false"));

d77 1
a77 1
        detail::atf_tp_reader(is)
d90 1
a90 1
    impl::atf_tps_writer& m_writer;
d105 1
a105 1
    output_muxer(impl::atf_tps_writer& writer) :
d190 17
d242 1
a242 1
    impl::change_directory(workdir);
a284 78
static void
tokenize_result(const std::string& line, std::string& out_state,
                std::string& out_arg, std::string& out_reason)
{
    const std::string::size_type pos = line.find_first_of(":(");
    if (pos == std::string::npos) {
        out_state = line;
        out_arg = "";
        out_reason = "";
    } else if (line[pos] == ':') {
        out_state = line.substr(0, pos);
        out_arg = "";
        out_reason = atf::text::trim(line.substr(pos + 1));
    } else if (line[pos] == '(') {
        const std::string::size_type pos2 = line.find("):", pos);
        if (pos2 == std::string::npos)
            throw std::runtime_error("Invalid test case result '" + line +
                "': unclosed optional argument");
        out_state = line.substr(0, pos);
        out_arg = line.substr(pos + 1, pos2 - pos - 1);
        out_reason = atf::text::trim(line.substr(pos2 + 2));
    } else
        UNREACHABLE;
}

static impl::test_case_result
handle_result(const std::string& state, const std::string& arg,
              const std::string& reason)
{
    PRE(state == "passed");

    if (!arg.empty() || !reason.empty())
        throw std::runtime_error("The test case result '" + state + "' cannot "
            "be accompanied by a reason nor an expected value");

    return impl::test_case_result(state, -1, reason);
}

static impl::test_case_result
handle_result_with_reason(const std::string& state, const std::string& arg,
                          const std::string& reason)
{
    PRE(state == "expected_death" || state == "expected_failure" ||
        state == "expected_timeout" || state == "failed" || state == "skipped");

    if (!arg.empty() || reason.empty())
        throw std::runtime_error("The test case result '" + state + "' must "
            "be accompanied by a reason but not by an expected value");

    return impl::test_case_result(state, -1, reason);
}

static impl::test_case_result
handle_result_with_reason_and_arg(const std::string& state,
                                  const std::string& arg,
                                  const std::string& reason)
{
    PRE(state == "expected_exit" || state == "expected_signal");

    if (reason.empty())
        throw std::runtime_error("The test case result '" + state + "' must "
            "be accompanied by a reason");

    int value;
    if (arg.empty()) {
        value = -1;
    } else {
        try {
            value = atf::text::to_type< int >(arg);
        } catch (const std::runtime_error& e) {
            throw std::runtime_error("The value '" + arg + "' passed to the '" +
                state + "' state must be an integer");
        }
    }

    return impl::test_case_result(state, value, reason);
}

a286 230
detail::atf_tp_reader::atf_tp_reader(std::istream& is) :
    m_is(is)
{
}

detail::atf_tp_reader::~atf_tp_reader(void)
{
}

void
detail::atf_tp_reader::got_tc(const std::string& ident,
                              const std::map< std::string, std::string >& md)
{
}

void
detail::atf_tp_reader::got_eof(void)
{
}

void
detail::atf_tp_reader::validate_and_insert(const std::string& name,
    const std::string& value, const size_t lineno,
    std::map< std::string, std::string >& md)
{
    using atf::parser::parse_error;

    if (value.empty())
        throw parse_error(lineno, "The value for '" + name +"' cannot be "
                          "empty");

    const std::string ident_regex = "^[_A-Za-z0-9]+$";
    const std::string integer_regex = "^[0-9]+$";

    if (name == "descr") {
        // Any non-empty value is valid.
    } else if (name == "has.cleanup") {
        try {
            (void)atf::text::to_bool(value);
        } catch (const std::runtime_error& e) {
            throw parse_error(lineno, "The has.cleanup property requires a"
                              " boolean value");
        }
    } else if (name == "ident") {
        if (!atf::text::match(value, ident_regex))
            throw parse_error(lineno, "The identifier must match " +
                              ident_regex + "; was '" + value + "'");
    } else if (name == "require.arch") {
    } else if (name == "require.config") {
    } else if (name == "require.machine") {
    } else if (name == "require.progs") {
    } else if (name == "require.user") {
    } else if (name == "timeout") {
        if (!atf::text::match(value, integer_regex))
            throw parse_error(lineno, "The timeout property requires an integer"
                              " value");
    } else if (name == "use.fs") {
        try {
            (void)atf::text::to_bool(value);
        } catch (const std::runtime_error& e) {
            throw parse_error(lineno, "The use.fs property requires a boolean"
                              " value");
        }
    } else if (name.size() > 2 && name[0] == 'X' && name[1] == '-') {
        // Any non-empty value is valid.
    } else {
        throw parse_error(lineno, "Unknown property '" + name + "'");
    }

    md.insert(std::make_pair(name, value));
}

void
detail::atf_tp_reader::read(void)
{
    using atf::parser::parse_error;
    using namespace atf_tp;

    std::pair< size_t, atf::parser::headers_map > hml =
        atf::parser::read_headers(m_is, 1);
    atf::parser::validate_content_type(hml.second,
        "application/X-atf-tp", 1);

    tokenizer tkz(m_is, hml.first);
    atf::parser::parser< tokenizer > p(tkz);

    try {
        atf::parser::token t = p.expect(text_type, "property name");
        if (t.text() != "ident")
            throw parse_error(t.lineno(), "First property of a test case "
                              "must be 'ident'");

        std::map< std::string, std::string > props;
        do {
            const std::string name = t.text();
            t = p.expect(colon_type, "`:'");
            const std::string value = atf::text::trim(p.rest_of_line());
            t = p.expect(nl_type, "new line");
            validate_and_insert(name, value, t.lineno(), props);

            t = p.expect(eof_type, nl_type, text_type, "property name, new "
                         "line or eof");
            if (t.type() == nl_type || t.type() == eof_type) {
                const std::map< std::string, std::string >::const_iterator
                    iter = props.find("ident");
                if (iter == props.end())
                    throw parse_error(t.lineno(), "Test case definition did "
                                      "not define an 'ident' property");
                ATF_PARSER_CALLBACK(p, got_tc((*iter).second, props));
                props.clear();

                if (t.type() == nl_type) {
                    t = p.expect(text_type, "property name");
                    if (t.text() != "ident")
                        throw parse_error(t.lineno(), "First property of a "
                                          "test case must be 'ident'");
                }
            }
        } while (t.type() != eof_type);
        ATF_PARSER_CALLBACK(p, got_eof());
    } catch (const parse_error& pe) {
        p.add_error(pe);
        p.reset(nl_type);
    }
}

impl::test_case_result
detail::parse_test_case_result(const std::string& line)
{
    std::string state, arg, reason;
    tokenize_result(line, state, arg, reason);

    if (state == "expected_death")
        return handle_result_with_reason(state, arg, reason);
    else if (state.compare(0, 13, "expected_exit") == 0)
        return handle_result_with_reason_and_arg(state, arg, reason);
    else if (state.compare(0, 16, "expected_failure") == 0)
        return handle_result_with_reason(state, arg, reason);
    else if (state.compare(0, 15, "expected_signal") == 0)
        return handle_result_with_reason_and_arg(state, arg, reason);
    else if (state.compare(0, 16, "expected_timeout") == 0)
        return handle_result_with_reason(state, arg, reason);
    else if (state == "failed")
        return handle_result_with_reason(state, arg, reason);
    else if (state == "passed")
        return handle_result(state, arg, reason);
    else if (state == "skipped")
        return handle_result_with_reason(state, arg, reason);
    else
        throw std::runtime_error("Unknown test case result type in: " + line);
}

impl::atf_tps_writer::atf_tps_writer(std::ostream& os) :
    m_os(os)
{
    atf::parser::headers_map hm;
    atf::parser::attrs_map ct_attrs;
    ct_attrs["version"] = "2";
    hm["Content-Type"] =
        atf::parser::header_entry("Content-Type", "application/X-atf-tps",
                                  ct_attrs);
    atf::parser::write_headers(hm, m_os);
}

void
impl::atf_tps_writer::info(const std::string& what, const std::string& val)
{
    m_os << "info: " << what << ", " << val << std::endl;
    m_os.flush();
}

void
impl::atf_tps_writer::ntps(size_t p_ntps)
{
    m_os << "tps-count: " << p_ntps << std::endl;
    m_os.flush();
}

void
impl::atf_tps_writer::start_tp(const std::string& tp, size_t ntcs)
{
    m_tpname = tp;
    m_os << "tp-start: " << tp << ", " << ntcs << std::endl;
    m_os.flush();
}

void
impl::atf_tps_writer::end_tp(const std::string& reason)
{
    PRE(reason.find('\n') == std::string::npos);
    if (reason.empty())
        m_os << "tp-end: " << m_tpname << std::endl;
    else
        m_os << "tp-end: " << m_tpname << ", " << reason << std::endl;
    m_os.flush();
}

void
impl::atf_tps_writer::start_tc(const std::string& tcname)
{
    m_tcname = tcname;
    m_os << "tc-start: " << tcname << std::endl;
    m_os.flush();
}

void
impl::atf_tps_writer::stdout_tc(const std::string& line)
{
    m_os << "tc-so:" << line << std::endl;
    m_os.flush();
}

void
impl::atf_tps_writer::stderr_tc(const std::string& line)
{
    m_os << "tc-se:" << line << std::endl;
    m_os.flush();
}

void
impl::atf_tps_writer::end_tc(const std::string& state,
                             const std::string& reason)
{
    std::string str = "tc-end: " + m_tcname + ", " + state;
    if (!reason.empty())
        str += ", " + reason;
    m_os << str << std::endl;
    m_os.flush();
}

d306 2
a307 2
        throw atf::parser::format_error("Test program returned failure "
                                        "exit status for test case list");
d312 1
a312 21
impl::test_case_result
impl::read_test_case_result(const atf::fs::path& results_path)
{
    std::ifstream results_file(results_path.c_str());
    if (!results_file)
        throw std::runtime_error("Failed to open " + results_path.str());

    std::string line, extra_line;
    std::getline(results_file, line);
    if (!results_file.good())
        throw std::runtime_error("Results file is empty");

    while (std::getline(results_file, extra_line).good())
        line += "<<NEWLINE UNEXPECTED>>" + extra_line;

    results_file.close();

    return detail::parse_test_case_result(line);
}

std::pair< std::string, atf::process::status >
d320 1
a320 1
                    atf_tps_writer& writer)
a359 2
    std::string reason;

d363 1
a363 2
        reason = "Test case timed out after " + atf::text::to_string(timeout) +
            " " + (timeout == 1 ? "second" : "seconds");
d366 1
a366 1
    return std::make_pair(reason, status);
@


1.1.1.4
log
@Import atf-0.11:

Experimental version released on October 20th, 2010.

* The ATF_CHECK* macros in atf-c++ were renamed to ATF_REQUIRE* to match
  their counterparts in atf-c.

* Clearly separated the modules in atf-c that are supposed to be public
  from those that are implementation details.  The header files for the
  internal modules are not installed any more.

* Made the atf-check tool private.  It is only required by atf-sh and being
  public has the danger of causing confusion.  Also, making it private
  simplifies the public API of atf.

* Changed atf-sh to enable per-command error checking (set -e) by default.
  This catches many cases in which a test case is broken but it is not
  reported as such because execution continues.

* Fixed the XSTL and CSS stylesheets to support expected failures.
@
text
@a41 1
#include <iostream>
d43 6
a48 5
#include "atf-c++/detail/env.hpp"
#include "atf-c++/detail/parser.hpp"
#include "atf-c++/detail/process.hpp"
#include "atf-c++/detail/sanity.hpp"
#include "atf-c++/detail/text.hpp"
a51 2
#include "io.hpp"
#include "signals.hpp"
a59 14
static void
check_stream(std::ostream& os)
{
    // If we receive a signal while writing to the stream, the bad bit gets set.
    // Things seem to behave fine afterwards if we clear such error condition.
    // However, I'm not sure if it's safe to query errno at this point.
    if (os.bad()) {
        if (errno == EINTR)
            os.clear();
        else
            throw std::runtime_error("Failed");
    }
}

d115 22
d237 2
a238 2
    for (int i = 1; i <= impl::last_signo; i++)
        impl::reset(i);
d363 1
a363 1
        } catch (const std::runtime_error&) {
d413 1
a413 1
        } catch (const std::runtime_error&) {
d433 1
a433 1
        } catch (const std::runtime_error&) {
d541 1
a541 1
    m_os << "info: " << what << ", " << val << "\n";
d548 1
a548 1
    m_os << "tps-count: " << p_ntps << "\n";
d556 1
a556 1
    m_os << "tp-start: " << tp << ", " << ntcs << "\n";
d565 1
a565 1
        m_os << "tp-end: " << m_tpname << "\n";
d567 1
a567 1
        m_os << "tp-end: " << m_tpname << ", " << reason << "\n";
d575 1
a575 1
    m_os << "tc-start: " << tcname << "\n";
d582 1
a582 2
    m_os << "tc-so:" << line << "\n";
    check_stream(m_os);
a583 1
    check_stream(m_os);
d589 1
a589 2
    m_os << "tc-se:" << line << "\n";
    check_stream(m_os);
a590 1
    check_stream(m_os);
d600 1
a600 1
    m_os << str << "\n";
d615 2
a616 1
    impl::pistream outin(child.stdout_fd());
a648 34
namespace {

static volatile bool terminate_poll;

static void
sigchld_handler(const int signo)
{
    terminate_poll = true;
}

class child_muxer : public impl::muxer {
    impl::atf_tps_writer& m_writer;

    void
    line_callback(const size_t index, const std::string& line)
    {
        switch (index) {
        case 0: m_writer.stdout_tc(line); break;
        case 1: m_writer.stderr_tc(line); break;
        default: UNREACHABLE;
        }
    }

public:
    child_muxer(const int* fds, const size_t nfds,
                impl::atf_tps_writer& writer) :
        muxer(fds, nfds),
        m_writer(writer)
    {
    }
};

} // anonymous namespace

a669 2
    terminate_poll = false;

d675 1
d678 4
a681 4
    impl::file_handle outfh = child.stdout_fd();
    impl::file_handle errfh = child.stderr_fd();

    bool timed_out = false;
a684 2
    int fds[2] = {outfh.get(), errfh.get()};
    child_muxer mux(fds, 2, writer);
d686 4
a689 4
        child_timer timeout_timer(timeout, child_pid, terminate_poll);
        signal_programmer sigchld(SIGCHLD, sigchld_handler);
        mux.mux(terminate_poll);
        timed_out = timeout_timer.fired();
a693 2
    ::killpg(child_pid, SIGTERM);
    mux.flush();
d699 3
a701 4
    if (timed_out) {
        // 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.
@


1.1.1.5
log
@Import atf 0.12:

Experimental version released on November 7th, 2010.

* Added the ATF_REQUIRE_THROW_RE to atf-c++, which is the same as
  ATF_REQUIRE_THROW but allows checking for the validity of the exception's
  error message by means of a regular expression.

* Added the ATF_REQUIRE_MATCH to atf-c++, which allows checking for a
  regular expression match in a string.

* Changed the default timeout for test cases from 5 minutes to 30 seconds.
  30 seconds is long enough for virtually all tests to complete, and 5
  minutes is a way too long pause in a test suite where a single test case
  stalls.

* Deprecated the use.fs property.  While this seemed like a good idea in
  the first place to impose more control on what test cases can do, it
  turns out to be bad.  First, use.fs=false prevents bogus test cases
  from dumping core so after-the-fact debugging is harder.  Second,
  supporting use.fs adds a lot of unnecessary complexity.  atf-run will
  now ignore any value provided to use.fs and will allow test cases to
  freely access the file system if they wish to.

* Added the atf_tc_get_config_var_as_{bool,long}{,_wd} functions to the atf-c
  library.  The 'text' module became private in 0.11 but was being used
  externally to simplify the parsing of configuration variables.

* Made atf-run recognize the 'unprivileged-user' configuration variable
  and automatically drop root privileges when a test case sets
  require.user=unprivileged.  Note that this is, by no means, done for
  security purposes; this is just for user convenience; tests should, in
  general, not be blindly run as root in the first place.
@
text
@a52 1
#include "requirements.hpp"
a55 1
#include "user.hpp"
d111 4
a114 1
            m_tcs[ident].insert(std::make_pair("timeout", "30"));
a269 5
    const std::pair< int, int > user = impl::get_required_user(
        params->metadata, params->config);
    if (user.first != -1 && user.second != -1)
        impl::drop_privileges(user);

d425 6
a430 1
        // Deprecated; ignore it.
@


1.1.1.6
log
@Import atf-0.13:

Experimental version released on March 31st, 2011.

This is the first release after the creation of the Kyua project, a more
modular and reliable replacement for ATF.  From now on, ATF will change to
accomodate the transition to this new codebase, but ATF will still continue
to see development in the short/medium term.  Check out the project page at
http://code.google.com/p/kyua/ for more details.

The changes in this release are:

* Added support to run the tests with the Kyua runtime engine (kyua-cli), a
  new package that aims to replace atf-run and atf-report.  The ATF tests
  can be run with the new system by issuing a 'make installcheck-kyua' from
  the top-level directory of the project (assuming the 'kyua' binary is
  available during the configuration stage of ATF).

* atf-run and atf-report are now in maintenance mode (but *not* deprecated
  yet!).  Kyua already implements a new, much more reliable runtime engine
  that provides similar features to these tools.  That said, it is not
  complete yet so all development efforts should go towards it.

* If GDB is installed, atf-run dumps the stack trace of crashing test
  programs in an attempt to aid debugging.  Contributed by Antti Kantee.

* Reverted default timeout change in previous release and reset its value
  to 5 minutes.  This was causing several issues, specially when running
  the existing NetBSD test suite in qemu.

* Fixed the 'match' output checker in atf-check to properly validate the
  last line of a file even if it does not have a newline.

* Added the ATF_REQUIRE_IN and ATF_REQUIRE_NOT_IN macros to atf-c++ to
  check for the presence (or lack thereof) of an element in a collection.

* PR bin/44176: Fixed a race condition in atf-run that would crash atf-run
  when the cleanup of a test case triggered asynchronous modifications to
  its work directory (e.g. killing a daemon process that cleans up a pid
  file in the work directory).

* PR bin/44301: Fixed the sample XSLT file to report bogus test programs
  instead of just listing them as having 0 test cases.
@
text
@d4 1
a4 1
// Copyright (c) 2007, 2008, 2009, 2010, 2011 The NetBSD Foundation, Inc.
d113 1
a113 1
            m_tcs[ident].insert(std::make_pair("timeout", "300"));
d727 1
a727 1
    ::killpg(child_pid, SIGKILL);
d730 1
@


1.1.1.7
log
@Import atf-0.14:

Experimental version released on June 14th, 2011.

* Added a pkg-config file for atf-sh and an aclocal file to ease the
  detection of atf-sh from autoconf scripts.

* Made the default test case body defined by atf_sh fail.  This is to
  ensure that test cases are properly defined in test programs and helps
  in catching typos in the names of the body functions.

* PR bin/44882: Made atf-run connect the stdin of test cases to /dev/zero.
  This provides more consistent results with "normal" execution (in
  particular, when tests are executed detached from a terminal).

* Made atf-run hardcode TZ=UTC for test cases.  It used to undefine TZ, but
  that does not take into account that libc determines the current timezone
  from a configuration file.

* All test programs will now print a warning when they are not run through
  atf-run(1) stating that this is unsupported and may deliver incorrect
  results.

* Added support for the 'require.files' test-case property.  This allows
  test cases to specify installed files that must be present for the test
  case to run.
@
text
@d242 1
a242 3
    atf::env::set("TZ", "UTC");

    atf::env::set("__RUNNING_INSIDE_ATF_RUN", "internal-yes-value");
a420 1
    } else if (name == "require.files") {
@


1.1.1.8
log
@Import atf 0.15: the major goal of this import is to reconcile any local
changes to the atf codebase with upstream code.  All local changes should
have been backported, with appropriate portability workarounds where
necessary.

This new release also includes other changes though, such as performance
improvements and bug fixes, and also a major new feature partially
implemented by pgoyette@@: the time to execute each test cases and test
program is now recorded and included in the output reports.

The import into NetBSD has been tested natively on amd64 and macppc, and
the full test suite has also been run through anita on amd64 and i386.
No regressions observed... but you never know.

From the NEWS file, the changes in this version are as follows:

Experimental version released on January 16th, 2012.

* Respect stdin in atf-check.  The previous release silenced stdin for any
  processes spawned by atf, not only test programs, which caused breakage
  in tests that pipe data through atf-check.

* Performance improvements to atf-sh.

* Enabled detection of unused parameters and variables in the code and
  fixed all warnings.

* Changed the behavior of "developer mode".  Compiler warnings are now
  enabled unconditionally regardless of whether we are in developer mode or
  not; developer mode is now only used to perform strict warning checks and
  to enable assertions.  Additionally, developer mode is now only
  automatically enabled when building from the repository, not for formal
  releases.

* Added new Autoconf M4 macros (ATF_ARG_WITH, ATF_CHECK_C and
  ATF_CHECK_CXX) to provide a consistent way of defining a --with-arg flag
  in configure scripts and detecting the presence of any of the ATF
  bindings.  Note that ATF_CHECK_SH was already introduced in 0.14, but it
  has now been modified to also honor --with-atf if instantiated.

* Added timing support to atf-run / atf-report.

* Added support for a 'require.memory' property, to specify the minimum
  amount of physical memory needed by the test case to yield valid results.

* PR bin/45690: Force an ISO-8859-1 encoding in the XML files generated by
  atf-report so that invalid data in the output of test cases does not
  mangle our report.
@
text
@d4 1
a4 1
// Copyright (c) 2007 The NetBSD Foundation, Inc.
a32 1
#include <sys/time.h>
a33 1
#include <fcntl.h>
a43 2
#include "atf-c/defs.h"

a169 18
std::string
generate_timestamp(void)
{
    struct timeval tv;
    if (gettimeofday(&tv, NULL) == -1)
        return "0.0";

    char buf[32];
    const int len = snprintf(buf, sizeof(buf), "%ld.%ld",
                             static_cast< long >(tv.tv_sec),
                             static_cast< long >(tv.tv_usec));
    if (len >= static_cast< int >(sizeof(buf)) || len < 0)
        return "0.0";
    else
        return buf;
}

static
a222 11
silence_stdin(void)
{
    ::close(STDIN_FILENO);
    int fd = ::open("/dev/null", O_RDONLY);
    if (fd == -1)
        throw std::runtime_error("Could not open /dev/null");
    INV(fd == STDIN_FILENO);
}

static
void
a246 2

    silence_stdin();
d384 2
a385 3
detail::atf_tp_reader::got_tc(
    const std::string& ident ATF_DEFS_ATTRIBUTE_UNUSED,
    const std::map< std::string, std::string >& md ATF_DEFS_ATTRIBUTE_UNUSED)
a424 7
    } else if (name == "require.memory") {
        try {
            (void)atf::text::to_bytes(value);
        } catch (const std::runtime_error&) {
            throw parse_error(lineno, "The require.memory property requires an "
                              "integer value representing an amount of bytes");
        }
d527 1
a527 1
    ct_attrs["version"] = "3";
d552 1
a552 2
    m_os << "tp-start: " << generate_timestamp() << ", " << tp << ", "
         << ntcs << "\n";
d561 1
a561 1
        m_os << "tp-end: " << generate_timestamp() << ", " << m_tpname << "\n";
d563 1
a563 2
        m_os << "tp-end: " << generate_timestamp() << ", " << m_tpname
             << ", " << reason << "\n";
d571 1
a571 1
    m_os << "tc-start: " << generate_timestamp() << ", " << tcname << "\n";
d597 1
a597 1
    std::string str =  ", " + m_tcname + ", " + state;
d600 1
a600 1
    m_os << "tc-end: " << generate_timestamp() << str << "\n";
d653 1
a653 1
sigchld_handler(const int signo ATF_DEFS_ATTRIBUTE_UNUSED)
@


