From 4225f1a9d0155b119d091f61e4095a60767db31f Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 26 Aug 2022 16:22:29 -0700 Subject: [PATCH] tests.tar: fix tests for macOS. macOS doesn't have a 'root' group (it uses 'wheel' instead), which we can work around by using 'sys', since that happens to have the same gid on Linux and BSD. (Android doesn't have a 'sys' group, but I can fix that and give it the same number myself -- we already have similar hacks for Linux Test Project tests -- and this seems like the only way out of our current situation that doesn't require abandoning the "sha" style of test we have here.) macOS uses a different device for /dev/null, so work around that too. I don't have a good workaround for macOS' weird sparse file behavior (not least because I still haven't understood what it does/doesn't support), so I've just disabled all sparse tests for now. I fixed some of the symlink tests (where macOS has group r-x and Linux group rwx) where we're just doing text comparisons, but I've just skipped the "sha" style tests that use symlinks for now. With this change, there are no test failures for me on macOS 12.5 or on current-ish debian. --- tests/tar.test | 101 ++++++++++++++++++++++++++++--------------------- 1 file changed, 58 insertions(+), 43 deletions(-) diff --git a/tests/tar.test b/tests/tar.test index 24a43a81..4b4ebbd7 100755 --- a/tests/tar.test +++ b/tests/tar.test @@ -17,7 +17,7 @@ LONG=$LONG$LONG$LONG$LONG$LONG$LONG$LONG$LONG LONG=${LONG:1:255} # Reproducible tarballs: override ownership and timestamp. -TAR='tar c --owner root --group root --mtime @1234567890' +TAR='tar c --owner root --group sys --mtime @1234567890' # Different tars add variable trailing NUL padding (1024 bytes is just minimum) # so look at first N 512-byte frames when analyzing header content. @@ -33,24 +33,24 @@ function LST() touch file testing "create file" "$TAR file | SUM 3" \ - "fecaecba936e604bb115627a6ef4db7c7a3a8f81\n" "" "" + "2735f3a18d770dd0d7145d76108532f72bef9927\n" "" "" testing "pass file" "$TAR file | LST" \ - "-rw-rw-r-- root/root 0 2009-02-13 23:31 file\n" "" "" + "-rw-rw-r-- root/sys 0 2009-02-13 23:31 file\n" "" "" touch file1 file2 echo -e "file1\nfile2" > files-newline testing "-T newline" "$TAR -T files-newline | LST" \ - "-rw-rw-r-- root/root 0 2009-02-13 23:31 file1\n-rw-rw-r-- root/root 0 2009-02-13 23:31 file2\n" "" "" + "-rw-rw-r-- root/sys 0 2009-02-13 23:31 file1\n-rw-rw-r-- root/sys 0 2009-02-13 23:31 file2\n" "" "" tr '\n' '\0' < files-newline > files-null testing "-T null" "$TAR --null -T files-null | LST" \ - "-rw-rw-r-- root/root 0 2009-02-13 23:31 file1\n-rw-rw-r-- root/root 0 2009-02-13 23:31 file2\n" "" "" + "-rw-rw-r-- root/sys 0 2009-02-13 23:31 file1\n-rw-rw-r-- root/sys 0 2009-02-13 23:31 file2\n" "" "" # The kernel has two hardwired meaningful UIDs: 0 (root) and 65534 (nobody). # (Technically changeable via /proc/sys/*/overflowuid but nobody ever does) skipnot id nobody >/dev/null -testing "pass user" "tar -c --owner nobody:65534 --group root --mtime @0 file | LST" \ - "-rw-rw-r-- nobody/root 0 1970-01-01 00:00 file\n" "" "" +testing "pass user" "tar -c --owner nobody:65534 --group sys --mtime @0 file | LST" \ + "-rw-rw-r-- nobody/sys 0 1970-01-01 00:00 file\n" "" "" # (We assume that if we have the nobody user, we also have the group, in the # absence of a good portable way to test for the existence of a named group.) skipnot id nobody >/dev/null @@ -64,96 +64,105 @@ testing "huge values" "tar c --owner 9999999 --group 8888888 --mtime @0 file | S touch -t 198701231234.56 file testing "pass mtime" \ - "tar c --owner root --group root file | LST --full-time" \ - "-rw-rw-r-- root/root 0 1987-01-23 12:34:56 file\n" "" "" + "tar c --owner root --group sys file | LST --full-time" \ + "-rw-rw-r-- root/sys 0 1987-01-23 12:34:56 file\n" "" "" testing "adjust mode" \ - "tar c --owner root --group root --mode a+x file | LST --full-time" \ - "-rwxrwxr-x root/root 0 1987-01-23 12:34:56 file\n" "" "" + "tar c --owner root --group sys --mode a+x file | LST --full-time" \ + "-rwxrwxr-x root/sys 0 1987-01-23 12:34:56 file\n" "" "" mkdir dir testing "create dir" "$TAR dir | SUM 3" \ - "05739c423d7d4a7f12b3dbb7c94149acb2bb4f8d\n" "" "" + "85add1060cfe831ca0cdc945158efe6db485b81e\n" "" "" testing "pass dir" "$TAR dir | LST" \ - "drwxrwxr-x root/root 0 2009-02-13 23:31 dir/\n" "" "" + "drwxrwxr-x root/sys 0 2009-02-13 23:31 dir/\n" "" "" # note: does _not_ include dir entry in archive, just file touch dir/file testing "create file in dir" "$TAR dir/file | SUM 3" \ - "2d7b96c7025987215f5a41f10eaa84311160afdb\n" "" "" + "d9e7fb3884430d29e7eed0dc04a2593dd260df14\n" "" "" # Tests recursion without worrying about content order testing "create dir and dir/file" "$TAR dir | SUM 3" \ - "0bcc8005a3e07eb63c9b735267aecc5b774795d7\n" "" "" + "a4e35f87e28c4565b60ba01dbe79e431914f8788\n" "" "" testing "pass dir/file" "$TAR dir | LST" \ - "drwxrwxr-x root/root 0 2009-02-13 23:31 dir/\n-rw-rw-r-- root/root 0 2009-02-13 23:31 dir/file\n" "" "" + "drwxrwxr-x root/sys 0 2009-02-13 23:31 dir/\n-rw-rw-r-- root/sys 0 2009-02-13 23:31 dir/file\n" "" "" echo boing > dir/that testing "tar C" "$TAR -C dir that | SUM 3" \ - "f0deff71bf4858eb0c5f49d99d052f12f1831feb\n" "" "" + "d469d4bc06def2d8808400ba30025ca295d05e4f\n" "" "" # / and .. only stripped from name, not symlink target. ln -s ../name.././.. dir/link +skipnot [ "$(uname)" != "Darwin" ] # different symlink permissions on Darwin testing "create symlink" "$TAR dir/link | SUM 3" \ - "7324cafbd9aeec5036b6efc54d741f11528aeb10\n" "" "" + "f841bf9d757c655c5d37f30be62acb7ae24f433c\n" "" "" # Also two explicit targets ln dir/file dir/hardlink testing "create hardlink" "$TAR dir/file dir/hardlink | SUM 3" \ - "c5383651f8c03ec0fe15e8a9e28a4e8e5273990d\n" "" "" + "519de8abd1b32debd495a0fc1d96082184abbdcc\n" "" "" ln dir/link dir/hlink +skipnot [ "$(uname)" != "Darwin" ] # different symlink permissions on Darwin testing "create hardlink to symlink" "$TAR dir/link dir/hlink | SUM 3" \ - "3bc16f8fb6fc8b05f691da8caf989a70ee99284a\n" "" "" + "de571a6dbf09e1485e513ad13a178b1729267452\n" "" "" skipnot mkfifo dir/fifo 2>/dev/null testing "create dir/fifo" "$TAR dir/fifo | SUM 3" \ - "bd1365db6e8ead4c813333f9666994c1899924d9\n" "" "" + "cad477bd0fc5173d0a43f4774f514035456960e6\n" "" "" # test L and K records # 4+96=100 (biggest short name), 4+97=101 (shortest long name) touch dir/${LONG:1:96} dir/${LONG:1:97} testing "create long fname" "$TAR dir/${LONG:1:97} dir/${LONG:1:96} | SUM 3" \ - "99348686fe9c9bf80f5740f1fc0c6f32f2021e3d\n" "" "" + "d70018505fa5df19ae73498cfc74d0281601e42e\n" "" "" ln -s dir/${LONG:1:96} dir/lshort ln -s dir/${LONG:1:97} dir/llong -testing "create long symlnk" "$TAR dir/lshort dir/llong | SUM 3" \ - "8a5d652dc85f252a2e3b3f47d1ecd699e98a5f4b\n" "" "" +skipnot [ "$(uname)" != "Darwin" ] # different symlink permissions on Darwin +testing "create long symlink" "$TAR dir/lshort dir/llong | SUM 3" \ + "07eaf397634b5443dbf2d3ec38a4302150fcfe82\n" "" "" ln -s $LONG dir/${LONG:5} +skipnot [ "$(uname)" != "Darwin" ] # different symlink permissions on Darwin testing "create long->long" "$TAR dir/${LONG:5} | SUM 7" \ - "543116b8e690a116a559ab5b673f9b6d6601c925\n" "" "" + "b9e24f53e27496c5125445230d201b4a36ff7398\n" "" "" # absolute and relative link names, broken and not ln -s file dir/linkok +skipnot [ "$(uname)" != "Darwin" ] # different symlink permissions on Darwin testing "create symlink" "$TAR dir/linkok | SUM 3" \ - "55652846506cf0a9d43b3ef03ccf9e98123befaf\n" "" "" + "f5669cfd179ddcdd5ca9f8a1561a99e11e0a08b1\n" "" "" + +symlink_perms=lrwxrwxrwx +[ "$(uname)" == "Darwin" ] && symlink_perms=lrwxrwxr-x ln -s /dev/null dir/linknull testing "pass absolute symlink" "$TAR dir/linknull | LST" \ - "lrwxrwxrwx root/root 0 2009-02-13 23:31 dir/linknull -> /dev/null\n" "" "" + "$symlink_perms root/sys 0 2009-02-13 23:31 dir/linknull -> /dev/null\n" "" "" ln -s rel/broken dir/relbrok testing "pass broken symlink" "$TAR dir/relbrok | LST" \ - "lrwxrwxrwx root/root 0 2009-02-13 23:31 dir/relbrok -> rel/broken\n" "" "" + "$symlink_perms root/sys 0 2009-02-13 23:31 dir/relbrok -> rel/broken\n" "" "" ln -s /does/not/exist dir/linkabsbrok testing "pass broken absolute symlink" "$TAR dir/linkabsbrok | LST" \ - "lrwxrwxrwx root/root 0 2009-02-13 23:31 dir/linkabsbrok -> /does/not/exist\n" \ + "$symlink_perms root/sys 0 2009-02-13 23:31 dir/linkabsbrok -> /does/not/exist\n" \ "" "" -# this expects devtmpfs values +nulldev=1,3 # devtmpfs values +[ "$(uname)" == "Darwin" ] && nulldev=3,2 testing "pass /dev/null" \ - "tar c --mtime @0 /dev/null 2>/dev/null | LST" \ - "crw-rw-rw- root/root 1,3 1970-01-01 00:00 dev/null\n" "" "" + "tar c --mtime @0 --group sys /dev/null 2>/dev/null | LST" \ + "crw-rw-rw- root/sys $nulldev 1970-01-01 00:00 dev/null\n" "" "" testing "--absolute-names" \ - "tar c --mtime @0 --absolute-names /dev/null 2>/dev/null | LST" \ - "crw-rw-rw- root/root 1,3 1970-01-01 00:00 /dev/null\n" "" "" + "tar c --mtime @0 --group sys --absolute-names /dev/null 2>/dev/null | LST" \ + "crw-rw-rw- root/sys $nulldev 1970-01-01 00:00 /dev/null\n" "" "" # compression types testing "autodetect gzip" 'LST -f "$FILES"/tar/tar.tgz' \ @@ -173,11 +182,11 @@ testing "-I gzip t" 'LST -Igzip -f "$FILES"/tar/tar.tgz' \ skipnot mknod dir/char c 12 34 2>/dev/null testing "character special" "tar --mtime @0 -cf test.tar dir/char && rm -f dir/char && tar xf test.tar && ls -l dir/char" \ - "crw-rw---- 1 root root 12, 34 1970-01-01 00:00 dir/char\n" "" "" + "crw-rw---- 1 root sys 12, 34 1970-01-01 00:00 dir/char\n" "" "" skipnot mknod dir/block b 23 45 2>/dev/null testing "block special" "tar --mtime @0 -cf test.tar dir/block && rm -f dir/block && tar xf test.tar && ls -l dir/block" \ - "brw-rw---- 1 root root 23, 45 1970-01-01 00:00 dir/block\n" "" "" + "brw-rw---- 1 root sys 23, 45 1970-01-01 00:00 dir/block\n" "" "" skipnot chown nobody dir/file 2>/dev/null testing "ownership" "$TAR dir/file | SUM 3" \ @@ -226,8 +235,9 @@ rm -rf path yes | head -n $((1<<18)) > bang { dd bs=$((1<<16)) count=1 status=none; dd bs=8192 seek=14 count=1 status=none; dd bs=4096 seek=64 count=5 status=none; } < bang > fweep +skipnot [ "$(uname)" != "Darwin" ] # very limited sparse on Darwin testing "sparse without overflow" "$TAR --sparse fweep | SUM 3" \ - "e1560110293247934493626d564c8f03c357cec5\n" "" "" + "50dc56c3c7eed163f0f37c0cfc2562852a612ad0\n" "" "" rm bang fweep for i in 1 3 5 7 9 14 27 36 128 256 300 304 @@ -235,8 +245,9 @@ do dd if=/dev/zero of=fweep bs=65536 seek=$i count=1 2>/dev/null done +skipnot [ "$(uname)" != "Darwin" ] # very limited sparse on Darwin testing "sparse single overflow" "$TAR --sparse fweep | SUM 6" \ - "063fc6519ea2607763bc591cc90dd15ac2b43eb8\n" "" "" + "81d59c3a7470201f92d60e63a43318ddde893f6d\n" "" "" rm fweep for i in $(seq 8 3 200) @@ -246,22 +257,26 @@ do done truncate -s 20m fweep2 +skipnot [ "$(uname)" != "Darwin" ] # very limited sparse on Darwin testing "sparse double overflow" "$TAR --sparse fweep | SUM 7" \ - "f1fe57f8313a9d682ec9013a80f3798910b6ff51\n" "" "" + "024aacd955e45f89bafedb3f37c8d39b4d556471\n" "" "" tar c --sparse fweep > fweep.tar rm fweep +skipnot [ "$(uname)" != "Darwin" ] # very limited sparse on Darwin testing "sparse extract" "tar xf fweep.tar && $TAR --sparse fweep | SUM 4" \ - "38dc57b8b95632a287db843c214b5c96d1cfe415\n" "" "" + "b949d3a3b4c6457c873f1ea9918fd9029c5ed4b3\n" "" "" +skipnot [ "$(uname)" != "Darwin" ] # very limited sparse on Darwin testing "sparse tvf" "tar tvf fweep.tar | grep -wq 13172736 && echo right size"\ "right size\n" "" "" rm fweep fweep.tar tar c --sparse fweep2 > fweep2.tar rm fweep2 +skipnot [ "$(uname)" != "Darwin" ] # very limited sparse on Darwin testing "sparse extract hole at end" \ "tar xf fweep2.tar && $TAR --sparse fweep2 | SUM 4" \ - "791060574c569e5c059e2b90c1961a3575898f97\n" "" "" + "807664bcad0e827793318ff742991d6f006b2127\n" "" "" rm fweep2 fweep2.tar testcmd "longname" "tf $FILES/tar/long_path.tar" \ @@ -292,10 +307,10 @@ rm -rf one test.tar mkdir ..dotsdir testing "create ..dotsdir" "$TAR ..dotsdir | SUM 3" \ - "de99091a91c74ef6b90093e9165b413670730572\n" "" "" + "62ff23c9b427020331992b9bc71f082099c1411f\n" "" "" testing "pass ..dotsdir" "$TAR ..dotsdir | LST" \ - "drwxrwxr-x root/root 0 2009-02-13 23:31 ..dotsdir/\n" "" "" + "drwxrwxr-x root/sys 0 2009-02-13 23:31 ..dotsdir/\n" "" "" rmdir ..dotsdir mkdir -p one/two/three/four/five -- 2.39.2