111be35a1SLionel Sambuc //
211be35a1SLionel Sambuc // Automated Testing Framework (atf)
311be35a1SLionel Sambuc //
411be35a1SLionel Sambuc // Copyright (c) 2009 The NetBSD Foundation, Inc.
511be35a1SLionel Sambuc // All rights reserved.
611be35a1SLionel Sambuc //
711be35a1SLionel Sambuc // Redistribution and use in source and binary forms, with or without
811be35a1SLionel Sambuc // modification, are permitted provided that the following conditions
911be35a1SLionel Sambuc // are met:
1011be35a1SLionel Sambuc // 1. Redistributions of source code must retain the above copyright
1111be35a1SLionel Sambuc // notice, this list of conditions and the following disclaimer.
1211be35a1SLionel Sambuc // 2. Redistributions in binary form must reproduce the above copyright
1311be35a1SLionel Sambuc // notice, this list of conditions and the following disclaimer in the
1411be35a1SLionel Sambuc // documentation and/or other materials provided with the distribution.
1511be35a1SLionel Sambuc //
1611be35a1SLionel Sambuc // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
1711be35a1SLionel Sambuc // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
1811be35a1SLionel Sambuc // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1911be35a1SLionel Sambuc // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2011be35a1SLionel Sambuc // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
2111be35a1SLionel Sambuc // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2211be35a1SLionel Sambuc // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
2311be35a1SLionel Sambuc // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2411be35a1SLionel Sambuc // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
2511be35a1SLionel Sambuc // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2611be35a1SLionel Sambuc // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
2711be35a1SLionel Sambuc // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2811be35a1SLionel Sambuc //
2911be35a1SLionel Sambuc
3011be35a1SLionel Sambuc #include <fstream>
3111be35a1SLionel Sambuc #include <iostream>
3211be35a1SLionel Sambuc #include <string>
3311be35a1SLionel Sambuc #include <vector>
3411be35a1SLionel Sambuc
3511be35a1SLionel Sambuc #include "../check.hpp"
3611be35a1SLionel Sambuc #include "../config.hpp"
3711be35a1SLionel Sambuc #include "../macros.hpp"
3811be35a1SLionel Sambuc
3911be35a1SLionel Sambuc #include "fs.hpp"
4011be35a1SLionel Sambuc #include "process.hpp"
4111be35a1SLionel Sambuc #include "test_helpers.hpp"
4211be35a1SLionel Sambuc
43*0a6a1f1dSLionel Sambuc // Path to the directory containing the libatf-c tests, used to locate the
44*0a6a1f1dSLionel Sambuc // process_helpers program. If NULL (the default), the code will use a
45*0a6a1f1dSLionel Sambuc // relative path. Otherwise, the provided path will be used; this is so
46*0a6a1f1dSLionel Sambuc // that we can locate the helpers binary if the installation uses a
47*0a6a1f1dSLionel Sambuc // different layout than the one we provide (as is the case in FreeBSD).
48*0a6a1f1dSLionel Sambuc #if defined(ATF_C_TESTS_BASE)
49*0a6a1f1dSLionel Sambuc static const char* atf_c_tests_base = ATF_C_TESTS_BASE;
50*0a6a1f1dSLionel Sambuc #else
51*0a6a1f1dSLionel Sambuc static const char* atf_c_tests_base = NULL;
52*0a6a1f1dSLionel Sambuc #endif
53*0a6a1f1dSLionel Sambuc #undef ATF_C_TESTS_BASE
54*0a6a1f1dSLionel Sambuc
55*0a6a1f1dSLionel Sambuc bool
build_check_cxx_o(const char * sfile)56*0a6a1f1dSLionel Sambuc build_check_cxx_o(const char* sfile)
5711be35a1SLionel Sambuc {
5811be35a1SLionel Sambuc std::vector< std::string > optargs;
5911be35a1SLionel Sambuc optargs.push_back("-I" + atf::config::get("atf_includedir"));
6011be35a1SLionel Sambuc optargs.push_back("-Wall");
6111be35a1SLionel Sambuc optargs.push_back("-Werror");
6211be35a1SLionel Sambuc
63*0a6a1f1dSLionel Sambuc return atf::check::build_cxx_o(sfile, "test.o",
64*0a6a1f1dSLionel Sambuc atf::process::argv_array(optargs));
6511be35a1SLionel Sambuc }
6611be35a1SLionel Sambuc
67*0a6a1f1dSLionel Sambuc bool
build_check_cxx_o_srcdir(const atf::tests::tc & tc,const char * sfile)68*0a6a1f1dSLionel Sambuc build_check_cxx_o_srcdir(const atf::tests::tc& tc, const char* sfile)
6911be35a1SLionel Sambuc {
7011be35a1SLionel Sambuc const atf::fs::path sfilepath =
7111be35a1SLionel Sambuc atf::fs::path(tc.get_config_var("srcdir")) / sfile;
72*0a6a1f1dSLionel Sambuc return build_check_cxx_o(sfilepath.c_str());
7311be35a1SLionel Sambuc }
7411be35a1SLionel Sambuc
7511be35a1SLionel Sambuc void
header_check(const char * hdrname)7611be35a1SLionel Sambuc header_check(const char *hdrname)
7711be35a1SLionel Sambuc {
78*0a6a1f1dSLionel Sambuc std::ofstream srcfile("test.cpp");
7911be35a1SLionel Sambuc ATF_REQUIRE(srcfile);
8011be35a1SLionel Sambuc srcfile << "#include <" << hdrname << ">\n";
8111be35a1SLionel Sambuc srcfile.close();
8211be35a1SLionel Sambuc
8311be35a1SLionel Sambuc const std::string failmsg = std::string("Header check failed; ") +
8411be35a1SLionel Sambuc hdrname + " is not self-contained";
85*0a6a1f1dSLionel Sambuc if (!build_check_cxx_o("test.cpp"))
86*0a6a1f1dSLionel Sambuc ATF_FAIL(failmsg);
8711be35a1SLionel Sambuc }
8811be35a1SLionel Sambuc
8911be35a1SLionel Sambuc atf::fs::path
get_process_helpers_path(const atf::tests::tc & tc,bool is_detail)90*0a6a1f1dSLionel Sambuc get_process_helpers_path(const atf::tests::tc& tc, bool is_detail)
9111be35a1SLionel Sambuc {
92*0a6a1f1dSLionel Sambuc const char* helper = "detail/process_helpers";
93*0a6a1f1dSLionel Sambuc if (atf_c_tests_base == NULL) {
94*0a6a1f1dSLionel Sambuc if (is_detail)
9511be35a1SLionel Sambuc return atf::fs::path(tc.get_config_var("srcdir")) /
96*0a6a1f1dSLionel Sambuc ".." / ".." / "atf-c" / helper;
97*0a6a1f1dSLionel Sambuc else
98*0a6a1f1dSLionel Sambuc return atf::fs::path(tc.get_config_var("srcdir")) /
99*0a6a1f1dSLionel Sambuc ".." / "atf-c" / helper;
10011be35a1SLionel Sambuc } else {
101*0a6a1f1dSLionel Sambuc return atf::fs::path(atf_c_tests_base) / helper;
10211be35a1SLionel Sambuc }
10311be35a1SLionel Sambuc }
104