pkg_config_test.sh revision 1.1.1.1
1# 2# Automated Testing Framework (atf) 3# 4# Copyright (c) 2008, 2010 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 atf-c.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 atf_check -s eq:0 -o save:stdout -e empty -x \ 47 "atf-version | head -n 1 | cut -d ' ' -f 4" 48 ver1=$(cat stdout) 49 echo "Version reported by atf-version: ${ver1}" 50 51 atf_check -s eq:0 -o save:stdout -e empty pkg-config --modversion "${1}" 52 ver2=$(cat stdout) 53 echo "Version reported by pkg-config: ${ver2}" 54 55 atf_check_equal ${ver1} ${ver2} 56} 57 58atf_test_case version 59version_head() 60{ 61 atf_set "descr" "Checks that the version in atf-c is correct" 62 atf_set "require.progs" "pkg-config" 63 atf_set "use.fs" "true" 64} 65version_body() 66{ 67 require_pc "atf-c" 68 69 check_version "atf-c" 70} 71 72atf_test_case build 73build_head() 74{ 75 atf_set "descr" "Checks that a test program can be built against" \ 76 "the C library based on the pkg-config information" 77 atf_set "require.progs" "pkg-config" 78 atf_set "use.fs" "true" 79} 80build_body() 81{ 82 require_pc "atf-c" 83 84 atf_check -s eq:0 -o save:stdout -e empty pkg-config --variable=cc atf-c 85 cc=$(cat stdout) 86 echo "Compiler is: ${cxx}" 87 atf_require_prog ${cxx} 88 89 cat >tp.c <<EOF 90#include <stdio.h> 91 92#include <atf-c.h> 93 94ATF_TC(tc); 95ATF_TC_HEAD(tc, tc) { 96 atf_tc_set_md_var(tc, "descr", "A test case"); 97} 98ATF_TC_BODY(tc, tc) { 99 printf("Running\n"); 100} 101 102ATF_TP_ADD_TCS(tp) { 103 ATF_TP_ADD_TC(tp, tc); 104 105 return atf_no_error(); 106} 107EOF 108 109 atf_check -s eq:0 -o save:stdout -e empty pkg-config --cflags atf-c 110 cflags=$(cat stdout) 111 echo "CFLAGS are: ${cflags}" 112 113 atf_check -s eq:0 -o save:stdout -e empty \ 114 pkg-config --libs-only-L --libs-only-other atf-c 115 ldflags=$(cat stdout) 116 atf_check -s eq:0 -o save:stdout -e empty pkg-config --libs-only-l atf-c 117 libs=$(cat stdout) 118 echo "LDFLAGS are: ${ldflags}" 119 echo "LIBS are: ${libs}" 120 121 atf_check -s eq:0 -o empty -e empty ${cc} ${cflags} -o tp.o -c tp.c 122 atf_check -s eq:0 -o empty -e empty ${cc} ${ldflags} -o tp tp.o ${libs} 123 124 libpath= 125 for f in ${ldflags}; do 126 case ${f} in 127 -L*) 128 dir=$(echo ${f} | sed -e 's,^-L,,') 129 if [ -z "${libpath}" ]; then 130 libpath="${dir}" 131 else 132 libpath="${libpath}:${dir}" 133 fi 134 ;; 135 *) 136 ;; 137 esac 138 done 139 140 atf_check -s eq:0 -o empty -e empty test -x tp 141 atf_check -s eq:0 -o match:'Running' -e empty -x \ 142 "LD_LIBRARY_PATH=${libpath} ./tp tc" 143} 144 145atf_init_test_cases() 146{ 147 atf_add_test_case version 148 atf_add_test_case build 149} 150 151# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 152