From 7852c2e999d15262aef744eeef4f52ed4cdc4334 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Tue, 17 Dec 2013 17:31:07 +0000 Subject: Add newlines to increase readability --- yarns/create-deploy.yarn | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/yarns/create-deploy.yarn b/yarns/create-deploy.yarn index f63c6ef..6b15eef 100644 --- a/yarns/create-deploy.yarn +++ b/yarns/create-deploy.yarn @@ -5,12 +5,14 @@ The following scenarios test tbdiff-deploy's ability to correctly transform the content of a target directory, to that of a source directory, given an appropriate binary delta created by tbdiff-create. + Changing of a file's contents ----------------------------- The simple tests that follow check that file contents is as expected; if the contents of the given files are different, the test will fail. + SCENARIO Changing the contents of a regular file works GIVEN a directory called 'A_dir' AND a regular file called 'foo_file' containing '1' in directory 'A_dir' @@ -20,6 +22,7 @@ contents of the given files are different, the test will fail. AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' THEN the files 'A_dir/foo_file' and 'B_dir/foo_file' have the same contents + SCENARIO Changing the contents of a directory works GIVEN a directory called 'A_dir' AND a directory called '1_dir' in directory 'A_dir' @@ -31,12 +34,14 @@ contents of the given files are different, the test will fail. AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' THEN the directories 'A_dir/1_dir' and 'B_dir/1_dir' have the same contents + Changing of a file's ownership ------------------------------ Trebuchet also takes into account POSIX metadata such as ownership, these scenarios are written to test that functionality. + SCENARIO Changing the group that owns a regular file works GIVEN a directory called 'A_dir' AND a regular file called 'foo_file' in directory 'A_dir' @@ -47,6 +52,7 @@ scenarios are written to test that functionality. AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' THEN the file 'A_dir/foo_file' is owned by the group '893' + SCENARIO Changing the group that owns a named pipe works GIVEN a directory called 'A_dir' AND a named pipe called 'foo_pipe' in directory 'A_dir' @@ -57,6 +63,7 @@ scenarios are written to test that functionality. AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' THEN the named pipe 'A_dir/foo_pipe' is owned by the group '594' + SCENARIO Changing the group that owns a symbolic link works GIVEN a directory called 'A_dir' AND a regular file called 'foo_file' in directory 'A_dir' @@ -69,6 +76,7 @@ scenarios are written to test that functionality. AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' THEN the symbolic link 'A_dir/link_to_foo_file' is owned by the group '608' + SCENARIO Changing the group that owns a directory works GIVEN a directory called 'A_dir' AND a directory called '1_dir' in directory 'A_dir' @@ -79,12 +87,14 @@ scenarios are written to test that functionality. AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' THEN the directory 'A_dir/1_dir' is owned by the group '675' + Changing of a file's permissions -------------------------------- These scenarios test that file permissions are correctly changed upon the deployment of a binary delta. + SCENARIO Changing the permissions of a regular file works GIVEN a directory called 'A_dir' AND a regular file called 'foo_file' in directory 'A_dir' @@ -95,6 +105,7 @@ deployment of a binary delta. AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' THEN the file 'A_dir/foo_file' has the permissions '-rw-rw-rw-' + SCENARIO Changing the permissions of a named pipe works GIVEN a directory called 'A_dir' AND a named pipe called 'foo_pipe' in directory 'A_dir' @@ -105,6 +116,7 @@ deployment of a binary delta. AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' THEN the named pipe 'A_dir/foo_pipe' has the permissions 'prw-rw-r--' + SCENARIO Changing the permissions of a directory works GIVEN a directory called 'A_dir' AND a directory called '1_dir' in directory 'A_dir' @@ -115,12 +127,14 @@ deployment of a binary delta. AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' THEN the directory 'A_dir/1_dir' has the permissions 'drwx---rwx' + Adding and removing of files ---------------------------- The following scenarios check that the deployment of a binary delta successfully removes and creates the appropriate files. + SCENARIO Adding and removing of regular files works GIVEN a directory called 'A_dir' AND a regular file called 'minus_file' in directory 'A_dir' @@ -131,6 +145,7 @@ successfully removes and creates the appropriate files. THEN the file 'A_dir/minus_file' no longer exists AND the directory 'A_dir' contains the regular file 'plus_file' + SCENARIO Adding and removing of named pipes works GIVEN a directory called 'A_dir' AND a named pipe called 'minus_pipe' in directory 'A_dir' @@ -141,6 +156,7 @@ successfully removes and creates the appropriate files. THEN the named pipe 'A_dir/minus_pipe' no longer exists AND the directory 'A_dir' contains the named pipe 'plus_pipe' + SCENARIO Adding and removing of symbolic links works GIVEN a directory called 'A_dir' AND a regular file called 'minus_file' in directory 'A_dir' @@ -153,6 +169,7 @@ successfully removes and creates the appropriate files. THEN the symbolic link 'A_dir/link_to_minus_file' no longer exists AND the directory 'A_dir' contains the symbolic link 'link_to_plus_file' + SCENARIO Adding and removing of directories works GIVEN a directory called 'A_dir' AND a directory called 'minus_dir' in directory 'A_dir' @@ -163,6 +180,7 @@ successfully removes and creates the appropriate files. THEN the directory 'A_dir/minus_dir' no longer exists AND the directory 'A_dir' contains the directory 'plus_dir' + SCENARIO Adding and removing of character devices works GIVEN a directory called 'A_dir' AND a character device called 'minus_chardev' with major number '1' and minor number '3' in directory 'A_dir' @@ -173,6 +191,7 @@ successfully removes and creates the appropriate files. THEN the character device 'A_dir/minus_chardev' no longer exists AND the directory 'A_dir' contains the character device 'plus_chardev' + SCENARIO Adding and removing of block devices works GIVEN a directory called 'A_dir' AND a block device called 'minus_blockdev' with major number '1' and minor number '3' in directory 'A_dir' @@ -183,12 +202,14 @@ successfully removes and creates the appropriate files. THEN the block device 'A_dir/minus_blockdev' no longer exists AND the directory 'A_dir' contains the block device 'plus_blockdev' + Changing modification time of a file ------------------------------------ In the following scenarios we check that modification times are correctly changed, if modification times are not identical, the test fails. + SCENARIO Changing the modification time of a regular file works GIVEN a directory called 'A_dir' AND a regular file called 'foo_file' containing '1' in directory 'A_dir' @@ -200,6 +221,7 @@ changed, if modification times are not identical, the test fails. AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' THEN the files 'A_dir/foo_file' and 'B_dir/foo_file' have the same modification time + SCENARIO Changing the modification time of a named pipe works GIVEN a directory called 'A_dir' AND a named pipe called 'foo_pipe' in directory 'A_dir' @@ -211,6 +233,7 @@ changed, if modification times are not identical, the test fails. AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' THEN the named pipes 'A_dir/foo_pipe' and 'B_dir/foo_pipe' have the same modification time + SCENARIO Changing the modification time of a symbolic link works GIVEN a directory called 'A_dir' AND a regular file called 'foo_file' in directory 'A_dir' @@ -224,6 +247,7 @@ changed, if modification times are not identical, the test fails. AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' THEN the symbolic links 'A_dir/link_to_foo_file' and 'B_dir/link_to_foo_file' have the same modification time + SCENARIO Changing the modification time of a directory works GIVEN a directory called 'A_dir' AND a directory called '1_dir' in directory 'A_dir' @@ -235,11 +259,13 @@ changed, if modification times are not identical, the test fails. AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' THEN the directories 'A_dir/1_dir' and 'B_dir/1_dir' have the same modification time + Changing what a symbolic link refers to --------------------------------------- Here we check that referenced files of symbolic links are correctly transformed. + SCENARIO Changing what a symbolic link refers to works GIVEN a directory called 'A_dir' AND a regular file called 'foo_file' in directory 'A_dir' @@ -251,12 +277,14 @@ Here we check that referenced files of symbolic links are correctly transformed. AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' THEN the symbolic links 'A_dir/link_to_foo_file' and 'B_dir/link_to_foo_file' refer to the same thing + Setting special file permissions for directories ------------------------------------------------ This scenario checks that the sticky bit of a directory has been changed appropriately upon the deployment of a binary delta. + SCENARIO Setting the sticky bit of a directory works GIVEN a directory called 'A_dir' AND a directory called '1_dir' in directory 'A_dir' @@ -267,8 +295,10 @@ appropriately upon the deployment of a binary delta. AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' THEN the directory 'A_dir/1_dir' has its sticky bit set + And this scenario checks that the setgid bit of a directory is set accordingly. + SCENARIO Setting the setgid bit of a directory works GIVEN a directory called 'A_dir' AND a directory called '1_dir' in directory 'A_dir' @@ -279,12 +309,14 @@ And this scenario checks that the setgid bit of a directory is set accordingly. AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' THEN the directory 'A_dir/1_dir' has its setgid bit set + Changing the device numbers of special files -------------------------------------------- These scenarios check that the minor and major device numbers of special files are appropriately changed when a patch has been generated and deployed. + SCENARIO Changing a character special file's device numbers works GIVEN a directory called 'A_dir' AND a character device called 'foo_chardev' with major number '3' and minor number '9' in directory 'A_dir' @@ -294,6 +326,7 @@ are appropriately changed when a patch has been generated and deployed. AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' THEN the character devices 'A_dir/foo_chardev' and 'B_dir/foo_chardev' have the same device numbers + SCENARIO Changing a block special file's device numbers works GIVEN a directory called 'A_dir' AND a block device called 'foo_blockdev' with major number '2' and minor number '7' in directory 'A_dir' @@ -303,6 +336,7 @@ are appropriately changed when a patch has been generated and deployed. AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' THEN the block devices 'A_dir/foo_blockdev' and 'B_dir/foo_blockdev' have the same device numbers + Changing, adding and removing of sockets ---------------------------------------- @@ -310,6 +344,7 @@ Sockets can only be moved, linked or removed by the file system, creation is only performed by the program that acts as the server, tbdiff won't be doing that so the only sensible operation is removal. + SCENARIO Removing of a socket works GIVEN a directory called 'A_dir' AND a socket called 'minus_socket' in directory 'A_dir' @@ -318,6 +353,7 @@ that so the only sensible operation is removal. AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' THEN the socket 'A_dir/minus_socket' no longer exists + SCENARIO Creation of a socket doesn't work GIVEN a directory called 'A_dir' AND a directory called 'B_dir' @@ -325,6 +361,7 @@ that so the only sensible operation is removal. WHEN tbdiff-create attempts to create a binary delta between directories 'A_dir' and 'B_dir', called 'AB.tbdiff' THEN stderr contains "tbdiff-create cannot create sockets" + SCENARIO Changing a socket doesn't work GIVEN a directory called 'A_dir' AND a socket called 'foo_socket' in directory 'A_dir' @@ -339,6 +376,7 @@ IMPLEMENTS Implementations for the creating and deploying of binary deltas --------------------------------------------------------------- + IMPLEMENTS GIVEN a regular file called '([^']+)' containing '([^']+)'(?: in directory '([^']+)')? [ -n "$MATCH_3" ] && mkdir -p "$DATADIR/$MATCH_3" echo "$MATCH_2" > "$DATADIR/$MATCH_3/$MATCH_1" @@ -347,31 +385,39 @@ Implementations for the creating and deploying of binary deltas [ -n "$MATCH_2" ] && mkdir -p "$DATADIR/$MATCH_2" touch "$DATADIR/$MATCH_2/$MATCH_1" + IMPLEMENTS GIVEN the (?:file|directory|named pipe|symbolic link) '([^']+)' is owned by the group '([^']+)' chgrp -h "$MATCH_2" "$DATADIR/$MATCH_1" + IMPLEMENTS GIVEN the (?:file|directory|named pipe) '([^']+)' has its permissions set to '([^']+)' chmod "$MATCH_2" "$DATADIR/$MATCH_1" + IMPLEMENTS GIVEN the (?:file|directory|named pipe|symbolic link) '([^']+)' has its modification time set to '([^']+)' "$SRCDIR/symtime" "$DATADIR/$MATCH_1" "$MATCH_2" + IMPLEMENTS GIVEN a named pipe called '([^']+)'(?: in directory '([^']+)')? [ -n "$MATCH_2" ] && mkdir -p "$DATADIR/$MATCH_2" mkfifo "$DATADIR/$MATCH_2/$MATCH_1" + IMPLEMENTS GIVEN a symbolic link called '([^']+)' referring to '([^']+)'(?: in directory '([^']+)')? [ -n "$MATCH_3" ] && mkdir -p "$DATADIR/$MATCH_3" ln -s "$DATADIR/$MATCH_2" "$DATADIR/$MATCH_3/$MATCH_1" + IMPLEMENTS GIVEN a directory called '([^']+)'(?: in directory '([^']+)')? [ -n "$MATCH_2" ] && mkdir -p "$DATADIR/$MATCH_2" mkdir "$DATADIR/$MATCH_2/$MATCH_1" + IMPLEMENTS GIVEN a (character|block) device called '([^']+)' with major number '([0-9]+)' and minor number '([0-9]+)'(?: in directory '([^']+)')? [ -n "$MATCH_5" ] && mkdir -p "$DATADIR/$MATCH_5" mknod "$DATADIR/$MATCH_5/$MATCH_2" "$(echo "$MATCH_1" | head -c 1)" "$MATCH_3" "$MATCH_4" + IMPLEMENTS GIVEN a socket called '([^']+)'(?: in directory '([^']+)')? [ -n "$MATCH_2" ] && mkdir -p "$DATADIR/$MATCH_2" "$SRCDIR/sockbind" "$DATADIR/$MATCH_2/$MATCH_1" @@ -383,42 +429,55 @@ Implementations for the creating and deploying of binary deltas set +e; "$@" 2> "$DATADIR/stderr"; set -e fi + IMPLEMENTS WHEN tbdiff-deploy applies the delta '([^']+)' to '([^']+)' cd "$DATADIR/$MATCH_2" "$SRCDIR/tbdiff-deploy/tbdiff-deploy" "$DATADIR/$MATCH_1" + IMPLEMENTS THEN the (?:files|directories) '([^']+)' and '([^']+)' have the same contents diff "$DATADIR/$MATCH_1" "$DATADIR/$MATCH_2" + IMPLEMENTS THEN the (?:file|directory|named pipe|symbolic link) '([^']+)' is owned by the group '([^']+)' test "$(stat -c %g "$DATADIR/$MATCH_1")" = "$MATCH_2" + IMPLEMENTS THEN the (?:file|directory|named pipe) '([^']+)' has the permissions '([^']+)' test "$(stat -c %A "$DATADIR/$MATCH_1")" = "$MATCH_2" + IMPLEMENTS THEN the (?:file|directory|named pipe|symbolic link|(?:character|block) device|socket) '([^']+)' no longer exists test ! -e "$DATADIR/$MATCH_1" + IMPLEMENTS THEN the (?:files|directories|named pipes|symbolic links) '([^']+)' and '([^']+)' have the same modification time test "$(stat -c %y "$DATADIR/$MATCH_1")" = "$(stat -c %y "$DATADIR/$MATCH_2")" + IMPLEMENTS THEN the directory '([^']+)' contains the symbolic link '([^']+)' test -h "$DATADIR/$MATCH_1/$MATCH_2" + IMPLEMENTS THEN the symbolic links '([^']+)' and '([^']+)' refer to the same thing test "$(readlink "$DATADIR/$MATCH_1")" = "$(readlink "$DATADIR/$MATCH_2")" + IMPLEMENTS THEN the directory '([^']+)' has its sticky bit set test -k "$DATADIR/$MATCH_1" + IMPLEMENTS THEN the directory '([^']+)' has its setgid bit set test -g "$DATADIR/$MATCH_1" + IMPLEMENTS THEN the directory '([^']+)' contains the ((?:character|block) device|named pipe|directory|regular file) '([^']+)' test -"$(echo "$MATCH_2" | sed -r 's/(named|regular) //' | head -c 1)" "$DATADIR/$MATCH_1/$MATCH_3" + IMPLEMENTS THEN the (?:block|character) devices '([^']+)' and '([^']+)' have the same device numbers test "$(stat -c '%t %T' "$DATADIR/$MATCH_1")" = "$(stat -c '%t %T' "$DATADIR/$MATCH_2")" + IMPLEMENTS THEN (\S+) contains "([^"]+)" grep "$MATCH_2" "$DATADIR/$MATCH_1" -- cgit v1.2.1 From 1d7bbf4e3a75a6be688090c9b06e11fca849cdce Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Tue, 17 Dec 2013 17:31:46 +0000 Subject: Scenarios testing extended attributes on file systems that support them --- yarns/create-deploy.yarn | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ yarns/tbdiff.shell-lib | 10 +++++++ 2 files changed, 83 insertions(+) diff --git a/yarns/create-deploy.yarn b/yarns/create-deploy.yarn index 6b15eef..1708e90 100644 --- a/yarns/create-deploy.yarn +++ b/yarns/create-deploy.yarn @@ -370,6 +370,57 @@ that so the only sensible operation is removal. WHEN tbdiff-create attempts to create a binary delta between directories 'A_dir' and 'B_dir', called 'AB.tbdiff' THEN stderr contains "tbdiff-create cannot create sockets" + +Changing, adding and removing of extended attributes +---------------------------------------------------- + +These scenarios test that, on a file system that supports them, extended +attributes are correctly set when a patch has been deployed. + + + SCENARIO Changing of a file's extended attributes works + ASSUMING DATADIR supports extended attributes + GIVEN a directory called 'A_dir' + AND a regular file called 'foo_file' in directory 'A_dir' + AND the file 'A_dir/foo_file' has the value of the extended attribute 'user.change' set to 'false' + AND a directory called 'B_dir' + AND a regular file called 'foo_file' in directory 'B_dir' + AND the file 'B_dir/foo_file' has the value of the extended attribute 'user.change' set to 'true' + WHEN tbdiff-create creates a binary delta between directories 'A_dir' and 'B_dir', called 'AB.tbdiff' + AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' + THEN the files 'A_dir/foo_file' and 'B_dir/foo_file' have the same extended attributes + + + SCENARIO Adding of a file's extended attributes works + ASSUMING DATADIR supports extended attributes + GIVEN a directory called 'A_dir' + AND a regular file called 'foo_file' in directory 'A_dir' + AND a directory called 'B_dir' + AND a regular file called 'foo_file' in directory 'B_dir' + AND the file 'B_dir/foo_file' has the value of the extended attribute 'user.plus' set to 'true' + WHEN tbdiff-create creates a binary delta between directories 'A_dir' and 'B_dir', called 'AB.tbdiff' + AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' + THEN the files 'A_dir/foo_file' and 'B_dir/foo_file' have the same extended attributes + + + SCENARIO Removing of a file's extended attributes works + +Currently, tbdiff doesn't remove extended attributes from a file if the target +of the diff has none, this is not intended behaviour. + + ASSUMING FIXME has been done + + ASSUMING DATADIR supports extended attributes + GIVEN a directory called 'A_dir' + AND a regular file called 'foo_file' in directory 'A_dir' + AND the file 'A_dir/foo_file' has the value of the extended attribute 'user.minus' set to 'true' + AND a directory called 'B_dir' + AND a regular file called 'foo_file' in directory 'B_dir' + WHEN tbdiff-create creates a binary delta between directories 'A_dir' and 'B_dir', called 'AB.tbdiff' + AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' + THEN the files 'A_dir/foo_file' and 'B_dir/foo_file' have the same extended attributes + + IMPLEMENTS ========== @@ -381,6 +432,19 @@ Implementations for the creating and deploying of binary deltas [ -n "$MATCH_3" ] && mkdir -p "$DATADIR/$MATCH_3" echo "$MATCH_2" > "$DATADIR/$MATCH_3/$MATCH_1" + + IMPLEMENTS ASSUMING DATADIR supports extended attributes + { + set +e + setfattr -x user.test "$DATADIR" 2> "$DATADIR/stderr" + } + grep -Fq "No such attribute" "$DATADIR/stderr" + + + IMPLEMENTS ASSUMING FIXME has been done + false + + IMPLEMENTS GIVEN a regular file called '([^']+)'(?: in directory '([^']+)')? [ -n "$MATCH_2" ] && mkdir -p "$DATADIR/$MATCH_2" touch "$DATADIR/$MATCH_2/$MATCH_1" @@ -422,6 +486,11 @@ Implementations for the creating and deploying of binary deltas [ -n "$MATCH_2" ] && mkdir -p "$DATADIR/$MATCH_2" "$SRCDIR/sockbind" "$DATADIR/$MATCH_2/$MATCH_1" + + IMPLEMENTS GIVEN the file '([^']+)' has the value of the extended attribute '([^']+)' set to '([^']+)' + setfattr -n "$MATCH_2" -v "$MATCH_3" "$DATADIR/$MATCH_1" + + IMPLEMENTS WHEN tbdiff-create (attempts to create|creates) a binary delta between directories '([^']+)' and '([^']+)', called '([^']+)' set "$SRCDIR/tbdiff-create/tbdiff-create" "$DATADIR/$MATCH_4" "$DATADIR/$MATCH_2" "$DATADIR/$MATCH_3" if [ $MATCH_1 == creates ]; then "$@" @@ -481,3 +550,7 @@ Implementations for the creating and deploying of binary deltas IMPLEMENTS THEN (\S+) contains "([^"]+)" grep "$MATCH_2" "$DATADIR/$MATCH_1" + + + IMPLEMENTS THEN the files '([^']+)' and '([^']+)' have the same extended attributes + compare_xattrs "$DATADIR/$MATCH_1" "$DATADIR/$MATCH_2" diff --git a/yarns/tbdiff.shell-lib b/yarns/tbdiff.shell-lib index 658efe6..33d9954 100644 --- a/yarns/tbdiff.shell-lib +++ b/yarns/tbdiff.shell-lib @@ -12,3 +12,13 @@ export SRCDIR="$(pwd)" fi } + +# Test that the extended attributes of two files are the same by comparing the +# output of `getfattr -d` on each file, which has been piped to `tail -n +2` in +# order to skip the first line of output, being the file name. + +compare_xattrs() +{ + test \ + "$(getfattr -d "$1" | tail -n +2)" = "$(getfattr -d "$2" | tail -n +2)" +} -- cgit v1.2.1 From 646dcf88fb2a79a9567f3fadf9711e2e6bc58176 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Wed, 18 Dec 2013 17:41:24 +0000 Subject: Remove old tests and any code specific to those tests --- tests/08_chardev_diff.sh | 29 ------ tests/09_chardev_add_remove.sh | 30 ------ tests/10_blockdev_diff.sh | 29 ------ tests/11_blockdev_add_remove.sh | 30 ------ tests/12_socket_remove.sh | 42 --------- tests/13_socket_add.sh | 38 -------- tests/14_socket_diff.sh | 44 --------- tests/15_xattr_add.sh | 37 -------- tests/dir_add_remove.sh.disabled | 41 -------- tests/dir_diff.sh.disabled | 40 -------- tests/fifo_add_remove.sh.disabled | 32 ------- tests/fifo_diff.sh.disabled | 32 ------- tests/regular_file_add_remove.sh.disabled | 32 ------- tests/regular_file_diff.sh.disabled | 40 -------- tests/run_tests.sh | 18 ---- tests/sockbind.c | 70 -------------- tests/symlink_add_remove.sh.disabled | 48 ---------- tests/symlink_diff.sh.disabled | 57 ----------- tests/test_lib.sh | 152 +----------------------------- 19 files changed, 2 insertions(+), 839 deletions(-) delete mode 100755 tests/08_chardev_diff.sh delete mode 100755 tests/09_chardev_add_remove.sh delete mode 100755 tests/10_blockdev_diff.sh delete mode 100755 tests/11_blockdev_add_remove.sh delete mode 100755 tests/12_socket_remove.sh delete mode 100755 tests/13_socket_add.sh delete mode 100755 tests/14_socket_diff.sh delete mode 100755 tests/15_xattr_add.sh delete mode 100755 tests/dir_add_remove.sh.disabled delete mode 100755 tests/dir_diff.sh.disabled delete mode 100755 tests/fifo_add_remove.sh.disabled delete mode 100755 tests/fifo_diff.sh.disabled delete mode 100755 tests/regular_file_add_remove.sh.disabled delete mode 100755 tests/regular_file_diff.sh.disabled delete mode 100644 tests/sockbind.c delete mode 100755 tests/symlink_add_remove.sh.disabled delete mode 100755 tests/symlink_diff.sh.disabled diff --git a/tests/08_chardev_diff.sh b/tests/08_chardev_diff.sh deleted file mode 100755 index c0cc72c..0000000 --- a/tests/08_chardev_diff.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -TEST_ID="08" -TEST_NAME="Character device difference" - -CREATE=`pwd`/$1 -DEPLOY=`pwd`/$2 -TEST_TOOLS=$3 - -. ./test_lib.sh - -############# Test specific code ############ - -setup_origin () { - mknod $ORIGIN/tochange c `stat /dev/null -c '%t %T'` -} - -setup_target () { - mknod $TARGET/tochange c `stat /dev/full -c '%t %T'` -} - -check_results () { - test -c $ORIGIN/tochange && - test "`stat -c '%t %T' $ORIGIN/tochange`" = \ - "`stat -c '%t %T' $TARGET/tochange`" -} - -############################################# -main $@ diff --git a/tests/09_chardev_add_remove.sh b/tests/09_chardev_add_remove.sh deleted file mode 100755 index edd7c93..0000000 --- a/tests/09_chardev_add_remove.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -TEST_ID="09" -TEST_NAME="Character device add and remove" - -CREATE=`pwd`/$1 -DEPLOY=`pwd`/$2 -TEST_TOOLS=$3 - -. ./test_lib.sh - -############# Test specific code ############ - -setup_block_major_minor="`stat /dev/null -c '%t %T'`" - -setup_origin () { - mknod $ORIGIN/toremove c $setup_block_major_minor -} - -setup_target () { - mknod $TARGET/toadd c $setup_block_major_minor -} - -check_results () { - test -c $ORIGIN/toadd && - test ! -c $ORIGIN/toremove -} - -############################################# -main $@ diff --git a/tests/10_blockdev_diff.sh b/tests/10_blockdev_diff.sh deleted file mode 100755 index ebb529a..0000000 --- a/tests/10_blockdev_diff.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -TEST_ID="10" -TEST_NAME="Block device difference" - -CREATE=`pwd`/$1 -DEPLOY=`pwd`/$2 -TEST_TOOLS=$3 - -. ./test_lib.sh - -############# Test specific code ############ - -setup_origin () { - mknod $ORIGIN/tochange b `stat /dev/null -c '%t %T'` -} - -setup_target () { - mknod $TARGET/tochange b `stat /dev/full -c '%t %T'` -} - -check_results () { - test -b $ORIGIN/tochange && - test "`stat -c '%t %T' $ORIGIN/tochange`" = \ - "`stat -c '%t %T' $TARGET/tochange`" -} - -############################################# -main $@ diff --git a/tests/11_blockdev_add_remove.sh b/tests/11_blockdev_add_remove.sh deleted file mode 100755 index 3cc4ecb..0000000 --- a/tests/11_blockdev_add_remove.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -TEST_ID="11" -TEST_NAME="Block device add and remove" - -CREATE=`pwd`/$1 -DEPLOY=`pwd`/$2 -TEST_TOOLS=$3 - -. ./test_lib.sh - -############# Test specific code ############ - -setup_block_major_minor="`stat /dev/null -c '%t %T'`" - -setup_origin () { - mknod $ORIGIN/toremove b $setup_block_major_minor -} - -setup_target () { - mknod $TARGET/toadd b $setup_block_major_minor -} - -check_results () { - test -b $ORIGIN/toadd && - test ! -b $ORIGIN/toremove -} - -############################################# -main $@ diff --git a/tests/12_socket_remove.sh b/tests/12_socket_remove.sh deleted file mode 100755 index d594b2a..0000000 --- a/tests/12_socket_remove.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -TEST_ID="12" -TEST_NAME="Socket device removal" - -CREATE=`pwd`/$1 -DEPLOY=`pwd`/$2 -TEST_TOOLS=$3 - -. ./test_lib.sh - -############# Test specific code ############ -# sockets can only be moved, linked or removed by the file system -# creation is only performed by the program that acts as the server -# tbdiff won't be doing that so the only sensible operation is removal -SOCKBIND=`mktemp` -setup_origin () { - # sockbind creates a socket then writes any data written to it to stdout - # have to fork it because it will never stop, have to wait for it to - # make the socket - gcc sockbind.c -o $SOCKBIND 2>/dev/null >/dev/null - $SOCKBIND "$ORIGIN/toremove" & - SOCKBINDPID=$! - until test -S "$ORIGIN/toremove"; do :; done - kill $SOCKBINDPID && wait $SOCKBINDPID 2>/dev/null - rm -f $SOCKBIND -} - -setup_target () { - true -} - -create_test_return () { - test $1 = 0 -} - -check_results () { - test ! -S "$ORIGIN/toremove" -} - -############################################# -main $@ diff --git a/tests/13_socket_add.sh b/tests/13_socket_add.sh deleted file mode 100755 index b8c84d6..0000000 --- a/tests/13_socket_add.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -TEST_ID="13" -TEST_NAME="Socket device addition" - -CREATE=`pwd`/$1 -DEPLOY=`pwd`/$2 -TEST_TOOLS=$3 - -. ./test_lib.sh - -############# Test specific code ############ -# sockets can't be added sensibly, test that it hasn't been -SOCKBIND=`mktemp` -setup_origin () { - true -} - -setup_target () { - gcc sockbind.c -o $SOCKBIND 2>/dev/null >/dev/null - $SOCKBIND "$TARGET/toadd" & - SOCKBINDPID=$! - until test -S "$TARGET/toadd"; do :; done - kill $SOCKBINDPID && wait $SOCKBINDPID 2>/dev/null - rm -f $SOCKBIND -} - -#tbdiff-create should fail when it would have to add a socket -create_test_return () { - test "$1" != "0" -} - -check_results () { - false #test should never reach this -} - -############################################# -main $@ diff --git a/tests/14_socket_diff.sh b/tests/14_socket_diff.sh deleted file mode 100755 index d7d393f..0000000 --- a/tests/14_socket_diff.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -TEST_ID="14" -TEST_NAME="Socket device difference" - -CREATE=`pwd`/$1 -DEPLOY=`pwd`/$2 -TEST_TOOLS=$3 - -. ./test_lib.sh - -############# Test specific code ############ -# sockets can't be changed sensibly, test that it hasn't been - -SOCKBIND=`mktemp` -setup_origin () { - gcc sockbind.c -o $SOCKBIND 2>/dev/null >/dev/null - $SOCKBIND "$ORIGIN/tochange" & - SOCKBINDPID=$! - until test -S "$ORIGIN/tochange"; do :; done - kill $SOCKBINDPID - wait $SOCKBINDPID 2>/dev/null || true #wait returns false -} - -setup_target () { - $SOCKBIND "$TARGET/tochange" & - SOCKBINDPID=$! - until test -S "$TARGET/tochange"; do :; done - kill $SOCKBINDPID && - wait $SOCKBINDPID 2>/dev/null #surpress terminated output - rm -f $SOCKBIND -} - -#tbdiff-create should fail to make a patch if it would have to change a socket -create_test_return () { - test "$1" != 0 -} - -check_results () { - false #test should never reach this -} - -############################################# -main $@ diff --git a/tests/15_xattr_add.sh b/tests/15_xattr_add.sh deleted file mode 100755 index 1dcec4c..0000000 --- a/tests/15_xattr_add.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -TEST_ID="15" -TEST_NAME="Extended Attributes manipulation" - -CREATE=`pwd`/$1 -DEPLOY=`pwd`/$2 -TEST_TOOLS=$3 - -. ./test_lib.sh - -############# Test specific code ############ -if is_command getfattr && is_command setfattr; then :; else - echo Test requires commands: getfattr, setfattr, attr >&2 - exit 127 -fi - -setup_origin () { - touch $ORIGIN/file && - setfattr -n "user.preserve" -v "true" $ORIGIN/file && - setfattr -n "user.change" -v "false" $ORIGIN/file && - setfattr -n "user.remove" -v "false" $ORIGIN/file -} - -setup_target () { - touch $TARGET/file && - setfattr -n "user.preserve" -v "true" $TARGET/file && - setfattr -n "user.change" -v "true" $TARGET/file && - setfattr -n "user.add" -v "true" $TARGET/file -} - -check_results () { - check_xattrs $ORIGIN/file $TARGET/file -} - -############################################# -main $@ diff --git a/tests/dir_add_remove.sh.disabled b/tests/dir_add_remove.sh.disabled deleted file mode 100755 index 295b0f9..0000000 --- a/tests/dir_add_remove.sh.disabled +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -TEST_ID="07" -TEST_NAME="Directory add remove" - -CREATE=`pwd`/$1 -DEPLOY=`pwd`/$2 -TEST_TOOLS=$3 - -. ./test_lib.sh - -############# Test specific code ############ - -setup_origin () { - mkdir -p $ORIGIN/remove/1/2/3/4 -} - -setup_target () { - mkdir -p $TARGET/add/4/3/2/1 && - mkdir -p $TARGET/addsticky && - mkdir -p $TARGET/addsetgid && - chown -h :cdrom $TARGET/add && - chown -h :cdrom $TARGET/add/4/3/2/1 && - chmod +t $TARGET/addsticky && - chmod g+s $TARGET/addsetgid -} - -check_results () { - test -d $ORIGIN/add/4/3/2/1 && - test ! -d $ORIGIN/remove && - test -k $ORIGIN/addsticky && - test -g $ORIGIN/addsetgid && - check_same_mtime $ORIGIN/add $TARGET/add && - check_same_mode $ORIGIN/add $TARGET/add && - check_same_uidgid $ORIGIN/add $TARGET/add && - check_same_mode $ORIGIN/add $TARGET/add && - check_same_uidgid $ORIGIN/add/4/3/2/1 $TARGET/add/4/3/2/1 -} - -############################################# -main $@ diff --git a/tests/dir_diff.sh.disabled b/tests/dir_diff.sh.disabled deleted file mode 100755 index f9f56dd..0000000 --- a/tests/dir_diff.sh.disabled +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash - -TEST_ID="06" -TEST_NAME="Dir difference" - -CREATE=`pwd`/$1 -DEPLOY=`pwd`/$2 -TEST_TOOLS=$3 - -. ./test_lib.sh - -############# Test specific code ############ - -setup_origin () { - mkdir $ORIGIN/a $ORIGIN/sticky $ORIGIN/setgid -} - -setup_target () { - mkdir $TARGET/a $TARGET/sticky $TARGET/setgid && - echo "1" > $TARGET/a/1 && - chown -h :cdrom $TARGET/a && - chmod +t $TARGET/sticky && - chmod g+s $TARGET/setgid && - chmod 707 $TARGET/a -} - -check_results () { - test -d $ORIGIN/a && - test -f $ORIGIN/a/1 && - test -k $ORIGIN/sticky && - test -g $ORIGIN/setgid && - check_same_mode $ORIGIN/a $TARGET/a && \ - check_same_uidgid $ORIGIN/a $TARGET/a && \ - check_same_mode $ORIGIN/a/1 $TARGET/a/1 && - check_same_uidgid $ORIGIN/a/1 $TARGET/a/1 && - check_content $ORIGIN/a/1 "1" -} - -############################################# -main $@ diff --git a/tests/fifo_add_remove.sh.disabled b/tests/fifo_add_remove.sh.disabled deleted file mode 100755 index 9db6d12..0000000 --- a/tests/fifo_add_remove.sh.disabled +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -TEST_ID="03" -TEST_NAME="Named pipe (FIFO) add remove test" - -CREATE=`pwd`/$1 -DEPLOY=`pwd`/$2 -TEST_TOOLS=$3 - -. ./test_lib.sh - -############# Test specific code ############ - -setup_origin () { - mkfifo $ORIGIN/remove -} - -setup_target () { - mkfifo $TARGET/add && - chmod 707 $TARGET/add && - chown -h :cdrom $TARGET/add -} - -check_results () { - test -p $ORIGIN/add && \ - test ! -p $ORIGIN/remove && \ - check_same_mtime $ORIGIN/add $TARGET/add && \ - check_same_uidgid $ORIGIN/add $TARGET/add -} - -############################################# -main $@ diff --git a/tests/fifo_diff.sh.disabled b/tests/fifo_diff.sh.disabled deleted file mode 100755 index f256414..0000000 --- a/tests/fifo_diff.sh.disabled +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -TEST_ID="02" -TEST_NAME="Named pipe (FIFO) diff test" - -CREATE=`pwd`/$1 -DEPLOY=`pwd`/$2 -TEST_TOOLS=$3 - -. ./test_lib.sh - -############# Test specific code ############ - -setup_origin () { - mkfifo $ORIGIN/remove -} - -setup_target () { - mkfifo $TARGET/add && - chmod 707 $TARGET/add && - chown -h :cdrom $TARGET/add -} - -check_results () { - test -p $ORIGIN/add && \ - test ! -p $ORIGIN/remove && \ - check_same_mtime $ORIGIN/add $TARGET/add && \ - check_same_uidgid $ORIGIN/add $TARGET/add -} - -############################################# -main $@ diff --git a/tests/regular_file_add_remove.sh.disabled b/tests/regular_file_add_remove.sh.disabled deleted file mode 100755 index 66b5bc8..0000000 --- a/tests/regular_file_add_remove.sh.disabled +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -TEST_ID="01" -TEST_NAME="Regular file add remove" - -CREATE=`pwd`/$1 -DEPLOY=`pwd`/$2 -TEST_TOOLS=$3 - -. ./test_lib.sh - -############# Test specific code ############ - -setup_origin () { - touch $ORIGIN/remove -} - -setup_target () { - echo 1 > $TARGET/add && - chown -h :cdrom $TARGET/add -} - -check_results () { - test -f $ORIGIN/add && \ - test ! -f $ORIGIN/remove && \ - check_content $ORIGIN/add "1" && \ - check_same_mtime $ORIGIN/add $TARGET/add && \ - check_same_uidgid $ORIGIN/add $TARGET/add -} - -############################################# -main $@ diff --git a/tests/regular_file_diff.sh.disabled b/tests/regular_file_diff.sh.disabled deleted file mode 100755 index 0e12454..0000000 --- a/tests/regular_file_diff.sh.disabled +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash - -TEST_ID="00" -TEST_NAME="Simple file diff" - -CREATE=`pwd`/$1 -DEPLOY=`pwd`/$2 -TEST_TOOLS=$3 - -. ./test_lib.sh - -############# Test specific code ############ - -ORG_FILE=$ORIGIN/b.txt -TGT_FILE=$TARGET/b.txt - -setup_origin () { - echo 1 >$ORIGIN/a.txt && - chgrp tty $ORIGIN/a.txt && - echo 1 > $ORG_FILE -} - -setup_target () { - echo 2 >$TARGET/a.txt && - chgrp tty $TARGET/a.txt && - echo 2 > $TGT_FILE && - chown :cdrom $TGT_FILE && - chmod 707 $TGT_FILE -} - -check_results () { - check_group $ORIGIN/a.txt tty && - check_content $ORG_FILE "2" && \ - check_perm $ORG_FILE 707 && \ - check_group $ORG_FILE cdrom && \ - check_same_mtime $ORG_FILE $TGT_FILE -} - -############################################# -main $@ diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 6fa2f29..ea92924 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -12,24 +12,6 @@ then exit 1 fi -ALLTESTSDIR=`pwd` - -for i in [0-9][0-9]*.sh -do - cd $ALLTESTSDIR - echo "#### Running $i" - ./$i ../tbdiff-create/tbdiff-create ../tbdiff-deploy/tbdiff-deploy - if [ $? -ne 0 ] - then - echo "Test program $i failed" 1>&2 - cd $ALLTESTSDIR - echo "-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-" - exit 1 - fi - echo "#####################################################################" -done - - echo "Starting baserock-system-config-sync tests" merge_pass_folder="bscs-merge.pass" merge_fail_folder="bscs-merge.fail" diff --git a/tests/sockbind.c b/tests/sockbind.c deleted file mode 100644 index f98b5ed..0000000 --- a/tests/sockbind.c +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#define MAX_CLIENTS 1 -#ifdef DEBUG -#define DEBUGPRINT(fmt, ...) fprintf(stderr, "DEBUG: %s %s %d: " fmt, \ - __FILE__, __func__, __LINE__, __VA_ARGS__) -#else -#define DEBUGPRINT(...) (void)0 -#endif - -int main(int argc, char *argv[]){ - struct sockaddr_un sock = { - .sun_family = AF_UNIX - }; - int sfd; - if (argc < 1){ - fprintf(stderr, "Usage: %s PATH\n", argv[0]); - return 1; - } - strncpy(sock.sun_path, argv[1], sizeof(sock) - offsetof(struct sockaddr_un, sun_path)); - DEBUGPRINT("%s", "Constructed socket address\n"); - if ((sfd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1){ - perror("socket"); - return 2; - } - DEBUGPRINT("Created socket fd=%d\n", sfd); - if (bind(sfd, (struct sockaddr*)&sock, sizeof(sock)) == -1){ - perror("bind"); - return 3; - } - if (listen(sfd, MAX_CLIENTS) == -1){ - perror("listen"); - return 4; - } - DEBUGPRINT("Listening to %d clients\n", MAX_CLIENTS); - { - struct sockaddr_un client_address; - socklen_t client_size = sizeof(client_address); - int cfd; - while ((cfd = accept(sfd, (struct sockaddr*)&client_address, - &client_size)) != -1) { - char buf[BUFSIZ]; - ssize_t rdcount = -1; - DEBUGPRINT("Listening to client fd=%d\n", cfd); - while ((rdcount = read(cfd, buf, sizeof(buf))) > 0) { - DEBUGPRINT("Read %zi bytes from client, " - "message was:\n%.*s", rdcount, - rdcount, buf); - write(STDOUT_FILENO, buf, rdcount); - } - assert(rdcount == 0 || rdcount == -1); - if (rdcount == -1) { - perror("read"); - return 5; - } - DEBUGPRINT("Finished listening to fd=%d\n", cfd); - close(cfd); - } - } - - close(sfd); - unlink(argv[1]); - return 0; -} diff --git a/tests/symlink_add_remove.sh.disabled b/tests/symlink_add_remove.sh.disabled deleted file mode 100755 index badf199..0000000 --- a/tests/symlink_add_remove.sh.disabled +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash - -TEST_ID="05" -TEST_NAME="Symlink add/remove" - -CREATE=`pwd`/$1 -DEPLOY=`pwd`/$2 -TEST_TOOLS=$3 - -. ./test_lib.sh - -############# Test specific code ############ - -setup_origin () { - ( - cd $ORIGIN - ln -s /foo remove && - mkdir -p data && - touch data/a data/b && - ln -s data datalink - ) -} - -setup_target () { - mkdir -p $TARGET/data && - touch $TARGET/data/a $TARGET/data/b && - ln -s /bar $TARGET/add && - chown -h :cdrom $TARGET/add -} - -check_results () { - test -L $ORIGIN/add && - test ! -L $ORIGIN/remove && - check_symlink $ORIGIN/add "/bar" && - check_same_mtime $ORIGIN/add $TARGET/add && - check_same_uidgid $ORIGIN/add $TARGET/add && - test ! -L $ORIGIN/datalink && - echo datalink not link && - test -d $ORIGIN/data && - echo data is dir && - test -f $ORIGIN/data/a && - echo a is dir && - test -f $ORIGIN/data/b && - echo b is dir -} - -############################################# -main $@ diff --git a/tests/symlink_diff.sh.disabled b/tests/symlink_diff.sh.disabled deleted file mode 100755 index d975191..0000000 --- a/tests/symlink_diff.sh.disabled +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash - -TEST_ID="04" -TEST_NAME="Symlink diff" - -CREATE=`pwd`/$1 -DEPLOY=`pwd`/$2 -TEST_TOOLS=$3 - -. ./test_lib.sh - -############# Test specific code ############ - -setup_origin () { - ( - cd $ORIGIN && - echo 1 >file && - chown :cdrom file && - mkdir -p dir && - chown :cdrom dir && - ln -s file flink && - ln -s dir dlink - ln -s /foo a - ) -} - -setup_target () { - ( - cd $TARGET && - echo 1 >file && - chown :cdrom file && - mkdir -p dir && - chown :cdrom dir && - ln -s file flink && - ln -s dir dlink - chgrp -h daemon flink dlink && - ln -s /bar a && - chown -h :cdrom a - ) -} - -check_results () { - test -f $ORIGIN/file && - check_group $ORIGIN/file cdrom && - test -d $ORIGIN/dir && - check_group $ORIGIN/dir cdrom && - check_group $ORIGIN/flink daemon && - check_group $ORIGIN/dlink daemon && - test -L $ORIGIN/a && \ - check_symlink $ORIGIN/a "/bar" && \ - check_group $ORIGIN/a cdrom && \ - check_same_mtime $ORIGIN/a $TARGET/a && \ - check_same_uidgid $ORIGIN/a $TARGET/a -} - -############################################# -main $@ diff --git a/tests/test_lib.sh b/tests/test_lib.sh index 81a6bc7..fde3fe2 100644 --- a/tests/test_lib.sh +++ b/tests/test_lib.sh @@ -4,9 +4,6 @@ FAIL=" FAIL" TESTDIR="$PWD/temp" rm -rf "$TESTDIR" mkdir "$TESTDIR" -IMGFILE=$TESTDIR/tbdiff.img -ORIGIN=$TESTDIR/orig -TARGET=$TESTDIR/target nums=( zero one two three four five six seven ) files=( null a.txt b.txt dirdir dirdir/fifo dirdir/symlinkb dirdir/chardev \ @@ -38,152 +35,7 @@ insertfiles() { fi } -# check_same_mtime FILE_A FILE_B -check_same_mtime () { - test $(stat -c %Y $1) = $(stat -c %Y $2) -} - -# check_same_uidgid FILE_A FILE_B -check_same_uidgid () { - test $(stat -c "%u.%g" $1) = $(stat -c "%u.%g" $2) -} - -# check_same_mode FILE_A FILE_B -check_same_mode () { - test $(stat -c "%f" $1) = $(stat -c "%f" $2) -} - -# check_content FILE EXPECTED_OCTAL_PERMISSIONS -check_perm () { - test $(stat -c %a $1) = $2 -} - -# check_content FILE EXPECTED_OCTAL_PERMISSIONS -check_symlink () { - test $(readlink $1) = $2 -} - -# check_content FILE EXPECTED_CONTENT -check_content () { - test $(cat $1) = $2 -} - -# check_group FILE EXPECTED_GROUP_NAME -check_group () { - test $(stat -c %G $1) = $2 -} - -check_xattrs () { - test "`getfattr -d $1 2>/dev/null | tail -n +2`" = \ - "`getfattr -d $2 2>/dev/null | tail -n +2`" -} - -# tests whether a command exists -is_command () { - type $1 >/dev/null 2>/dev/null -} - -#check_command COMMAND_STRING TEST_COMMAND COMMAND_DESCRIPTION -check_command () { - COMMAND_STRING="$1" - COMMAND_DESCRIPTION="$2" - TEST_COMMAND="$3" - eval $COMMAND_STRING - RETVAL=$? - if is_command "$TEST_COMMAND"; then #test explicitly checks return - if $TEST_COMMAND $RETVAL; then - if [ "$RETVAL" != "0" ]; then - echo $COMMAND_STRING expected failure in \ - $COMMAND_DESCRIPTION >&2 - echo $OK - exit 0 - fi - else - if [ "$RETVAL" = "0" ]; then - echo $COMMAND_STRING Unexpected success in \ - $COMMAND_DESCRIPTION >&2 - echo $FAIL - cleanup_and_exit - else - echo $COMMAND_STRING Unexpected failure in \ - $COMMAND_DESCRIPTION >&2 - echo $FAIL - cleanup_and_exit - fi - fi - elif [ "$RETVAL" != "0" ]; then #return value expected to be 0 - echo $COMMAND_STRING Unexpected failure $COMMAND_DESCRIPTION >&2 - echo $FAIL - cleanup_and_exit - fi -} - -start () { - if [ $# -ne 2 ] - then - echo "ERROR: Not enough arguments." - cleanup_and_exit - fi - - if [ ! -f "$1" ] - then - echo "ERROR: $1 is an invalid tbdiff-create path" 1>&2 - cleanup_and_exit - fi - - if [ ! -f "$2" ] - then - echo "ERROR: $1 is an invalid tbdiff-deploy path" 1>&2 - cleanup_and_exit - fi -} - cleanup_and_exit () { - rm -rf $TESTDIR - exit 1 -} -command_succeeded () { - test "$1" = "0" -} -main () { - start "$@" - echo -n "$TEST_ID Setting up $TEST_NAME test: " - if [ ! -d $TESTDIR ] - then - echo $FAIL - echo "Couldn't create temporary directory for test. " \ - "Please check mktemp accepts -d and permissions." >&2 - cleanup_and_exit - fi - mkdir -p $ORIGIN && - check_command 'setup_origin' "$TEST_ID-$TEST_NAME: creating origin" \ - 'command_succeeded' && - mkdir -p $TARGET && - check_command 'setup_target' "$TEST_ID-$TEST_NAME: creating target" \ - 'command_succeeded' && - - echo $OK - - echo "$TEST_ID Performing $TEST_NAME image creation and deployment: " - sleep 2s && - CWD=$(pwd) && - check_command "$CREATE $IMGFILE $ORIGIN $TARGET" \ - "$TEST_ID-$TEST_NAME: creating image" \ - 'create_test_return' - - cd $ORIGIN && - check_command "$DEPLOY $IMGFILE" \ - "$TEST_ID-$TEST_NAME: deploying image" \ - 'deploy_test_return' - - cd $CWD - echo -n "$TEST_ID Checking $TEST_NAME results: " - check_results - if test "x$?" != "x0" - then - echo $FAIL - echo "Applying image did not produce the expected results" 1>&2 - cleanup_and_exit - fi - echo $OK + rm -rf $TESTDIR + exit 1 } -- cgit v1.2.1