1240116Smarcel# Copyright (c) 2008 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 26240116Smarcel# The following tests assume that the atfc++.pc file is installed in a 27240116Smarcel# directory that is known by pkg-config. Otherwise they will fail, 28240116Smarcel# and you will be required to adjust PKG_CONFIG_PATH accordingly. 29240116Smarcel# 30240116Smarcel# It would be possible to bypass this requirement by setting the path 31240116Smarcel# explicitly during the tests, but then this would not do a real check 32240116Smarcel# to ensure that the installation is working. 33240116Smarcel 34240116Smarcelrequire_pc() 35240116Smarcel{ 36240116Smarcel pkg-config ${1} || atf_fail "pkg-config could not locate ${1}.pc;" \ 37240116Smarcel "maybe need to set PKG_CONFIG_PATH?" 38240116Smarcel} 39240116Smarcel 40240116Smarcelcheck_version() 41240116Smarcel{ 42262855Sjmmv ver1=$($(atf_get_srcdir)/detail/version_helper) 43262855Sjmmv echo "Version reported by builtin PACKAGE_VERSION: ${ver1}" 44240116Smarcel 45240116Smarcel atf_check -s eq:0 -o save:stdout -e empty pkg-config --modversion "${1}" 46240116Smarcel ver2=$(cat stdout) 47240116Smarcel echo "Version reported by pkg-config: ${ver2}" 48240116Smarcel 49240116Smarcel atf_check_equal ${ver1} ${ver2} 50240116Smarcel} 51240116Smarcel 52240116Smarcelatf_test_case version 53240116Smarcelversion_head() 54240116Smarcel{ 55240116Smarcel atf_set "descr" "Checks that the version in atf-c++ is correct" 56262855Sjmmv atf_set "require.progs" "pkg-config" 57240116Smarcel} 58240116Smarcelversion_body() 59240116Smarcel{ 60240116Smarcel require_pc "atf-c++" 61240116Smarcel 62240116Smarcel check_version "atf-c++" 63240116Smarcel} 64240116Smarcel 65240116Smarcelatf_test_case build 66240116Smarcelbuild_head() 67240116Smarcel{ 68240116Smarcel atf_set "descr" "Checks that a test program can be built against" \ 69240116Smarcel "the C++ library based on the pkg-config information" 70240116Smarcel atf_set "require.progs" "pkg-config" 71240116Smarcel} 72240116Smarcelbuild_body() 73240116Smarcel{ 74240116Smarcel require_pc "atf-c++" 75240116Smarcel 76240116Smarcel atf_check -s eq:0 -o save:stdout -e empty \ 77240116Smarcel pkg-config --variable=cxx atf-c++ 78240116Smarcel cxx=$(cat stdout) 79240116Smarcel echo "Compiler is: ${cxx}" 80240116Smarcel atf_require_prog ${cxx} 81240116Smarcel 82240116Smarcel cat >tp.cpp <<EOF 83240116Smarcel#include <iostream> 84240116Smarcel 85240116Smarcel#include <atf-c++.hpp> 86240116Smarcel 87240116SmarcelATF_TEST_CASE(tc); 88240116SmarcelATF_TEST_CASE_HEAD(tc) { 89240116Smarcel set_md_var("descr", "A test case"); 90240116Smarcel} 91240116SmarcelATF_TEST_CASE_BODY(tc) { 92240116Smarcel std::cout << "Running\n"; 93240116Smarcel} 94240116Smarcel 95240116SmarcelATF_INIT_TEST_CASES(tcs) { 96240116Smarcel ATF_ADD_TEST_CASE(tcs, tc); 97240116Smarcel} 98240116SmarcelEOF 99240116Smarcel 100240116Smarcel atf_check -s eq:0 -o save:stdout -e empty pkg-config --cflags atf-c++ 101240116Smarcel cxxflags=$(cat stdout) 102240116Smarcel echo "CXXFLAGS are: ${cxxflags}" 103240116Smarcel 104240116Smarcel atf_check -s eq:0 -o save:stdout -e empty \ 105240116Smarcel pkg-config --libs-only-L --libs-only-other atf-c++ 106240116Smarcel ldflags=$(cat stdout) 107240116Smarcel atf_check -s eq:0 -o save:stdout -e empty \ 108240116Smarcel pkg-config --libs-only-l atf-c++ 109240116Smarcel libs=$(cat stdout) 110240116Smarcel echo "LDFLAGS are: ${ldflags}" 111240116Smarcel echo "LIBS are: ${libs}" 112240116Smarcel 113240116Smarcel atf_check -s eq:0 -o empty -e empty ${cxx} ${cxxflags} -o tp.o -c tp.cpp 114240116Smarcel atf_check -s eq:0 -o empty -e empty ${cxx} ${ldflags} -o tp tp.o ${libs} 115240116Smarcel 116240116Smarcel libpath= 117240116Smarcel for f in ${ldflags}; do 118240116Smarcel case ${f} in 119240116Smarcel -L*) 120240116Smarcel dir=$(echo ${f} | sed -e 's,^-L,,') 121240116Smarcel if [ -z "${libpath}" ]; then 122240116Smarcel libpath="${dir}" 123240116Smarcel else 124240116Smarcel libpath="${libpath}:${dir}" 125240116Smarcel fi 126240116Smarcel ;; 127240116Smarcel *) 128240116Smarcel ;; 129240116Smarcel esac 130240116Smarcel done 131240116Smarcel 132240116Smarcel atf_check -s eq:0 -o empty -e empty test -x tp 133240116Smarcel atf_check -s eq:0 -o match:'Running' -e empty -x \ 134240116Smarcel "LD_LIBRARY_PATH=${libpath} ./tp tc" 135240116Smarcel} 136240116Smarcel 137240116Smarcelatf_init_test_cases() 138240116Smarcel{ 139240116Smarcel atf_add_test_case version 140240116Smarcel atf_add_test_case build 141240116Smarcel} 142240116Smarcel 143240116Smarcel# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 144