1240116Smarcel// Copyright (c) 2009 The NetBSD Foundation, Inc. 2240116Smarcel// All rights reserved. 3240116Smarcel// 4240116Smarcel// Redistribution and use in source and binary forms, with or without 5240116Smarcel// modification, are permitted provided that the following conditions 6240116Smarcel// are met: 7240116Smarcel// 1. Redistributions of source code must retain the above copyright 8240116Smarcel// notice, this list of conditions and the following disclaimer. 9240116Smarcel// 2. Redistributions in binary form must reproduce the above copyright 10240116Smarcel// notice, this list of conditions and the following disclaimer in the 11240116Smarcel// documentation and/or other materials provided with the distribution. 12240116Smarcel// 13240116Smarcel// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 14240116Smarcel// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 15240116Smarcel// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 16240116Smarcel// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17240116Smarcel// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 18240116Smarcel// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19240116Smarcel// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 20240116Smarcel// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21240116Smarcel// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 22240116Smarcel// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23240116Smarcel// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 24240116Smarcel// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25240116Smarcel 26275988Sngie#include "atf-c++/detail/test_helpers.hpp" 27275988Sngie 28240116Smarcel#include <fstream> 29240116Smarcel#include <iostream> 30240116Smarcel#include <string> 31240116Smarcel#include <vector> 32240116Smarcel 33275988Sngie#include <atf-c++.hpp> 34240116Smarcel 35275988Sngie#include "atf-c++/check.hpp" 36275988Sngie#include "atf-c++/detail/env.hpp" 37275988Sngie#include "atf-c++/detail/fs.hpp" 38275988Sngie#include "atf-c++/detail/process.hpp" 39240116Smarcel 40262849Sjmmv// Path to the directory containing the libatf-c tests, used to locate the 41262849Sjmmv// process_helpers program. If NULL (the default), the code will use a 42262849Sjmmv// relative path. Otherwise, the provided path will be used; this is so 43262849Sjmmv// that we can locate the helpers binary if the installation uses a 44262849Sjmmv// different layout than the one we provide (as is the case in FreeBSD). 45262849Sjmmv#if defined(ATF_C_TESTS_BASE) 46262849Sjmmvstatic const char* atf_c_tests_base = ATF_C_TESTS_BASE; 47262849Sjmmv#else 48262849Sjmmvstatic const char* atf_c_tests_base = NULL; 49262849Sjmmv#endif 50262849Sjmmv#undef ATF_C_TESTS_BASE 51262849Sjmmv 52262855Sjmmvbool 53262855Sjmmvbuild_check_cxx_o(const char* sfile) 54240116Smarcel{ 55240116Smarcel std::vector< std::string > optargs; 56275988Sngie optargs.push_back("-I" + atf::env::get("ATF_INCLUDEDIR", ATF_INCLUDEDIR)); 57240116Smarcel optargs.push_back("-Wall"); 58240116Smarcel optargs.push_back("-Werror"); 59240116Smarcel 60262855Sjmmv return atf::check::build_cxx_o(sfile, "test.o", 61262855Sjmmv atf::process::argv_array(optargs)); 62240116Smarcel} 63240116Smarcel 64262855Sjmmvbool 65262855Sjmmvbuild_check_cxx_o_srcdir(const atf::tests::tc& tc, const char* sfile) 66240116Smarcel{ 67240116Smarcel const atf::fs::path sfilepath = 68240116Smarcel atf::fs::path(tc.get_config_var("srcdir")) / sfile; 69262855Sjmmv return build_check_cxx_o(sfilepath.c_str()); 70240116Smarcel} 71240116Smarcel 72240116Smarcelvoid 73240116Smarcelheader_check(const char *hdrname) 74240116Smarcel{ 75260578Sjmmv std::ofstream srcfile("test.cpp"); 76240116Smarcel ATF_REQUIRE(srcfile); 77240116Smarcel srcfile << "#include <" << hdrname << ">\n"; 78240116Smarcel srcfile.close(); 79240116Smarcel 80240116Smarcel const std::string failmsg = std::string("Header check failed; ") + 81240116Smarcel hdrname + " is not self-contained"; 82262855Sjmmv if (!build_check_cxx_o("test.cpp")) 83262855Sjmmv ATF_FAIL(failmsg); 84240116Smarcel} 85240116Smarcel 86240116Smarcelatf::fs::path 87251108Smarcelget_process_helpers_path(const atf::tests::tc& tc, bool is_detail) 88240116Smarcel{ 89262849Sjmmv const char* helper = "detail/process_helpers"; 90262849Sjmmv if (atf_c_tests_base == NULL) { 91262849Sjmmv if (is_detail) 92262849Sjmmv return atf::fs::path(tc.get_config_var("srcdir")) / 93262849Sjmmv ".." / ".." / "atf-c" / helper; 94262849Sjmmv else 95262849Sjmmv return atf::fs::path(tc.get_config_var("srcdir")) / 96262849Sjmmv ".." / "atf-c" / helper; 97262849Sjmmv } else { 98262849Sjmmv return atf::fs::path(atf_c_tests_base) / helper; 99262849Sjmmv } 100240116Smarcel} 101