head	1.8;
access;
symbols
	perseant-exfatfs-base-20261102:1.8
	perseant-exfatfs-base-20250801:1.8
	perseant-exfatfs-base-20240630:1.8
	perseant-exfatfs:1.8.0.18
	perseant-exfatfs-base:1.8
	cjep_sun2x:1.8.0.16
	cjep_sun2x-base:1.8
	cjep_staticlib_x-base1:1.8
	cjep_staticlib_x:1.8.0.14
	cjep_staticlib_x-base:1.8
	phil-wifi-20200421:1.8
	phil-wifi-20200411:1.8
	phil-wifi-20200406:1.8
	pgoyette-compat-merge-20190127:1.8
	pgoyette-compat-20190127:1.8
	pgoyette-compat-20190118:1.8
	pgoyette-compat-1226:1.8
	pgoyette-compat-1126:1.8
	pgoyette-compat-1020:1.8
	pgoyette-compat-0930:1.8
	pgoyette-compat-0906:1.8
	pgoyette-compat-0728:1.8
	pgoyette-compat-0625:1.8
	pgoyette-compat-0521:1.8
	pgoyette-compat-0502:1.8
	pgoyette-compat-0422:1.8
	pgoyette-compat-0415:1.8
	pgoyette-compat-0407:1.8
	pgoyette-compat-0330:1.8
	pgoyette-compat-0322:1.8
	pgoyette-compat-0315:1.8
	pgoyette-compat:1.8.0.12
	pgoyette-compat-base:1.8
	perseant-stdc-iso10646:1.8.0.10
	perseant-stdc-iso10646-base:1.8
	prg-localcount2-base3:1.8
	prg-localcount2-base2:1.8
	prg-localcount2-base1:1.8
	prg-localcount2:1.8.0.8
	prg-localcount2-base:1.8
	pgoyette-localcount-20170426:1.8
	bouyer-socketcan-base1:1.8
	pgoyette-localcount-20170320:1.8
	bouyer-socketcan:1.8.0.6
	bouyer-socketcan-base:1.8
	pgoyette-localcount-20170107:1.8
	pgoyette-localcount-20161104:1.8
	localcount-20160914:1.8
	pgoyette-localcount-20160806:1.8
	pgoyette-localcount-20160726:1.8
	pgoyette-localcount:1.8.0.4
	pgoyette-localcount-base:1.8
	netbsd-6-0-6-RELEASE:1.6
	netbsd-6-1-5-RELEASE:1.6
	yamt-pagecache-base9:1.8
	yamt-pagecache-tag8:1.5.6.1
	netbsd-6-1-4-RELEASE:1.6
	netbsd-6-0-5-RELEASE:1.6
	tls-earlyentropy:1.8.0.2
	tls-earlyentropy-base:1.8
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.8
	riastradh-drm2-base3:1.8
	netbsd-6-1-3-RELEASE:1.6
	netbsd-6-0-4-RELEASE:1.6
	netbsd-6-1-2-RELEASE:1.6
	netbsd-6-0-3-RELEASE:1.6
	netbsd-6-1-1-RELEASE:1.6
	riastradh-drm2-base2:1.7
	riastradh-drm2-base1:1.7
	riastradh-drm2:1.7.0.2
	riastradh-drm2-base:1.7
	netbsd-6-1:1.6.0.10
	netbsd-6-0-2-RELEASE:1.6
	netbsd-6-1-RELEASE:1.6
	khorben-n900:1.7.0.6
	netbsd-6-1-RC4:1.6
	netbsd-6-1-RC3:1.6
	agc-symver:1.7.0.4
	agc-symver-base:1.7
	netbsd-6-1-RC2:1.6
	netbsd-6-1-RC1:1.6
	atf-0-17:1.1.1.5
	yamt-pagecache-base8:1.6
	netbsd-6-0-1-RELEASE:1.6
	yamt-pagecache-base7:1.6
	matt-nb6-plus-nbase:1.6
	yamt-pagecache-base6:1.6
	netbsd-6-0:1.6.0.8
	netbsd-6-0-RELEASE:1.6
	netbsd-6-0-RC2:1.6
	tls-maxphys:1.6.0.6
	tls-maxphys-base:1.8
	matt-nb6-plus:1.6.0.4
	matt-nb6-plus-base:1.6
	netbsd-6-0-RC1:1.6
	atf-0-16:1.1.1.4
	yamt-pagecache-base5:1.6
	yamt-pagecache-base4:1.6
	netbsd-6:1.6.0.2
	netbsd-6-base:1.6
	atf-0-15:1.1.1.4
	yamt-pagecache-base3:1.5
	yamt-pagecache-base2:1.5
	yamt-pagecache:1.5.0.6
	yamt-pagecache-base:1.5
	atf-0-14:1.1.1.3
	cherry-xenmp:1.5.0.4
	cherry-xenmp-base:1.5
	atf-0-13:1.1.1.3
	bouyer-quota2-nbase:1.5
	bouyer-quota2:1.5.0.2
	bouyer-quota2-base:1.5
	matt-mips64-premerge-20101231:1.5
	atf-0-12:1.1.1.3
	atf-0-11:1.1.1.3
	atf-0-10:1.1.1.2
	atf-0-9:1.1.1.1
	atf-0-8:1.1.1.1
	TNF:1.1.1;
locks; strict;
comment	@// @;


1.8
date	2014.02.08.19.13.43;	author jmmv;	state dead;
branches;
next	1.7;
commitid	V1QGpoY6GYJZzkox;

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

1.6
date	2012.01.16.22.41.30;	author jmmv;	state Exp;
branches
	1.6.6.1;
next	1.5;

1.5
date	2010.10.20.09.17.23;	author jmmv;	state Exp;
branches
	1.5.6.1;
next	1.4;

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

1.3
date	2010.06.18.16.13.56;	author pooka;	state Exp;
branches;
next	1.2;

1.2
date	2010.06.16.15.17.37;	author pooka;	state Exp;
branches;
next	1.1;

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

1.6.6.1
date	2013.02.25.00.24.55;	author tls;	state Exp;
branches;
next	1.6.6.2;

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

1.5.6.1
date	2012.04.17.00.03.02;	author yamt;	state Exp;
branches;
next	1.5.6.2;

1.5.6.2
date	2014.05.22.15.40.11;	author yamt;	state dead;
branches;
next	;
commitid	TzMwNuE6CLSD5yBx;

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

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

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

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

1.1.1.5
date	2013.02.15.17.04.17;	author jmmv;	state Exp;
branches;
next	;


desc
@@


1.8
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/time.h>
}

#include <cctype>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <memory>
#include <sstream>
#include <utility>
#include <vector>

#include "atf-c/defs.h"

#include "atf-c++/detail/application.hpp"
#include "atf-c++/detail/fs.hpp"
#include "atf-c++/detail/sanity.hpp"
#include "atf-c++/detail/text.hpp"
#include "atf-c++/detail/ui.hpp"

#include "reader.hpp"

typedef std::auto_ptr< std::ostream > ostream_ptr;

static ostream_ptr
open_outfile(const atf::fs::path& path)
{
    ostream_ptr osp;
    if (path.str() == "-")
        osp = ostream_ptr(new std::ofstream("/dev/stdout"));
    else
        osp = ostream_ptr(new std::ofstream(path.c_str()));
    if (!(*osp))
        throw std::runtime_error("Could not create file " + path.str());
    return osp;
}

static std::string
format_tv(struct timeval* tv)
{
    std::ostringstream output;
    output << static_cast< long >(tv->tv_sec) << '.'
           << std::setfill('0') << std::setw(6)
           << static_cast< long >(tv->tv_usec);
    return output.str();
}

// ------------------------------------------------------------------------
// The "writer" interface.
// ------------------------------------------------------------------------

//!
//! \brief A base class that defines an output format.
//!
//! The writer base class defines a generic interface to output formats.
//! This is meant to be subclassed, and each subclass can redefine any
//! method to format the information as it wishes.
//!
//! This class is not tied to a output stream nor a file because, depending
//! on the output format, we will want to write to a single file or to
//! multiple ones.
//!
class writer {
public:
    writer(void) {}
    virtual ~writer(void) {}

    virtual void write_info(const std::string&, const std::string&) {}
    virtual void write_ntps(size_t) {}
    virtual void write_tp_start(const std::string&, size_t) {}
    virtual void write_tp_end(struct timeval*, const std::string&) {}
    virtual void write_tc_start(const std::string&) {}
    virtual void write_tc_stdout_line(const std::string&) {}
    virtual void write_tc_stderr_line(const std::string&) {}
    virtual void write_tc_end(const std::string&, struct timeval*,
                              const std::string&) {}
    virtual void write_eof(void) {}
};

// ------------------------------------------------------------------------
// The "csv_writer" class.
// ------------------------------------------------------------------------

//!
//! \brief A very simple plain-text output format.
//!
//! The csv_writer class implements a very simple plain-text output
//! format that summarizes the results of each executed test case.  The
//! results are meant to be easily parseable by third-party tools, hence
//! they are formatted as a CSV file.
//!
class csv_writer : public writer {
    ostream_ptr m_os;
    bool m_failed;

    std::string m_tpname;
    std::string m_tcname;

public:
    csv_writer(const atf::fs::path& p) :
        m_os(open_outfile(p))
    {
    }

    virtual
    void
    write_tp_start(const std::string& name,
                   size_t ntcs ATF_DEFS_ATTRIBUTE_UNUSED)
    {
        m_tpname = name;
        m_failed = false;
    }

    virtual
    void
    write_tp_end(struct timeval* tv, const std::string& reason)
    {
        const std::string timestamp = format_tv(tv);

        if (!reason.empty())
            (*m_os) << "tp, " << timestamp << ", " << m_tpname << ", bogus, "
                    << reason << "\n";
        else if (m_failed)
            (*m_os) << "tp, " << timestamp << ", "<< m_tpname << ", failed\n";
        else
            (*m_os) << "tp, " << timestamp << ", "<< m_tpname << ", passed\n";
    }

    virtual
    void
    write_tc_start(const std::string& name)
    {
        m_tcname = name;
    }

    virtual
    void
    write_tc_end(const std::string& state, struct timeval* tv,
                 const std::string& reason)
    {
        std::string str = m_tpname + ", " + m_tcname + ", " + state;
        if (!reason.empty())
            str += ", " + reason;
        (*m_os) << "tc, " << format_tv(tv) << ", " << str << "\n";

        if (state == "failed")
            m_failed = true;
    }
};

// ------------------------------------------------------------------------
// The "ticker_writer" class.
// ------------------------------------------------------------------------

//!
//! \brief A console-friendly output format.
//!
//! The ticker_writer class implements a formatter that is user-friendly
//! in the sense that it shows the execution of test cases in an easy to
//! read format.  It is not meant to be parseable and its format can
//! freely change across releases.
//!
class ticker_writer : public writer {
    ostream_ptr m_os;

    size_t m_curtp, m_ntps;
    size_t m_tcs_passed, m_tcs_failed, m_tcs_skipped, m_tcs_expected_failures;
    std::string m_tcname, m_tpname;
    std::vector< std::string > m_failed_tcs;
    std::map< std::string, std::string > m_expected_failures_tcs;
    std::vector< std::string > m_failed_tps;

    void
    write_info(const std::string& what, const std::string& val)
    {
        if (what == "tests.root") {
            (*m_os) << "Tests root: " << val << "\n\n";
        }
    }

    void
    write_ntps(size_t ntps)
    {
        m_curtp = 1;
        m_tcs_passed = 0;
        m_tcs_failed = 0;
        m_tcs_skipped = 0;
        m_tcs_expected_failures = 0;
        m_ntps = ntps;
    }

    void
    write_tp_start(const std::string& tp, size_t ntcs)
    {
        using atf::text::to_string;
        using atf::ui::format_text;

        m_tpname = tp;

        (*m_os) << format_text(tp + " (" + to_string(m_curtp) +
                               "/" + to_string(m_ntps) + "): " +
                               to_string(ntcs) + " test cases")
                << "\n";
        (*m_os).flush();
    }

    void
    write_tp_end(struct timeval* tv, const std::string& reason)
    {
        using atf::ui::format_text_with_tag;

        m_curtp++;

        if (!reason.empty()) {
            (*m_os) << format_text_with_tag("BOGUS TEST PROGRAM: Cannot "
                                            "trust its results because "
                                            "of `" + reason + "'",
                                            m_tpname + ": ", false)
                    << "\n";
            m_failed_tps.push_back(m_tpname);
        }
        (*m_os) << "[" << format_tv(tv) << "s]\n\n";
        (*m_os).flush();

        m_tpname.clear();
    }

    void
    write_tc_start(const std::string& tcname)
    {
        m_tcname = tcname;

        (*m_os) << "    " + tcname + ": ";
        (*m_os).flush();
    }

    void
    write_tc_end(const std::string& state, struct timeval* tv,
                 const std::string& reason)
    {
        std::string str;

        (*m_os) << "[" << format_tv(tv) << "s] ";

        if (state == "expected_death" || state == "expected_exit" ||
            state == "expected_failure" || state == "expected_signal" ||
            state == "expected_timeout") {
            str = "Expected failure: " + reason;
            m_tcs_expected_failures++;
            m_expected_failures_tcs[m_tpname + ":" + m_tcname] = reason;
        } else if (state == "failed") {
            str = "Failed: " + reason;
            m_tcs_failed++;
            m_failed_tcs.push_back(m_tpname + ":" + m_tcname);
        } else if (state == "passed") {
            str = "Passed.";
            m_tcs_passed++;
        } else if (state == "skipped") {
            str = "Skipped: " + reason;
            m_tcs_skipped++;
        } else
            UNREACHABLE;

        // XXX Wrap text.  format_text_with_tag does not currently allow
        // to specify the current column, which is needed because we have
        // already printed the tc's name.
        (*m_os) << str << '\n';

        m_tcname = "";
    }

    static void
    write_expected_failures(const std::map< std::string, std::string >& xfails,
                            std::ostream& os)
    {
        using atf::ui::format_text;
        using atf::ui::format_text_with_tag;

        os << format_text("Test cases for known bugs:") << "\n";

        for (std::map< std::string, std::string >::const_iterator iter =
             xfails.begin(); iter != xfails.end(); iter++) {
            const std::string& name = (*iter).first;
            const std::string& reason = (*iter).second;

            os << format_text_with_tag(reason, "    " + name + ": ", false)
               << "\n";
        }
    }

    void
    write_eof(void)
    {
        using atf::text::join;
        using atf::text::to_string;
        using atf::ui::format_text;
        using atf::ui::format_text_with_tag;

        if (!m_failed_tps.empty()) {
            (*m_os) << format_text("Failed (bogus) test programs:")
                    << "\n";
            (*m_os) << format_text_with_tag(join(m_failed_tps, ", "),
                                            "    ", false) << "\n\n";
        }

        if (!m_expected_failures_tcs.empty()) {
            write_expected_failures(m_expected_failures_tcs, *m_os);
            (*m_os) << "\n";
        }

        if (!m_failed_tcs.empty()) {
            (*m_os) << format_text("Failed test cases:") << "\n";
            (*m_os) << format_text_with_tag(join(m_failed_tcs, ", "),
                                            "    ", false) << "\n\n";
        }

        (*m_os) << format_text("Summary for " + to_string(m_ntps) +
                               " test programs:") << "\n";
        (*m_os) << format_text_with_tag(to_string(m_tcs_passed) +
                                        " passed test cases.",
                                        "    ", false) << "\n";
        (*m_os) << format_text_with_tag(to_string(m_tcs_failed) +
                                        " failed test cases.",
                                        "    ", false) << "\n";
        (*m_os) << format_text_with_tag(to_string(m_tcs_expected_failures) +
                                        " expected failed test cases.",
                                        "    ", false) << "\n";
        (*m_os) << format_text_with_tag(to_string(m_tcs_skipped) +
                                        " skipped test cases.",
                                        "    ", false) << "\n";
    }

public:
    ticker_writer(const atf::fs::path& p) :
        m_os(open_outfile(p))
    {
    }
};

// ------------------------------------------------------------------------
// The "xml" class.
// ------------------------------------------------------------------------

//!
//! \brief A single-file XML output format.
//!
//! The xml_writer class implements a formatter that prints the results
//! of test cases in an XML format easily parseable later on by other
//! utilities.
//!
class xml_writer : public writer {
    ostream_ptr m_os;

    std::string m_tcname, m_tpname;

    static
    std::string
    attrval(const std::string& str)
    {
        return str;
    }

    static
    std::string
    elemval(const std::string& str)
    {
        std::ostringstream buf;
        for (std::string::const_iterator iter = str.begin();
             iter != str.end(); iter++) {
            const int character = static_cast< unsigned char >(*iter);
            if (character == '&') {
                buf << "&amp;";
            } else if (character == '<') {
                buf << "&lt;";
            } else if (character == '>') {
                buf << "&gt;";
            } else if (std::isalnum(character) || std::ispunct(character) ||
                       std::isspace(character)) {
                buf << static_cast< char >(character);
            } else {
                buf << "&amp;#" << character << ";";
            }
        }
        return buf.str();
    }

    void
    write_info(const std::string& what, const std::string& val)
    {
        (*m_os) << "<info class=\"" << what << "\">" << val << "</info>\n";
    }

    void
    write_tp_start(const std::string& tp,
                   size_t ntcs ATF_DEFS_ATTRIBUTE_UNUSED)
    {
        (*m_os) << "<tp id=\"" << attrval(tp) << "\">\n";
    }

    void
    write_tp_end(struct timeval* tv, const std::string& reason)
    {
        if (!reason.empty())
            (*m_os) << "<failed>" << elemval(reason) << "</failed>\n";
        (*m_os) << "<tp-time>" << format_tv(tv) << "</tp-time>";
        (*m_os) << "</tp>\n";
    }

    void
    write_tc_start(const std::string& tcname)
    {
        (*m_os) << "<tc id=\"" << attrval(tcname) << "\">\n";
    }

    void
    write_tc_stdout_line(const std::string& line)
    {
        (*m_os) << "<so>" << elemval(line) << "</so>\n";
    }

    void
    write_tc_stderr_line(const std::string& line)
    {
        (*m_os) << "<se>" << elemval(line) << "</se>\n";
    }

    void
    write_tc_end(const std::string& state, struct timeval* tv,
                 const std::string& reason)
    {
        std::string str;

        if (state == "expected_death" || state == "expected_exit" ||
            state == "expected_failure" || state == "expected_signal" ||
            state == "expected_timeout") {
            (*m_os) << "<" << state << ">" << elemval(reason)
                    << "</" << state << ">\n";
        } else if (state == "passed") {
            (*m_os) << "<passed />\n";
        } else if (state == "failed") {
            (*m_os) << "<failed>" << elemval(reason) << "</failed>\n";
        } else if (state == "skipped") {
            (*m_os) << "<skipped>" << elemval(reason) << "</skipped>\n";
        } else
            UNREACHABLE;
        (*m_os) << "<tc-time>" << format_tv(tv) << "</tc-time>";
        (*m_os) << "</tc>\n";
    }

    void
    write_eof(void)
    {
        (*m_os) << "</tests-results>\n";
    }

public:
    xml_writer(const atf::fs::path& p) :
        m_os(open_outfile(p))
    {
        (*m_os) << "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
                << "<!DOCTYPE tests-results PUBLIC "
                   "\"-//NetBSD//DTD ATF Tests Results 0.1//EN\" "
                   "\"http://www.NetBSD.org/XML/atf/tests-results.dtd\">\n\n"
                   "<tests-results>\n";
    }
};

// ------------------------------------------------------------------------
// The "converter" class.
// ------------------------------------------------------------------------

//!
//! \brief A reader that redirects events to multiple writers.
//!
//! The converter class implements an atf_tps_reader that, for each event
//! raised by the parser, redirects it to multiple writers so that they
//! can reformat it according to their output rules.
//!
class converter : public atf::atf_report::atf_tps_reader {
    typedef std::vector< writer* > outs_vector;
    outs_vector m_outs;

    void
    got_info(const std::string& what, const std::string& val)
    {
        for (outs_vector::iterator iter = m_outs.begin();
             iter != m_outs.end(); iter++)
            (*iter)->write_info(what, val);
    }

    void
    got_ntps(size_t ntps)
    {
        for (outs_vector::iterator iter = m_outs.begin();
             iter != m_outs.end(); iter++)
            (*iter)->write_ntps(ntps);
    }

    void
    got_tp_start(const std::string& tp, size_t ntcs)
    {
        for (outs_vector::iterator iter = m_outs.begin();
             iter != m_outs.end(); iter++)
            (*iter)->write_tp_start(tp, ntcs);
    }

    void
    got_tp_end(struct timeval* tv, const std::string& reason)
    {
        for (outs_vector::iterator iter = m_outs.begin();
             iter != m_outs.end(); iter++)
            (*iter)->write_tp_end(tv, reason);
    }

    void
    got_tc_start(const std::string& tcname)
    {
        for (outs_vector::iterator iter = m_outs.begin();
             iter != m_outs.end(); iter++)
            (*iter)->write_tc_start(tcname);
    }

    void
    got_tc_stdout_line(const std::string& line)
    {
        for (outs_vector::iterator iter = m_outs.begin();
             iter != m_outs.end(); iter++)
            (*iter)->write_tc_stdout_line(line);
    }

    void
    got_tc_stderr_line(const std::string& line)
    {
        for (outs_vector::iterator iter = m_outs.begin();
             iter != m_outs.end(); iter++)
            (*iter)->write_tc_stderr_line(line);
    }

    void
    got_tc_end(const std::string& state, struct timeval* tv,
               const std::string& reason)
    {
        for (outs_vector::iterator iter = m_outs.begin();
             iter != m_outs.end(); iter++)
            (*iter)->write_tc_end(state, tv, reason);
    }

    void
    got_eof(void)
    {
        for (outs_vector::iterator iter = m_outs.begin();
             iter != m_outs.end(); iter++)
            (*iter)->write_eof();
    }

public:
    converter(std::istream& is) :
        atf::atf_report::atf_tps_reader(is)
    {
    }

    ~converter(void)
    {
        for (outs_vector::iterator iter = m_outs.begin();
             iter != m_outs.end(); iter++)
            delete *iter;
    }

    void
    add_output(const std::string& fmt, const atf::fs::path& p)
    {
        if (fmt == "csv") {
            m_outs.push_back(new csv_writer(p));
        } else if (fmt == "ticker") {
            m_outs.push_back(new ticker_writer(p));
        } else if (fmt == "xml") {
            m_outs.push_back(new xml_writer(p));
        } else
            throw std::runtime_error("Unknown format `" + fmt + "'");
    }
};

// ------------------------------------------------------------------------
// The "atf_report" class.
// ------------------------------------------------------------------------

class atf_report : public atf::application::app {
    static const char* m_description;

    typedef std::pair< std::string, atf::fs::path > fmt_path_pair;
    std::vector< fmt_path_pair > m_oflags;

    void process_option(int, const char*);
    options_set specific_options(void) const;

public:
    atf_report(void);

    int main(void);
};

const char* atf_report::m_description =
    "atf-report is a tool that parses the output of atf-run and "
    "generates user-friendly reports in multiple different formats.";

atf_report::atf_report(void) :
    app(m_description, "atf-report(1)", "atf(7)")
{
}

void
atf_report::process_option(int ch, const char* arg)
{
    switch (ch) {
    case 'o':
        {
            std::string str(arg);
            std::string::size_type pos = str.find(':');
            if (pos == std::string::npos)
                throw std::runtime_error("Syntax error in -o option");
            else {
                std::string fmt = str.substr(0, pos);
                atf::fs::path path = atf::fs::path(str.substr(pos + 1));
                m_oflags.push_back(fmt_path_pair(fmt, path));
            }
        }
        break;

    default:
        UNREACHABLE;
    }
}

atf_report::options_set
atf_report::specific_options(void)
    const
{
    using atf::application::option;
    options_set opts;
    opts.insert(option('o', "fmt:path", "Adds a new output file; multiple "
                                        "ones can be specified, and a - "
                                        "path means stdout"));
    return opts;
}

int
atf_report::main(void)
{
    if (m_argc > 0)
        throw std::runtime_error("No arguments allowed");

    if (m_oflags.empty())
        m_oflags.push_back(fmt_path_pair("ticker", atf::fs::path("-")));

    // Look for path duplicates.
    std::set< atf::fs::path > paths;
    for (std::vector< fmt_path_pair >::const_iterator iter = m_oflags.begin();
         iter != m_oflags.end(); iter++) {
        atf::fs::path p = (*iter).second;
        if (p == atf::fs::path("/dev/stdout"))
            p = atf::fs::path("-");
        if (paths.find(p) != paths.end())
            throw std::runtime_error("The file `" + p.str() + "' was "
                                     "specified more than once");
        paths.insert((*iter).second);
    }

    // Generate the output files.
    converter cnv(std::cin);
    for (std::vector< fmt_path_pair >::const_iterator iter = m_oflags.begin();
         iter != m_oflags.end(); iter++)
        cnv.add_output((*iter).first, (*iter).second);
    cnv.read();

    return EXIT_SUCCESS;
}

int
main(int argc, char* const* argv)
{
    return atf_report().run(argc, argv);
}
@


1.7
log
@Fix merge conflicts after import of atf 0.17.
@
text
@@


1.6
log
@Resolve conflicts after the import of atf 0.15.
@
text
@d34 1
a384 1
    size_t m_curtp, m_ntps;
d398 1
a398 1
        std::string ostr;
d401 12
a412 5
            switch (*iter) {
            case '&': ostr += "&amp;"; break;
            case '<': ostr += "&lt;"; break;
            case '>': ostr += "&gt;"; break;
            default:  ostr += *iter;
d415 1
a415 1
        return ostr;
@


1.6.6.1
log
@resync with head
@
text
@a33 1
#include <cctype>
d384 1
d398 1
a398 1
        std::ostringstream buf;
d401 5
a405 12
            const int character = static_cast< unsigned char >(*iter);
            if (character == '&') {
                buf << "&amp;";
            } else if (character == '<') {
                buf << "&lt;";
            } else if (character == '>') {
                buf << "&gt;";
            } else if (std::isalnum(character) || std::ispunct(character) ||
                       std::isspace(character)) {
                buf << static_cast< char >(character);
            } else {
                buf << "&amp;#" << character << ";";
d408 1
a408 1
        return buf.str();
@


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


1.5
log
@Resolve import conflicts.
@
text
@d4 1
a4 1
// Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
d30 4
d36 1
d39 1
d43 2
d55 1
a55 1
ostream_ptr
d68 10
d101 1
a101 1
    virtual void write_tp_end(const std::string&) {}
d105 2
a106 1
    virtual void write_tc_end(const std::string&, const std::string&) {}
d137 2
a138 1
    write_tp_start(const std::string& name, size_t ntcs)
d146 1
a146 1
    write_tp_end(const std::string& reason)
d148 2
d151 2
a152 1
            (*m_os) << "tp, " << m_tpname << ", bogus, " << reason << "\n";
d154 1
a154 1
            (*m_os) << "tp, " << m_tpname << ", failed\n";
d156 1
a156 1
            (*m_os) << "tp, " << m_tpname << ", passed\n";
d168 2
a169 1
    write_tc_end(const std::string& state, const std::string& reason)
d171 1
a171 1
        std::string str = "tc, " + m_tpname + ", " + m_tcname + ", " + state;
d174 1
a174 1
        (*m_os) << str << "\n";
d238 1
a238 1
    write_tp_end(const std::string& reason)
d252 1
a252 1
        (*m_os) << "\n";
d268 2
a269 1
    write_tc_end(const std::string& state, const std::string& reason)
d273 2
d297 1
a297 1
        (*m_os) << str << "\n";
d418 2
a419 1
    write_tp_start(const std::string& tp, size_t ntcs)
d425 1
a425 1
    write_tp_end(const std::string& reason)
d429 1
d452 2
a453 1
    write_tc_end(const std::string& state, const std::string& reason)
d470 1
d484 1
a484 1
        (*m_os) << "<?xml version=\"1.0\"?>\n"
d532 1
a532 1
    got_tp_end(const std::string& reason)
d536 1
a536 1
            (*iter)->write_tp_end(reason);
d564 2
a565 1
    got_tc_end(const std::string& state, const std::string& reason)
d569 1
a569 1
            (*iter)->write_tc_end(state, reason);
d673 3
@


1.5.6.1
log
@sync with head
@
text
@d4 1
a4 1
// Copyright (c) 2007 The NetBSD Foundation, Inc.
a29 4
extern "C" {
#include <sys/time.h>
}

a31 1
#include <iomanip>
a33 1
#include <sstream>
a36 2
#include "atf-c/defs.h"

d47 1
a47 1
static ostream_ptr
a59 10
static std::string
format_tv(struct timeval* tv)
{
    std::ostringstream output;
    output << static_cast< long >(tv->tv_sec) << '.'
           << std::setfill('0') << std::setw(6)
           << static_cast< long >(tv->tv_usec);
    return output.str();
}

d83 1
a83 1
    virtual void write_tp_end(struct timeval*, const std::string&) {}
d87 1
a87 2
    virtual void write_tc_end(const std::string&, struct timeval*,
                              const std::string&) {}
d118 1
a118 2
    write_tp_start(const std::string& name,
                   size_t ntcs ATF_DEFS_ATTRIBUTE_UNUSED)
d126 1
a126 1
    write_tp_end(struct timeval* tv, const std::string& reason)
a127 2
        const std::string timestamp = format_tv(tv);

d129 1
a129 2
            (*m_os) << "tp, " << timestamp << ", " << m_tpname << ", bogus, "
                    << reason << "\n";
d131 1
a131 1
            (*m_os) << "tp, " << timestamp << ", "<< m_tpname << ", failed\n";
d133 1
a133 1
            (*m_os) << "tp, " << timestamp << ", "<< m_tpname << ", passed\n";
d145 1
a145 2
    write_tc_end(const std::string& state, struct timeval* tv,
                 const std::string& reason)
d147 1
a147 1
        std::string str = m_tpname + ", " + m_tcname + ", " + state;
d150 1
a150 1
        (*m_os) << "tc, " << format_tv(tv) << ", " << str << "\n";
d214 1
a214 1
    write_tp_end(struct timeval* tv, const std::string& reason)
d228 1
a228 1
        (*m_os) << "[" << format_tv(tv) << "s]\n\n";
d244 1
a244 2
    write_tc_end(const std::string& state, struct timeval* tv,
                 const std::string& reason)
a247 2
        (*m_os) << "[" << format_tv(tv) << "s] ";

d270 1
a270 1
        (*m_os) << str << '\n';
d391 1
a391 2
    write_tp_start(const std::string& tp,
                   size_t ntcs ATF_DEFS_ATTRIBUTE_UNUSED)
d397 1
a397 1
    write_tp_end(struct timeval* tv, const std::string& reason)
a400 1
        (*m_os) << "<tp-time>" << format_tv(tv) << "</tp-time>";
d423 1
a423 2
    write_tc_end(const std::string& state, struct timeval* tv,
                 const std::string& reason)
a439 1
        (*m_os) << "<tc-time>" << format_tv(tv) << "</tc-time>";
d453 1
a453 1
        (*m_os) << "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
d501 1
a501 1
    got_tp_end(struct timeval* tv, const std::string& reason)
d505 1
a505 1
            (*iter)->write_tp_end(tv, reason);
d533 1
a533 2
    got_tc_end(const std::string& state, struct timeval* tv,
               const std::string& reason)
d537 1
a537 1
            (*iter)->write_tc_end(state, tv, reason);
a640 3
    if (m_argc > 0)
        throw std::runtime_error("No arguments allowed");

@


1.5.6.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.4
log
@Fix merge conflicts for atf 0.10.
@
text
@d37 5
a41 5
#include "atf-c++/application.hpp"
#include "atf-c++/fs.hpp"
#include "atf-c++/sanity.hpp"
#include "atf-c++/text.hpp"
#include "atf-c++/ui.hpp"
d129 1
a129 2
            (*m_os) << "tp, " << m_tpname << ", bogus, " << reason
                    << std::endl;
d131 1
a131 1
            (*m_os) << "tp, " << m_tpname << ", failed" << std::endl;
d133 1
a133 1
            (*m_os) << "tp, " << m_tpname << ", passed" << std::endl;
d150 1
a150 1
        (*m_os) << str << std::endl;
d176 1
a176 1
    std::vector< std::string > m_expected_failures_tcs;
d183 1
a183 2
            (*m_os) << "Tests root: " << val << std::endl
                    << std::endl;
d209 1
a209 1
                << std::endl;
d225 1
a225 1
                    << std::endl;
d228 1
a228 1
        (*m_os) << std::endl;
d253 1
a253 1
            m_expected_failures_tcs.push_back(m_tpname + ":" + m_tcname);
d270 1
a270 1
        (*m_os) << str << std::endl;
d275 19
d304 1
a304 1
                    << std::endl;
d306 1
a306 2
                                            "    ", false) << std::endl
                    << std::endl;
d310 2
a311 4
            (*m_os) << format_text("Test cases for known bugs:") << std::endl;
            (*m_os) << format_text_with_tag(join(m_expected_failures_tcs, ", "),
                                            "    ", false) << std::endl
                    << std::endl;
d315 1
a315 1
            (*m_os) << format_text("Failed test cases:") << std::endl;
d317 1
a317 2
                                            "    ", false) << std::endl
                    << std::endl;
d321 1
a321 2
                               " test programs:")
                << std::endl;
d324 1
a324 2
                                        "    ", false)
                << std::endl;
d327 1
a327 2
                                        "    ", false)
                << std::endl;
d330 1
a330 2
                                        "    ", false)
                << std::endl;
d333 1
a333 2
                                        "    ", false)
                << std::endl;
d387 1
a387 2
        (*m_os) << "<info class=\"" << what << "\">" << val << "</info>"
                << std::endl;
d393 1
a393 1
        (*m_os) << "<tp id=\"" << attrval(tp) << "\">" << std::endl;
d400 2
a401 3
            (*m_os) << "<failed>" << elemval(reason) << "</failed>"
                    << std::endl;
        (*m_os) << "</tp>" << std::endl;
d407 1
a407 1
        (*m_os) << "<tc id=\"" << attrval(tcname) << "\">" << std::endl;
d413 1
a413 1
        (*m_os) << "<so>" << elemval(line) << "</so>" << std::endl;
d419 1
a419 1
        (*m_os) << "<se>" << elemval(line) << "</se>" << std::endl;
d431 1
a431 1
                    << "</" << state << ">" << std::endl;
d433 1
a433 1
            (*m_os) << "<passed />" << std::endl;
d435 1
a435 2
            (*m_os) << "<failed>" << elemval(reason)
                    << "</failed>" << std::endl;
d437 1
a437 2
            (*m_os) << "<skipped>" << elemval(reason)
                    << "</skipped>" << std::endl;
d440 1
a440 1
        (*m_os) << "</tc>" << std::endl;
d446 1
a446 1
        (*m_os) << "</tests-results>" << std::endl;
d453 1
a453 1
        (*m_os) << "<?xml version=\"1.0\"?>" << std::endl
d456 2
a457 4
                   "\"http://www.NetBSD.org/XML/atf/tests-results.dtd\">"
                << std::endl
                << std::endl
                << "<tests-results>" << std::endl;
@


1.3
log
@Handle xfail in a few more places.  Found by, la la la, the new tests.
@
text
@a38 1
#include "atf-c++/formats.hpp"
d43 2
d87 1
a87 1
    virtual void write_tc_end(const atf::tests::tcr&) {}
d146 1
a146 1
    write_tc_end(const atf::tests::tcr& tcr)
d148 6
a153 6
        std::string str = "tc, ";
        if (tcr.get_state() == atf::tests::tcr::passed_state) {
            str += m_tpname + ", " + m_tcname + ", passed";
        } else if (tcr.get_state() == atf::tests::tcr::failed_state) {
            str += m_tpname + ", " + m_tcname + ", failed, " +
                   tcr.get_reason();
a154 9
        } else if (tcr.get_state() == atf::tests::tcr::skipped_state) {
            str += m_tpname + ", " + m_tcname + ", skipped, " +
                   tcr.get_reason();
        } else if (tcr.get_state() == atf::tests::tcr::xfail_state) {
            str += m_tpname + ", " + m_tcname + ", xfail, " +
                   tcr.get_reason();
        } else
            UNREACHABLE;
        (*m_os) << str << std::endl;
d174 1
a174 1
    size_t m_tcs_passed, m_tcs_failed, m_tcs_skipped, m_tcs_xfail;
d177 1
d196 1
a196 1
        m_tcs_xfail = 0;
d246 1
a246 1
    write_tc_end(const atf::tests::tcr& tcr)
d250 11
a260 2
        atf::tests::tcr::state s = tcr.get_state();
        if (s == atf::tests::tcr::passed_state) {
d263 2
a264 6
        } else if (s == atf::tests::tcr::failed_state) {
            str = "Failed: " + tcr.get_reason();
            m_tcs_failed++;
            m_failed_tcs.push_back(m_tpname + ":" + m_tcname);
        } else if (s == atf::tests::tcr::skipped_state) {
            str = "Skipped: " + tcr.get_reason();
a265 3
	} else if (s == atf::tests::tcr::xfail_state) {
            str = "Expected failure: " + tcr.get_reason();
            m_tcs_xfail++;
d293 7
d318 2
a319 2
        (*m_os) << format_text_with_tag(to_string(m_tcs_xfail) +
                                        " expected failures.",
a349 1
    size_t m_tcs_passed, m_tcs_failed, m_tcs_skipped, m_tcs_xfail;
a350 2
    std::vector< std::string > m_failed_tcs;
    std::vector< std::string > m_failed_tps;
d417 1
a417 1
    write_tc_end(const atf::tests::tcr& tcr)
d421 6
a426 2
        atf::tests::tcr::state s = tcr.get_state();
        if (s == atf::tests::tcr::passed_state) {
d428 2
a429 2
        } else if (s == atf::tests::tcr::failed_state) {
            (*m_os) << "<failed>" << elemval(tcr.get_reason())
d431 2
a432 2
        } else if (s == atf::tests::tcr::skipped_state) {
            (*m_os) << "<skipped>" << elemval(tcr.get_reason())
a433 3
        } else if (s == atf::tests::tcr::xfail_state) {
            (*m_os) << "<xfail>" << elemval(tcr.get_reason())
                    << "</xfail>" << std::endl;
d470 1
a470 1
class converter : public atf::formats::atf_tps_reader {
d531 1
a531 1
    got_tc_end(const atf::tests::tcr& tcr)
d535 1
a535 1
            (*iter)->write_tc_end(tcr);
d548 1
a548 1
        atf::formats::atf_tps_reader(is)
@


1.2
log
@Introduce expected failures to atf.  They can be used to flag tests
which are known to fail, e.g.:

        atf_tc_set_md_var(tc, "xfail", "PR kern/43456");

Expected failures do not count towards the ultimate pass/fail result
from the test run:

pain-rustique:39:~/<2>src/tests/fs/ptyfs> atf-run t_nullpts | atf-report
Tests root: /home/pooka/src/wholesrc2/src/tests/fs/ptyfs

t_nullpts (1/1): 1 test cases
    nullrevoke: Expected failure: PR kern/43456

Summary for 1 test programs:
    0 passed test cases.
    0 failed test cases.
    1 expected failures.
    0 skipped test cases.
pain-rustique:40:~/<2>src/tests/fs/ptyfs> echo $?
0

However, an xfail test which passes will count as a failure, i.e.
xfail inverts test case success/fail.  This way we can get a better
sense from the ultimate verdict of the NetBSD atf run by seeing if
there were any unexpected failures, i.e. new regressions.

This feature will be present in the upcoming atf 0.10 release,
possibly with finer grained control.

patch reviewed by jmmv
@
text
@d157 3
d431 3
@


1.1
log
@Initial revision
@
text
@d179 1
a179 1
    size_t m_tcs_passed, m_tcs_failed, m_tcs_skipped;
d200 1
d265 3
d313 4
d345 1
a345 1
    size_t m_tcs_passed, m_tcs_failed, m_tcs_skipped;
@


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.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
@d39 1
a43 2
#include "reader.hpp"

d86 1
a86 1
    virtual void write_tc_end(const std::string&, const std::string&) {}
d145 1
a145 1
    write_tc_end(const std::string& state, const std::string& reason)
d147 12
a158 3
        std::string str = "tc, " + m_tpname + ", " + m_tcname + ", " + state;
        if (!reason.empty())
            str += ", " + reason;
a159 3

        if (state == "failed")
            m_failed = true;
d179 1
a179 1
    size_t m_tcs_passed, m_tcs_failed, m_tcs_skipped, m_tcs_expected_failures;
a181 1
    std::vector< std::string > m_expected_failures_tcs;
a199 1
        m_tcs_expected_failures = 0;
d249 1
a249 1
    write_tc_end(const std::string& state, const std::string& reason)
d253 6
a258 8
        if (state == "expected_death" || state == "expected_exit" ||
            state == "expected_failure" || state == "expected_signal" ||
            state == "expected_timeout") {
            str = "Expected failure: " + reason;
            m_tcs_expected_failures++;
            m_expected_failures_tcs.push_back(m_tpname + ":" + m_tcname);
        } else if (state == "failed") {
            str = "Failed: " + reason;
d261 2
a262 5
        } else if (state == "passed") {
            str = "Passed.";
            m_tcs_passed++;
        } else if (state == "skipped") {
            str = "Skipped: " + reason;
a290 7
        if (!m_expected_failures_tcs.empty()) {
            (*m_os) << format_text("Test cases for known bugs:") << std::endl;
            (*m_os) << format_text_with_tag(join(m_expected_failures_tcs, ", "),
                                            "    ", false) << std::endl
                    << std::endl;
        }

a308 4
        (*m_os) << format_text_with_tag(to_string(m_tcs_expected_failures) +
                                        " expected failed test cases.",
                                        "    ", false)
                << std::endl;
d337 1
d339 2
d407 1
a407 1
    write_tc_end(const std::string& state, const std::string& reason)
d411 2
a412 6
        if (state == "expected_death" || state == "expected_exit" ||
            state == "expected_failure" || state == "expected_signal" ||
            state == "expected_timeout") {
            (*m_os) << "<" << state << ">" << elemval(reason)
                    << "</" << state << ">" << std::endl;
        } else if (state == "passed") {
d414 2
a415 2
        } else if (state == "failed") {
            (*m_os) << "<failed>" << elemval(reason)
d417 2
a418 2
        } else if (state == "skipped") {
            (*m_os) << "<skipped>" << elemval(reason)
d456 1
a456 1
class converter : public atf::atf_report::atf_tps_reader {
d517 1
a517 1
    got_tc_end(const std::string& state, const std::string& reason)
d521 1
a521 1
            (*iter)->write_tc_end(state, reason);
d534 1
a534 1
        atf::atf_report::atf_tps_reader(is)
@


1.1.1.3
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
@d37 5
a41 5
#include "atf-c++/detail/application.hpp"
#include "atf-c++/detail/fs.hpp"
#include "atf-c++/detail/sanity.hpp"
#include "atf-c++/detail/text.hpp"
#include "atf-c++/detail/ui.hpp"
d129 2
a130 1
            (*m_os) << "tp, " << m_tpname << ", bogus, " << reason << "\n";
d132 1
a132 1
            (*m_os) << "tp, " << m_tpname << ", failed\n";
d134 1
a134 1
            (*m_os) << "tp, " << m_tpname << ", passed\n";
d151 1
a151 1
        (*m_os) << str << "\n";
d177 1
a177 1
    std::map< std::string, std::string > m_expected_failures_tcs;
d184 2
a185 1
            (*m_os) << "Tests root: " << val << "\n\n";
d211 1
a211 1
                << "\n";
d227 1
a227 1
                    << "\n";
d230 1
a230 1
        (*m_os) << "\n";
d255 1
a255 1
            m_expected_failures_tcs[m_tpname + ":" + m_tcname] = reason;
d272 1
a272 1
        (*m_os) << str << "\n";
a276 19
    static void
    write_expected_failures(const std::map< std::string, std::string >& xfails,
                            std::ostream& os)
    {
        using atf::ui::format_text;
        using atf::ui::format_text_with_tag;

        os << format_text("Test cases for known bugs:") << "\n";

        for (std::map< std::string, std::string >::const_iterator iter =
             xfails.begin(); iter != xfails.end(); iter++) {
            const std::string& name = (*iter).first;
            const std::string& reason = (*iter).second;

            os << format_text_with_tag(reason, "    " + name + ": ", false)
               << "\n";
        }
    }

d287 1
a287 1
                    << "\n";
d289 2
a290 1
                                            "    ", false) << "\n\n";
d294 4
a297 2
            write_expected_failures(m_expected_failures_tcs, *m_os);
            (*m_os) << "\n";
d301 1
a301 1
            (*m_os) << format_text("Failed test cases:") << "\n";
d303 2
a304 1
                                            "    ", false) << "\n\n";
d308 2
a309 1
                               " test programs:") << "\n";
d312 2
a313 1
                                        "    ", false) << "\n";
d316 2
a317 1
                                        "    ", false) << "\n";
d320 2
a321 1
                                        "    ", false) << "\n";
d324 2
a325 1
                                        "    ", false) << "\n";
d379 2
a380 1
        (*m_os) << "<info class=\"" << what << "\">" << val << "</info>\n";
d386 1
a386 1
        (*m_os) << "<tp id=\"" << attrval(tp) << "\">\n";
d393 3
a395 2
            (*m_os) << "<failed>" << elemval(reason) << "</failed>\n";
        (*m_os) << "</tp>\n";
d401 1
a401 1
        (*m_os) << "<tc id=\"" << attrval(tcname) << "\">\n";
d407 1
a407 1
        (*m_os) << "<so>" << elemval(line) << "</so>\n";
d413 1
a413 1
        (*m_os) << "<se>" << elemval(line) << "</se>\n";
d425 1
a425 1
                    << "</" << state << ">\n";
d427 1
a427 1
            (*m_os) << "<passed />\n";
d429 2
a430 1
            (*m_os) << "<failed>" << elemval(reason) << "</failed>\n";
d432 2
a433 1
            (*m_os) << "<skipped>" << elemval(reason) << "</skipped>\n";
d436 1
a436 1
        (*m_os) << "</tc>\n";
d442 1
a442 1
        (*m_os) << "</tests-results>\n";
d449 1
a449 1
        (*m_os) << "<?xml version=\"1.0\"?>\n"
d452 4
a455 2
                   "\"http://www.NetBSD.org/XML/atf/tests-results.dtd\">\n\n"
                   "<tests-results>\n";
@


1.1.1.4
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.
a29 4
extern "C" {
#include <sys/time.h>
}

a31 1
#include <iomanip>
a33 1
#include <sstream>
a36 2
#include "atf-c/defs.h"

d47 1
a47 1
static ostream_ptr
a59 10
static std::string
format_tv(struct timeval* tv)
{
    std::ostringstream output;
    output << static_cast< long >(tv->tv_sec) << '.'
           << std::setfill('0') << std::setw(6)
           << static_cast< long >(tv->tv_usec);
    return output.str();
}

d83 1
a83 1
    virtual void write_tp_end(struct timeval*, const std::string&) {}
d87 1
a87 2
    virtual void write_tc_end(const std::string&, struct timeval*,
                              const std::string&) {}
d118 1
a118 2
    write_tp_start(const std::string& name,
                   size_t ntcs ATF_DEFS_ATTRIBUTE_UNUSED)
d126 1
a126 1
    write_tp_end(struct timeval* tv, const std::string& reason)
a127 2
        const std::string timestamp = format_tv(tv);

d129 1
a129 2
            (*m_os) << "tp, " << timestamp << ", " << m_tpname << ", bogus, "
                    << reason << "\n";
d131 1
a131 1
            (*m_os) << "tp, " << timestamp << ", "<< m_tpname << ", failed\n";
d133 1
a133 1
            (*m_os) << "tp, " << timestamp << ", "<< m_tpname << ", passed\n";
d145 1
a145 2
    write_tc_end(const std::string& state, struct timeval* tv,
                 const std::string& reason)
d147 1
a147 1
        std::string str = m_tpname + ", " + m_tcname + ", " + state;
d150 1
a150 1
        (*m_os) << "tc, " << format_tv(tv) << ", " << str << "\n";
d214 1
a214 1
    write_tp_end(struct timeval* tv, const std::string& reason)
d228 1
a228 1
        (*m_os) << "[" << format_tv(tv) << "s]\n\n";
d244 1
a244 2
    write_tc_end(const std::string& state, struct timeval* tv,
                 const std::string& reason)
a247 2
        (*m_os) << "[" << format_tv(tv) << "s] ";

d270 1
a270 1
        (*m_os) << str << '\n';
d391 1
a391 2
    write_tp_start(const std::string& tp,
                   size_t ntcs ATF_DEFS_ATTRIBUTE_UNUSED)
d397 1
a397 1
    write_tp_end(struct timeval* tv, const std::string& reason)
a400 1
        (*m_os) << "<tp-time>" << format_tv(tv) << "</tp-time>";
d423 1
a423 2
    write_tc_end(const std::string& state, struct timeval* tv,
                 const std::string& reason)
a439 1
        (*m_os) << "<tc-time>" << format_tv(tv) << "</tc-time>";
d453 1
a453 1
        (*m_os) << "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
d501 1
a501 1
    got_tp_end(struct timeval* tv, const std::string& reason)
d505 1
a505 1
            (*iter)->write_tp_end(tv, reason);
d533 1
a533 2
    got_tc_end(const std::string& state, struct timeval* tv,
               const std::string& reason)
d537 1
a537 1
            (*iter)->write_tc_end(state, tv, reason);
a640 3
    if (m_argc > 0)
        throw std::runtime_error("No arguments allowed");

@


1.1.1.5
log
@Import atf 0.17:

Experimental version released on February 14th, 2013.

* Added the atf_utils_cat_file, atf_utils_compare_file,
  atf_utils_copy_file, atf_utils_create_file, atf_utils_file_exists,
  atf_utils_fork, atf_utils_grep_file, atf_utils_grep_string,
  atf_utils_readline, atf_utils_redirect and atf_utils_wait utility
  functions to atf-c-api.  Documented the already-public
  atf_utils_free_charpp function.

* Added the cat_file, compare_file, copy_file, create_file, file_exists,
  fork, grep_collection, grep_file, grep_string, redirect and wait
  functions to the atf::utils namespace of atf-c++-api.  These are
  wrappers around the same functions added to the atf-c-api library.

* Added the ATF_CHECK_MATCH, ATF_CHECK_MATCH_MSG, ATF_REQUIRE_MATCH and
  ATF_REQUIRE_MATCH_MSG macros to atf-c to simplify the validation of a
  string against a regular expression.

* Miscellaneous fixes for manpage typos and compilation problems with
  clang.

* Added caching of the results of those configure tests that rely on
  executing a test program.  This should help crossbuild systems by
  providing a mechanism to pre-specify what the results should be.

* PR bin/45690: Make atf-report convert any non-printable characters to
  a plain-text representation (matching their corresponding hexadecimal
  entities) in XML output files.  This is to prevent the output of test
  cases from breaking xsltproc later.
@
text
@a33 1
#include <cctype>
d384 1
d398 1
a398 1
        std::ostringstream buf;
d401 5
a405 12
            const int character = static_cast< unsigned char >(*iter);
            if (character == '&') {
                buf << "&amp;";
            } else if (character == '<') {
                buf << "&lt;";
            } else if (character == '>') {
                buf << "&gt;";
            } else if (std::isalnum(character) || std::ispunct(character) ||
                       std::isspace(character)) {
                buf << static_cast< char >(character);
            } else {
                buf << "&amp;#" << character << ";";
d408 1
a408 1
        return buf.str();
@


