Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/atf/atf-c++/tests.hpp
39507 views
1
// Copyright (c) 2007 The NetBSD Foundation, Inc.
2
// All rights reserved.
3
//
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions
6
// are met:
7
// 1. Redistributions of source code must retain the above copyright
8
// notice, this list of conditions and the following disclaimer.
9
// 2. Redistributions in binary form must reproduce the above copyright
10
// notice, this list of conditions and the following disclaimer in the
11
// documentation and/or other materials provided with the distribution.
12
//
13
// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14
// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17
// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24
// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26
#if !defined(ATF_CXX_TESTS_HPP)
27
#define ATF_CXX_TESTS_HPP
28
29
#include <map>
30
#include <memory>
31
#include <string>
32
33
extern "C" {
34
#include <atf-c/defs.h>
35
}
36
37
namespace atf {
38
namespace tests {
39
40
namespace detail {
41
42
class atf_tp_writer {
43
std::ostream& m_os;
44
45
bool m_is_first;
46
47
public:
48
atf_tp_writer(std::ostream&);
49
50
void start_tc(const std::string&);
51
void end_tc(void);
52
void tc_meta_data(const std::string&, const std::string&);
53
};
54
55
bool match(const std::string&, const std::string&);
56
57
} // namespace
58
59
// ------------------------------------------------------------------------
60
// The "vars_map" class.
61
// ------------------------------------------------------------------------
62
63
typedef std::map< std::string, std::string > vars_map;
64
65
// ------------------------------------------------------------------------
66
// The "tc" class.
67
// ------------------------------------------------------------------------
68
69
struct tc_impl;
70
71
class tc {
72
// Non-copyable.
73
tc(const tc&);
74
tc& operator=(const tc&);
75
76
std::unique_ptr< tc_impl > pimpl;
77
78
protected:
79
virtual void head(void);
80
virtual void body(void) const = 0;
81
virtual void cleanup(void) const;
82
83
void require_kmod(const std::string&) const;
84
void require_prog(const std::string&) const;
85
86
friend struct tc_impl;
87
88
public:
89
tc(const std::string&, const bool);
90
virtual ~tc(void);
91
92
void init(const vars_map&);
93
94
const std::string get_config_var(const std::string&) const;
95
const std::string get_config_var(const std::string&, const std::string&)
96
const;
97
const std::string get_md_var(const std::string&) const;
98
const vars_map get_md_vars(void) const;
99
bool has_config_var(const std::string&) const;
100
bool has_md_var(const std::string&) const;
101
void set_md_var(const std::string&, const std::string&);
102
103
void run(const std::string&) const;
104
void run_cleanup(void) const;
105
106
// To be called from the child process only.
107
static void pass(void) ATF_DEFS_ATTRIBUTE_NORETURN;
108
static void fail(const std::string&) ATF_DEFS_ATTRIBUTE_NORETURN;
109
static void fail_nonfatal(const std::string&);
110
static void skip(const std::string&) ATF_DEFS_ATTRIBUTE_NORETURN;
111
static void check_errno(const char*, const int, const int, const char*,
112
const bool);
113
static void require_errno(const char*, const int, const int, const char*,
114
const bool);
115
static void expect_pass(void);
116
static void expect_fail(const std::string&);
117
static void expect_exit(const int, const std::string&);
118
static void expect_signal(const int, const std::string&);
119
static void expect_death(const std::string&);
120
static void expect_timeout(const std::string&);
121
};
122
123
} // namespace tests
124
} // namespace atf
125
126
#endif // !defined(ATF_CXX_TESTS_HPP)
127
128