blob: 85e74658919984528ad03e409132ddeb7cfd3652 [file] [log] [blame]
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +00001#!/bin/sh
2# Copyright 2008 by Denys Vlasenko
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02003# Licensed under GPLv2, see file LICENSE in this source tree.
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +00004
Mike Frysingercaa79402009-11-04 18:41:22 -05005. ./testing.sh
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +00006
Dan Fandrich775965d2010-08-10 23:33:57 -07007umask 022
8
Denis Vlasenko29ec0b92008-07-11 21:43:11 +00009# ls -ln shows date. Need to remove that, it's variable.
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000010# sed: coalesce spaces
11# cut: remove date
Denys Vlasenko03f6ee22010-03-28 20:07:42 +020012# grep: remove "total NNN" lines
13FILTER_LS="sed 's/ */ /g' | cut -d' ' -f 1-5,9- | grep -v '^total '"
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000014
15
16# newc cpio archive of directory cpio.testdir with empty x and y hardlinks
17hexdump="\
Denis Vlasenko29ec0b92008-07-11 21:43:11 +000018\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 Vlasenko0a38bcf2008-04-05 02:46:47 +000028
Denis Vlasenko687a26f2008-05-02 21:46:30 +000029user=$(id -u)
30group=$(id -g)
31
Denis Vlasenko29ec0b92008-07-11 21:43:11 +000032rm -rf cpio.testdir cpio.testdir2 2>/dev/null
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000033
Denis Vlasenko29ec0b92008-07-11 21:43:11 +000034# testing "test name" "command" "expected result" "file input" "stdin"
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000035
Denys Vlasenkoc0211e92010-05-11 04:32:04 +020036optional FEATURE_LS_SORTFILES FEATURE_LS_TIMESTAMPS
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000037testing "cpio extracts zero-sized hardlinks" \
Matheus Izvekov4640ccc2010-04-26 13:53:57 +020038"$ECHO -ne '$hexdump' | bzcat | cpio -i 2>&1; echo \$?;
Denis Vlasenko29ec0b92008-07-11 21:43:11 +000039ls -ln cpio.testdir | $FILTER_LS" \
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000040"\
411 blocks
420
Denis Vlasenko687a26f2008-05-02 21:46:30 +000043-rw-r--r-- 2 $user $group 0 x
44-rw-r--r-- 2 $user $group 0 y
Denys Vlasenkod86b4c32010-06-18 02:00:55 +020045" "" ""
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020046SKIP=
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000047
Denys Vlasenko1fbcb802010-01-10 02:47:32 +010048
Denys Vlasenko6ae64262009-07-18 16:22:26 +020049test x"$SKIP_KNOWN_BUGS" = x"" && {
Denys Vlasenko398c6592009-05-28 02:03:29 +020050# Currently fails. Numerous buglets: "1 blocks" versus "1 block",
Matheus Izvekov4640ccc2010-04-26 13:53:57 +020051# does not list cpio.testdir/x and cpio.testdir/y
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000052testing "cpio lists hardlinks" \
Denis Vlasenko29ec0b92008-07-11 21:43:11 +000053"$ECHO -ne '$hexdump' | bzcat | cpio -t 2>&1; echo \$?" \
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000054"\
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000055cpio.testdir
56cpio.testdir/x
57cpio.testdir/y
Denys Vlasenkoaf1c8e82010-01-05 04:43:21 +0100581 blocks
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +0000590
Denys Vlasenkod86b4c32010-06-18 02:00:55 +020060" "" ""
Denys Vlasenko6ae64262009-07-18 16:22:26 +020061}
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000062
Denys Vlasenko1fbcb802010-01-10 02:47:32 +010063
Denis Vlasenko29ec0b92008-07-11 21:43:11 +000064# More complex case
65rm -rf cpio.testdir cpio.testdir2 2>/dev/null
66mkdir cpio.testdir
67touch cpio.testdir/solo
68touch cpio.testdir/empty
69echo x >cpio.testdir/nonempty
70ln cpio.testdir/empty cpio.testdir/empty1
71ln cpio.testdir/nonempty cpio.testdir/nonempty1
72mkdir cpio.testdir2
73
Denys Vlasenkoc0211e92010-05-11 04:32:04 +020074optional FEATURE_CPIO_O LONG_OPTS FEATURE_LS_SORTFILES FEATURE_LS_TIMESTAMPS
Denis Vlasenko29ec0b92008-07-11 21:43:11 +000075testing "cpio extracts zero-sized hardlinks 2" \
Matheus Izvekov4640ccc2010-04-26 13:53:57 +020076"find cpio.testdir | cpio -H newc --create | (cd cpio.testdir2 && cpio -i 2>&1); echo \$?;
Denis Vlasenko29ec0b92008-07-11 21:43:11 +000077ls -ln cpio.testdir2/cpio.testdir | $FILTER_LS" \
78"\
Denys Vlasenko398c6592009-05-28 02:03:29 +0200792 blocks
Denis Vlasenko29ec0b92008-07-11 21:43:11 +0000800
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 Vlasenkod86b4c32010-06-18 02:00:55 +020086" "" ""
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020087SKIP=
Denis Vlasenko29ec0b92008-07-11 21:43:11 +000088
Denys Vlasenko1fbcb802010-01-10 02:47:32 +010089# Was trying to create "/usr/bin", correct is "usr/bin".
90rm -rf cpio.testdir
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020091optional FEATURE_CPIO_P
Denys Vlasenko1fbcb802010-01-10 02:47:32 +010092testing "cpio -p with absolute paths" \
Matheus Izvekov4640ccc2010-04-26 13:53:57 +020093"echo /usr/bin | cpio -dp cpio.testdir 2>&1; echo \$?;
Denys Vlasenko1fbcb802010-01-10 02:47:32 +010094ls cpio.testdir" \
95"\
961 blocks
970
98usr
Denys Vlasenkod86b4c32010-06-18 02:00:55 +020099" "" ""
100SKIP=
101
Denys Vlasenko0f022c02010-06-18 12:28:05 +0200102# chown on a link was affecting file, dropping its suid/sgid bits
Denys Vlasenkod86b4c32010-06-18 02:00:55 +0200103rm -rf cpio.testdir
Denys Vlasenko9297dbc2010-07-05 21:37:12 +0200104optional FEATURE_CPIO_O FEATURE_STAT_FORMAT
Denys Vlasenkod86b4c32010-06-18 02:00:55 +0200105mkdir cpio.testdir
106touch cpio.testdir/file
Denys Vlasenko0f022c02010-06-18 12:28:05 +0200107chmod 6755 cpio.testdir/file # sets suid/sgid bits
Denys Vlasenkod86b4c32010-06-18 02:00:55 +0200108ln -sf file cpio.testdir/link
Denys Vlasenko0f022c02010-06-18 12:28:05 +0200109testing "cpio restores suid/sgid bits" \
Denys Vlasenkod86b4c32010-06-18 02:00:55 +0200110"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"\
113file
114link
1156755 file
116" "" ""
Denys Vlasenkoff0e8752010-05-10 04:16:43 +0200117SKIP=
Denys Vlasenko1fbcb802010-01-10 02:47:32 +0100118
Pascal Bellard873bb312010-10-18 00:54:51 +0200119# avoid 'not created: newer or same age file exists' message for directories
120rm -rf cpio.testdir cpio.testdir2 2>/dev/null
121mkdir cpio.testdir
122testing "cpio extracts in existing directory" \
123"$ECHO -ne '$hexdump' | bzcat | cpio -id 2>&1; echo \$?" \
124"\
1251 blocks
1260
127" "" ""
128SKIP=
Denys Vlasenko1fbcb802010-01-10 02:47:32 +0100129
Denys Vlasenko52ae0982016-12-12 09:26:16 +0100130optional FEATURE_CPIO_O
Aaro Koskinen46443a32016-11-03 00:25:05 +0200131testing "cpio uses by default uid/gid" \
Denys Vlasenko5fa5c4b2020-06-23 21:28:19 +0200132"echo $0 | cpio -o -H newc | cpio -tv 2>&1 | head -n1 | awk ' { print \$2 } '; echo \$?" \
Aaro Koskinen46443a32016-11-03 00:25:05 +0200133"\
134$user/$group
1350
136" "" ""
137SKIP=
138
Denys Vlasenko52ae0982016-12-12 09:26:16 +0100139optional FEATURE_CPIO_O
Aaro Koskinen46443a32016-11-03 00:25:05 +0200140testing "cpio -R with create" \
Denys Vlasenko5fa5c4b2020-06-23 21:28:19 +0200141"echo $0 | cpio -o -H newc -R 1234:5678 | cpio -tv 2>&1 | head -n1 | awk ' { print \$2 } '; echo \$?" \
Aaro Koskinen46443a32016-11-03 00:25:05 +0200142"\
1431234/5678
1440
145" "" ""
146SKIP=
147
Denys Vlasenko52ae0982016-12-12 09:26:16 +0100148optional FEATURE_CPIO_O
Aaro Koskinen46443a32016-11-03 00:25:05 +0200149testing "cpio -R with extract" \
Denys Vlasenko5fa5c4b2020-06-23 21:28:19 +0200150"echo $0 | cpio -o -H newc | cpio -tv -R 8765:4321 2>&1 | head -n1 | awk ' { print \$2 } '; echo \$?" \
Aaro Koskinen46443a32016-11-03 00:25:05 +0200151"\
1528765/4321
1530
154" "" ""
155SKIP=
156
Denis Vlasenko29ec0b92008-07-11 21:43:11 +0000157# Clean up
158rm -rf cpio.testdir cpio.testdir2 2>/dev/null
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +0000159
160exit $FAILCOUNT