blob: 7aee774a1d7517d76c674faca302d42bc5a79ebf [file] [log] [blame]
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +00001#!/bin/sh
2# Copyright 2008 by Denys Vlasenko
3# Licensed under GPL v2, see file LICENSE for details.
4
Mike Frysingercaa79402009-11-04 18:41:22 -05005. ./testing.sh
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +00006
Denis Vlasenko29ec0b92008-07-11 21:43:11 +00007# ls -ln shows date. Need to remove that, it's variable.
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +00008# sed: coalesce spaces
9# cut: remove date
Denys Vlasenko03f6ee22010-03-28 20:07:42 +020010# grep: remove "total NNN" lines
11FILTER_LS="sed 's/ */ /g' | cut -d' ' -f 1-5,9- | grep -v '^total '"
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000012
13
14# newc cpio archive of directory cpio.testdir with empty x and y hardlinks
15hexdump="\
Denis Vlasenko29ec0b92008-07-11 21:43:11 +000016\x42\x5a\x68\x39\x31\x41\x59\x26\x53\x59\x64\x1e\x91\x8c\x00\x00\
17\x48\x7f\x80\x4c\x48\x08\x00\x28\x01\xff\xe0\x3f\x24\x14\x00\x0e\
18\x20\xdc\x60\x20\x00\x92\x11\xea\xa0\x1a\x00\x00\x00\x03\x20\x8a\
19\x93\xd4\x9a\x68\x1a\x0d\x1e\x91\xa1\xa0\x06\x98\xe3\x5c\x2f\xd9\
20\x26\xa1\x25\x24\x20\xed\x47\xc7\x21\x40\x2b\x6e\xf2\xe6\xfe\x98\
21\x13\x68\xa8\xbd\x82\xb2\x4f\x26\x02\x24\x16\x5b\x22\x16\x72\x74\
22\x15\xcd\xc1\xa6\x9e\xa6\x5e\x6c\x16\x37\x35\x01\x99\xc4\x81\x21\
23\x29\x28\x4b\x69\x51\xa9\x3c\x1a\x9b\x0a\xe1\xe4\xb4\xaf\x85\x73\
24\xba\x23\x10\x59\xe8\xb3\xe1\xa1\x63\x05\x8c\x4f\xc5\xdc\x91\x4e\
25\x14\x24\x19\x07\xa4\x63\x00"
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000026
Denis Vlasenko687a26f2008-05-02 21:46:30 +000027user=$(id -u)
28group=$(id -g)
29
Denis Vlasenko29ec0b92008-07-11 21:43:11 +000030rm -rf cpio.testdir cpio.testdir2 2>/dev/null
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000031
Denis Vlasenko29ec0b92008-07-11 21:43:11 +000032# testing "test name" "command" "expected result" "file input" "stdin"
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000033
Denys Vlasenkoc0211e92010-05-11 04:32:04 +020034optional FEATURE_LS_SORTFILES FEATURE_LS_TIMESTAMPS
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000035testing "cpio extracts zero-sized hardlinks" \
Matheus Izvekov4640ccc2010-04-26 13:53:57 +020036"$ECHO -ne '$hexdump' | bzcat | cpio -i 2>&1; echo \$?;
Denis Vlasenko29ec0b92008-07-11 21:43:11 +000037ls -ln cpio.testdir | $FILTER_LS" \
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000038"\
391 blocks
400
Denis Vlasenko687a26f2008-05-02 21:46:30 +000041-rw-r--r-- 2 $user $group 0 x
42-rw-r--r-- 2 $user $group 0 y
Denys Vlasenkod86b4c32010-06-18 02:00:55 +020043" "" ""
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020044SKIP=
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000045
Denys Vlasenko1fbcb802010-01-10 02:47:32 +010046
Denys Vlasenko6ae64262009-07-18 16:22:26 +020047test x"$SKIP_KNOWN_BUGS" = x"" && {
Denys Vlasenko398c6592009-05-28 02:03:29 +020048# Currently fails. Numerous buglets: "1 blocks" versus "1 block",
Matheus Izvekov4640ccc2010-04-26 13:53:57 +020049# does not list cpio.testdir/x and cpio.testdir/y
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000050testing "cpio lists hardlinks" \
Denis Vlasenko29ec0b92008-07-11 21:43:11 +000051"$ECHO -ne '$hexdump' | bzcat | cpio -t 2>&1; echo \$?" \
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000052"\
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000053cpio.testdir
54cpio.testdir/x
55cpio.testdir/y
Denys Vlasenkoaf1c8e82010-01-05 04:43:21 +0100561 blocks
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +0000570
Denys Vlasenkod86b4c32010-06-18 02:00:55 +020058" "" ""
Denys Vlasenko6ae64262009-07-18 16:22:26 +020059}
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +000060
Denys Vlasenko1fbcb802010-01-10 02:47:32 +010061
Denis Vlasenko29ec0b92008-07-11 21:43:11 +000062# More complex case
63rm -rf cpio.testdir cpio.testdir2 2>/dev/null
64mkdir cpio.testdir
65touch cpio.testdir/solo
66touch cpio.testdir/empty
67echo x >cpio.testdir/nonempty
68ln cpio.testdir/empty cpio.testdir/empty1
69ln cpio.testdir/nonempty cpio.testdir/nonempty1
70mkdir cpio.testdir2
71
Denys Vlasenkoc0211e92010-05-11 04:32:04 +020072optional FEATURE_CPIO_O LONG_OPTS FEATURE_LS_SORTFILES FEATURE_LS_TIMESTAMPS
Denis Vlasenko29ec0b92008-07-11 21:43:11 +000073testing "cpio extracts zero-sized hardlinks 2" \
Matheus Izvekov4640ccc2010-04-26 13:53:57 +020074"find cpio.testdir | cpio -H newc --create | (cd cpio.testdir2 && cpio -i 2>&1); echo \$?;
Denis Vlasenko29ec0b92008-07-11 21:43:11 +000075ls -ln cpio.testdir2/cpio.testdir | $FILTER_LS" \
76"\
Denys Vlasenko398c6592009-05-28 02:03:29 +0200772 blocks
Denis Vlasenko29ec0b92008-07-11 21:43:11 +0000780
79-rw-r--r-- 2 $user $group 0 empty
80-rw-r--r-- 2 $user $group 0 empty1
81-rw-r--r-- 2 $user $group 2 nonempty
82-rw-r--r-- 2 $user $group 2 nonempty1
83-rw-r--r-- 1 $user $group 0 solo
Denys Vlasenkod86b4c32010-06-18 02:00:55 +020084" "" ""
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020085SKIP=
Denis Vlasenko29ec0b92008-07-11 21:43:11 +000086
Denys Vlasenko1fbcb802010-01-10 02:47:32 +010087# Was trying to create "/usr/bin", correct is "usr/bin".
88rm -rf cpio.testdir
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020089optional FEATURE_CPIO_P
Denys Vlasenko1fbcb802010-01-10 02:47:32 +010090testing "cpio -p with absolute paths" \
Matheus Izvekov4640ccc2010-04-26 13:53:57 +020091"echo /usr/bin | cpio -dp cpio.testdir 2>&1; echo \$?;
Denys Vlasenko1fbcb802010-01-10 02:47:32 +010092ls cpio.testdir" \
93"\
941 blocks
950
96usr
Denys Vlasenkod86b4c32010-06-18 02:00:55 +020097" "" ""
98SKIP=
99
Denys Vlasenko0f022c02010-06-18 12:28:05 +0200100# chown on a link was affecting file, dropping its suid/sgid bits
Denys Vlasenkod86b4c32010-06-18 02:00:55 +0200101rm -rf cpio.testdir
Denys Vlasenko9297dbc2010-07-05 21:37:12 +0200102optional FEATURE_CPIO_O FEATURE_STAT_FORMAT
Denys Vlasenkod86b4c32010-06-18 02:00:55 +0200103mkdir cpio.testdir
104touch cpio.testdir/file
Denys Vlasenko0f022c02010-06-18 12:28:05 +0200105chmod 6755 cpio.testdir/file # sets suid/sgid bits
Denys Vlasenkod86b4c32010-06-18 02:00:55 +0200106ln -sf file cpio.testdir/link
Denys Vlasenko0f022c02010-06-18 12:28:05 +0200107testing "cpio restores suid/sgid bits" \
Denys Vlasenkod86b4c32010-06-18 02:00:55 +0200108"cd cpio.testdir && { echo file; echo link; } | cpio -ovHnewc >pack.cpio && rm ???? && cpio -idmvu <pack.cpio 2>/dev/null;
109 stat -c '%a %n' file" \
110"\
111file
112link
1136755 file
114" "" ""
Denys Vlasenkoff0e8752010-05-10 04:16:43 +0200115SKIP=
Denys Vlasenko1fbcb802010-01-10 02:47:32 +0100116
117
Denis Vlasenko29ec0b92008-07-11 21:43:11 +0000118# Clean up
119rm -rf cpio.testdir cpio.testdir2 2>/dev/null
Denis Vlasenko0a38bcf2008-04-05 02:46:47 +0000120
121exit $FAILCOUNT