t_test.sh revision 1.2
11.1Sjmmv# Copyright 2012 Google Inc. 21.1Sjmmv# All rights reserved. 31.1Sjmmv# 41.1Sjmmv# Redistribution and use in source and binary forms, with or without 51.1Sjmmv# modification, are permitted provided that the following conditions are 61.1Sjmmv# met: 71.1Sjmmv# 81.1Sjmmv# * Redistributions of source code must retain the above copyright 91.1Sjmmv# notice, this list of conditions and the following disclaimer. 101.1Sjmmv# * Redistributions in binary form must reproduce the above copyright 111.1Sjmmv# notice, this list of conditions and the following disclaimer in the 121.1Sjmmv# documentation and/or other materials provided with the distribution. 131.1Sjmmv# * Neither the name of Google Inc. nor the names of its contributors 141.1Sjmmv# may be used to endorse or promote products derived from this software 151.1Sjmmv# without specific prior written permission. 161.1Sjmmv# 171.1Sjmmv# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 181.1Sjmmv# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 191.1Sjmmv# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 201.1Sjmmv# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 211.1Sjmmv# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 221.1Sjmmv# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 231.1Sjmmv# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 241.1Sjmmv# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 251.1Sjmmv# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 261.1Sjmmv# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 271.1Sjmmv# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 281.1Sjmmv 291.1Sjmmv# Helper function for the various one_* test cases. 301.1Sjmmv# 311.1Sjmmv# The first argument must be one of C, CXX or SH, and this indicates the 321.1Sjmmv# language of the test program. 331.1Sjmmv# 341.1Sjmmv# The second argument is the name of the test program, without an extension. 351.1Sjmmv# The corresponding source file must exist in the current directory. 361.1Sjmmvone_test() { 371.2Sjoerg 381.2Sjoerg if [ ! -e /usr/bin/gcc -a -e /usr/bin/clang ]; then 391.2Sjoerg export HAVE_LLVM=yes 401.2Sjoerg fi 411.1Sjmmv local lang="${1}"; shift 421.1Sjmmv local name="${1}"; shift 431.1Sjmmv 441.1Sjmmv cat >Makefile <<EOF 451.1Sjmmv.include <bsd.own.mk> 461.1SjmmvTESTSDIR = \${TESTSBASE}/fake 471.1SjmmvTESTS_${lang} = ${name} 481.1Sjmmv.include <bsd.test.mk> 491.1SjmmvEOF 501.1Sjmmv 511.1Sjmmv atf_check -o ignore make 521.1Sjmmv mkdir -p root/usr/tests/fake 531.1Sjmmv create_make_conf mk.conf owngrp DESTDIR="$(pwd)/root" 541.1Sjmmv atf_check -o ignore make install 551.1Sjmmv 561.1Sjmmv atf_check -o match:'ident: one_tc' "./root/usr/tests/fake/${name}" -l 571.1Sjmmv} 581.1Sjmmv 591.1Sjmmvatf_test_case one_c 601.1Sjmmvone_c_body() { 611.1Sjmmv cat >t_fake.c <<EOF 621.1Sjmmv#include <atf-c.h> 631.1SjmmvATF_TC_WITHOUT_HEAD(one_tc); 641.1SjmmvATF_TC_BODY(one_tc, tc) 651.1Sjmmv{ 661.1Sjmmv atf_tc_fail("Failing explicitly"); 671.1Sjmmv} 681.1Sjmmv 691.1SjmmvATF_TP_ADD_TCS(tp) 701.1Sjmmv{ 711.1Sjmmv ATF_TP_ADD_TC(tp, one_tc); 721.1Sjmmv return atf_no_error(); 731.1Sjmmv} 741.1SjmmvEOF 751.1Sjmmv one_test C t_fake 761.1Sjmmv} 771.1Sjmmv 781.1Sjmmvatf_test_case one_cxx 791.1Sjmmvone_cxx_body() { 801.1Sjmmv cat >t_fake.cpp <<EOF 811.1Sjmmv#include <atf-c++.hpp> 821.1SjmmvATF_TEST_CASE_WITHOUT_HEAD(one_tc); 831.1SjmmvATF_TEST_CASE_BODY(one_tc) 841.1Sjmmv{ 851.1Sjmmv fail("Failing explicitly"); 861.1Sjmmv} 871.1Sjmmv 881.1SjmmvATF_INIT_TEST_CASES(tcs) 891.1Sjmmv{ 901.1Sjmmv ATF_ADD_TEST_CASE(tcs, one_tc); 911.1Sjmmv} 921.1SjmmvEOF 931.1Sjmmv one_test CXX t_fake 941.1Sjmmv} 951.1Sjmmv 961.1Sjmmvatf_test_case one_sh 971.1Sjmmvone_sh_body() { 981.1Sjmmv cat >t_fake.sh <<EOF 991.1Sjmmvatf_test_case one_tc 1001.1Sjmmvone_tc_body() { 1011.1Sjmmv atf_fail "Failing explicitly" 1021.1Sjmmv} 1031.1Sjmmv 1041.1Sjmmvatf_init_test_cases() { 1051.1Sjmmv atf_add_test_case one_tc 1061.1Sjmmv} 1071.1SjmmvEOF 1081.1Sjmmv one_test SH t_fake 1091.1Sjmmv} 1101.1Sjmmv 1111.1Sjmmvatf_init_test_cases() { 1121.1Sjmmv atf_add_test_case one_c 1131.1Sjmmv atf_add_test_case one_cxx 1141.1Sjmmv atf_add_test_case one_sh 1151.1Sjmmv} 116