pkg_config_test.sh revision 258289
1142661Sphantom# 2142661Sphantom# Automated Testing Framework (atf) 3103899Smike# 4142661Sphantom# Copyright (c) 2008 The NetBSD Foundation, Inc. 5142661Sphantom# All rights reserved. 6103899Smike# 7142661Sphantom# Redistribution and use in source and binary forms, with or without 8142661Sphantom# modification, are permitted provided that the following conditions 9103899Smike# are met: 10142661Sphantom# 1. Redistributions of source code must retain the above copyright 11142661Sphantom# notice, this list of conditions and the following disclaimer. 12142661Sphantom# 2. Redistributions in binary form must reproduce the above copyright 13142661Sphantom# notice, this list of conditions and the following disclaimer in the 14142661Sphantom# documentation and/or other materials provided with the distribution. 15142661Sphantom# 16142661Sphantom# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 17142661Sphantom# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 18103899Smike# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19142661Sphantom# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20142661Sphantom# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 21142661Sphantom# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22142661Sphantom# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23142661Sphantom# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24142661Sphantom# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25142661Sphantom# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26142661Sphantom# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27142661Sphantom# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28142661Sphantom# 29142661Sphantom 30103899Smike# The following tests assume that the atf-c.pc file is installed in a 31103899Smike# directory that is known by pkg-config. Otherwise they will fail, 32103899Smike# and you will be required to adjust PKG_CONFIG_PATH accordingly. 337495Sjkh# 347495Sjkh# It would be possible to bypass this requirement by setting the path 357495Sjkh# explicitly during the tests, but then this would not do a real check 36103899Smike# to ensure that the installation is working. 377495Sjkh 38142661Sphantomrequire_pc() 397495Sjkh{ 40142661Sphantom pkg-config ${1} || atf_fail "pkg-config could not locate ${1}.pc;" \ 41142661Sphantom "maybe need to set PKG_CONFIG_PATH?" 42142661Sphantom} 43142661Sphantom 44142661Sphantomcheck_version() 45142661Sphantom{ 46142661Sphantom atf_check -s eq:0 -o save:stdout -e empty -x \ 47142661Sphantom "atf-version | head -n 1 | cut -d ' ' -f 4" 48142661Sphantom ver1=$(cat stdout) 49142661Sphantom echo "Version reported by atf-version: ${ver1}" 50142661Sphantom 51142661Sphantom atf_check -s eq:0 -o save:stdout -e empty pkg-config --modversion "${1}" 52142661Sphantom ver2=$(cat stdout) 53142661Sphantom echo "Version reported by pkg-config: ${ver2}" 54142661Sphantom 55142661Sphantom atf_check_equal ${ver1} ${ver2} 56142661Sphantom} 57142661Sphantom 58142661Sphantomatf_test_case version 59142661Sphantomversion_head() 60142661Sphantom{ 61142661Sphantom atf_set "descr" "Checks that the version in atf-c is correct" 62142661Sphantom atf_set "require.progs" "atf-version pkg-config" 63142661Sphantom} 64142661Sphantomversion_body() 65142661Sphantom{ 66142661Sphantom require_pc "atf-c" 67142661Sphantom 68142661Sphantom check_version "atf-c" 69142661Sphantom} 70142661Sphantom 71142661Sphantomatf_test_case build 72142661Sphantombuild_head() 73142661Sphantom{ 74142661Sphantom atf_set "descr" "Checks that a test program can be built against" \ 75142661Sphantom "the C library based on the pkg-config information" 76142661Sphantom atf_set "require.progs" "pkg-config" 77142661Sphantom} 7835545Sachebuild_body() 7935545Sache{ 807495Sjkh require_pc "atf-c" 81142661Sphantom 82142661Sphantom atf_check -s eq:0 -o save:stdout -e empty pkg-config --variable=cc atf-c 83142661Sphantom cc=$(cat stdout) 84142661Sphantom echo "Compiler is: ${cxx}" 85103899Smike atf_require_prog ${cxx} 86103521Smike 87103521Smike cat >tp.c <<EOF 88103521Smike#include <stdio.h> 89103521Smike 90103521Smike#include <atf-c.h> 9146673Sjkh 92142661SphantomATF_TC(tc); 93154867SstefanfATF_TC_HEAD(tc, tc) { 94103899Smike atf_tc_set_md_var(tc, "descr", "A test case"); 9546673Sjkh} 967495SjkhATF_TC_BODY(tc, tc) { 97142661Sphantom printf("Running\n"); 98} 99 100ATF_TP_ADD_TCS(tp) { 101 ATF_TP_ADD_TC(tp, tc); 102 103 return atf_no_error(); 104} 105EOF 106 107 atf_check -s eq:0 -o save:stdout -e empty pkg-config --cflags atf-c 108 cflags=$(cat stdout) 109 echo "CFLAGS are: ${cflags}" 110 111 atf_check -s eq:0 -o save:stdout -e empty \ 112 pkg-config --libs-only-L --libs-only-other atf-c 113 ldflags=$(cat stdout) 114 atf_check -s eq:0 -o save:stdout -e empty pkg-config --libs-only-l atf-c 115 libs=$(cat stdout) 116 echo "LDFLAGS are: ${ldflags}" 117 echo "LIBS are: ${libs}" 118 119 atf_check -s eq:0 -o empty -e empty ${cc} ${cflags} -o tp.o -c tp.c 120 atf_check -s eq:0 -o empty -e empty ${cc} ${ldflags} -o tp tp.o ${libs} 121 122 libpath= 123 for f in ${ldflags}; do 124 case ${f} in 125 -L*) 126 dir=$(echo ${f} | sed -e 's,^-L,,') 127 if [ -z "${libpath}" ]; then 128 libpath="${dir}" 129 else 130 libpath="${libpath}:${dir}" 131 fi 132 ;; 133 *) 134 ;; 135 esac 136 done 137 138 atf_check -s eq:0 -o empty -e empty test -x tp 139 atf_check -s eq:0 -o match:'Running' -e empty -x \ 140 "LD_LIBRARY_PATH=${libpath} ./tp tc" 141} 142 143atf_init_test_cases() 144{ 145 atf_add_test_case version 146 atf_add_test_case build 147} 148 149# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 150