Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions testsuite/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Test suites for openrsync.

All tests are for the kyua framework.

run-orig/ contains slightly changed tests from GNU rsync. See the
README.md in there.

src/ contains a new test suite. See the README.md in there.

## src/ instructions

Edit conf.sh to your liking.

Run like this:

`./generate-kyua && kyua test`

You can also run the individual test cases like this:
`./test5_symlink-kills-dir.test`

Requirements:
- pkg misc/cstream is required for some modes of testing.
- perl5 for some one-liners

Makefile has some useful functions you might want to check out.

7 changes: 7 additions & 0 deletions testsuite/src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dir1
dir2
dir3
tests_kyua.sh
Kyuafile
find1
find2
5 changes: 5 additions & 0 deletions testsuite/src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
all:

run:
./generate-kyua
-kyua test
1 change: 1 addition & 0 deletions testsuite/src/conf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rsync=${rsync-openrsync}
68 changes: 68 additions & 0 deletions testsuite/src/generate-kyua
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#! /bin/sh

test_counter=10000

doit ()
{
local name
local names=""

echo '#! /usr/bin/env atf-sh'
echo

# This loop iterates over all the *.test files and
# generates a single Kuya file with multiple tests.
# Note that it includes the literal block in the
# loop.

for file in test[0-9]*.test ; do
test_counter=$(($test_counter + 1))
# name needs to conform to sh function identifier rules
name=`echo $file | sed 's/[- ]/_/g'`
name=${name%%.*}
names="$names $name"

echo atf_test_case $name

cat << EOF

${name}_head()
{
atf_set "descr" "${file%.test}"
}

${name}_body()
{
export tstdir=`pwd`
if "`pwd`/$file" ; then
atf_pass
else
atf_fail "$file failed"
fi
}


EOF
done

echo 'atf_init_test_cases()'
echo '{'
for name in $names ; do
echo " atf_add_test_case $name"
done
echo '}'

}

doit "$@" > tests_kyua.tmp && mv tests_kyua.tmp tests_kyua.sh
chmod a+x tests_kyua.sh

cat << EOF > Kyuafile
syntax(2)

-- The name of the test suite must be defined.
test_suite('openrsynctests')

-- This specifies the test programs
atf_test_program{name='tests_kyua.sh'}
EOF
90 changes: 90 additions & 0 deletions testsuite/src/lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#! /bin/sh

set -u
set -e

# Library of functions.
# Intended to be sourced by scripts (or interactive shells if you want).

genfile_stdout_16m ()
{
seq -f%015g 1048576
}
genfile_stdout_1m ()
{
seq -f%015g 65536
}
genfile ()
{
#touch "$1"
genfile_stdout_1m > "$1"
}

# makes a directory path and optionally a file in it.
# if you want the last element to be a directory, add / at the end
mkdirfile ()
{
case "$1" in
'') error that cannot work;;
*/) mkdir -p "$1";;
*/*) mkdir -p "${1%/*}"; genfile "$1";;
*) genfile "$1";;
esac
}

mkdirsymlink ()
{
(
mkdir -p "$1"
cd "$1"
ln -sf "$2" "$3"
)
}

# make a first interesting tree
generate_tree_1 ()
{
mkdirfile foo/bar/baz/one.txt
mkdirfile foo/bar/baz/one2.txt
mkdirfile 'foo/bar/baz/ two.txt'
mkdirfile 'foo/bar/baz/two 2.txt'
mkdirfile 'foo/bar/baz/two3.txt '
mkdirsymlink foo/baz/ ../bar/baz/one.txt three.txt
mkdirfile one/two/three/four.txt
mkdirfile foo/five/one/two/five/blah.txt
mkdirfile foo/one/two/five/blah.txt
}

# a frontend for find
# first argument is a dir to chdir to
findme ()
{
if [ $# -lt 2 ] ; then
echo usage: different 1>&2
return 1
fi
(
cd "$1" ; shift
# Cut out the inode number and blocks used.
# Maybe later also cut out size in bytes for directories.
find "$@" -ls | sed 's/^ *[0-9]* *[0-9]* *//' | sort
)
}

# compare two trees. This will later be modular to pick between:
# - diff
# - find . -print0 | sort --zero-terminated | xargs -0 tar fc foo.tar
# - mtree
compare_trees ()
{
if [ $# -ne 2 ] ; then
echo usage: different 1>&2
return 1
fi
# files_and_permissions
findme "$1" . > find1
findme "$2" . > find2
diff -u find[12]
# file contents
diff -ru "$1" "$2"
}
18 changes: 18 additions & 0 deletions testsuite/src/test1_minusa.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#! /bin/sh

. ${tstdir-.}/lib.sh
. ${tstdir-.}/conf.sh

rm -rf dir1 dir2 dir3
# make the copy-from-here tree
mkdir dir1
cd dir1
generate_tree_1
# make the tree we want to compare to
mkdir ../dir2
cd ../dir2
generate_tree_1

cd ..
$rsync -a dir1/ dir3
compare_trees dir2 dir3