1*d8f5b04cSrillig# $NetBSD: t_tar.sh,v 1.3 2024/04/28 07:27:40 rillig Exp $ 228604916Sjruoho# 328604916Sjruoho# Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. 428604916Sjruoho# All rights reserved. 528604916Sjruoho# 628604916Sjruoho# Redistribution and use in source and binary forms, with or without 728604916Sjruoho# modification, are permitted provided that the following conditions 828604916Sjruoho# are met: 928604916Sjruoho# 1. Redistributions of source code must retain the above copyright 1028604916Sjruoho# notice, this list of conditions and the following disclaimer. 1128604916Sjruoho# 2. Redistributions in binary form must reproduce the above copyright 1228604916Sjruoho# notice, this list of conditions and the following disclaimer in the 1328604916Sjruoho# documentation and/or other materials provided with the distribution. 1428604916Sjruoho# 1528604916Sjruoho# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1628604916Sjruoho# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1728604916Sjruoho# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1828604916Sjruoho# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 1928604916Sjruoho# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2028604916Sjruoho# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2128604916Sjruoho# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2228604916Sjruoho# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2328604916Sjruoho# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2428604916Sjruoho# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2528604916Sjruoho# POSSIBILITY OF SUCH DAMAGE. 2628604916Sjruoho# 2728604916Sjruoho 2828604916Sjruohoatf_test_case append 2928604916Sjruohoappend_head() { 3028604916Sjruoho atf_set "descr" "Ensure that appending a file to an archive" \ 3128604916Sjruoho "produces the same results as if the file" \ 3228604916Sjruoho "had been there during the archive's creation" 3328604916Sjruoho} 3428604916Sjruohoappend_body() { 3528604916Sjruoho touch foo bar 3628604916Sjruoho 3728604916Sjruoho # store both foo and bar into file1.tar 38*d8f5b04cSrillig atf_check -s exit:0 -o empty -e empty tar -cf file1.tar foo bar 3928604916Sjruoho 4028604916Sjruoho # store foo into file2.tar, then append bar to file2.tar 41*d8f5b04cSrillig atf_check -s exit:0 -o empty -e empty tar -cf file2.tar foo 42*d8f5b04cSrillig atf_check -s exit:0 -o empty -e empty tar -rf file2.tar bar 4328604916Sjruoho 4428604916Sjruoho # ensure that file1.tar and file2.tar are equal 45*d8f5b04cSrillig atf_check -s exit:0 -o empty -e empty cmp file1.tar file2.tar 4628604916Sjruoho} 4728604916Sjruoho 4890de0732Schristosatf_test_case rd_base256_size 4990de0732Schristosrd_base256_size_head() { 5090de0732Schristos atf_set "descr" "Test extracting an archive whose member size" \ 5190de0732Schristos "is encoded as base-256 number (GNU style)" 5290de0732Schristos} 5390de0732Schristosrd_base256_size_body() { 5490de0732Schristos # prepare random file data for comparison 5590de0732Schristos # take 0x1200CF bytes in order to test that we: 5690de0732Schristos # - handle multiple bytes of size field correctly 5790de0732Schristos # - do not fail on NUL bytes 5890de0732Schristos # - do not fail on char values > 0x80 (with signed char) 5990de0732Schristos dd if=/dev/urandom of=reference.bin bs=1179855 count=1 6090de0732Schristos # write test archive header 6190de0732Schristos # - filename 6290de0732Schristos printf 'output.bin' > test.tar 6390de0732Schristos # - pad to 100 octets 6490de0732Schristos head -c 90 /dev/zero >> test.tar 6590de0732Schristos # - mode, uid, gid 6690de0732Schristos printf '%07d\0%07d\0%07d\0' 644 177776 177775 >> test.tar 6790de0732Schristos # - size (base-256) 6890de0732Schristos printf '\x80\0\0\0\0\0\0\0\0\x12\x00\xCF' >> test.tar 6990de0732Schristos # - timestamp, checksum 7090de0732Schristos printf '%011d\0%06d\0 0' 13377546642 12460 >> test.tar 7190de0732Schristos # - pad empty linkname (100 octets) 7290de0732Schristos head -c 100 /dev/zero >> test.tar 7390de0732Schristos # - magic, user name 7490de0732Schristos printf 'ustar \0nobody' >> test.tar 7590de0732Schristos # - pad user name field to 32 bytes 7690de0732Schristos head -c 26 /dev/zero >> test.tar 7790de0732Schristos # - group name 7890de0732Schristos printf 'nogroup' >> test.tar 7990de0732Schristos # - pad to full block 8090de0732Schristos head -c 208 /dev/zero >> test.tar 8190de0732Schristos # append file data to the test archive 8290de0732Schristos cat reference.bin >> test.tar 8390de0732Schristos # pad to full block + append two terminating null blocks 8490de0732Schristos head -c 1450 /dev/zero >> test.tar 8590de0732Schristos 8690de0732Schristos # test extracting the test archive 87*d8f5b04cSrillig atf_check -s exit:0 -o empty -e empty tar -xf test.tar 8890de0732Schristos 8990de0732Schristos # ensure that output.bin is equal to reference.bin 90*d8f5b04cSrillig atf_check -s exit:0 -o empty -e empty cmp output.bin reference.bin 9190de0732Schristos} 9290de0732Schristos 9328604916Sjruohoatf_init_test_cases() 9428604916Sjruoho{ 9528604916Sjruoho atf_add_test_case append 9690de0732Schristos atf_add_test_case rd_base256_size 9728604916Sjruoho} 98