1# $OpenBSD: Makefile,v 1.3 2023/11/11 02:52:55 gkoehler Exp $
2
3# Copyright (c) 2008 Marco Pfatschbacher <mpf@openbsd.org>
4# Copyright (c) 2017 Alexander Bluhm <bluhm@openbsd.org>
5#
6# Permission to use, copy, modify, and distribute this software for any
7# purpose with or without fee is hereby granted, provided that the above
8# copyright notice and this permission notice appear in all copies.
9#
10# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
18CLEANFILES=	*.gz rc rcmotd multi owner out perm
19
20# Test if gzip(1) detects truncated or corrupted files
21
22REGRESS_TARGETS+=	run-regress-integrity
23run-regress-integrity:
24	@echo "\n==== $@ ===="
25	# create gz
26	gzip -v </etc/rc >rc.gz
27	# check that everything is ok
28	gzip -vt rc.gz
29
30REGRESS_TARGETS+=	run-regress-truncate-2k
31run-regress-truncate-2k:
32	@echo "\n==== $@ ===="
33	# truncate at 2k
34	gzip </etc/rc >rc.gz
35	dd if=rc.gz bs=1k count=2 of=2k.gz
36	# check that truncation is detected
37	! gzip -vt 2k.gz
38
39REGRESS_TARGETS+=	run-regress-truncate-1k
40run-regress-truncate-1k:
41	@echo "\n==== $@ ===="
42	# truncate at 1k
43	gzip </etc/rc >rc.gz
44	dd if=rc.gz bs=1k count=1 of=1k.gz
45	# check that truncation is detected
46	! gzip -vt 1k.gz
47
48REGRESS_TARGETS+=	run-regress-skip
49run-regress-skip:
50	@echo "\n==== $@ ===="
51	# skip some data in the middle
52	gzip </etc/rc >rc.gz
53	dd if=rc.gz bs=1k count=1 of=skip.gz
54	dd if=rc.gz bs=1k seek=2 skip=2 conv=notrunc of=skip.gz
55	# check that corruption is detected
56	! gzip -vt skip.gz
57
58JOT100!=	jot 100
59REGRESS_TARGETS+=	run-regress-fuzz
60run-regress-fuzz:
61	@echo "\n==== $@ ===="
62	# simple fuzzer that modifies one random byte at a random offset
63	gzip </etc/rc >rc.gz
64.for i in ${JOT100}
65	dd if=rc.gz bs=1k of=fuzz.gz status=none
66	RANDOM=$i;\
67	    where=$$((RANDOM % 2048 + 256)); fuzz=$$((RANDOM % 256));\
68	    orig=`dd if=rc.gz bs=1 skip=$$where count=1 status=none |\
69	    hexdump -e '"%d"'`;\
70	    echo "$i/100: fuzzing byte @$$where: $$orig -> $$fuzz";\
71	    echo -n \\0`printf "%o" $$fuzz` |\
72	    dd bs=1 seek=$$where conv=notrunc of=fuzz.gz status=none
73	cmp -s rc.gz fuzz.gz || ! gzip -vt fuzz.gz
74.endfor
75
76# test basic gzip functionality
77
78REGRESS_TARGETS+=	run-regress-gunzip
79run-regress-gunzip:
80	@echo "\n==== $@ ===="
81	# gzip and gunzip
82	gzip -v </etc/rc >rc.gz
83	gunzip -f rc.gz
84	# check that uncompressed file does match
85	diff -up /etc/rc rc
86
87REGRESS_TARGETS+=	run-regress-multi
88run-regress-multi:
89	@echo "\n==== $@ ===="
90	# compress multiple files
91	gzip -c /etc/rc /etc/motd >multi.gz
92	# check multiple gzip file
93	gzip -vt multi.gz
94	gunzip -f multi.gz
95	# check that gunzipped files do match
96	cat /etc/rc /etc/motd >rcmotd
97	diff -up rcmotd multi
98
99# Test -N
100
101REGRESS_TARGETS+=	run-regress-name
102run-regress-name:
103	@echo "\n==== $@ ===="
104	# check gunzip -N
105	gzip -c /etc/rc >in.gz
106	rm -f rc
107	gunzip -N in.gz
108	diff -up /etc/rc rc
109	# check that -N works with -l
110	gzip -c /etc/rc >in.gz
111	gzip -lN in.gz | grep -q ' rc$$'
112	gzip -lN <in.gz | grep -q ' rc$$'
113	# check that stdout ignores -N
114	rm -f out
115	gzip -dN <in.gz >out
116	diff -up /etc/rc out
117	# check that zcat ignores -N
118	rm -f out
119	zcat -N in.gz >out
120	diff -up /etc/rc out
121
122# Test permissions
123
124REGRESS_TARGETS+=	run-regress-perm-zip
125run-regress-perm-zip:
126	@echo "\n==== $@ ===="
127	# compress file with special permissions
128	cat /etc/rc >perm
129	chmod 614 perm
130	rm -f perm.gz
131	gzip perm
132	ls -l perm.gz | grep '^-rw---xr-- '
133
134REGRESS_TARGETS+=	run-regress-perm-unzip
135run-regress-perm-unzip:
136	@echo "\n==== $@ ===="
137	# uncompress file with special permissions
138	gzip </etc/rc >perm.gz
139	chmod 614 perm.gz
140	rm -f perm
141	gunzip perm.gz
142	ls -l perm | grep '^-rw---xr-- '
143
144REGRESS_TARGETS+=	run-regress-owner-zip
145run-regress-owner-zip:
146	@echo "\n==== $@ ===="
147	# compress file as root with user and group nobody
148	rm -f owner
149	cat /etc/rc >owner
150	${SUDO} chown nobody:nobody owner
151	rm -f owner.gz
152	${SUDO} gzip owner
153	ls -l owner.gz | grep ' nobody  *nobody '
154
155REGRESS_TARGETS+=	run-regress-owner-unzip
156run-regress-owner-unzip:
157	@echo "\n==== $@ ===="
158	# uncompress file with special permissions
159	rm -f owner.gz
160	gzip </etc/rc >owner.gz
161	${SUDO} chown nobody:nobody owner.gz
162	rm -f owner
163	${SUDO} gunzip owner.gz
164	ls -l owner | grep ' nobody  *nobody '
165
166.include <bsd.regress.mk>
167