xref: /openbsd/regress/usr.sbin/syslogd/Makefile (revision a762f82b)
1#	$OpenBSD: Makefile,v 1.36 2023/10/12 16:59:24 anton Exp $
2
3# The following ports must be installed for the regression tests:
4# p5-Socket6		Perl defines relating to AF_INET6 sockets
5# p5-IO-Socket-SSL	perl interface to SSL sockets
6# p5-BSD-Resource	BSD process resource limit and priority functions
7#
8# This package enables additional interoperability tests
9# rsyslog		syslog daemon supporting databases, TCP, SSL, RELP
10#
11# Check wether all required perl packages are installed.  If some
12# are missing print a warning and skip the tests, but do not fail.
13
14PERL_REQUIRE !=	perl -Mstrict -Mwarnings -e ' \
15    eval { require Socket6 } or print $@; \
16    eval { require IO::Socket::SSL } or print $@; \
17    eval { require BSD::Resource } or print $@; \
18'
19.if ! empty (PERL_REQUIRE)
20regress:
21	@echo "${PERL_REQUIRE}"
22	@echo 'run "pkg_add p5-Socket6 p5-IO-Socket-SSL p5-BSD-Resource"'
23	@echo SKIPPED
24.endif
25
26# Automatically generate regress targets from test cases in directory.
27
28PROGS =			ttylog logflush
29PERLS =			Client.pm Proc.pm RSyslogd.pm Server.pm \
30			Syslogc.pm   Syslogd.pm funcs.pl syslogd.pl
31ARGS !=			cd ${.CURDIR} && ls args-*.pl
32REGRESS_TARGETS =	${ARGS:S/^/run-/}
33.if ! exists(/usr/local/sbin/rsyslogd)
34REGRESS_SKIP_TARGETS =	${REGRESS_TARGETS:Mrun-args-rsyslog*}
35.endif
36LDFLAGS +=		-lutil
37CLEANFILES +=		*.log *.log.? *.conf ktrace.out stamp-* *.pid
38CLEANFILES +=		*.out *.sock *.ktrace *.fstat ttylog *.ph */*.ph
39CLEANFILES +=		*.pem *.req *.key *.crt *.srl empty toobig diskimage vnd
40
41run-args-rsyslog-client-tls.pl run-args-rsyslog-tls.pl:
42	# rsyslogd TLS client side is totally unreliable.  Startup of
43	# GnuTLS may take a long time on slow machines.  Disable test.
44	@echo DISABLED
45
46.MAIN: all
47
48REGRESS_SETUP_ONCE +=	setup
49setup:
50	[ -z "${SUDO}" ] || ${SUDO} true
51	${SUDO} /etc/rc.d/syslogd stop
52
53REGRESS_CLEANUP +=	cleanup
54cleanup:
55	-${SUDO} /etc/rc.d/syslogd restart
56
57# Set variables so that make runs with and without obj directory.
58# Only do that if necessary to keep visible output short.
59
60.if ${.CURDIR} == ${.OBJDIR}
61PERLINC =	-I.
62PERLPATH =
63.else
64PERLINC =	-I${.CURDIR} -I${.OBJDIR}
65PERLPATH =	${.CURDIR}/
66.endif
67
68# The arg tests take a perl hash with arguments controlling the
69# test parameters.  Generally they consist of client, syslogd, server.
70
71.for a in ${ARGS}
72run-$a: $a
73	time SUDO=${SUDO} KTRACE=${KTRACE} SYSLOGD=${SYSLOGD} perl ${PERLINC} ${PERLPATH}syslogd.pl ${PERLPATH}$a
74.endfor
75
76# create certificates for TLS
77
78127.0.0.1.crt:
79	openssl req -batch -new -subj /L=OpenBSD/O=syslogd-regress/OU=syslogd/CN=127.0.0.1/ -nodes -newkey rsa -keyout 127.0.0.1.key -x509 -out $@
80	${SUDO} rm -f /etc/ssl/private/127.0.0.1:6514.key
81	${SUDO} rm -f /etc/ssl/127.0.0.1:6514.crt
82	${SUDO} rm -f /etc/ssl/private/127.0.0.1.key
83	${SUDO} rm -f /etc/ssl/127.0.0.1.crt
84	${SUDO} cp 127.0.0.1.key /etc/ssl/private/127.0.0.1.key
85	${SUDO} cp 127.0.0.1.crt /etc/ssl/127.0.0.1.crt
86	${SUDO} cp 127.0.0.1.key /etc/ssl/private/::1.key
87	${SUDO} cp 127.0.0.1.crt /etc/ssl/::1.crt
88	${SUDO} cp 127.0.0.1.key /etc/ssl/private/localhost.key
89	${SUDO} cp 127.0.0.1.crt /etc/ssl/localhost.crt
90
91ca.crt fake-ca.crt:
92	openssl req -batch -new -subj /L=OpenBSD/O=syslogd-regress/OU=ca/CN=root/ -nodes -newkey rsa -keyout ${@:R}.key -x509 -out $@
93
94client.req server.req:
95	openssl req -batch -new -subj /L=OpenBSD/O=syslogd-regress/OU=${@:R}/CN=localhost/ -nodes -newkey rsa -keyout ${@:R}.key -out $@
96
97client.crt server.crt: ca.crt ${@:R}.req
98	openssl x509 -CAcreateserial -CAkey ca.key -CA ca.crt -req -in ${@:R}.req -out $@
99
100empty:
101	true >$@
102
103toobig:
104	dd if=/dev/zero of=$@ bs=1 count=1 seek=50M
105
106sys/syscall.ph: /usr/include/sys/syscall.h
107	cd /usr/include && h2ph -h -d ${.OBJDIR} ${@:R:S/$/.h/}
108
109# Create a full file system on vnd to trigger ENOSPC error.
110
111.PHONY: disk mount unconfig
112
113disk: unconfig
114	dd if=/dev/zero of=diskimage bs=512 count=4k
115	vnconfig diskimage >vnd
116	newfs -b 4096 -f 2048 -m 0 $$(<vnd)c
117
118mount: disk
119	mkdir -p /mnt/regress-syslogd
120	mount /dev/$$(<vnd)c /mnt/regress-syslogd
121
122unconfig:
123	-umount -f /dev/$$(<vnd)c 2>/dev/null || true
124	-rmdir /mnt/regress-syslogd 2>/dev/null || true
125	-vnconfig -u $$(<vnd) 2>/dev/null || true
126
127stamp-filesystem:
128	${SUDO} ${.MAKE} -C ${.CURDIR} mount
129	${SUDO} chmod 1777 /mnt/regress-syslogd
130	date >$@
131
132REGRESS_CLEANUP +=	cleanup-filesystem
133cleanup-filesystem:
134	rm -f stamp-filesystem
135	-${SUDO} umount /mnt/regress-syslogd
136	-${SUDO} ${.MAKE} -C ${.CURDIR} unconfig
137
138${REGRESS_TARGETS:M*filesystem*}: stamp-filesystem
139${REGRESS_TARGETS:M*tls*}: client.crt server.crt 127.0.0.1.crt
140${REGRESS_TARGETS:M*multilisten*}: 127.0.0.1.crt
141${REGRESS_TARGETS:M*empty*}: empty
142${REGRESS_TARGETS:M*toobig*}: toobig
143${REGRESS_TARGETS:M*fake*}: fake-ca.crt
144${REGRESS_TARGETS:M*sendsyslog*}: sys/syscall.ph
145${REGRESS_TARGETS}: ttylog logflush
146
147# make perl syntax check for all args files
148
149.PHONY: syntax libevent
150
151syntax: stamp-syntax
152
153stamp-syntax: ${PERLS} ${ARGS}
154.for p in ${PERLS}
155	@perl -c ${PERLINC} ${PERLPATH}$p
156.endfor
157.for a in ${ARGS}
158	@perl -c ${PERLPATH}$a
159.endfor
160	@date >$@
161
162# run the tests with all variants of libevent backend
163libevent:
164	cd ${.CURDIR} && EVENT_NOKQUEUE=1 EVENT_NOPOLL=1 ${MAKE} regress
165	cd ${.CURDIR} && EVENT_NOKQUEUE=1 EVENT_NOSELECT=1 ${MAKE} regress
166	cd ${.CURDIR} && EVENT_NOPOLL=1 EVENT_NOSELECT=1 ${MAKE} regress
167
168.include <bsd.regress.mk>
169