1*11be35a1SLionel Sambuc# Copyright 2012 Google Inc. 2*11be35a1SLionel Sambuc# All rights reserved. 3*11be35a1SLionel Sambuc# 4*11be35a1SLionel Sambuc# Redistribution and use in source and binary forms, with or without 5*11be35a1SLionel Sambuc# modification, are permitted provided that the following conditions are 6*11be35a1SLionel Sambuc# met: 7*11be35a1SLionel Sambuc# 8*11be35a1SLionel Sambuc# * Redistributions of source code must retain the above copyright 9*11be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer. 10*11be35a1SLionel Sambuc# * Redistributions in binary form must reproduce the above copyright 11*11be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer in the 12*11be35a1SLionel Sambuc# documentation and/or other materials provided with the distribution. 13*11be35a1SLionel Sambuc# * Neither the name of Google Inc. nor the names of its contributors 14*11be35a1SLionel Sambuc# may be used to endorse or promote products derived from this software 15*11be35a1SLionel Sambuc# without specific prior written permission. 16*11be35a1SLionel Sambuc# 17*11be35a1SLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18*11be35a1SLionel Sambuc# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19*11be35a1SLionel Sambuc# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20*11be35a1SLionel Sambuc# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21*11be35a1SLionel Sambuc# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22*11be35a1SLionel Sambuc# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23*11be35a1SLionel Sambuc# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24*11be35a1SLionel Sambuc# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25*11be35a1SLionel Sambuc# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26*11be35a1SLionel Sambuc# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27*11be35a1SLionel Sambuc# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28*11be35a1SLionel Sambuc 29*11be35a1SLionel Sambuc# Helper function for the various one_* test cases. 30*11be35a1SLionel Sambuc# 31*11be35a1SLionel Sambuc# The first argument must be one of C, CXX or SH, and this indicates the 32*11be35a1SLionel Sambuc# language of the test program. 33*11be35a1SLionel Sambuc# 34*11be35a1SLionel Sambuc# The second argument is the name of the test program, without an extension. 35*11be35a1SLionel Sambuc# The corresponding source file must exist in the current directory. 36*11be35a1SLionel Sambucone_test() { 37*11be35a1SLionel Sambuc local lang="${1}"; shift 38*11be35a1SLionel Sambuc local name="${1}"; shift 39*11be35a1SLionel Sambuc 40*11be35a1SLionel Sambuc cat >Makefile <<EOF 41*11be35a1SLionel Sambuc.include <bsd.own.mk> 42*11be35a1SLionel SambucTESTSDIR = \${TESTSBASE}/fake 43*11be35a1SLionel SambucTESTS_${lang} = ${name} 44*11be35a1SLionel Sambuc.include <bsd.test.mk> 45*11be35a1SLionel SambucEOF 46*11be35a1SLionel Sambuc 47*11be35a1SLionel Sambuc atf_check -o ignore make 48*11be35a1SLionel Sambuc mkdir -p root/usr/tests/fake 49*11be35a1SLionel Sambuc create_make_conf mk.conf owngrp DESTDIR="$(pwd)/root" 50*11be35a1SLionel Sambuc atf_check -o ignore make install 51*11be35a1SLionel Sambuc 52*11be35a1SLionel Sambuc atf_check -o match:'ident: one_tc' "./root/usr/tests/fake/${name}" -l 53*11be35a1SLionel Sambuc} 54*11be35a1SLionel Sambuc 55*11be35a1SLionel Sambucatf_test_case one_c 56*11be35a1SLionel Sambucone_c_body() { 57*11be35a1SLionel Sambuc cat >t_fake.c <<EOF 58*11be35a1SLionel Sambuc#include <atf-c.h> 59*11be35a1SLionel SambucATF_TC_WITHOUT_HEAD(one_tc); 60*11be35a1SLionel SambucATF_TC_BODY(one_tc, tc) 61*11be35a1SLionel Sambuc{ 62*11be35a1SLionel Sambuc atf_tc_fail("Failing explicitly"); 63*11be35a1SLionel Sambuc} 64*11be35a1SLionel Sambuc 65*11be35a1SLionel SambucATF_TP_ADD_TCS(tp) 66*11be35a1SLionel Sambuc{ 67*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, one_tc); 68*11be35a1SLionel Sambuc return atf_no_error(); 69*11be35a1SLionel Sambuc} 70*11be35a1SLionel SambucEOF 71*11be35a1SLionel Sambuc one_test C t_fake 72*11be35a1SLionel Sambuc} 73*11be35a1SLionel Sambuc 74*11be35a1SLionel Sambucatf_test_case one_cxx 75*11be35a1SLionel Sambucone_cxx_body() { 76*11be35a1SLionel Sambuc cat >t_fake.cpp <<EOF 77*11be35a1SLionel Sambuc#include <atf-c++.hpp> 78*11be35a1SLionel SambucATF_TEST_CASE_WITHOUT_HEAD(one_tc); 79*11be35a1SLionel SambucATF_TEST_CASE_BODY(one_tc) 80*11be35a1SLionel Sambuc{ 81*11be35a1SLionel Sambuc fail("Failing explicitly"); 82*11be35a1SLionel Sambuc} 83*11be35a1SLionel Sambuc 84*11be35a1SLionel SambucATF_INIT_TEST_CASES(tcs) 85*11be35a1SLionel Sambuc{ 86*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, one_tc); 87*11be35a1SLionel Sambuc} 88*11be35a1SLionel SambucEOF 89*11be35a1SLionel Sambuc one_test CXX t_fake 90*11be35a1SLionel Sambuc} 91*11be35a1SLionel Sambuc 92*11be35a1SLionel Sambucatf_test_case one_sh 93*11be35a1SLionel Sambucone_sh_body() { 94*11be35a1SLionel Sambuc cat >t_fake.sh <<EOF 95*11be35a1SLionel Sambucatf_test_case one_tc 96*11be35a1SLionel Sambucone_tc_body() { 97*11be35a1SLionel Sambuc atf_fail "Failing explicitly" 98*11be35a1SLionel Sambuc} 99*11be35a1SLionel Sambuc 100*11be35a1SLionel Sambucatf_init_test_cases() { 101*11be35a1SLionel Sambuc atf_add_test_case one_tc 102*11be35a1SLionel Sambuc} 103*11be35a1SLionel SambucEOF 104*11be35a1SLionel Sambuc one_test SH t_fake 105*11be35a1SLionel Sambuc} 106*11be35a1SLionel Sambuc 107*11be35a1SLionel Sambucatf_init_test_cases() { 108*11be35a1SLionel Sambuc atf_add_test_case one_c 109*11be35a1SLionel Sambuc atf_add_test_case one_cxx 110*11be35a1SLionel Sambuc atf_add_test_case one_sh 111*11be35a1SLionel Sambuc} 112