Path: blob/main/contrib/atf/atf-c/pkg_config_test.sh
39481 views
# Copyright (c) 2008 The NetBSD Foundation, Inc.1# All rights reserved.2#3# Redistribution and use in source and binary forms, with or without4# modification, are permitted provided that the following conditions5# are met:6# 1. Redistributions of source code must retain the above copyright7# notice, this list of conditions and the following disclaimer.8# 2. Redistributions in binary form must reproduce the above copyright9# notice, this list of conditions and the following disclaimer in the10# documentation and/or other materials provided with the distribution.11#12# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND13# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,14# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF15# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.16# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY17# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE19# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS20# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER21# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR22# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN23# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2425# The following tests assume that the atf-c.pc file is installed in a26# directory that is known by pkg-config. Otherwise they will fail,27# and you will be required to adjust PKG_CONFIG_PATH accordingly.28#29# It would be possible to bypass this requirement by setting the path30# explicitly during the tests, but then this would not do a real check31# to ensure that the installation is working.3233require_pc()34{35pkg-config ${1} || atf_fail "pkg-config could not locate ${1}.pc;" \36"maybe need to set PKG_CONFIG_PATH?"37}3839check_version()40{41ver1=$($(atf_get_srcdir)/detail/version_helper)42echo "Version reported by builtin PACKAGE_VERSION: ${ver1}"4344atf_check -s eq:0 -o save:stdout -e empty pkg-config --modversion "${1}"45ver2=$(cat stdout)46echo "Version reported by pkg-config: ${ver2}"4748atf_check_equal ${ver1} ${ver2}49}5051atf_test_case version52version_head()53{54atf_set "descr" "Checks that the version in atf-c is correct"55atf_set "require.progs" "pkg-config"56}57version_body()58{59require_pc "atf-c"6061check_version "atf-c"62}6364atf_test_case build65build_head()66{67atf_set "descr" "Checks that a test program can be built against" \68"the C library based on the pkg-config information"69atf_set "require.progs" "pkg-config"70}71build_body()72{73require_pc "atf-c"7475atf_check -s eq:0 -o save:stdout -e empty pkg-config --variable=cc atf-c76cc=$(cat stdout)77echo "Compiler is: ${cxx}"78atf_require_prog ${cxx}7980cat >tp.c <<EOF81#include <stdio.h>8283#include <atf-c.h>8485ATF_TC(tc);86ATF_TC_HEAD(tc, tc) {87atf_tc_set_md_var(tc, "descr", "A test case");88}89ATF_TC_BODY(tc, tc) {90printf("Running\n");91}9293ATF_TP_ADD_TCS(tp) {94ATF_TP_ADD_TC(tp, tc);9596return atf_no_error();97}98EOF99100atf_check -s eq:0 -o save:stdout -e empty pkg-config --cflags atf-c101cflags=$(cat stdout)102echo "CFLAGS are: ${cflags}"103104atf_check -s eq:0 -o save:stdout -e empty \105pkg-config --libs-only-L --libs-only-other atf-c106ldflags=$(cat stdout)107atf_check -s eq:0 -o save:stdout -e empty pkg-config --libs-only-l atf-c108libs=$(cat stdout)109echo "LDFLAGS are: ${ldflags}"110echo "LIBS are: ${libs}"111112atf_check -s eq:0 -o empty -e empty ${cc} ${cflags} -o tp.o -c tp.c113atf_check -s eq:0 -o empty -e empty ${cc} ${ldflags} -o tp tp.o ${libs}114115libpath=116for f in ${ldflags}; do117case ${f} in118-L*)119dir=$(echo ${f} | sed -e 's,^-L,,')120if [ -z "${libpath}" ]; then121libpath="${dir}"122else123libpath="${libpath}:${dir}"124fi125;;126*)127;;128esac129done130131atf_check -s eq:0 -o empty -e empty test -x tp132atf_check -s eq:0 -o match:'Running' -e empty -x \133"LD_LIBRARY_PATH=${libpath} ./tp tc"134}135136atf_init_test_cases()137{138atf_add_test_case version139atf_add_test_case build140}141142# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4143144145