Date: Sun, 29 Dec 2013 12:30:06 +0000 (UTC) From: Julio Merino <jmmv@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r260037 - in stable/10: etc/mtree share share/examples share/examples/tests share/examples/tests/tests/plain share/mk share/tests Message-ID: <201312291230.rBTCU6jR022180@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jmmv Date: Sun Dec 29 12:30:06 2013 New Revision: 260037 URL: http://svnweb.freebsd.org/changeset/base/260037 Log: Add sample test programs. This is a MFC of the following into stable/10: - r258299 Add some sample test programs. - r258552 Generate plain sh test programs from a source file. As usual, "make tinderbox" clean on ref10-amd64. Added: stable/10/share/examples/tests/ - copied from r258299, head/share/examples/tests/ stable/10/share/examples/tests/tests/plain/cp_test.sh - copied unchanged from r258552, head/share/examples/tests/tests/plain/cp_test.sh stable/10/share/tests/ - copied from r258299, head/share/tests/ Deleted: stable/10/share/examples/tests/tests/plain/cp_test Modified: stable/10/etc/mtree/BSD.tests.dist stable/10/share/Makefile stable/10/share/examples/Makefile stable/10/share/mk/plain.test.mk Directory Properties: stable/10/ (props changed) Modified: stable/10/etc/mtree/BSD.tests.dist ============================================================================== --- stable/10/etc/mtree/BSD.tests.dist Sun Dec 29 11:19:09 2013 (r260036) +++ stable/10/etc/mtree/BSD.tests.dist Sun Dec 29 12:30:06 2013 (r260037) @@ -38,6 +38,16 @@ .. .. .. + share + examples + tests + atf + .. + plain + .. + .. + .. + .. usr.bin atf atf-sh Modified: stable/10/share/Makefile ============================================================================== --- stable/10/share/Makefile Sun Dec 29 11:19:09 2013 (r260036) +++ stable/10/share/Makefile Sun Dec 29 12:30:06 2013 (r260037) @@ -26,6 +26,7 @@ SUBDIR= ${_colldef} \ ${_syscons} \ tabset \ termcap \ + ${_tests} \ ${_timedef} \ ${_zoneinfo} @@ -80,6 +81,10 @@ _doc= doc _syscons= syscons .endif +.if ${MK_TESTS} != "no" +_tests= tests +.endif + .if ${MK_ZONEINFO} != "no" _zoneinfo= zoneinfo .endif Modified: stable/10/share/examples/Makefile ============================================================================== --- stable/10/share/examples/Makefile Sun Dec 29 11:19:09 2013 (r260036) +++ stable/10/share/examples/Makefile Sun Dec 29 12:30:06 2013 (r260037) @@ -249,4 +249,8 @@ SUBDIR+=pf .endif .endif +.if ${MK_TESTS} != "no" +SUBDIR+=tests +.endif + .include <bsd.subdir.mk> Copied: stable/10/share/examples/tests/tests/plain/cp_test.sh (from r258552, head/share/examples/tests/tests/plain/cp_test.sh) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/share/examples/tests/tests/plain/cp_test.sh Sun Dec 29 12:30:06 2013 (r260037, copy of r258552, head/share/examples/tests/tests/plain/cp_test.sh) @@ -0,0 +1,84 @@ +# $FreeBSD$ +# +# Copyright 2013 Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of Google Inc. nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# +# INTRODUCTION +# +# This plain test program mimics the structure and contents of its +# ATF-based counterpart. It attempts to represent various test cases +# in different separate functions and just calls them all from main. +# +# In reality, plain test programs can be much simpler. All they have +# to do is return 0 on success and non-0 otherwise. +# + +set -e + +# Prints an error message and exits. +err() { + echo "${@}" 1>&2 + exit 1 +} + +# Auxiliary function to compare two files for equality. +verify_copy() { + if ! cmp -s "${1}" "${2}"; then + diff -u "${1}" "${2}" + err "${1} and ${2} differ, but they should be equal" + fi +} + +simple_test() { + echo 'File 1' >file1 + cp file1 file2 || err "cp failed" + verify_copy file1 file2 +} + +force_test() { + echo 'File 1' >file1 + echo 'File 2' >file2 + chmod 400 file2 + cp -f file1 file2 || err "cp failed" + verify_copy file1 file2 +} + +# If you have read the cp_test.sh counterpart in the atf/ directory, you +# may think that the sequencing of tests below and the exposed behavior +# to the user is very similar. But you'd be wrong. +# +# There are two major differences with this and the ATF version. The +# first is that the code below has no provisions to detect failures in +# one test and continue running the other tests: the first failure +# causes the whole test program to exit. The second is that this +# particular "main" has no arguments: without ATF, all test programs may +# expose a different command-line interface, and this is an issue for +# consistency purposes. +simple_test +force_test Modified: stable/10/share/mk/plain.test.mk ============================================================================== --- stable/10/share/mk/plain.test.mk Sun Dec 29 11:19:09 2013 (r260036) +++ stable/10/share/mk/plain.test.mk Sun Dec 29 12:30:06 2013 (r260037) @@ -46,6 +46,16 @@ _TESTS+= ${PLAIN_TESTS_SH} .for _T in ${PLAIN_TESTS_SH} SCRIPTSDIR_${_T}= ${TESTSDIR} TEST_INTERFACE.${_T}= plain +CLEANFILES+= ${_T} ${_T}.tmp +# TODO(jmmv): It seems to me that this SED and SRC functionality should +# exist in bsd.prog.mk along the support for SCRIPTS. Move it there if +# this proves to be useful within the tests. +PLAIN_TESTS_SH_SED_${_T}?= # empty +PLAIN_TESTS_SH_SRC_${_T}?= ${_T}.sh +${_T}: ${PLAIN_TESTS_SH_SRC_${_T}} + cat ${.ALLSRC} | sed ${PLAIN_TESTS_SH_SED_${_T}} >${.TARGET}.tmp + chmod +x ${.TARGET}.tmp + mv ${.TARGET}.tmp ${.TARGET} .endfor .endif
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201312291230.rBTCU6jR022180>