summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2017-06-22 16:10:35 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2017-06-22 16:10:35 +0000
commit5b7370690005926f920dad7ca27d52eefc7f8dde (patch)
tree4d17f2e894a0aeab8eb3a9f4daf770e3db130920 /regress
parentf9379ae966a84a3d43dfc27c50bc073e9849ec18 (diff)
Convert shell script tests to regress make rules. Having only one
tool and more verbosity allows better debugging. Additional tests check that gzip and gunzip preserve file permissions and ownership.
Diffstat (limited to 'regress')
-rw-r--r--regress/usr.bin/gzip/Makefile144
-rw-r--r--regress/usr.bin/gzip/t1.sh70
-rw-r--r--regress/usr.bin/gzip/t2.sh39
3 files changed, 135 insertions, 118 deletions
diff --git a/regress/usr.bin/gzip/Makefile b/regress/usr.bin/gzip/Makefile
index 6a17ae8851a..2777447a75c 100644
--- a/regress/usr.bin/gzip/Makefile
+++ b/regress/usr.bin/gzip/Makefile
@@ -1,17 +1,143 @@
-# $OpenBSD: Makefile,v 1.1 2008/08/20 09:29:51 mpf Exp $
+# $OpenBSD: Makefile,v 1.2 2017/06/22 16:10:34 bluhm Exp $
-TESTSCRIPTS=t1 t2
+# Copyright (c) 2008 Marco Pfatschbacher <mpf@openbsd.org>
+# Copyright (c) 2017 Alexander Bluhm <bluhm@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.
-.for t in ${TESTSCRIPTS}
-REGRESS_TARGETS+=t-${t}
-CLEANFILES+=${t}.gz
+CLEANFILES= *.gz rc rcmotd multi owner perm
-t-${t}:
- sh ${.CURDIR}/${t}.sh ${.CURDIR} ${.OBJDIR}
+# Test if gzip(1) detects truncated or corrupted files
+
+REGRESS_TARGETS+= run-regress-integrity
+run-regress-integrity:
+ @echo "\n==== $@ ===="
+ # create gz
+ gzip -v </etc/rc >rc.gz
+ # check that everything is ok
+ gzip -vt rc.gz
+
+REGRESS_TARGETS+= run-regress-truncate-2k
+run-regress-truncate-2k:
+ @echo "\n==== $@ ===="
+ # truncate at 2k
+ gzip </etc/rc >rc.gz
+ dd if=rc.gz bs=1k count=2 of=2k.gz
+ # check that truncation is detected
+ ! gzip -vt 2k.gz
+
+REGRESS_TARGETS+= run-regress-truncate-1k
+run-regress-truncate-1k:
+ @echo "\n==== $@ ===="
+ # truncate at 1k
+ gzip </etc/rc >rc.gz
+ dd if=rc.gz bs=1k count=1 of=1k.gz
+ # check that truncation is detected
+ ! gzip -vt 1k.gz
+
+REGRESS_TARGETS+= run-regress-skip
+run-regress-skip:
+ @echo "\n==== $@ ===="
+ # skip some data in the middle
+ gzip </etc/rc >rc.gz
+ dd if=rc.gz bs=1k count=1 of=skip.gz
+ dd if=rc.gz bs=1k seek=2 skip=2 conv=notrunc of=skip.gz
+ # check that corruption is detected
+ ! gzip -vt skip.gz
+
+JOT100!= jot 100
+REGRESS_TARGETS+= run-regress-fuzz
+run-regress-fuzz:
+ @echo "\n==== $@ ===="
+ # simple fuzzer that modifies one random byte at a random offset
+ gzip </etc/rc >rc.gz
+.for i in ${JOT100}
+ dd if=rc.gz bs=1k of=fuzz.gz status=none
+ RANDOM=$i;\
+ where=$$((RANDOM % 2048 + 256)); fuzz=$$((RANDOM % 256));\
+ orig=`dd if=rc.gz bs=1 skip=$$where count=1 status=none |\
+ hexdump -e '"%d"'`;\
+ echo "$i/100: fuzzing byte @$$where: $$orig -> $$fuzz";\
+ echo -n \\0`printf "%o" $$fuzz` |\
+ dd bs=1 seek=$$where conv=notrunc of=fuzz.gz status=none
+ cmp -s rc.gz fuzz.gz || ! gzip -vt fuzz.gz
.endfor
-CLEANFILES+=*.test
+# test basic gzip functionality
+
+REGRESS_TARGETS+= run-regress-gunzip
+run-regress-gunzip:
+ @echo "\n==== $@ ===="
+ # gzip and gunzip
+ gzip -v </etc/rc >rc.gz
+ gunzip -f rc.gz
+ # check that uncompressed file does match
+ diff -up /etc/rc rc
+
+REGRESS_TARGETS+= run-regress-multi
+run-regress-multi:
+ @echo "\n==== $@ ===="
+ # compress multiple files
+ gzip -c /etc/rc /etc/motd >multi.gz
+ # check multiple gzip file
+ gzip -vt multi.gz
+ gunzip -f multi.gz
+ # check that gunzipped files do match
+ cat /etc/rc /etc/motd >rcmotd
+ diff -up rcmotd multi
+
+# Test permissions
+
+REGRESS_TARGETS+= run-regress-perm-zip
+run-regress-perm-zip:
+ @echo "\n==== $@ ===="
+ # compress file with special permissions
+ cat /etc/rc >perm
+ chmod 614 perm
+ rm -f perm.gz
+ gzip perm
+ ls -l perm.gz | grep '^-rw---xr-- '
+
+REGRESS_TARGETS+= run-regress-perm-unzip
+run-regress-perm-unzip:
+ @echo "\n==== $@ ===="
+ # uncompress file with special permissions
+ gzip </etc/rc >perm.gz
+ chmod 614 perm.gz
+ rm -f perm
+ gunzip perm.gz
+ ls -l perm | grep '^-rw---xr-- '
+
+REGRESS_TARGETS+= run-regress-owner-zip
+run-regress-owner-zip:
+ @echo "\n==== $@ ===="
+ # compress file as root with user and group nobody
+ rm -f owner
+ cat /etc/rc >owner
+ ${SUDO} chown nobody:nobody owner
+ rm -f owner.gz
+ ${SUDO} gzip owner
+ ls -l owner.gz | grep ' nobody *nobody '
-.PHONY: ${REGRESS_TARGETS}
+REGRESS_TARGETS+= run-regress-owner-unzip
+run-regress-owner-unzip:
+ @echo "\n==== $@ ===="
+ # uncompress file with special permissions
+ rm -f owner.gz
+ gzip </etc/rc >owner.gz
+ ${SUDO} chown nobody:nobody owner.gz
+ rm -f owner
+ ${SUDO} gunzip owner.gz
+ ls -l owner | grep ' nobody *nobody '
.include <bsd.regress.mk>
diff --git a/regress/usr.bin/gzip/t1.sh b/regress/usr.bin/gzip/t1.sh
deleted file mode 100644
index 8eb29931990..00000000000
--- a/regress/usr.bin/gzip/t1.sh
+++ /dev/null
@@ -1,70 +0,0 @@
-#!/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
deleted file mode 100644
index 9d2d39f4c67..00000000000
--- a/regress/usr.bin/gzip/t2.sh
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/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