1 // Copyright (c) 2009 The NetBSD Foundation, Inc.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions
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.
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.
26 #include "atf-c++/detail/test_helpers.hpp"
33 #include <atf-c++.hpp>
35 #include "atf-c++/check.hpp"
36 #include "atf-c++/detail/env.hpp"
37 #include "atf-c++/detail/fs.hpp"
38 #include "atf-c++/detail/process.hpp"
40 // Path to the directory containing the libatf-c tests, used to locate the
41 // process_helpers program. If NULL (the default), the code will use a
42 // relative path. Otherwise, the provided path will be used; this is so
43 // that we can locate the helpers binary if the installation uses a
44 // different layout than the one we provide (as is the case in FreeBSD).
45 #if defined(ATF_C_TESTS_BASE)
46 static const char* atf_c_tests_base = ATF_C_TESTS_BASE;
48 static const char* atf_c_tests_base = NULL;
50 #undef ATF_C_TESTS_BASE
53 build_check_cxx_o(const char* sfile)
55 std::vector< std::string > optargs;
56 optargs.push_back("-I" + atf::env::get("ATF_INCLUDEDIR", ATF_INCLUDEDIR));
57 optargs.push_back("-Wall");
58 optargs.push_back("-Werror");
60 return atf::check::build_cxx_o(sfile, "test.o",
61 atf::process::argv_array(optargs));
65 build_check_cxx_o_srcdir(const atf::tests::tc& tc, const char* sfile)
67 const atf::fs::path sfilepath =
68 atf::fs::path(tc.get_config_var("srcdir")) / sfile;
69 return build_check_cxx_o(sfilepath.c_str());
73 header_check(const char *hdrname)
75 std::ofstream srcfile("test.cpp");
77 srcfile << "#include <" << hdrname << ">\n";
80 const std::string failmsg = std::string("Header check failed; ") +
81 hdrname + " is not self-contained";
82 if (!build_check_cxx_o("test.cpp"))
87 get_process_helpers_path(const atf::tests::tc& tc, bool is_detail)
89 const char* helper = "detail/process_helpers";
90 if (atf_c_tests_base == NULL) {
92 return atf::fs::path(tc.get_config_var("srcdir")) /
93 ".." / ".." / "atf-c" / helper;
95 return atf::fs::path(tc.get_config_var("srcdir")) /
96 ".." / "atf-c" / helper;
98 return atf::fs::path(atf_c_tests_base) / helper;