1*0659fc67Sjmmv //
2*0659fc67Sjmmv // Automated Testing Framework (atf)
3*0659fc67Sjmmv //
4*0659fc67Sjmmv // Copyright (c) 2007 The NetBSD Foundation, Inc.
5*0659fc67Sjmmv // All rights reserved.
6*0659fc67Sjmmv //
7*0659fc67Sjmmv // Redistribution and use in source and binary forms, with or without
8*0659fc67Sjmmv // modification, are permitted provided that the following conditions
9*0659fc67Sjmmv // are met:
10*0659fc67Sjmmv // 1. Redistributions of source code must retain the above copyright
11*0659fc67Sjmmv // notice, this list of conditions and the following disclaimer.
12*0659fc67Sjmmv // 2. Redistributions in binary form must reproduce the above copyright
13*0659fc67Sjmmv // notice, this list of conditions and the following disclaimer in the
14*0659fc67Sjmmv // documentation and/or other materials provided with the distribution.
15*0659fc67Sjmmv //
16*0659fc67Sjmmv // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17*0659fc67Sjmmv // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18*0659fc67Sjmmv // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19*0659fc67Sjmmv // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20*0659fc67Sjmmv // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21*0659fc67Sjmmv // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*0659fc67Sjmmv // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23*0659fc67Sjmmv // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*0659fc67Sjmmv // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25*0659fc67Sjmmv // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26*0659fc67Sjmmv // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27*0659fc67Sjmmv // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*0659fc67Sjmmv //
29*0659fc67Sjmmv
30*0659fc67Sjmmv extern "C" {
31*0659fc67Sjmmv #include "atf-c/utils.h"
32*0659fc67Sjmmv }
33*0659fc67Sjmmv
34*0659fc67Sjmmv #include <cstdlib>
35*0659fc67Sjmmv #include <iostream>
36*0659fc67Sjmmv
37*0659fc67Sjmmv #include "utils.hpp"
38*0659fc67Sjmmv
39*0659fc67Sjmmv void
cat_file(const std::string & path,const std::string & prefix)40*0659fc67Sjmmv atf::utils::cat_file(const std::string& path, const std::string& prefix)
41*0659fc67Sjmmv {
42*0659fc67Sjmmv atf_utils_cat_file(path.c_str(), prefix.c_str());
43*0659fc67Sjmmv }
44*0659fc67Sjmmv
45*0659fc67Sjmmv void
copy_file(const std::string & source,const std::string & destination)46*0659fc67Sjmmv atf::utils::copy_file(const std::string& source, const std::string& destination)
47*0659fc67Sjmmv {
48*0659fc67Sjmmv atf_utils_copy_file(source.c_str(), destination.c_str());
49*0659fc67Sjmmv }
50*0659fc67Sjmmv
51*0659fc67Sjmmv bool
compare_file(const std::string & path,const std::string & contents)52*0659fc67Sjmmv atf::utils::compare_file(const std::string& path, const std::string& contents)
53*0659fc67Sjmmv {
54*0659fc67Sjmmv return atf_utils_compare_file(path.c_str(), contents.c_str());
55*0659fc67Sjmmv }
56*0659fc67Sjmmv
57*0659fc67Sjmmv void
create_file(const std::string & path,const std::string & contents)58*0659fc67Sjmmv atf::utils::create_file(const std::string& path, const std::string& contents)
59*0659fc67Sjmmv {
60*0659fc67Sjmmv atf_utils_create_file(path.c_str(), "%s", contents.c_str());
61*0659fc67Sjmmv }
62*0659fc67Sjmmv
63*0659fc67Sjmmv bool
file_exists(const std::string & path)64*0659fc67Sjmmv atf::utils::file_exists(const std::string& path)
65*0659fc67Sjmmv {
66*0659fc67Sjmmv return atf_utils_file_exists(path.c_str());
67*0659fc67Sjmmv }
68*0659fc67Sjmmv
69*0659fc67Sjmmv pid_t
fork(void)70*0659fc67Sjmmv atf::utils::fork(void)
71*0659fc67Sjmmv {
72*0659fc67Sjmmv std::cout.flush();
73*0659fc67Sjmmv std::cerr.flush();
74*0659fc67Sjmmv return atf_utils_fork();
75*0659fc67Sjmmv }
76*0659fc67Sjmmv
77*0659fc67Sjmmv bool
grep_file(const std::string & regex,const std::string & path)78*0659fc67Sjmmv atf::utils::grep_file(const std::string& regex, const std::string& path)
79*0659fc67Sjmmv {
80*0659fc67Sjmmv return atf_utils_grep_file("%s", path.c_str(), regex.c_str());
81*0659fc67Sjmmv }
82*0659fc67Sjmmv
83*0659fc67Sjmmv bool
grep_string(const std::string & regex,const std::string & str)84*0659fc67Sjmmv atf::utils::grep_string(const std::string& regex, const std::string& str)
85*0659fc67Sjmmv {
86*0659fc67Sjmmv return atf_utils_grep_string("%s", str.c_str(), regex.c_str());
87*0659fc67Sjmmv }
88*0659fc67Sjmmv
89*0659fc67Sjmmv void
redirect(const int fd,const std::string & path)90*0659fc67Sjmmv atf::utils::redirect(const int fd, const std::string& path)
91*0659fc67Sjmmv {
92*0659fc67Sjmmv if (fd == STDOUT_FILENO)
93*0659fc67Sjmmv std::cout.flush();
94*0659fc67Sjmmv else if (fd == STDERR_FILENO)
95*0659fc67Sjmmv std::cerr.flush();
96*0659fc67Sjmmv atf_utils_redirect(fd, path.c_str());
97*0659fc67Sjmmv }
98*0659fc67Sjmmv
99*0659fc67Sjmmv void
wait(const pid_t pid,const int exitstatus,const std::string & expout,const std::string & experr)100*0659fc67Sjmmv atf::utils::wait(const pid_t pid, const int exitstatus,
101*0659fc67Sjmmv const std::string& expout, const std::string& experr)
102*0659fc67Sjmmv {
103*0659fc67Sjmmv atf_utils_wait(pid, exitstatus, expout.c_str(), experr.c_str());
104*0659fc67Sjmmv }
105