111be35a1SLionel Sambuc# 211be35a1SLionel Sambuc# Automated Testing Framework (atf) 311be35a1SLionel Sambuc# 411be35a1SLionel Sambuc# Copyright (c) 2008 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# The following tests assume that the atfc++.pc file is installed in a 3111be35a1SLionel Sambuc# directory that is known by pkg-config. Otherwise they will fail, 3211be35a1SLionel Sambuc# and you will be required to adjust PKG_CONFIG_PATH accordingly. 3311be35a1SLionel Sambuc# 3411be35a1SLionel Sambuc# It would be possible to bypass this requirement by setting the path 3511be35a1SLionel Sambuc# explicitly during the tests, but then this would not do a real check 3611be35a1SLionel Sambuc# to ensure that the installation is working. 3711be35a1SLionel Sambuc 3811be35a1SLionel Sambucrequire_pc() 3911be35a1SLionel Sambuc{ 4011be35a1SLionel Sambuc pkg-config ${1} || atf_fail "pkg-config could not locate ${1}.pc;" \ 4111be35a1SLionel Sambuc "maybe need to set PKG_CONFIG_PATH?" 4211be35a1SLionel Sambuc} 4311be35a1SLionel Sambuc 4411be35a1SLionel Sambuccheck_version() 4511be35a1SLionel Sambuc{ 46*0a6a1f1dSLionel Sambuc ver1=$($(atf_get_srcdir)/detail/version_helper) 47*0a6a1f1dSLionel Sambuc echo "Version reported by builtin PACKAGE_VERSION: ${ver1}" 4811be35a1SLionel Sambuc 4911be35a1SLionel Sambuc atf_check -s eq:0 -o save:stdout -e empty pkg-config --modversion "${1}" 5011be35a1SLionel Sambuc ver2=$(cat stdout) 5111be35a1SLionel Sambuc echo "Version reported by pkg-config: ${ver2}" 5211be35a1SLionel Sambuc 5311be35a1SLionel Sambuc atf_check_equal ${ver1} ${ver2} 5411be35a1SLionel Sambuc} 5511be35a1SLionel Sambuc 5611be35a1SLionel Sambucatf_test_case version 5711be35a1SLionel Sambucversion_head() 5811be35a1SLionel Sambuc{ 5911be35a1SLionel Sambuc atf_set "descr" "Checks that the version in atf-c++ is correct" 6011be35a1SLionel Sambuc atf_set "require.progs" "atf-version pkg-config" 6111be35a1SLionel Sambuc} 6211be35a1SLionel Sambucversion_body() 6311be35a1SLionel Sambuc{ 6411be35a1SLionel Sambuc require_pc "atf-c++" 6511be35a1SLionel Sambuc 6611be35a1SLionel Sambuc check_version "atf-c++" 6711be35a1SLionel Sambuc} 6811be35a1SLionel Sambuc 6911be35a1SLionel Sambucatf_test_case build 7011be35a1SLionel Sambucbuild_head() 7111be35a1SLionel Sambuc{ 7211be35a1SLionel Sambuc atf_set "descr" "Checks that a test program can be built against" \ 7311be35a1SLionel Sambuc "the C++ library based on the pkg-config information" 7411be35a1SLionel Sambuc atf_set "require.progs" "pkg-config" 7511be35a1SLionel Sambuc} 7611be35a1SLionel Sambucbuild_body() 7711be35a1SLionel Sambuc{ 7811be35a1SLionel Sambuc require_pc "atf-c++" 7911be35a1SLionel Sambuc 8011be35a1SLionel Sambuc atf_check -s eq:0 -o save:stdout -e empty \ 8111be35a1SLionel Sambuc pkg-config --variable=cxx atf-c++ 8211be35a1SLionel Sambuc cxx=$(cat stdout) 8311be35a1SLionel Sambuc echo "Compiler is: ${cxx}" 8411be35a1SLionel Sambuc atf_require_prog ${cxx} 8511be35a1SLionel Sambuc 8611be35a1SLionel Sambuc cat >tp.cpp <<EOF 8711be35a1SLionel Sambuc#include <iostream> 8811be35a1SLionel Sambuc 8911be35a1SLionel Sambuc#include <atf-c++.hpp> 9011be35a1SLionel Sambuc 9111be35a1SLionel SambucATF_TEST_CASE(tc); 9211be35a1SLionel SambucATF_TEST_CASE_HEAD(tc) { 9311be35a1SLionel Sambuc set_md_var("descr", "A test case"); 9411be35a1SLionel Sambuc} 9511be35a1SLionel SambucATF_TEST_CASE_BODY(tc) { 9611be35a1SLionel Sambuc std::cout << "Running\n"; 9711be35a1SLionel Sambuc} 9811be35a1SLionel Sambuc 9911be35a1SLionel SambucATF_INIT_TEST_CASES(tcs) { 10011be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, tc); 10111be35a1SLionel Sambuc} 10211be35a1SLionel SambucEOF 10311be35a1SLionel Sambuc 10411be35a1SLionel Sambuc atf_check -s eq:0 -o save:stdout -e empty pkg-config --cflags atf-c++ 10511be35a1SLionel Sambuc cxxflags=$(cat stdout) 10611be35a1SLionel Sambuc echo "CXXFLAGS are: ${cxxflags}" 10711be35a1SLionel Sambuc 10811be35a1SLionel Sambuc atf_check -s eq:0 -o save:stdout -e empty \ 10911be35a1SLionel Sambuc pkg-config --libs-only-L --libs-only-other atf-c++ 11011be35a1SLionel Sambuc ldflags=$(cat stdout) 11111be35a1SLionel Sambuc atf_check -s eq:0 -o save:stdout -e empty \ 11211be35a1SLionel Sambuc pkg-config --libs-only-l atf-c++ 11311be35a1SLionel Sambuc libs=$(cat stdout) 11411be35a1SLionel Sambuc echo "LDFLAGS are: ${ldflags}" 11511be35a1SLionel Sambuc echo "LIBS are: ${libs}" 11611be35a1SLionel Sambuc 11711be35a1SLionel Sambuc atf_check -s eq:0 -o empty -e empty ${cxx} ${cxxflags} -o tp.o -c tp.cpp 11811be35a1SLionel Sambuc atf_check -s eq:0 -o empty -e empty ${cxx} ${ldflags} -o tp tp.o ${libs} 11911be35a1SLionel Sambuc 12011be35a1SLionel Sambuc libpath= 12111be35a1SLionel Sambuc for f in ${ldflags}; do 12211be35a1SLionel Sambuc case ${f} in 12311be35a1SLionel Sambuc -L*) 12411be35a1SLionel Sambuc dir=$(echo ${f} | sed -e 's,^-L,,') 12511be35a1SLionel Sambuc if [ -z "${libpath}" ]; then 12611be35a1SLionel Sambuc libpath="${dir}" 12711be35a1SLionel Sambuc else 12811be35a1SLionel Sambuc libpath="${libpath}:${dir}" 12911be35a1SLionel Sambuc fi 13011be35a1SLionel Sambuc ;; 13111be35a1SLionel Sambuc *) 13211be35a1SLionel Sambuc ;; 13311be35a1SLionel Sambuc esac 13411be35a1SLionel Sambuc done 13511be35a1SLionel Sambuc 13611be35a1SLionel Sambuc atf_check -s eq:0 -o empty -e empty test -x tp 13711be35a1SLionel Sambuc atf_check -s eq:0 -o match:'Running' -e empty -x \ 13811be35a1SLionel Sambuc "LD_LIBRARY_PATH=${libpath} ./tp tc" 13911be35a1SLionel Sambuc} 14011be35a1SLionel Sambuc 14111be35a1SLionel Sambucatf_init_test_cases() 14211be35a1SLionel Sambuc{ 14311be35a1SLionel Sambuc atf_add_test_case version 14411be35a1SLionel Sambuc atf_add_test_case build 14511be35a1SLionel Sambuc} 14611be35a1SLionel Sambuc 14711be35a1SLionel Sambuc# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 148