// Copyright (c) 2007 The NetBSD Foundation, Inc.1// All rights reserved.2//3// Redistribution and use in source and binary forms, with or without4// modification, are permitted provided that the following conditions5// are met:6// 1. Redistributions of source code must retain the above copyright7// notice, this list of conditions and the following disclaimer.8// 2. Redistributions in binary form must reproduce the above copyright9// notice, this list of conditions and the following disclaimer in the10// documentation and/or other materials provided with the distribution.11//12// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND13// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,14// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF15// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.16// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY17// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE19// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS20// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER21// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR22// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN23// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2425#if !defined(ATF_CXX_TESTS_HPP)26#define ATF_CXX_TESTS_HPP2728#include <map>29#include <memory>30#include <string>3132extern "C" {33#include <atf-c/defs.h>34}3536namespace atf {37namespace tests {3839namespace detail {4041class atf_tp_writer {42std::ostream& m_os;4344bool m_is_first;4546public:47atf_tp_writer(std::ostream&);4849void start_tc(const std::string&);50void end_tc(void);51void tc_meta_data(const std::string&, const std::string&);52};5354bool match(const std::string&, const std::string&);5556} // namespace5758// ------------------------------------------------------------------------59// The "vars_map" class.60// ------------------------------------------------------------------------6162typedef std::map< std::string, std::string > vars_map;6364// ------------------------------------------------------------------------65// The "tc" class.66// ------------------------------------------------------------------------6768struct tc_impl;6970class tc {71// Non-copyable.72tc(const tc&);73tc& operator=(const tc&);7475std::unique_ptr< tc_impl > pimpl;7677protected:78virtual void head(void);79virtual void body(void) const = 0;80virtual void cleanup(void) const;8182void require_kmod(const std::string&) const;83void require_prog(const std::string&) const;8485friend struct tc_impl;8687public:88tc(const std::string&, const bool);89virtual ~tc(void);9091void init(const vars_map&);9293const std::string get_config_var(const std::string&) const;94const std::string get_config_var(const std::string&, const std::string&)95const;96const std::string get_md_var(const std::string&) const;97const vars_map get_md_vars(void) const;98bool has_config_var(const std::string&) const;99bool has_md_var(const std::string&) const;100void set_md_var(const std::string&, const std::string&);101102void run(const std::string&) const;103void run_cleanup(void) const;104105// To be called from the child process only.106static void pass(void) ATF_DEFS_ATTRIBUTE_NORETURN;107static void fail(const std::string&) ATF_DEFS_ATTRIBUTE_NORETURN;108static void fail_nonfatal(const std::string&);109static void skip(const std::string&) ATF_DEFS_ATTRIBUTE_NORETURN;110static void check_errno(const char*, const int, const int, const char*,111const bool);112static void require_errno(const char*, const int, const int, const char*,113const bool);114static void expect_pass(void);115static void expect_fail(const std::string&);116static void expect_exit(const int, const std::string&);117static void expect_signal(const int, const std::string&);118static void expect_death(const std::string&);119static void expect_timeout(const std::string&);120};121122} // namespace tests123} // namespace atf124125#endif // !defined(ATF_CXX_TESTS_HPP)126127128