summaryrefslogtreecommitdiff
path: root/regress/usr.bin
diff options
context:
space:
mode:
authorMarco Pfatschbacher <mpf@cvs.openbsd.org>2008-08-20 09:29:52 +0000
committerMarco Pfatschbacher <mpf@cvs.openbsd.org>2008-08-20 09:29:52 +0000
commitae40cc90b11c5d23bc76db88c0fa03ed3dff53bb (patch)
treee3de51d80d107a2ec8c67e1903b299502e2862cf /regress/usr.bin
parent80502d0aae5f4784171090c27164e6c4c1d04253 (diff)
Regression tests for gzip(1):
- Test if we detect truncated or corrupted files. - Test basic functionality OK millert@, markus@
Diffstat (limited to 'regress/usr.bin')
-rw-r--r--regress/usr.bin/Makefile6
-rw-r--r--regress/usr.bin/gzip/Makefile17
-rw-r--r--regress/usr.bin/gzip/t1.sh70
-rw-r--r--regress/usr.bin/gzip/t2.sh39
4 files changed, 129 insertions, 3 deletions
diff --git a/regress/usr.bin/Makefile b/regress/usr.bin/Makefile
index e3811f50c83..9896cf325f6 100644
--- a/regress/usr.bin/Makefile
+++ b/regress/usr.bin/Makefile
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile,v 1.18 2006/03/14 03:57:42 ray Exp $
+# $OpenBSD: Makefile,v 1.19 2008/08/20 09:29:51 mpf Exp $
# $NetBSD: Makefile,v 1.1 1997/12/30 23:27:11 cgd Exp $
-SUBDIR+= basename bc cap_mkdb dc diff diff3 dirname grep gzsig m4 make patch
-SUBDIR+= rcs sdiff sort ssh tsort
+SUBDIR+= basename bc cap_mkdb dc diff diff3 dirname grep gzip gzsig
+SUBDIR+= m4 make patch rcs sdiff sort ssh tsort
.include <bsd.subdir.mk>
diff --git a/regress/usr.bin/gzip/Makefile b/regress/usr.bin/gzip/Makefile
new file mode 100644
index 00000000000..6a17ae8851a
--- /dev/null
+++ b/regress/usr.bin/gzip/Makefile
@@ -0,0 +1,17 @@
+# $OpenBSD: Makefile,v 1.1 2008/08/20 09:29:51 mpf Exp $
+
+TESTSCRIPTS=t1 t2
+
+.for t in ${TESTSCRIPTS}
+REGRESS_TARGETS+=t-${t}
+CLEANFILES+=${t}.gz
+
+t-${t}:
+ sh ${.CURDIR}/${t}.sh ${.CURDIR} ${.OBJDIR}
+.endfor
+
+CLEANFILES+=*.test
+
+.PHONY: ${REGRESS_TARGETS}
+
+.include <bsd.regress.mk>
diff --git a/regress/usr.bin/gzip/t1.sh b/regress/usr.bin/gzip/t1.sh
new file mode 100644
index 00000000000..8eb29931990
--- /dev/null
+++ b/regress/usr.bin/gzip/t1.sh
@@ -0,0 +1,70 @@
+#!/bin/sh
+# $OpenBSD: t1.sh,v 1.1 2008/08/20 09:29:51 mpf Exp $
+
+# Test if gzip(1) detects truncated or corrupted files
+
+# Copyright (c) 2008 Marco Pfatschbacher <mpf@openbsd.org>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+# truncate at 2k
+gzip < /etc/rc | dd bs=1k count=2 of=t1.gz 2>/dev/null
+if gzip -vt t1.gz; then
+ echo "=> ERROR: truncation not detected!"
+ exit 1
+else
+ echo "=> OK"
+fi
+
+# truncate at 1k
+gzip < /etc/rc | dd bs=1k count=1 of=t1.gz 2>/dev/null
+if gzip -vt t1.gz; then
+ echo "=> ERROR: truncation not detected!"
+ exit 1
+else
+ echo "=> OK"
+fi
+
+# skip some data in the middle
+gzip < /etc/rc | dd bs=1k seek=1 >> t1.gz 2>/dev/null
+if gzip -vt t1.gz; then
+ echo "=> ERROR: corruption not detected!"
+ exit 1
+else
+ echo "=> OK"
+fi
+
+# simple fuzzer that modifies one random byte at a random offset
+
+gzip < /etc/rc > t1.gz
+for i in `jot 100`; do
+ where=$((RANDOM % 2048 + 256)) # random offset (but skip the header)
+ orig=`dd if=t1.gz skip=$where bs=1 count=1 2>/dev/null |\
+ hexdump -e '"%d"'`
+ fuzz=$((((orig + RANDOM) % 256) + 1))
+ if [ $fuzz = $orig ]; then
+ fuzz=$(((fuzz + 1) % 256))
+ fi
+ echo "$i/100: fuzzing byte @$where: $orig -> $fuzz"
+
+ if (dd if=t1.gz bs=1 count=$where 2>/dev/null; \
+ echo -n \\0`printf "%o" $fuzz`; \
+ dd if=t1.gz bs=1 skip=$((where+1)) 2>/dev/null) | gzip -tv; then
+ echo "=> ERROR: corruption not detected!"
+ exit 1
+ else
+ echo "=> OK"
+ fi
+done
+
+exit 0
diff --git a/regress/usr.bin/gzip/t2.sh b/regress/usr.bin/gzip/t2.sh
new file mode 100644
index 00000000000..9d2d39f4c67
--- /dev/null
+++ b/regress/usr.bin/gzip/t2.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+# $OpenBSD: t2.sh,v 1.1 2008/08/20 09:29:51 mpf Exp $
+
+# test basic gzip functionality
+
+gzip -c /etc/rc > t1.gz
+if ! gzip -vt t1.gz; then
+ echo "=> ERROR: could not gzip"
+ exit 1
+else
+ echo "=> OK"
+fi
+
+if ! gunzip -c t1.gz | cmp -s - /etc/rc; then
+ echo "=> ERROR: uncompressed file does not match"
+ gunzip -c t1.gz | diff - /etc/rc
+ exit 1
+else
+ echo "=> OK"
+fi
+
+gzip -c /etc/rc /etc/motd > t1.gz
+if ! gzip -vt t1.gz; then
+ echo "=> ERROR: could not gzip multiple files"
+ exit 1
+else
+ echo "=> OK"
+fi
+
+cat /etc/rc /etc/motd > rcmotd.test
+if ! gunzip -c t1.gz | cmp -s - rcmotd.test; then
+ echo "=> ERROR: gunzipped files do not match"
+ gunzip -c t1.gz | diff - rcmotd.test
+ exit 1
+else
+ echo "=> OK"
+fi
+
+exit 0