1240116Smarcel# 2240116Smarcel# Automated Testing Framework (atf) 3240116Smarcel# 4240116Smarcel# Copyright (c) 2008 The NetBSD Foundation, Inc. 5240116Smarcel# All rights reserved. 6240116Smarcel# 7240116Smarcel# Redistribution and use in source and binary forms, with or without 8240116Smarcel# modification, are permitted provided that the following conditions 9240116Smarcel# are met: 10240116Smarcel# 1. Redistributions of source code must retain the above copyright 11240116Smarcel# notice, this list of conditions and the following disclaimer. 12240116Smarcel# 2. Redistributions in binary form must reproduce the above copyright 13240116Smarcel# notice, this list of conditions and the following disclaimer in the 14240116Smarcel# documentation and/or other materials provided with the distribution. 15240116Smarcel# 16240116Smarcel# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 17240116Smarcel# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 18240116Smarcel# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19240116Smarcel# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20240116Smarcel# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 21240116Smarcel# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22240116Smarcel# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23240116Smarcel# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24240116Smarcel# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25240116Smarcel# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26240116Smarcel# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27240116Smarcel# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28240116Smarcel# 29240116Smarcel 30240116Smarcel# The following tests assume that the atfc++.pc file is installed in a 31240116Smarcel# directory that is known by pkg-config. Otherwise they will fail, 32240116Smarcel# and you will be required to adjust PKG_CONFIG_PATH accordingly. 33240116Smarcel# 34240116Smarcel# It would be possible to bypass this requirement by setting the path 35240116Smarcel# explicitly during the tests, but then this would not do a real check 36240116Smarcel# to ensure that the installation is working. 37240116Smarcel 38240116Smarcelrequire_pc() 39240116Smarcel{ 40240116Smarcel pkg-config ${1} || atf_fail "pkg-config could not locate ${1}.pc;" \ 41240116Smarcel "maybe need to set PKG_CONFIG_PATH?" 42240116Smarcel} 43240116Smarcel 44240116Smarcelcheck_version() 45240116Smarcel{ 46262855Sjmmv ver1=$($(atf_get_srcdir)/detail/version_helper) 47262855Sjmmv echo "Version reported by builtin PACKAGE_VERSION: ${ver1}" 48240116Smarcel 49240116Smarcel atf_check -s eq:0 -o save:stdout -e empty pkg-config --modversion "${1}" 50240116Smarcel ver2=$(cat stdout) 51240116Smarcel echo "Version reported by pkg-config: ${ver2}" 52240116Smarcel 53240116Smarcel atf_check_equal ${ver1} ${ver2} 54240116Smarcel} 55240116Smarcel 56240116Smarcelatf_test_case version 57240116Smarcelversion_head() 58240116Smarcel{ 59240116Smarcel atf_set "descr" "Checks that the version in atf-c++ is correct" 60262855Sjmmv atf_set "require.progs" "pkg-config" 61240116Smarcel} 62240116Smarcelversion_body() 63240116Smarcel{ 64240116Smarcel require_pc "atf-c++" 65240116Smarcel 66240116Smarcel check_version "atf-c++" 67240116Smarcel} 68240116Smarcel 69240116Smarcelatf_test_case build 70240116Smarcelbuild_head() 71240116Smarcel{ 72240116Smarcel atf_set "descr" "Checks that a test program can be built against" \ 73240116Smarcel "the C++ library based on the pkg-config information" 74240116Smarcel atf_set "require.progs" "pkg-config" 75240116Smarcel} 76240116Smarcelbuild_body() 77240116Smarcel{ 78240116Smarcel require_pc "atf-c++" 79240116Smarcel 80240116Smarcel atf_check -s eq:0 -o save:stdout -e empty \ 81240116Smarcel pkg-config --variable=cxx atf-c++ 82240116Smarcel cxx=$(cat stdout) 83240116Smarcel echo "Compiler is: ${cxx}" 84240116Smarcel atf_require_prog ${cxx} 85240116Smarcel 86240116Smarcel cat >tp.cpp <<EOF 87240116Smarcel#include <iostream> 88240116Smarcel 89240116Smarcel#include <atf-c++.hpp> 90240116Smarcel 91240116SmarcelATF_TEST_CASE(tc); 92240116SmarcelATF_TEST_CASE_HEAD(tc) { 93240116Smarcel set_md_var("descr", "A test case"); 94240116Smarcel} 95240116SmarcelATF_TEST_CASE_BODY(tc) { 96240116Smarcel std::cout << "Running\n"; 97240116Smarcel} 98240116Smarcel 99240116SmarcelATF_INIT_TEST_CASES(tcs) { 100240116Smarcel ATF_ADD_TEST_CASE(tcs, tc); 101240116Smarcel} 102240116SmarcelEOF 103240116Smarcel 104240116Smarcel atf_check -s eq:0 -o save:stdout -e empty pkg-config --cflags atf-c++ 105240116Smarcel cxxflags=$(cat stdout) 106240116Smarcel echo "CXXFLAGS are: ${cxxflags}" 107240116Smarcel 108240116Smarcel atf_check -s eq:0 -o save:stdout -e empty \ 109240116Smarcel pkg-config --libs-only-L --libs-only-other atf-c++ 110240116Smarcel ldflags=$(cat stdout) 111240116Smarcel atf_check -s eq:0 -o save:stdout -e empty \ 112240116Smarcel pkg-config --libs-only-l atf-c++ 113240116Smarcel libs=$(cat stdout) 114240116Smarcel echo "LDFLAGS are: ${ldflags}" 115240116Smarcel echo "LIBS are: ${libs}" 116240116Smarcel 117240116Smarcel atf_check -s eq:0 -o empty -e empty ${cxx} ${cxxflags} -o tp.o -c tp.cpp 118240116Smarcel atf_check -s eq:0 -o empty -e empty ${cxx} ${ldflags} -o tp tp.o ${libs} 119240116Smarcel 120240116Smarcel libpath= 121240116Smarcel for f in ${ldflags}; do 122240116Smarcel case ${f} in 123240116Smarcel -L*) 124240116Smarcel dir=$(echo ${f} | sed -e 's,^-L,,') 125240116Smarcel if [ -z "${libpath}" ]; then 126240116Smarcel libpath="${dir}" 127240116Smarcel else 128240116Smarcel libpath="${libpath}:${dir}" 129240116Smarcel fi 130240116Smarcel ;; 131240116Smarcel *) 132240116Smarcel ;; 133240116Smarcel esac 134240116Smarcel done 135240116Smarcel 136240116Smarcel atf_check -s eq:0 -o empty -e empty test -x tp 137240116Smarcel atf_check -s eq:0 -o match:'Running' -e empty -x \ 138240116Smarcel "LD_LIBRARY_PATH=${libpath} ./tp tc" 139240116Smarcel} 140240116Smarcel 141240116Smarcelatf_init_test_cases() 142240116Smarcel{ 143240116Smarcel atf_add_test_case version 144240116Smarcel atf_add_test_case build 145240116Smarcel} 146240116Smarcel 147240116Smarcel# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 148