diff options
| author | rillig <rillig@NetBSD.org> | 2022-05-22 17:55:08 +0000 |
|---|---|---|
| committer | rillig <rillig@NetBSD.org> | 2022-05-22 17:55:08 +0000 |
| commit | 18877136ad0816a7170cc2aed092aa79bcd3a449 (patch) | |
| tree | d9e6f67d099849f0cb6c0119aad7ae81e005f4c1 | |
| parent | 6bd5a954ba66a738f48d8f4a751ed537cf3ff8c7 (diff) | |
tests/compress: demonstrate truncation of target file
Reported by Giorgos Keramidas in PR#19722.
| -rw-r--r-- | distrib/sets/lists/tests/mi | 5 | ||||
| -rw-r--r-- | etc/mtree/NetBSD.dist.tests | 3 | ||||
| -rw-r--r-- | tests/usr.bin/Makefile | 4 | ||||
| -rw-r--r-- | tests/usr.bin/compress/Makefile | 7 | ||||
| -rw-r--r-- | tests/usr.bin/compress/t_pr_19722.sh | 89 |
5 files changed, 104 insertions, 4 deletions
diff --git a/distrib/sets/lists/tests/mi b/distrib/sets/lists/tests/mi index 5ef6f6faa6c..ee7d369384c 100644 --- a/distrib/sets/lists/tests/mi +++ b/distrib/sets/lists/tests/mi @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1205 2022/05/12 20:49:21 rillig Exp $ +# $NetBSD: mi,v 1.1206 2022/05/22 17:55:08 rillig Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -4629,6 +4629,9 @@ ./usr/tests/usr.bin/col/rlf2.in tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/col/rlf3.in tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/col/t_col tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/compress tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/compress/Atffile tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/compress/t_pr_19722 tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/config tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/config/Atffile tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/config/Kyuafile tests-usr.bin-tests compattestfile,atf,kyua diff --git a/etc/mtree/NetBSD.dist.tests b/etc/mtree/NetBSD.dist.tests index 89824fd7a5b..361f48999c2 100644 --- a/etc/mtree/NetBSD.dist.tests +++ b/etc/mtree/NetBSD.dist.tests @@ -1,4 +1,4 @@ -# $NetBSD: NetBSD.dist.tests,v 1.191 2022/04/29 22:17:50 pgoyette Exp $ +# $NetBSD: NetBSD.dist.tests,v 1.192 2022/05/22 17:55:08 rillig Exp $ ./usr/libdata/debug/usr/tests ./usr/libdata/debug/usr/tests/atf @@ -429,6 +429,7 @@ ./usr/tests/usr.bin/config/support/arch/regress/conf ./usr/tests/usr.bin/config/support/conf ./usr/tests/usr.bin/cpio +./usr/tests/usr.bin/compress ./usr/tests/usr.bin/cut ./usr/tests/usr.bin/diff ./usr/tests/usr.bin/dirname diff --git a/tests/usr.bin/Makefile b/tests/usr.bin/Makefile index 583782452ec..7818237165b 100644 --- a/tests/usr.bin/Makefile +++ b/tests/usr.bin/Makefile @@ -1,11 +1,11 @@ -# $NetBSD: Makefile,v 1.35 2021/10/12 17:24:36 nia Exp $ +# $NetBSD: Makefile,v 1.36 2022/05/22 17:55:08 rillig Exp $ # .include <bsd.own.mk> TESTSDIR= ${TESTSBASE}/usr.bin -TESTS_SUBDIRS= awk basename bzip2 cc cmp config cpio col cut \ +TESTS_SUBDIRS= awk basename bzip2 cc cmp compress config cpio col cut \ diff dirname find fstat gdb grep gzip id indent \ infocmp jot ld locale m4 make mixerctl mkdep nbperf \ netpgpverify patch pkill pr printf pwhash rump_server \ diff --git a/tests/usr.bin/compress/Makefile b/tests/usr.bin/compress/Makefile new file mode 100644 index 00000000000..465b5c2c59f --- /dev/null +++ b/tests/usr.bin/compress/Makefile @@ -0,0 +1,7 @@ +# $NetBSD: Makefile,v 1.1 2022/05/22 17:55:08 rillig Exp $ + +TESTSDIR= ${TESTSBASE}/usr.bin/compress + +TESTS_SH= t_pr_19722 + +.include <bsd.test.mk> diff --git a/tests/usr.bin/compress/t_pr_19722.sh b/tests/usr.bin/compress/t_pr_19722.sh new file mode 100644 index 00000000000..30f84d50453 --- /dev/null +++ b/tests/usr.bin/compress/t_pr_19722.sh @@ -0,0 +1,89 @@ +# $NetBSD: t_pr_19722.sh,v 1.1 2022/05/22 17:55:08 rillig Exp $ +# +# Copyright (c) 2022 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +# https://gnats.netbsd.org/19722 +# +# Before TODO:rev from TODO:date, trying to uncompress a nonexistent or +# malformed source file resulted in a truncated target file. + + +atf_test_case 'no_source_no_target' +no_source_no_target_body() +{ + + atf_check \ + -s 'not-exit:0' \ + -e 'inline:uncompress: file.Z: No such file or directory\n' \ + uncompress -f 'file' + + # FIXME: The target file must not be created. + atf_check cat 'file' + atf_check test ! -f 'nonexistent.Z' +} + + +atf_test_case 'no_source_existing_target' +no_source_existing_target_body() +{ + + echo 'before' > 'file' + + atf_check \ + -s 'not-exit:0' \ + -e 'inline:uncompress: file.Z: No such file or directory\n' \ + uncompress -f 'file' + + # FIXME: The target file must not be truncated. + atf_check cat 'file' +} + + +atf_test_case 'broken_source_existing_target' +broken_source_existing_target_body() +{ + # If the source file is not compressed, preserve the target file. + + echo 'broken' > 'file.Z' + echo 'before' > 'file' + + atf_check \ + -s 'not-exit:0' \ + -e 'inline:uncompress: file.Z: Inappropriate file type or format\n' \ + uncompress -f 'file.Z' + + # FIXME: Must not be removed, must not be truncated. + atf_check test ! -f 'file' +} + + +atf_init_test_cases() +{ + + atf_add_test_case no_source_no_target + atf_add_test_case no_source_existing_target + atf_add_test_case broken_source_existing_target +} |
