summaryrefslogtreecommitdiff
path: root/testsuite/cpio.tests
blob: b4c41dd9aa766a45f8ab970e5295e5f6a3979581 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/sh
# Copyright 2008 by Denys Vlasenko
# Licensed under GPL v2, see file LICENSE for details.

. ./testing.sh

# ls -ln shows date. Need to remove that, it's variable.
# sed: coalesce spaces
# cut: remove date
# grep: remove "total NNN" lines
FILTER_LS="sed 's/  */ /g' | cut -d' ' -f 1-5,9- | grep -v '^total '"


# newc cpio archive of directory cpio.testdir with empty x and y hardlinks
hexdump="\
\x42\x5a\x68\x39\x31\x41\x59\x26\x53\x59\x64\x1e\x91\x8c\x00\x00\
\x48\x7f\x80\x4c\x48\x08\x00\x28\x01\xff\xe0\x3f\x24\x14\x00\x0e\
\x20\xdc\x60\x20\x00\x92\x11\xea\xa0\x1a\x00\x00\x00\x03\x20\x8a\
\x93\xd4\x9a\x68\x1a\x0d\x1e\x91\xa1\xa0\x06\x98\xe3\x5c\x2f\xd9\
\x26\xa1\x25\x24\x20\xed\x47\xc7\x21\x40\x2b\x6e\xf2\xe6\xfe\x98\
\x13\x68\xa8\xbd\x82\xb2\x4f\x26\x02\x24\x16\x5b\x22\x16\x72\x74\
\x15\xcd\xc1\xa6\x9e\xa6\x5e\x6c\x16\x37\x35\x01\x99\xc4\x81\x21\
\x29\x28\x4b\x69\x51\xa9\x3c\x1a\x9b\x0a\xe1\xe4\xb4\xaf\x85\x73\
\xba\x23\x10\x59\xe8\xb3\xe1\xa1\x63\x05\x8c\x4f\xc5\xdc\x91\x4e\
\x14\x24\x19\x07\xa4\x63\x00"

user=$(id -u)
group=$(id -g)

rm -rf cpio.testdir cpio.testdir2 2>/dev/null

# testing "test name" "command" "expected result" "file input" "stdin"

testing "cpio extracts zero-sized hardlinks" \
"$ECHO -ne '$hexdump' | bzcat | cpio -i 2>&1; echo \$?;
ls -ln cpio.testdir | $FILTER_LS" \
"\
1 blocks
0
-rw-r--r-- 2 $user $group 0 x
-rw-r--r-- 2 $user $group 0 y
" \
	"" ""


test x"$SKIP_KNOWN_BUGS" = x"" && {
# Currently fails. Numerous buglets: "1 blocks" versus "1 block",
# does not list cpio.testdir/x and cpio.testdir/y
testing "cpio lists hardlinks" \
"$ECHO -ne '$hexdump' | bzcat | cpio -t 2>&1; echo \$?" \
"\
cpio.testdir
cpio.testdir/x
cpio.testdir/y
1 blocks
0
" \
	"" ""
}


# More complex case
rm -rf cpio.testdir cpio.testdir2 2>/dev/null
mkdir cpio.testdir
touch cpio.testdir/solo
touch cpio.testdir/empty
echo x >cpio.testdir/nonempty
ln cpio.testdir/empty cpio.testdir/empty1
ln cpio.testdir/nonempty cpio.testdir/nonempty1
mkdir cpio.testdir2

optional FEATURE_CPIO_O LONG_OPTS
testing "cpio extracts zero-sized hardlinks 2" \
"find cpio.testdir | cpio -H newc --create | (cd cpio.testdir2 && cpio -i 2>&1); echo \$?;
ls -ln cpio.testdir2/cpio.testdir | $FILTER_LS" \
"\
2 blocks
0
-rw-r--r-- 2 $user $group 0 empty
-rw-r--r-- 2 $user $group 0 empty1
-rw-r--r-- 2 $user $group 2 nonempty
-rw-r--r-- 2 $user $group 2 nonempty1
-rw-r--r-- 1 $user $group 0 solo
" \
	"" ""
SKIP=


# Was trying to create "/usr/bin", correct is "usr/bin".
rm -rf cpio.testdir
optional FEATURE_CPIO_P
testing "cpio -p with absolute paths" \
"echo /usr/bin | cpio -dp cpio.testdir 2>&1; echo \$?;
ls cpio.testdir" \
"\
1 blocks
0
usr
" \
	"" ""
SKIP=


# Clean up
rm -rf cpio.testdir cpio.testdir2 2>/dev/null

exit $FAILCOUNT