t_tar.sh revision 1.3 1 1.3 rillig # $NetBSD: t_tar.sh,v 1.3 2024/04/28 07:27:40 rillig Exp $
2 1.1 jruoho #
3 1.1 jruoho # Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
4 1.1 jruoho # All rights reserved.
5 1.1 jruoho #
6 1.1 jruoho # Redistribution and use in source and binary forms, with or without
7 1.1 jruoho # modification, are permitted provided that the following conditions
8 1.1 jruoho # are met:
9 1.1 jruoho # 1. Redistributions of source code must retain the above copyright
10 1.1 jruoho # notice, this list of conditions and the following disclaimer.
11 1.1 jruoho # 2. Redistributions in binary form must reproduce the above copyright
12 1.1 jruoho # notice, this list of conditions and the following disclaimer in the
13 1.1 jruoho # documentation and/or other materials provided with the distribution.
14 1.1 jruoho #
15 1.1 jruoho # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 1.1 jruoho # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 1.1 jruoho # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 1.1 jruoho # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 1.1 jruoho # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 1.1 jruoho # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 1.1 jruoho # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 1.1 jruoho # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.1 jruoho # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 1.1 jruoho # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1 jruoho # POSSIBILITY OF SUCH DAMAGE.
26 1.1 jruoho #
27 1.1 jruoho
28 1.1 jruoho atf_test_case append
29 1.1 jruoho append_head() {
30 1.1 jruoho atf_set "descr" "Ensure that appending a file to an archive" \
31 1.1 jruoho "produces the same results as if the file" \
32 1.1 jruoho "had been there during the archive's creation"
33 1.1 jruoho }
34 1.1 jruoho append_body() {
35 1.1 jruoho touch foo bar
36 1.1 jruoho
37 1.1 jruoho # store both foo and bar into file1.tar
38 1.3 rillig atf_check -s exit:0 -o empty -e empty tar -cf file1.tar foo bar
39 1.1 jruoho
40 1.1 jruoho # store foo into file2.tar, then append bar to file2.tar
41 1.3 rillig atf_check -s exit:0 -o empty -e empty tar -cf file2.tar foo
42 1.3 rillig atf_check -s exit:0 -o empty -e empty tar -rf file2.tar bar
43 1.1 jruoho
44 1.1 jruoho # ensure that file1.tar and file2.tar are equal
45 1.3 rillig atf_check -s exit:0 -o empty -e empty cmp file1.tar file2.tar
46 1.1 jruoho }
47 1.1 jruoho
48 1.2 christos atf_test_case rd_base256_size
49 1.2 christos rd_base256_size_head() {
50 1.2 christos atf_set "descr" "Test extracting an archive whose member size" \
51 1.2 christos "is encoded as base-256 number (GNU style)"
52 1.2 christos }
53 1.2 christos rd_base256_size_body() {
54 1.2 christos # prepare random file data for comparison
55 1.2 christos # take 0x1200CF bytes in order to test that we:
56 1.2 christos # - handle multiple bytes of size field correctly
57 1.2 christos # - do not fail on NUL bytes
58 1.2 christos # - do not fail on char values > 0x80 (with signed char)
59 1.2 christos dd if=/dev/urandom of=reference.bin bs=1179855 count=1
60 1.2 christos # write test archive header
61 1.2 christos # - filename
62 1.2 christos printf 'output.bin' > test.tar
63 1.2 christos # - pad to 100 octets
64 1.2 christos head -c 90 /dev/zero >> test.tar
65 1.2 christos # - mode, uid, gid
66 1.2 christos printf '%07d\0%07d\0%07d\0' 644 177776 177775 >> test.tar
67 1.2 christos # - size (base-256)
68 1.2 christos printf '\x80\0\0\0\0\0\0\0\0\x12\x00\xCF' >> test.tar
69 1.2 christos # - timestamp, checksum
70 1.2 christos printf '%011d\0%06d\0 0' 13377546642 12460 >> test.tar
71 1.2 christos # - pad empty linkname (100 octets)
72 1.2 christos head -c 100 /dev/zero >> test.tar
73 1.2 christos # - magic, user name
74 1.2 christos printf 'ustar \0nobody' >> test.tar
75 1.2 christos # - pad user name field to 32 bytes
76 1.2 christos head -c 26 /dev/zero >> test.tar
77 1.2 christos # - group name
78 1.2 christos printf 'nogroup' >> test.tar
79 1.2 christos # - pad to full block
80 1.2 christos head -c 208 /dev/zero >> test.tar
81 1.2 christos # append file data to the test archive
82 1.2 christos cat reference.bin >> test.tar
83 1.2 christos # pad to full block + append two terminating null blocks
84 1.2 christos head -c 1450 /dev/zero >> test.tar
85 1.2 christos
86 1.2 christos # test extracting the test archive
87 1.3 rillig atf_check -s exit:0 -o empty -e empty tar -xf test.tar
88 1.2 christos
89 1.2 christos # ensure that output.bin is equal to reference.bin
90 1.3 rillig atf_check -s exit:0 -o empty -e empty cmp output.bin reference.bin
91 1.2 christos }
92 1.2 christos
93 1.1 jruoho atf_init_test_cases()
94 1.1 jruoho {
95 1.1 jruoho atf_add_test_case append
96 1.2 christos atf_add_test_case rd_base256_size
97 1.1 jruoho }
98