Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/atf/atf-c++/check.cpp
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
#include "atf-c++/check.hpp"
27
28
#include <cstring>
29
30
extern "C" {
31
#include "atf-c/build.h"
32
#include "atf-c/error.h"
33
}
34
35
#include "atf-c++/detail/exceptions.hpp"
36
#include "atf-c++/detail/process.hpp"
37
#include "atf-c++/detail/sanity.hpp"
38
39
namespace impl = atf::check;
40
#define IMPL_NAME "atf::check"
41
42
// ------------------------------------------------------------------------
43
// The "check_result" class.
44
// ------------------------------------------------------------------------
45
46
impl::check_result::check_result(const atf_check_result_t* result)
47
{
48
std::memcpy(&m_result, result, sizeof(m_result));
49
}
50
51
impl::check_result::~check_result(void)
52
{
53
atf_check_result_fini(&m_result);
54
}
55
56
bool
57
impl::check_result::exited(void)
58
const
59
{
60
return atf_check_result_exited(&m_result);
61
}
62
63
int
64
impl::check_result::exitcode(void)
65
const
66
{
67
PRE(exited());
68
return atf_check_result_exitcode(&m_result);
69
}
70
71
bool
72
impl::check_result::signaled(void)
73
const
74
{
75
return atf_check_result_signaled(&m_result);
76
}
77
78
int
79
impl::check_result::termsig(void)
80
const
81
{
82
PRE(signaled());
83
return atf_check_result_termsig(&m_result);
84
}
85
86
const std::string
87
impl::check_result::stdout_path(void) const
88
{
89
return atf_check_result_stdout(&m_result);
90
}
91
92
const std::string
93
impl::check_result::stderr_path(void) const
94
{
95
return atf_check_result_stderr(&m_result);
96
}
97
98
// ------------------------------------------------------------------------
99
// Free functions.
100
// ------------------------------------------------------------------------
101
102
bool
103
impl::build_c_o(const std::string& sfile, const std::string& ofile,
104
const atf::process::argv_array& optargs)
105
{
106
bool success;
107
108
atf_error_t err = atf_check_build_c_o(sfile.c_str(), ofile.c_str(),
109
optargs.exec_argv(), &success);
110
if (atf_is_error(err))
111
throw_atf_error(err);
112
113
return success;
114
}
115
116
bool
117
impl::build_cpp(const std::string& sfile, const std::string& ofile,
118
const atf::process::argv_array& optargs)
119
{
120
bool success;
121
122
atf_error_t err = atf_check_build_cpp(sfile.c_str(), ofile.c_str(),
123
optargs.exec_argv(), &success);
124
if (atf_is_error(err))
125
throw_atf_error(err);
126
127
return success;
128
}
129
130
bool
131
impl::build_cxx_o(const std::string& sfile, const std::string& ofile,
132
const atf::process::argv_array& optargs)
133
{
134
bool success;
135
136
atf_error_t err = atf_check_build_cxx_o(sfile.c_str(), ofile.c_str(),
137
optargs.exec_argv(), &success);
138
if (atf_is_error(err))
139
throw_atf_error(err);
140
141
return success;
142
}
143
144
std::unique_ptr< impl::check_result >
145
impl::exec(const atf::process::argv_array& argva)
146
{
147
atf_check_result_t result;
148
149
atf_error_t err = atf_check_exec_array(argva.exec_argv(), &result);
150
if (atf_is_error(err))
151
throw_atf_error(err);
152
153
return std::unique_ptr< impl::check_result >(new impl::check_result(&result));
154
}
155
156