diff options
author | jmmv <jmmv@FreeBSD.org> | 2013-12-11 04:09:17 +0000 |
---|---|---|
committer | jmmv <jmmv@FreeBSD.org> | 2013-12-11 04:09:17 +0000 |
commit | cfc6ad9bc622f4196577ecf38575ca78dfe5c005 (patch) | |
tree | c357c3541ca854e3c662bf4b75f67946d3672f84 /bin/mv | |
parent | 865b783eec56bcde5b1f272b4b441a7c6a6c10fa (diff) | |
download | FreeBSD-src-cfc6ad9bc622f4196577ecf38575ca78dfe5c005.zip FreeBSD-src-cfc6ad9bc622f4196577ecf38575ca78dfe5c005.tar.gz |
Migrate tools/regression/bin/ tests to the new layout.
This change is a proof of concept on how to easily integrate existing
tests from the tools/regression/ hierarchy into the /usr/tests/ test
suite and on how to adapt them to the new layout for src.
To achieve these goals, this change:
- Moves tests from tools/regression/bin/<tool>/ to bin/<tool>/tests/.
- Renames the previous regress.sh files to legacy_test.sh.
- Adds Makefiles to build and install the tests and all their supporting
data files into /usr/tests/bin/.
- Plugs the legacy_test test programs into the test suite using the new
TAP backend for Kyua (appearing in 0.8) so that the code of the test
programs does not have to change.
- Registers the new directories in the BSD.test.dist mtree file.
Reviewed by: freebsd-testing
Approved by: rpaulo (mentor)
Diffstat (limited to 'bin/mv')
-rw-r--r-- | bin/mv/Makefile | 6 | ||||
-rw-r--r-- | bin/mv/tests/Makefile | 9 | ||||
-rw-r--r-- | bin/mv/tests/legacy_test.sh | 296 |
3 files changed, 311 insertions, 0 deletions
diff --git a/bin/mv/Makefile b/bin/mv/Makefile index 8405782..ad8cc4f 100644 --- a/bin/mv/Makefile +++ b/bin/mv/Makefile @@ -1,6 +1,12 @@ # @(#)Makefile 8.2 (Berkeley) 4/2/94 # $FreeBSD$ +.include <bsd.own.mk> + PROG= mv +.if ${MK_TESTS} != "no" +SUBDIR+= tests +.endif + .include <bsd.prog.mk> diff --git a/bin/mv/tests/Makefile b/bin/mv/tests/Makefile new file mode 100644 index 0000000..051a3b6 --- /dev/null +++ b/bin/mv/tests/Makefile @@ -0,0 +1,9 @@ +# $FreeBSD$ + +.include <bsd.own.mk> + +TESTSDIR= ${TESTSBASE}/bin/mv + +TAP_TESTS_SH= legacy_test + +.include <tap.test.mk> diff --git a/bin/mv/tests/legacy_test.sh b/bin/mv/tests/legacy_test.sh new file mode 100644 index 0000000..d0a5e83 --- /dev/null +++ b/bin/mv/tests/legacy_test.sh @@ -0,0 +1,296 @@ +#!/bin/sh +# $FreeBSD$ + +# A directory in a device different from that where the tests are run +TMPDIR=/tmp/regress.$$ +COUNT=0 + +# Begin an individual test +begin() +{ + COUNT=`expr $COUNT + 1` + OK=1 + if [ -z "$FS" ] + then + NAME="$1" + else + NAME="$1 (cross device)" + fi + rm -rf testdir $TMPDIR/testdir + mkdir -p testdir $TMPDIR/testdir + cd testdir +} + +# End an individual test +end() +{ + if [ $OK = 1 ] + then + printf 'ok ' + else + printf 'not ok ' + fi + echo "$COUNT - $NAME" + cd .. + rm -rf testdir $TMPDIR/testdir +} + +# Make a file that can later be verified +mkf() +{ + CN=`basename $1` + echo "$CN-$CN" >$1 +} + +# Verify that the file specified is correct +ckf() +{ + if [ -f $2 ] && echo "$1-$1" | diff - $2 >/dev/null + then + ok + else + notok + fi +} + +# Make a fifo that can later be verified +mkp() +{ + mkfifo $1 +} + +# Verify that the file specified is correct +ckp() +{ + if [ -p $2 ] + then + ok + else + notok + fi +} + +# Make a directory that can later be verified +mkd() +{ + CN=`basename $1` + mkdir -p $1/"$CN-$CN" +} + +# Verify that the directory specified is correct +ckd() +{ + if [ -d $2/$1-$1 ] + then + ok + else + notok + fi +} + +# Verify that the specified file does not exist +# (is not there) +cknt() +{ + if [ -r $1 ] + then + notok + else + ok + fi +} + +# A part of a test succeeds +ok() +{ + : +} + +# A part of a test fails +notok() +{ + OK=0 +} + +# Verify that the exit code passed is for unsuccessful termination +ckfail() +{ + if [ $1 -gt 0 ] + then + ok + else + notok + fi +} + +# Verify that the exit code passed is for successful termination +ckok() +{ + if [ $1 -eq 0 ] + then + ok + else + notok + fi +} + +# Run all tests locally and across devices +echo 1..32 +for FS in '' $TMPDIR/testdir/ +do + begin 'Rename file' + mkf fa + mv fa ${FS}fb + ckok $? + ckf fa ${FS}fb + cknt fa + end + + begin 'Move files into directory' + mkf fa + mkf fb + mkdir -p ${FS}1/2/3 + mv fa fb ${FS}1/2/3 + ckok $? + ckf fa ${FS}1/2/3/fa + ckf fb ${FS}1/2/3/fb + cknt fa + cknt fb + end + + begin 'Move file from directory to file' + mkdir -p 1/2/3 + mkf 1/2/3/fa + mv 1/2/3/fa ${FS}fb + ckok $? + ckf fa ${FS}fb + cknt 1/2/3/fa + end + + begin 'Move file from directory to existing file' + mkdir -p 1/2/3 + mkf 1/2/3/fa + :> ${FS}fb + mv 1/2/3/fa ${FS}fb + ckok $? + ckf fa ${FS}fb + cknt 1/2/3/fa + end + + begin 'Move file from directory to existing directory' + mkdir -p 1/2/3 + mkf 1/2/3/fa + mkdir -p ${FS}db/fa + # Should fail per POSIX step 3a: + # Destination path is a file of type directory and + # source_file is not a file of type directory + mv 1/2/3/fa ${FS}db 2>/dev/null + ckfail $? + ckf fa 1/2/3/fa + end + + begin 'Move file from directory to directory' + mkdir -p da1/da2/da3 + mkdir -p ${FS}db1/db2/db3 + mkf da1/da2/da3/fa + mv da1/da2/da3/fa ${FS}db1/db2/db3/fb + ckok $? + ckf fa ${FS}db1/db2/db3/fb + cknt da1/da2/da3/fa + end + + begin 'Rename directory' + mkd da + mv da ${FS}db + ckok $? + ckd da ${FS}db + cknt da + end + + begin 'Move directory to directory name' + mkd da1/da2/da3/da + mkdir -p ${FS}db1/db2/db3 + mv da1/da2/da3/da ${FS}db1/db2/db3/db + ckok $? + ckd da ${FS}db1/db2/db3/db + cknt da1/da2/da3/da + end + + begin 'Move directory to directory' + mkd da1/da2/da3/da + mkdir -p ${FS}db1/db2/db3 + mv da1/da2/da3/da ${FS}db1/db2/db3 + ckok $? + ckd da ${FS}db1/db2/db3/da + cknt da1/da2/da3/da + end + + begin 'Move directory to existing empty directory' + mkd da1/da2/da3/da + mkdir -p ${FS}db1/db2/db3/da + mv da1/da2/da3/da ${FS}db1/db2/db3 + ckok $? + ckd da ${FS}db1/db2/db3/da + cknt da1/da2/da3/da + end + + begin 'Move directory to existing non-empty directory' + mkd da1/da2/da3/da + mkdir -p ${FS}db1/db2/db3/da/full + # Should fail (per the semantics of rename(2)) + mv da1/da2/da3/da ${FS}db1/db2/db3 2>/dev/null + ckfail $? + ckd da da1/da2/da3/da + end + + begin 'Move directory to existing file' + mkd da1/da2/da3/da + mkdir -p ${FS}db1/db2/db3 + :> ${FS}db1/db2/db3/da + # Should fail per POSIX step 3b: + # Destination path is a file not of type directory + # and source_file is a file of type directory + mv da1/da2/da3/da ${FS}db1/db2/db3/da 2>/dev/null + ckfail $? + ckd da da1/da2/da3/da + end + + begin 'Rename fifo' + mkp fa + mv fa ${FS}fb + ckok $? + ckp fa ${FS}fb + cknt fa + end + + begin 'Move fifos into directory' + mkp fa + mkp fb + mkdir -p ${FS}1/2/3 + mv fa fb ${FS}1/2/3 + ckok $? + ckp fa ${FS}1/2/3/fa + ckp fb ${FS}1/2/3/fb + cknt fa + cknt fb + end + + begin 'Move fifo from directory to fifo' + mkdir -p 1/2/3 + mkp 1/2/3/fa + mv 1/2/3/fa ${FS}fb + ckok $? + ckp fa ${FS}fb + cknt 1/2/3/fa + end + + begin 'Move fifo from directory to directory' + mkdir -p da1/da2/da3 + mkdir -p ${FS}db1/db2/db3 + mkp da1/da2/da3/fa + mv da1/da2/da3/fa ${FS}db1/db2/db3/fb + ckok $? + ckp fa ${FS}db1/db2/db3/fb + cknt da1/da2/da3/fa + end +done |