btrfs-progs: rework testsuite export
authorDavid Sterba <dsterba@suse.com>
Thu, 8 Feb 2018 14:34:04 +0000 (15:34 +0100)
committerDavid Sterba <dsterba@suse.com>
Tue, 13 Feb 2018 14:41:32 +0000 (15:41 +0100)
Move the testsuite to tests/ and make the tarball generation more
deterministic. As there could be many random temporary files left in the
test directories, we can't just copy them. Use 'git ls-tree' to
filter just what we want, this needs a slight extension of the file list
specification.

Signed-off-by: David Sterba <dsterba@suse.com>
.gitignore
Makefile
tests/export-tests.sh [deleted file]
tests/export-testsuite.sh [new file with mode: 0755]
tests/testsuite-files [new file with mode: 0644]
testsuites-list [deleted file]

index a41ad8c..4abd3ee 100644 (file)
@@ -43,7 +43,7 @@ libbtrfs.so.0.1
 library-test
 library-test-static
 /fssum
-testsuites-id
+testsuite-id
 
 /tests/*-tests-results.txt
 /tests/test-console.txt
index 3a5e01d..65ec100 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -333,7 +333,7 @@ test: test-fsck test-mkfs test-convert test-misc test-fuzz test-cli
 
 testsuite: btrfs-corrupt-block fssum
        @echo "Export tests as a package"
-       $(Q)bash tests/export-tests.sh
+       $(Q)cd tests && ./export-testsuite.sh
 
 #
 # NOTE: For static compiles, you need to have all the required libs
diff --git a/tests/export-tests.sh b/tests/export-tests.sh
deleted file mode 100755 (executable)
index 0ed7dd9..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/bin/bash
-# export the testsuite files to a separate tar
-
-TESTSUITES_LIST_FILE=$PWD/testsuites-list
-if ! [ -f $TESTSUITES_LIST_FILE ];then
-       echo "testsuites list file is not exsit."
-       exit 1
-fi
-
-TESTSUITES_LIST=$(cat $TESTSUITES_LIST_FILE)
-if [ -z "$TESTSUITES_LIST" ]; then
-       echo "no file be list in testsuites-list"
-       exit 1
-fi
-
-DEST="btrfs-progs-tests.tar.gz"
-if [ -f $DEST ];then
-       echo "remove exsit package: " $DEST
-       rm $DEST
-fi
-
-TEST_ID=$PWD/testsuites-id
-if [ -f $TEST_ID ];then
-       rm $TEST_ID
-fi
-VERSION=`./version.sh`
-TIMESTAMP=`date -u "+%Y-%m-%d %T %Z"`
-
-echo "git version: " $VERSION > $TEST_ID
-echo "this tar is created in: " $TIMESTAMP >> $TEST_ID
-
-echo "begin create tar:  " $DEST
-tar --exclude-vcs-ignores -zScf $DEST -C ../ $TESTSUITES_LIST
-if [ $? -eq 0 ]; then
-       echo "create tar successfully."
-fi
-rm $TEST_ID
diff --git a/tests/export-testsuite.sh b/tests/export-testsuite.sh
new file mode 100755 (executable)
index 0000000..31b6ecf
--- /dev/null
@@ -0,0 +1,55 @@
+#!/bin/bash
+# export the testsuite files to a separate tar
+
+if ! [ -f testsuite-files ]; then
+       echo "ERROR: cannot find testsuite-files"
+       exit 1
+fi
+
+set -e
+
+TESTSUITE_TAR="btrfs-progs-tests.tar.gz"
+rm -f "$TESTSUITE_TAR"
+
+TIMESTAMP=`date -u "+%Y-%m-%d %T %Z"`
+
+{
+       echo "VERSION=`cat ../VERSION`"
+       echo "GIT_VERSION=`git describe`"
+       echo "TIMESTAMP='$TIMESTAMP'"
+} > testsuite-id
+
+# Due to potentially unwanted files in the testsuite (restored images or other
+# temporary files) we can't simply copy everything so the tar
+#
+# The testsuite-files specifier:
+# F file
+#   - directly copy the file from the given path, may be a git tracked file or
+#     a built binary
+# G path
+#   - a path relative to the top of git, recursively traversed; path
+#     postprocessing is needed so the tar gets it relative to tests/
+while read t f; do
+       case "$t" in
+               F) echo "$f";;
+               G)
+                       here=`pwd`
+                       cd ..
+                       git ls-tree -r --name-only --full-name HEAD "$f" |
+                               sed -e 's#^tests/##' |
+                               sed -e 's#^Documentation#../Documentation#'
+                       cd "$here"
+                       ;;
+       esac
+done < testsuite-files > testsuite-files-all
+
+echo "create tar: $TESTSUITE_TAR"
+tar cz --sparse -f "$TESTSUITE_TAR" -T testsuite-files-all
+if [ $? -eq 0 ]; then
+       echo "tar created successfully"
+       cat testsuite-id
+       rm -f testsuite-files-all
+       rm -f testsuite-id
+else
+       exit $?
+fi
diff --git a/tests/testsuite-files b/tests/testsuite-files
new file mode 100644 (file)
index 0000000..d75e235
--- /dev/null
@@ -0,0 +1,22 @@
+F README.md
+G Documentation/
+F testsuite-id
+F ../fssum
+F ../btrfs-corrupt-block
+F common
+F common.convert
+F common.local
+G tests/cli-tests/
+F cli-tests.sh
+G tests/convert-tests/
+F convert-tests.sh
+G tests/fsck-tests/
+F fsck-tests.sh
+G tests/fuzz-tests/
+F fuzz-tests.sh
+G tests/misc-tests/
+F misc-tests.sh
+G tests/mkfs-tests/
+F mkfs-tests.sh
+F scan-results.sh
+F test-console.sh
diff --git a/testsuites-list b/testsuites-list
deleted file mode 100644 (file)
index a24591f..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-btrfs-progs/testsuites-id
-btrfs-progs/fssum
-btrfs-progs/btrfs-corrupt-block
-btrfs-progs/Documentation/
-btrfs-progs/tests/cli-tests
-btrfs-progs/tests/cli-tests.sh
-btrfs-progs/tests/common
-btrfs-progs/tests/common.convert
-btrfs-progs/tests/common.local
-btrfs-progs/tests/convert-tests
-btrfs-progs/tests/convert-tests.sh
-btrfs-progs/tests/fsck-tests
-btrfs-progs/tests/fsck-tests.sh
-btrfs-progs/tests/fuzz-tests/
-btrfs-progs/tests/fuzz-tests.sh
-btrfs-progs/tests/misc-tests/
-btrfs-progs/tests/misc-tests.sh
-btrfs-progs/tests/mkfs-tests/
-btrfs-progs/tests/mkfs-tests.sh
-btrfs-progs/tests/README.md
-btrfs-progs/tests/scan-results.sh
-btrfs-progs/tests/test-console.sh