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