The branch main has been updated by des:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=6cb78fa479c7ac8d2b615f903638691a32dc855c

commit 6cb78fa479c7ac8d2b615f903638691a32dc855c
Author:     Dag-Erling Smørgrav <[email protected]>
AuthorDate: 2023-03-16 11:31:01 +0000
Commit:     Dag-Erling Smørgrav <[email protected]>
CommitDate: 2023-03-16 11:31:22 +0000

    tarfs: Repeat tests using GNU tar if available.
    
    Sponsored by:   Juniper Networks, Inc.
    Sponsored by:   Klara, Inc.
    Reviewed by:    ngie, asomers
    Differential Revision:  https://reviews.freebsd.org/D39018
---
 tests/sys/fs/tarfs/mktar.c       |  11 ++--
 tests/sys/fs/tarfs/tarfs_test.sh | 106 +++++++++++++++++++++++++++++++++++----
 2 files changed, 104 insertions(+), 13 deletions(-)

diff --git a/tests/sys/fs/tarfs/mktar.c b/tests/sys/fs/tarfs/mktar.c
index 9b3d7910a12c..4e7d1acc1c82 100644
--- a/tests/sys/fs/tarfs/mktar.c
+++ b/tests/sys/fs/tarfs/mktar.c
@@ -48,6 +48,7 @@
 #define SHORTLINKNAME  "short_link"
 #define LONGLINKNAME   "long_link"
 
+static bool opt_g;
 static bool opt_v;
 
 static void verbose(const char *fmt, ...)
@@ -163,7 +164,7 @@ static void
 usage(void)
 {
 
-       fprintf(stderr, "usage: %s [-v] tarfile\n", PROGNAME);
+       fprintf(stderr, "usage: %s [-gv] tarfile\n", PROGNAME);
        exit(EXIT_FAILURE);
 }
 
@@ -175,8 +176,10 @@ main(int argc, char *argv[])
        int opt, wstatus;
        pid_t pid;
 
-       while ((opt = getopt(argc, argv, "v")) != -1)
+       while ((opt = getopt(argc, argv, "gv")) != -1)
                switch (opt) {
+               case 'g':
+                       opt_g = true;
                case 'v':
                        opt_v = true;
                        break;
@@ -220,10 +223,12 @@ main(int argc, char *argv[])
                err(1, "fork()");
        if (pid == 0) {
                verbose("creating tarball");
-               execlp("tar", "tar",
+               execlp(opt_g ? "gtar" : "tar",
+                   "tar",
                    "-c",
                    "-f", tarfilename,
                    "-C", dirname,
+                   "--posix",
                    "--zstd",
 #if 0
                    "--options", "zstd:frame-per-file",
diff --git a/tests/sys/fs/tarfs/tarfs_test.sh b/tests/sys/fs/tarfs/tarfs_test.sh
index 32576cbf57b6..6e44a8081cb2 100644
--- a/tests/sys/fs/tarfs/tarfs_test.sh
+++ b/tests/sys/fs/tarfs/tarfs_test.sh
@@ -26,12 +26,23 @@
 # SUCH DAMAGE.
 #
 
-mktar="$(dirname $(realpath "$0"))"/mktar
 mnt="$(realpath ${TMPDIR:-/tmp})/mnt"
 
 # expected SHA256 checksum of file contained in test tarball
 sum=4da2143234486307bb44eaa610375301781a577d1172f362b88bb4b1643dee62
 
+tar() {
+       if [ -n "${TARFS_USE_GNU_TAR}" ] ; then
+               gtar --posix --absolute-names "$@"
+       else
+               bsdtar "$@"
+       fi
+}
+
+mktar() {
+       "$(atf_get_srcdir)"/mktar ${TARFS_USE_GNU_TAR+-g} "$@"
+}
+
 atf_test_case tarfs_basic cleanup
 tarfs_basic_head() {
        atf_set "descr" "Basic function test"
@@ -41,7 +52,7 @@ tarfs_basic_body() {
        local tarball="${PWD}/tarfs_test.tar.zst"
        kldload -n tarfs || atf_skip "This test requires tarfs and could not 
load it"
        mkdir "${mnt}"
-       "${mktar}" "${tarball}"
+       mktar "${tarball}"
        atf_check mount -rt tarfs "${tarball}" "${mnt}"
        atf_check -o match:"^${tarball} on ${mnt} \(tarfs," mount
        atf_check_equal "$(stat -f%d,%i "${mnt}"/sparse_file)" "$(stat -f%d,%i 
"${mnt}"/hard_link)"
@@ -53,6 +64,20 @@ tarfs_basic_cleanup() {
        umount "${mnt}" || true
 }
 
+atf_test_case tarfs_basic_gnu cleanup
+tarfs_basic_gnu_head() {
+       atf_set "descr" "Basic function test using GNU tar"
+       atf_set "require.user" "root"
+       atf_set "require.progs" "gtar"
+}
+tarfs_basic_gnu_body() {
+       TARFS_USE_GNU_TAR=true
+       tarfs_basic_body
+}
+tarfs_basic_gnu_cleanup() {
+       tarfs_basic_cleanup
+}
+
 atf_test_case tarfs_notdir_device cleanup
 tarfs_notdir_device_head() {
        atf_set "descr" "Regression test for PR 269519 and 269561"
@@ -62,11 +87,11 @@ tarfs_notdir_device_body() {
        kldload -n tarfs || atf_skip "This test requires tarfs and could not 
load it"
        mkdir "${mnt}"
        atf_check mknod d b 0xdead 0xbeef
-       tar cf tarfs_notdir.tar d
+       tar -cf tarfs_notdir.tar d
        rm d
        mkdir d
        echo "boom" >d/f
-       tar rf tarfs_notdir.tar d/f
+       tar -rf tarfs_notdir.tar d/f
        atf_check -s not-exit:0 -e match:"Invalid" \
            mount -rt tarfs tarfs_notdir.tar "${mnt}"
 }
@@ -74,6 +99,20 @@ tarfs_notdir_device_cleanup() {
        umount "${mnt}" || true
 }
 
+atf_test_case tarfs_notdir_device_gnu cleanup
+tarfs_notdir_device_gnu_head() {
+       atf_set "descr" "Regression test for PR 269519 and 269561 using GNU tar"
+       atf_set "require.user" "root"
+       atf_set "require.progs" "gtar"
+}
+tarfs_notdir_device_gnu_body() {
+       TARFS_USE_GNU_TAR=true
+       tarfs_notdir_device_body
+}
+tarfs_notdir_device_gnu_cleanup() {
+       tarfs_notdir_device_cleanup
+}
+
 atf_test_case tarfs_notdir_dot cleanup
 tarfs_notdir_dot_head() {
        atf_set "descr" "Regression test for PR 269519 and 269561"
@@ -83,11 +122,11 @@ tarfs_notdir_dot_body() {
        kldload -n tarfs || atf_skip "This test requires tarfs and could not 
load it"
        mkdir "${mnt}"
        echo "hello" >d
-       tar cf tarfs_notdir.tar d
+       tar -cf tarfs_notdir.tar d
        rm d
        mkdir d
        echo "world" >d/f
-       tar rf tarfs_notdir.tar d/./f
+       tar -rf tarfs_notdir.tar d/./f
        atf_check -s not-exit:0 -e match:"Invalid" \
            mount -rt tarfs tarfs_notdir.tar "${mnt}"
 }
@@ -95,6 +134,20 @@ tarfs_notdir_dot_cleanup() {
        umount "${mnt}" || true
 }
 
+atf_test_case tarfs_notdir_dot_gnu cleanup
+tarfs_notdir_dot_gnu_head() {
+       atf_set "descr" "Regression test for PR 269519 and 269561 using GNU tar"
+       atf_set "require.user" "root"
+       atf_set "require.progs" "gtar"
+}
+tarfs_notdir_dot_gnu_body() {
+       TARFS_USE_GNU_TAR=true
+       tarfs_notdir_dot_body
+}
+tarfs_notdir_dot_gnu_cleanup() {
+       tarfs_notdir_dot_cleanup
+}
+
 atf_test_case tarfs_notdir_dotdot cleanup
 tarfs_notdir_dotdot_head() {
        atf_set "descr" "Regression test for PR 269519 and 269561"
@@ -104,11 +157,11 @@ tarfs_notdir_dotdot_body() {
        kldload -n tarfs || atf_skip "This test requires tarfs and could not 
load it"
        mkdir "${mnt}"
        echo "hello" >d
-       tar cf tarfs_notdir.tar d
+       tar -cf tarfs_notdir.tar d
        rm d
        mkdir d
        echo "world" >f
-       tar rf tarfs_notdir.tar d/../f
+       tar -rf tarfs_notdir.tar d/../f
        atf_check -s not-exit:0 -e match:"Invalid" \
            mount -rt tarfs tarfs_notdir.tar "${mnt}"
 }
@@ -116,6 +169,20 @@ tarfs_notdir_dotdot_cleanup() {
        umount "${mnt}" || true
 }
 
+atf_test_case tarfs_notdir_dotdot_gnu cleanup
+tarfs_notdir_dotdot_gnu_head() {
+       atf_set "descr" "Regression test for PR 269519 and 269561 using GNU tar"
+       atf_set "require.user" "root"
+       atf_set "require.progs" "gtar"
+}
+tarfs_notdir_dotdot_gnu_body() {
+       TARFS_USE_GNU_TAR=true
+       tarfs_notdir_dotdot_body
+}
+tarfs_notdir_dotdot_gnu_cleanup() {
+       tarfs_notdir_dotdot_cleanup
+}
+
 atf_test_case tarfs_notdir_file cleanup
 tarfs_notdir_file_head() {
        atf_set "descr" "Regression test for PR 269519 and 269561"
@@ -125,11 +192,11 @@ tarfs_notdir_file_body() {
        kldload -n tarfs || atf_skip "This test requires tarfs and could not 
load it"
        mkdir "${mnt}"
        echo "hello" >d
-       tar cf tarfs_notdir.tar d
+       tar -cf tarfs_notdir.tar d
        rm d
        mkdir d
        echo "world" >d/f
-       tar rf tarfs_notdir.tar d/f
+       tar -rf tarfs_notdir.tar d/f
        atf_check -s not-exit:0 -e match:"Invalid" \
            mount -rt tarfs tarfs_notdir.tar "${mnt}"
 }
@@ -137,10 +204,29 @@ tarfs_notdir_file_cleanup() {
        umount "${mnt}" || true
 }
 
+atf_test_case tarfs_notdir_file_gnu cleanup
+tarfs_notdir_file_gnu_head() {
+       atf_set "descr" "Regression test for PR 269519 and 269561 using GNU tar"
+       atf_set "require.user" "root"
+       atf_set "require.progs" "gtar"
+}
+tarfs_notdir_file_gnu_body() {
+       TARFS_USE_GNU_TAR=true
+       tarfs_notdir_file_body
+}
+tarfs_notdir_file_gnu_cleanup() {
+       tarfs_notdir_file_cleanup
+}
+
 atf_init_test_cases() {
        atf_add_test_case tarfs_basic
+       atf_add_test_case tarfs_basic_gnu
        atf_add_test_case tarfs_notdir_device
+       atf_add_test_case tarfs_notdir_device_gnu
        atf_add_test_case tarfs_notdir_dot
+       atf_add_test_case tarfs_notdir_dot_gnu
        atf_add_test_case tarfs_notdir_dotdot
+       atf_add_test_case tarfs_notdir_dotdot_gnu
        atf_add_test_case tarfs_notdir_file
+       atf_add_test_case tarfs_notdir_file_gnu
 }

Reply via email to