1# 2# Automated Testing Framework (atf) 3# 4# Copyright (c) 2008 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# The following tests assume that the atfc++.pc file is installed in a 31# directory that is known by pkg-config. Otherwise they will fail, 32# and you will be required to adjust PKG_CONFIG_PATH accordingly. 33# 34# It would be possible to bypass this requirement by setting the path 35# explicitly during the tests, but then this would not do a real check 36# to ensure that the installation is working. 37 38require_pc() 39{ 40 pkg-config ${1} || atf_fail "pkg-config could not locate ${1}.pc;" \ 41 "maybe need to set PKG_CONFIG_PATH?" 42} 43 44check_version() 45{ 46 ver1=$($(atf_get_srcdir)/detail/version_helper) 47 echo "Version reported by builtin PACKAGE_VERSION: ${ver1}" 48 49 atf_check -s eq:0 -o save:stdout -e empty pkg-config --modversion "${1}" 50 ver2=$(cat stdout) 51 echo "Version reported by pkg-config: ${ver2}" 52 53 atf_check_equal ${ver1} ${ver2} 54} 55 56atf_test_case version 57version_head() 58{ 59 atf_set "descr" "Checks that the version in atf-c++ is correct" 60 atf_set "require.progs" "pkg-config" 61} 62version_body() 63{ 64 require_pc "atf-c++" 65 66 check_version "atf-c++" 67} 68 69atf_test_case build 70build_head() 71{ 72 atf_set "descr" "Checks that a test program can be built against" \ 73 "the C++ library based on the pkg-config information" 74 atf_set "require.progs" "pkg-config" 75} 76build_body() 77{ 78 require_pc "atf-c++" 79 80 atf_check -s eq:0 -o save:stdout -e empty \ 81 pkg-config --variable=cxx atf-c++ 82 cxx=$(cat stdout) 83 echo "Compiler is: ${cxx}" 84 atf_require_prog ${cxx} 85 86 cat >tp.cpp <<EOF 87#include <iostream> 88 89#include <atf-c++.hpp> 90 91ATF_TEST_CASE(tc); 92ATF_TEST_CASE_HEAD(tc) { 93 set_md_var("descr", "A test case"); 94} 95ATF_TEST_CASE_BODY(tc) { 96 std::cout << "Running\n"; 97} 98 99ATF_INIT_TEST_CASES(tcs) { 100 ATF_ADD_TEST_CASE(tcs, tc); 101} 102EOF 103 104 atf_check -s eq:0 -o save:stdout -e empty pkg-config --cflags atf-c++ 105 cxxflags=$(cat stdout) 106 echo "CXXFLAGS are: ${cxxflags}" 107 108 atf_check -s eq:0 -o save:stdout -e empty \ 109 pkg-config --libs-only-L --libs-only-other atf-c++ 110 ldflags=$(cat stdout) 111 atf_check -s eq:0 -o save:stdout -e empty \ 112 pkg-config --libs-only-l atf-c++ 113 libs=$(cat stdout) 114 echo "LDFLAGS are: ${ldflags}" 115 echo "LIBS are: ${libs}" 116 117 atf_check -s eq:0 -o empty -e empty ${cxx} ${cxxflags} -o tp.o -c tp.cpp 118 atf_check -s eq:0 -o empty -e empty ${cxx} ${ldflags} -o tp tp.o ${libs} 119 120 libpath= 121 for f in ${ldflags}; do 122 case ${f} in 123 -L*) 124 dir=$(echo ${f} | sed -e 's,^-L,,') 125 if [ -z "${libpath}" ]; then 126 libpath="${dir}" 127 else 128 libpath="${libpath}:${dir}" 129 fi 130 ;; 131 *) 132 ;; 133 esac 134 done 135 136 atf_check -s eq:0 -o empty -e empty test -x tp 137 atf_check -s eq:0 -o match:'Running' -e empty -x \ 138 "LD_LIBRARY_PATH=${libpath} ./tp tc" 139} 140 141atf_init_test_cases() 142{ 143 atf_add_test_case version 144 atf_add_test_case build 145} 146 147# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 148