From 6b6578da250d89a0a5929d4639fd8e44303c5a3d Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 10 Mar 2023 17:35:07 -0600 Subject: [PATCH] Add new test for "directory exists" and make TEST_HOST less chatty. --- tests/cpio.test | 54 +++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/tests/cpio.test b/tests/cpio.test index 183dadde..6f5eddef 100755 --- a/tests/cpio.test +++ b/tests/cpio.test @@ -6,15 +6,20 @@ # This means all possible values of strlen(name)+1 % 4, # plus file sizes of at least 0-4. +CPIO="cpio${TEST_HOST:+ --quiet}" +CPI_O="$CPIO -o -H newc" + touch a bb ccc dddd -testing "name padding" "cpio -o -H newc|cpio -it" "a\nbb\nccc\ndddd\n" "" "a\nbb\nccc\ndddd\n" +testing "name padding" "$CPI_O|$CPIO -it" "a\nbb\nccc\ndddd\n" \ + "" "a\nbb\nccc\ndddd\n" rm a bb ccc dddd touch a printf '1' >b printf '22' >c printf '333' >d -testing "file padding" "cpio -o -H newc|cpio -it" "a\nb\nc\nd\n" "" "a\nb\nc\nd\n" +testing "file padding" "$CPI_O|$CPIO -it" "a\nb\nc\nd\n" "" \ + "a\nb\nc\nd\n" rm a b c d touch a @@ -25,50 +30,55 @@ printf '333' >dddd # the relevant bit should be here: # 110*5 + 4*3 + 2 + 6*3 = 550 + 12 + 20 = 582 # files are padded to n*4, names are padded to 2 + n*4 due to the header length -testing "archive length" "cpio -o -H newc|dd ibs=2 skip=291 count=5 2>/dev/null" "TRAILER!!!" "" "a\nbb\nccc\ndddd\n" -testing "archive magic" "cpio -o -H newc|dd ibs=2 count=3 2>/dev/null" "070701" "" "a\n" +testing "archive length" "$CPI_O|dd ibs=2 skip=291 count=5 2>/dev/null" "TRAILER!!!" "" "a\nbb\nccc\ndddd\n" +testing "archive magic" "$CPI_O|dd ibs=2 count=3 2>/dev/null" "070701" "" "a\n" # check name length (8 bytes before the empty "crc") -testing "name length" "cpio -o -H newc|dd ibs=2 skip=47 count=4 2>/dev/null" "00000002" "" "a\n" -testing "-t" "cpio -o -H newc|cpio -it" "a\nbb\n" "" "a\nbb" -testing "-t --quiet" "cpio -o -H newc|cpio -it --quiet" "a\nbb\n" "" "a\nbb" +testing "name length" "$CPI_O|dd ibs=2 skip=47 count=4 2>/dev/null" "00000002" "" "a\n" +testing "-t" "$CPI_O|$CPIO -it" "a\nbb\n" "" "a\nbb" +# Only actually tests anything on toybox. :) +testing "-t --quiet" "$CPI_O|$CPIO -it --quiet" "a\nbb\n" "" "a\nbb" mkdir out -testing "-p" "cpio -p out && find out | sort" "out\nout/a\nout/bb\n" "" "a\nbb" +testing "-p" "$CPIO -p out && find out | sort" "out\nout/a\nout/bb\n" "" "a\nbb" rm -rf out -testing "-pd" "cpio -pd out && find out | sort" "out\nout/a\nout/bb\n" "" "a\nbb" +testing "-pd" "$CPIO -pd out && find out | sort" "out\nout/a\nout/bb\n" "" "a\nbb" rm a bb ccc dddd # archive dangling symlinks and empty files even if we cannot open them touch a; chmod a-rwx a; ln -s a/cant b -toyonly testing "archives unreadable empty files" "cpio -o -H newc|cpio -it" "b\na\n" "" "b\na\n" +toyonly testing "archives unreadable empty files" "$CPI_O|$CPIO -it" "b\na\n" "" "b\na\n" chmod u+rw a; rm -f a b mkdir a echo "old" >a/b -echo "a/b" | cpio -o -H newc >a.cpio +echo "a/b" | $CPI_O >a.cpio +testing "directory exists is not an error" \ + "$CPI_O | { $CPIO -i 2>&1 || echo bad; }" "" "" "a\n" rm -rf a -testing "-i doesn't create leading directories" "cpio -i /dev/null; [ -e a ] || echo yes" "yes\n" "" "" +testing "-i doesn't create leading directories" \ + "$CPIO -i /dev/null; [ -e a ] || echo yes" "yes\n" "" "" rm -rf a -testing "-id creates leading directories" "cpio -id a/b -find a | cpio -o -H newc >a.cpio -testing "-i keeps existing files" "echo new >a/b && cpio -i /dev/null; cat a/b" "new\n" "" "" -testing "-id keeps existing files" "echo new >a/b && cpio -id /dev/null; cat a/b" "new\n" "" "" -testing "-iu replaces existing files; no error" "echo new >a/b && cpio -iu a/b && cpio -idu /dev/null; cat a.cpio; done | cpio -t -H newc" \ +find a | $CPI_O >a.cpio +testing "-i keeps existing files" "echo new >a/b && $CPIO -i /dev/null; cat a/b" "new\n" "" "" +testing "-id keeps existing files" "echo new >a/b && $CPIO -id /dev/null; cat a/b" "new\n" "" "" +testing "-iu replaces existing files; no error" "echo new >a/b && $CPIO -iu a/b && $CPIO -idu /dev/null; cat a.cpio; done | $CPIO -t -H newc" \ "a\na/b\na\na/b\n" "" "" rm -rf a a.cpio -testing "error on empty file" "cpio -i 2>/dev/null || echo err" "err\n" "" "" +testing "error on empty file" "$CPIO -i 2>/dev/null || echo err" "err\n" "" "" mkdir a touch a/file ln -s a/symlink a/symlink mkdir a/dir -find a | cpio -o -H newc >a.cpio +find a | $CPI_O >a.cpio if [ "$(id -u)" -eq 0 ]; then # We chown between user "root" and the last user in /etc/passwd, # and group "root" and the last group in /etc/group. @@ -80,5 +90,5 @@ if [ "$(id -u)" -eq 0 ]; then chown -h "${USR}:${GRP}" a/file a/symlink a/dir fi skipnot [ $(id -u) -eq 0 ] -testing "-t preserve ownership" "cpio -t /dev/null && stat -c '%U:%G' a/file a/symlink a/dir" "${USR}:${GRP}\n${USR}:${GRP}\n${USR}:${GRP}\n" "" "" +testing "-t preserve ownership" "$CPIO -t /dev/null && stat -c '%U:%G' a/file a/symlink a/dir" "${USR}:${GRP}\n${USR}:${GRP}\n${USR}:${GRP}\n" "" "" rm -rf a a.cpio -- 2.39.2