Denis Vlasenko | 0a38bcf | 2008-04-05 02:46:47 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Copyright 2008 by Denys Vlasenko |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 3 | # Licensed under GPLv2, see file LICENSE in this source tree. |
Denis Vlasenko | 0a38bcf | 2008-04-05 02:46:47 +0000 | [diff] [blame] | 4 | |
Mike Frysinger | caa7940 | 2009-11-04 18:41:22 -0500 | [diff] [blame] | 5 | . ./testing.sh |
Denis Vlasenko | 0a38bcf | 2008-04-05 02:46:47 +0000 | [diff] [blame] | 6 | |
Dan Fandrich | 775965d | 2010-08-10 23:33:57 -0700 | [diff] [blame] | 7 | umask 022 |
| 8 | |
Denis Vlasenko | 29ec0b9 | 2008-07-11 21:43:11 +0000 | [diff] [blame] | 9 | # ls -ln shows date. Need to remove that, it's variable. |
Denis Vlasenko | 0a38bcf | 2008-04-05 02:46:47 +0000 | [diff] [blame] | 10 | # sed: coalesce spaces |
| 11 | # cut: remove date |
Denys Vlasenko | 03f6ee2 | 2010-03-28 20:07:42 +0200 | [diff] [blame] | 12 | # grep: remove "total NNN" lines |
| 13 | FILTER_LS="sed 's/ */ /g' | cut -d' ' -f 1-5,9- | grep -v '^total '" |
Denis Vlasenko | 0a38bcf | 2008-04-05 02:46:47 +0000 | [diff] [blame] | 14 | |
| 15 | |
| 16 | # newc cpio archive of directory cpio.testdir with empty x and y hardlinks |
| 17 | hexdump="\ |
Denis Vlasenko | 29ec0b9 | 2008-07-11 21:43:11 +0000 | [diff] [blame] | 18 | \x42\x5a\x68\x39\x31\x41\x59\x26\x53\x59\x64\x1e\x91\x8c\x00\x00\ |
| 19 | \x48\x7f\x80\x4c\x48\x08\x00\x28\x01\xff\xe0\x3f\x24\x14\x00\x0e\ |
| 20 | \x20\xdc\x60\x20\x00\x92\x11\xea\xa0\x1a\x00\x00\x00\x03\x20\x8a\ |
| 21 | \x93\xd4\x9a\x68\x1a\x0d\x1e\x91\xa1\xa0\x06\x98\xe3\x5c\x2f\xd9\ |
| 22 | \x26\xa1\x25\x24\x20\xed\x47\xc7\x21\x40\x2b\x6e\xf2\xe6\xfe\x98\ |
| 23 | \x13\x68\xa8\xbd\x82\xb2\x4f\x26\x02\x24\x16\x5b\x22\x16\x72\x74\ |
| 24 | \x15\xcd\xc1\xa6\x9e\xa6\x5e\x6c\x16\x37\x35\x01\x99\xc4\x81\x21\ |
| 25 | \x29\x28\x4b\x69\x51\xa9\x3c\x1a\x9b\x0a\xe1\xe4\xb4\xaf\x85\x73\ |
| 26 | \xba\x23\x10\x59\xe8\xb3\xe1\xa1\x63\x05\x8c\x4f\xc5\xdc\x91\x4e\ |
| 27 | \x14\x24\x19\x07\xa4\x63\x00" |
Denis Vlasenko | 0a38bcf | 2008-04-05 02:46:47 +0000 | [diff] [blame] | 28 | |
Denis Vlasenko | 687a26f | 2008-05-02 21:46:30 +0000 | [diff] [blame] | 29 | user=$(id -u) |
| 30 | group=$(id -g) |
| 31 | |
Denis Vlasenko | 29ec0b9 | 2008-07-11 21:43:11 +0000 | [diff] [blame] | 32 | rm -rf cpio.testdir cpio.testdir2 2>/dev/null |
Denis Vlasenko | 0a38bcf | 2008-04-05 02:46:47 +0000 | [diff] [blame] | 33 | |
Denis Vlasenko | 29ec0b9 | 2008-07-11 21:43:11 +0000 | [diff] [blame] | 34 | # testing "test name" "command" "expected result" "file input" "stdin" |
Denis Vlasenko | 0a38bcf | 2008-04-05 02:46:47 +0000 | [diff] [blame] | 35 | |
Denys Vlasenko | c0211e9 | 2010-05-11 04:32:04 +0200 | [diff] [blame] | 36 | optional FEATURE_LS_SORTFILES FEATURE_LS_TIMESTAMPS |
Denis Vlasenko | 0a38bcf | 2008-04-05 02:46:47 +0000 | [diff] [blame] | 37 | testing "cpio extracts zero-sized hardlinks" \ |
Matheus Izvekov | 4640ccc | 2010-04-26 13:53:57 +0200 | [diff] [blame] | 38 | "$ECHO -ne '$hexdump' | bzcat | cpio -i 2>&1; echo \$?; |
Denis Vlasenko | 29ec0b9 | 2008-07-11 21:43:11 +0000 | [diff] [blame] | 39 | ls -ln cpio.testdir | $FILTER_LS" \ |
Denis Vlasenko | 0a38bcf | 2008-04-05 02:46:47 +0000 | [diff] [blame] | 40 | "\ |
| 41 | 1 blocks |
| 42 | 0 |
Denis Vlasenko | 687a26f | 2008-05-02 21:46:30 +0000 | [diff] [blame] | 43 | -rw-r--r-- 2 $user $group 0 x |
| 44 | -rw-r--r-- 2 $user $group 0 y |
Denys Vlasenko | d86b4c3 | 2010-06-18 02:00:55 +0200 | [diff] [blame] | 45 | " "" "" |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 46 | SKIP= |
Denis Vlasenko | 0a38bcf | 2008-04-05 02:46:47 +0000 | [diff] [blame] | 47 | |
Denys Vlasenko | 1fbcb80 | 2010-01-10 02:47:32 +0100 | [diff] [blame] | 48 | |
Denys Vlasenko | 6ae6426 | 2009-07-18 16:22:26 +0200 | [diff] [blame] | 49 | test x"$SKIP_KNOWN_BUGS" = x"" && { |
Denys Vlasenko | 398c659 | 2009-05-28 02:03:29 +0200 | [diff] [blame] | 50 | # Currently fails. Numerous buglets: "1 blocks" versus "1 block", |
Matheus Izvekov | 4640ccc | 2010-04-26 13:53:57 +0200 | [diff] [blame] | 51 | # does not list cpio.testdir/x and cpio.testdir/y |
Denis Vlasenko | 0a38bcf | 2008-04-05 02:46:47 +0000 | [diff] [blame] | 52 | testing "cpio lists hardlinks" \ |
Denis Vlasenko | 29ec0b9 | 2008-07-11 21:43:11 +0000 | [diff] [blame] | 53 | "$ECHO -ne '$hexdump' | bzcat | cpio -t 2>&1; echo \$?" \ |
Denis Vlasenko | 0a38bcf | 2008-04-05 02:46:47 +0000 | [diff] [blame] | 54 | "\ |
Denis Vlasenko | 0a38bcf | 2008-04-05 02:46:47 +0000 | [diff] [blame] | 55 | cpio.testdir |
| 56 | cpio.testdir/x |
| 57 | cpio.testdir/y |
Denys Vlasenko | af1c8e8 | 2010-01-05 04:43:21 +0100 | [diff] [blame] | 58 | 1 blocks |
Denis Vlasenko | 0a38bcf | 2008-04-05 02:46:47 +0000 | [diff] [blame] | 59 | 0 |
Denys Vlasenko | d86b4c3 | 2010-06-18 02:00:55 +0200 | [diff] [blame] | 60 | " "" "" |
Denys Vlasenko | 6ae6426 | 2009-07-18 16:22:26 +0200 | [diff] [blame] | 61 | } |
Denis Vlasenko | 0a38bcf | 2008-04-05 02:46:47 +0000 | [diff] [blame] | 62 | |
Denys Vlasenko | 1fbcb80 | 2010-01-10 02:47:32 +0100 | [diff] [blame] | 63 | |
Denis Vlasenko | 29ec0b9 | 2008-07-11 21:43:11 +0000 | [diff] [blame] | 64 | # More complex case |
| 65 | rm -rf cpio.testdir cpio.testdir2 2>/dev/null |
| 66 | mkdir cpio.testdir |
| 67 | touch cpio.testdir/solo |
| 68 | touch cpio.testdir/empty |
| 69 | echo x >cpio.testdir/nonempty |
| 70 | ln cpio.testdir/empty cpio.testdir/empty1 |
| 71 | ln cpio.testdir/nonempty cpio.testdir/nonempty1 |
| 72 | mkdir cpio.testdir2 |
| 73 | |
Denys Vlasenko | c0211e9 | 2010-05-11 04:32:04 +0200 | [diff] [blame] | 74 | optional FEATURE_CPIO_O LONG_OPTS FEATURE_LS_SORTFILES FEATURE_LS_TIMESTAMPS |
Denis Vlasenko | 29ec0b9 | 2008-07-11 21:43:11 +0000 | [diff] [blame] | 75 | testing "cpio extracts zero-sized hardlinks 2" \ |
Matheus Izvekov | 4640ccc | 2010-04-26 13:53:57 +0200 | [diff] [blame] | 76 | "find cpio.testdir | cpio -H newc --create | (cd cpio.testdir2 && cpio -i 2>&1); echo \$?; |
Denis Vlasenko | 29ec0b9 | 2008-07-11 21:43:11 +0000 | [diff] [blame] | 77 | ls -ln cpio.testdir2/cpio.testdir | $FILTER_LS" \ |
| 78 | "\ |
Denys Vlasenko | 398c659 | 2009-05-28 02:03:29 +0200 | [diff] [blame] | 79 | 2 blocks |
Denis Vlasenko | 29ec0b9 | 2008-07-11 21:43:11 +0000 | [diff] [blame] | 80 | 0 |
| 81 | -rw-r--r-- 2 $user $group 0 empty |
| 82 | -rw-r--r-- 2 $user $group 0 empty1 |
| 83 | -rw-r--r-- 2 $user $group 2 nonempty |
| 84 | -rw-r--r-- 2 $user $group 2 nonempty1 |
| 85 | -rw-r--r-- 1 $user $group 0 solo |
Denys Vlasenko | d86b4c3 | 2010-06-18 02:00:55 +0200 | [diff] [blame] | 86 | " "" "" |
Denys Vlasenko | ff0e875 | 2010-05-10 04:16:43 +0200 | [diff] [blame] | 87 | SKIP= |
Denis Vlasenko | 29ec0b9 | 2008-07-11 21:43:11 +0000 | [diff] [blame] | 88 | |
Denys Vlasenko | 1fbcb80 | 2010-01-10 02:47:32 +0100 | [diff] [blame] | 89 | # Was trying to create "/usr/bin", correct is "usr/bin". |
| 90 | rm -rf cpio.testdir |
Denys Vlasenko | ff0e875 | 2010-05-10 04:16:43 +0200 | [diff] [blame] | 91 | optional FEATURE_CPIO_P |
Denys Vlasenko | 1fbcb80 | 2010-01-10 02:47:32 +0100 | [diff] [blame] | 92 | testing "cpio -p with absolute paths" \ |
Matheus Izvekov | 4640ccc | 2010-04-26 13:53:57 +0200 | [diff] [blame] | 93 | "echo /usr/bin | cpio -dp cpio.testdir 2>&1; echo \$?; |
Denys Vlasenko | 1fbcb80 | 2010-01-10 02:47:32 +0100 | [diff] [blame] | 94 | ls cpio.testdir" \ |
| 95 | "\ |
| 96 | 1 blocks |
| 97 | 0 |
| 98 | usr |
Denys Vlasenko | d86b4c3 | 2010-06-18 02:00:55 +0200 | [diff] [blame] | 99 | " "" "" |
| 100 | SKIP= |
| 101 | |
Denys Vlasenko | 0f022c0 | 2010-06-18 12:28:05 +0200 | [diff] [blame] | 102 | # chown on a link was affecting file, dropping its suid/sgid bits |
Denys Vlasenko | d86b4c3 | 2010-06-18 02:00:55 +0200 | [diff] [blame] | 103 | rm -rf cpio.testdir |
Denys Vlasenko | 9297dbc | 2010-07-05 21:37:12 +0200 | [diff] [blame] | 104 | optional FEATURE_CPIO_O FEATURE_STAT_FORMAT |
Denys Vlasenko | d86b4c3 | 2010-06-18 02:00:55 +0200 | [diff] [blame] | 105 | mkdir cpio.testdir |
| 106 | touch cpio.testdir/file |
Denys Vlasenko | 0f022c0 | 2010-06-18 12:28:05 +0200 | [diff] [blame] | 107 | chmod 6755 cpio.testdir/file # sets suid/sgid bits |
Denys Vlasenko | d86b4c3 | 2010-06-18 02:00:55 +0200 | [diff] [blame] | 108 | ln -sf file cpio.testdir/link |
Denys Vlasenko | 0f022c0 | 2010-06-18 12:28:05 +0200 | [diff] [blame] | 109 | testing "cpio restores suid/sgid bits" \ |
Denys Vlasenko | d86b4c3 | 2010-06-18 02:00:55 +0200 | [diff] [blame] | 110 | "cd cpio.testdir && { echo file; echo link; } | cpio -ovHnewc >pack.cpio && rm ???? && cpio -idmvu <pack.cpio 2>/dev/null; |
| 111 | stat -c '%a %n' file" \ |
| 112 | "\ |
| 113 | file |
| 114 | link |
| 115 | 6755 file |
| 116 | " "" "" |
Denys Vlasenko | ff0e875 | 2010-05-10 04:16:43 +0200 | [diff] [blame] | 117 | SKIP= |
Denys Vlasenko | 1fbcb80 | 2010-01-10 02:47:32 +0100 | [diff] [blame] | 118 | |
Pascal Bellard | 873bb31 | 2010-10-18 00:54:51 +0200 | [diff] [blame] | 119 | # avoid 'not created: newer or same age file exists' message for directories |
| 120 | rm -rf cpio.testdir cpio.testdir2 2>/dev/null |
| 121 | mkdir cpio.testdir |
| 122 | testing "cpio extracts in existing directory" \ |
| 123 | "$ECHO -ne '$hexdump' | bzcat | cpio -id 2>&1; echo \$?" \ |
| 124 | "\ |
| 125 | 1 blocks |
| 126 | 0 |
| 127 | " "" "" |
| 128 | SKIP= |
Denys Vlasenko | 1fbcb80 | 2010-01-10 02:47:32 +0100 | [diff] [blame] | 129 | |
Denys Vlasenko | 52ae098 | 2016-12-12 09:26:16 +0100 | [diff] [blame] | 130 | optional FEATURE_CPIO_O |
Aaro Koskinen | 46443a3 | 2016-11-03 00:25:05 +0200 | [diff] [blame] | 131 | testing "cpio uses by default uid/gid" \ |
Denys Vlasenko | 5fa5c4b | 2020-06-23 21:28:19 +0200 | [diff] [blame] | 132 | "echo $0 | cpio -o -H newc | cpio -tv 2>&1 | head -n1 | awk ' { print \$2 } '; echo \$?" \ |
Aaro Koskinen | 46443a3 | 2016-11-03 00:25:05 +0200 | [diff] [blame] | 133 | "\ |
| 134 | $user/$group |
| 135 | 0 |
| 136 | " "" "" |
| 137 | SKIP= |
| 138 | |
Denys Vlasenko | 52ae098 | 2016-12-12 09:26:16 +0100 | [diff] [blame] | 139 | optional FEATURE_CPIO_O |
Aaro Koskinen | 46443a3 | 2016-11-03 00:25:05 +0200 | [diff] [blame] | 140 | testing "cpio -R with create" \ |
Denys Vlasenko | 5fa5c4b | 2020-06-23 21:28:19 +0200 | [diff] [blame] | 141 | "echo $0 | cpio -o -H newc -R 1234:5678 | cpio -tv 2>&1 | head -n1 | awk ' { print \$2 } '; echo \$?" \ |
Aaro Koskinen | 46443a3 | 2016-11-03 00:25:05 +0200 | [diff] [blame] | 142 | "\ |
| 143 | 1234/5678 |
| 144 | 0 |
| 145 | " "" "" |
| 146 | SKIP= |
| 147 | |
Denys Vlasenko | 52ae098 | 2016-12-12 09:26:16 +0100 | [diff] [blame] | 148 | optional FEATURE_CPIO_O |
Aaro Koskinen | 46443a3 | 2016-11-03 00:25:05 +0200 | [diff] [blame] | 149 | testing "cpio -R with extract" \ |
Denys Vlasenko | 5fa5c4b | 2020-06-23 21:28:19 +0200 | [diff] [blame] | 150 | "echo $0 | cpio -o -H newc | cpio -tv -R 8765:4321 2>&1 | head -n1 | awk ' { print \$2 } '; echo \$?" \ |
Aaro Koskinen | 46443a3 | 2016-11-03 00:25:05 +0200 | [diff] [blame] | 151 | "\ |
| 152 | 8765/4321 |
| 153 | 0 |
| 154 | " "" "" |
| 155 | SKIP= |
| 156 | |
Denis Vlasenko | 29ec0b9 | 2008-07-11 21:43:11 +0000 | [diff] [blame] | 157 | # Clean up |
| 158 | rm -rf cpio.testdir cpio.testdir2 2>/dev/null |
Denis Vlasenko | 0a38bcf | 2008-04-05 02:46:47 +0000 | [diff] [blame] | 159 | |
| 160 | exit $FAILCOUNT |