1 # $NetBSD: t_gzip.sh,v 1.4 2024/10/15 18:09:31 martin Exp $ 2 # 3 # Copyright (c) 2008 The NetBSD Foundation, Inc. 4 # All rights reserved. 5 # 6 # Redistribution and use in source and binary forms, with or without 7 # modification, are permitted provided that the following conditions 8 # are met: 9 # 1. Redistributions of source code must retain the above copyright 10 # notice, this list of conditions and the following disclaimer. 11 # 2. Redistributions in binary form must reproduce the above copyright 12 # notice, this list of conditions and the following disclaimer in the 13 # documentation and/or other materials provided with the distribution. 14 # 15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 # POSSIBILITY OF SUCH DAMAGE. 26 # 27 28 atf_test_case concatenated 29 concatenated_head() 30 { 31 atf_set "descr" "Checks concatenated gzipped data" 32 } 33 concatenated_body() 34 { 35 echo -n "aaaa" | gzip > tmp.gz 36 echo -n "bbbb" | gzip >> tmp.gz 37 38 atf_check -o inline:"aaaabbbb" gzip -d tmp.gz -c 39 } 40 41 atf_test_case pipe 42 pipe_head() 43 { 44 atf_set "descr" "Checks input from pipe" 45 } 46 pipe_body() 47 { 48 atf_check -x "dd if=/dev/zero count=102400 2>/dev/null \ 49 | gzip -c | dd bs=1 2>/dev/null | gzip -tc" 50 } 51 52 atf_test_case truncated 53 truncated_head() 54 { 55 atf_set "descr" "Checks that gzip fails on truncated data" 56 } 57 truncated_body() 58 { 59 cat >truncated.gz.uue <<EOF 60 begin-base64 644 truncated.gz 61 H4sIAAAAAAAAA0tMSk7hAgCspIpYCg== 62 ==== 63 EOF 64 uudecode -m truncated.gz.uue 65 66 atf_check -s ne:0 -e ignore gzip -d truncated.gz 67 } 68 69 atf_test_case crcerror 70 crcerror_head() 71 { 72 atf_set "descr" "Checks that gzip fails on crc error" 73 } 74 crcerror_body() 75 { 76 cat >crcerror.gz.uue <<EOF 77 begin-base64 644 crcerror.gz 78 H4sIAAAAAAAAA0tMSk7hAgCspFhYBQAAAA== 79 ==== 80 EOF 81 uudecode -m crcerror.gz.uue 82 83 atf_check -s ne:0 -e ignore gzip -d crcerror.gz 84 } 85 86 atf_test_case good 87 good_head() 88 { 89 atf_set "descr" "Checks decompressing correct file" 90 } 91 good_body() 92 { 93 cat >good.gz.uue <<EOF 94 begin-base64 644 good.gz 95 H4sICC8G8UAAA2FiY2QAS0xKTuECAKykilgFAAAA 96 ==== 97 EOF 98 uudecode -m good.gz.uue 99 100 atf_check gzip -d good.gz 101 } 102 103 atf_test_case lzip 104 lzip_head() 105 { 106 atf_set "descr" "Checks lzip compression levels (PR/58223)" 107 atf_set "require.progs" "lzip" 108 } 109 lzip_body() 110 { 111 n=net_tests.tar 112 tar -C /usr/tests/net -cf $n . 113 for i in $(jot 10 0 9); do 114 f=$n.$i.lz 115 lzip -$ic < $n > $f 116 gunzip -t $f > /dev/null 117 done 118 } 119 120 atf_init_test_cases() 121 { 122 atf_add_test_case concatenated 123 atf_add_test_case pipe 124 atf_add_test_case truncated 125 atf_add_test_case crcerror 126 atf_add_test_case good 127 atf_add_test_case lzip 128 } 129