new variable in bsd.regress.mk

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

new variable in bsd.regress.mk

Sergey Bronnikov-3
Hi,

some regression tests depends on 3rd party modules and now some tests contains
duplicate code which check precense of dependencies and install them in case of
abcense. Perhaps it would be better to care about dependencies in the
bsd.regress.mk and specify dependencies in special variable in tests.
This patch intoduce PKG_REQUIRED var and adopt tests where it is required.

diff --git a/regress/sys/fileops/Makefile.inc b/regress/sys/fileops/Makefile.inc
index d6d2c05781e..b327a383c8f 100644
--- a/regress/sys/fileops/Makefile.inc
+++ b/regress/sys/fileops/Makefile.inc
@@ -1,7 +1,6 @@
 # $OpenBSD: Makefile.inc,v 1.3 2017/08/15 17:16:39 sf Exp $
 
-PERL_REQUIRE != perl -e 'eval { require File::Slurp } or print $$@'
-
+PKG_REQUIRED= p5-File-Slurp
 TESTS1= create read mmap
 TESTS2= many_files_root many_files_subdir file_write
 TESTS= ${TESTS1} ${TESTS2}
@@ -48,16 +47,9 @@ run-regress-${t}: stamp-setup ${.OBJDIR}/../fileops
 
 .for t in ${TESTS2}
 REGRESS_TARGETS+= run-regress-${t}
-.if ! empty(PERL_REQUIRE)
-run-regress-${t}:
- @echo "${PERL_REQUIRE}"
- @echo "Install the p5-File-Slurp package to run the fileops ${t} subtest"
- @echo SKIPPED
-.else
 run-regress-${t}: stamp-setup
  @echo '\n======== $@ ========'
  perl ${.CURDIR}/../fileops2.pl ${t} ${FILEOPS_MNT}
-.endif
 .endfor
 
 REGRESS_TARGETS+= run-regress-cleanup
diff --git a/regress/sys/net/Makefile b/regress/sys/net/Makefile
index d56a7cc9189..653060732ec 100644
--- a/regress/sys/net/Makefile
+++ b/regress/sys/net/Makefile
@@ -1,5 +1,7 @@
 # $OpenBSD: Makefile,v 1.13 2017/11/17 10:29:16 bluhm Exp $
 
+PKG_REQUIRED += scapy py-libdnet
+
 SUBDIR += etherip loop
 SUBDIR += pf_divert pf_forward pf_fragment pf_print pf_state pf_table
 SUBDIR += rdomains rtable vxlan
diff --git a/regress/sys/net/pf_divert/Makefile b/regress/sys/net/pf_divert/Makefile
index 2c5f538ed8d..aaad41af726 100644
--- a/regress/sys/net/pf_divert/Makefile
+++ b/regress/sys/net/pf_divert/Makefile
@@ -3,20 +3,8 @@
 # The following ports must be installed for the regression tests:
 # p5-IO-Socket-INET6 object interface for AF_INET and AF_INET6 domain sockets
 # p5-Socket6 Perl defines relating to AF_INET6 sockets
-#
-# Check wether all required perl packages are installed.  If some
-# are missing print a warning and skip the tests, but do not fail.
-
-PERL_REQUIRE != perl -Mstrict -Mwarnings -e ' \
-    eval { require IO::Socket::INET6 } or print $@; \
-    eval { require Socket6 } or print $@; \
-'
-.if ! empty(PERL_REQUIRE)
-regress:
- @echo "${PERL_REQUIRE}"
- @echo install these perl packages for additional tests
- @echo SKIPPED
-.endif
+
+PKG_REQUIRED += p5-IO-Socket-INET6 p5-Socket6
 
 # Fill out these variables as you have to test divert with the pf
 # kernel running on a remote machine.  You have to specify a local
diff --git a/regress/sys/net/pflow/Makefile b/regress/sys/net/pflow/Makefile
index 122fe9b13e9..d6acd95d7ea 100644
--- a/regress/sys/net/pflow/Makefile
+++ b/regress/sys/net/pflow/Makefile
@@ -27,6 +27,7 @@
 # Destroy it in the end.
 
 REGRESS_TARGETS=template_v10 flow_10_4 flow_10_6 ifconfig
+PKG_REQUIRED += p5-Net-Flow
 
 PROG=   gen_traffic
 LDADD=  -levent
diff --git a/regress/sys/netinet/arp/Makefile b/regress/sys/netinet/arp/Makefile
index 7081e928b99..8578c2b6614 100644
--- a/regress/sys/netinet/arp/Makefile
+++ b/regress/sys/netinet/arp/Makefile
@@ -6,17 +6,7 @@
 # py-libdnet          python interface to libdnet
 # scapy               powerful interactive packet manipulation in python
 
-.if ! (make(clean) || make(cleandir) || make(obj))
-# Check wether all required python packages are installed.  If some
-# are missing print a warning and skip the tests, but do not fail.
-PYTHON_IMPORT != python2.7 -c 'from scapy.all import *' 2>&1 || true
-.endif
-.if ! empty(PYTHON_IMPORT)
-regress:
- @echo '${PYTHON_IMPORT}'
- @echo install python and the scapy module for additional tests
- @echo SKIPPED
-.endif
+PKG_REQUIRED += python-2.7 scapy py-libdnet
 
 # This test needs a manual setup of two machines
 # Set up machines: LOCAL REMOTE
diff --git a/regress/sys/netinet/frag/Makefile b/regress/sys/netinet/frag/Makefile
index 195634b5d07..381cc6950dc 100644
--- a/regress/sys/netinet/frag/Makefile
+++ b/regress/sys/netinet/frag/Makefile
@@ -6,20 +6,7 @@
 # py-libdnet          python interface to libdnet
 # scapy               powerful interactive packet manipulation in python
 
-.if ! (make(clean) || make(cleandir) || make(obj))
-# Check wether all required python packages are installed.  If some
-# are missing print a warning and skip the tests, but do not fail.
-PYTHON_IMPORT !!= python2.7 -c 'from scapy.all import *' 2>&1 || true
-.endif
-
-.if ! empty(PYTHON_IMPORT)
-.BEGIN:
- @true
-regress:
- @echo '${PYTHON_IMPORT}'
- @echo Install python and the scapy module for additional tests.
- @echo SKIPPED
-.endif
+PKG_REQUIRED += python-2.7 scapy py-libdnet
 
 # This test needs a manual setup of two machines
 # Set up machines: LOCAL REMOTE
diff --git a/regress/sys/netinet/pmtu/Makefile b/regress/sys/netinet/pmtu/Makefile
index 447637aa900..04b7d067f40 100644
--- a/regress/sys/netinet/pmtu/Makefile
+++ b/regress/sys/netinet/pmtu/Makefile
@@ -6,17 +6,7 @@
 # py-libdnet          python interface to libdnet
 # scapy               powerful interactive packet manipulation in python
 
-.if ! (make(clean) || make(cleandir) || make(obj))
-# Check wether all required python packages are installed.  If some
-# are missing print a warning and skip the tests, but do not fail.
-PYTHON_IMPORT != python2.7 -c 'from scapy.all import *' 2>&1 || true
-.endif
-.if ! empty(PYTHON_IMPORT)
-regress:
- @echo '${PYTHON_IMPORT}'
- @echo install python and the scapy module for additional tests
- @echo SKIPPED
-.endif
+PKG_REQUIRED += python-2.7 scapy py-libdnet
 
 # This test needs a manual setup of two machines
 # Set up machines: LOCAL REMOTE
diff --git a/regress/sys/netinet6/frag6/Makefile b/regress/sys/netinet6/frag6/Makefile
index 40432839443..1f86f41a152 100644
--- a/regress/sys/netinet6/frag6/Makefile
+++ b/regress/sys/netinet6/frag6/Makefile
@@ -6,20 +6,7 @@
 # py-libdnet          python interface to libdnet
 # scapy               powerful interactive packet manipulation in python
 
-.if ! (make(clean) || make(cleandir) || make(obj))
-# Check wether all required python packages are installed.  If some
-# are missing print a warning and skip the tests, but do not fail.
-PYTHON_IMPORT !!= python2.7 -c 'from scapy.all import *' 2>&1 || true
-.endif
-
-.if ! empty(PYTHON_IMPORT)
-.BEGIN:
- @true
-regress:
- @echo '${PYTHON_IMPORT}'
- @echo Install python and the scapy module for additional tests.
- @echo SKIPPED
-.endif
+PKG_REQUIRED += python-2.7 scapy py-libdnet
 
 # This test needs a manual setup of two machines
 # Set up machines: LOCAL REMOTE
diff --git a/regress/sys/netinet6/nd6/Makefile b/regress/sys/netinet6/nd6/Makefile
index ba7011d8c56..e9c7d22285d 100644
--- a/regress/sys/netinet6/nd6/Makefile
+++ b/regress/sys/netinet6/nd6/Makefile
@@ -6,18 +6,7 @@
 # py-libdnet          python interface to libdnet
 # scapy               powerful interactive packet manipulation in python
 
-.if ! (make(clean) || make(cleandir) || make(obj))
-# Check wether all required python packages are installed.  If some
-# are missing print a warning and skip the tests, but do not fail.
-PYTHON_IMPORT !!= python2.7 -c 'from scapy.all import *' 2>&1 || true
-.endif
-
-.if ! empty(PYTHON_IMPORT)
-regress:
- @echo '${PYTHON_IMPORT}'
- @echo Install python and the scapy module for additional tests.
- @echo SKIPPED
-.endif
+PKG_REQUIRED += python-2.7 scapy py-libdnet
 
 # This test needs a manual setup of two machines
 # Set up machines: LOCAL REMOTE
diff --git a/regress/sys/netinet6/rh0/Makefile b/regress/sys/netinet6/rh0/Makefile
index d1d4804304c..9c96d7505cf 100644
--- a/regress/sys/netinet6/rh0/Makefile
+++ b/regress/sys/netinet6/rh0/Makefile
@@ -6,20 +6,7 @@
 # py-libdnet python interface to libdnet
 # scapy powerful interactive packet manipulation in python
 
-.if ! (make(clean) || make(cleandir) || make(obj))
-# Check wether all required python packages are installed.  If some
-# are missing print a warning and skip the tests, but do not fail.
-PYTHON_IMPORT !!= python2.7 -c 'from scapy.all import *' 2>&1 || true
-.endif
-
-.if ! empty(PYTHON_IMPORT)
-.BEGIN:
- @true
-regress:
- @echo '${PYTHON_IMPORT}'
- @echo Install python and the scapy module for additional tests.
- @echo SKIPPED
-.endif
+PKG_REQUIRED += scapy py-libdnet
 
 # This test needs a manual setup of two machines
 # Set up machines: LOCAL REMOTE
diff --git a/regress/usr.sbin/ldapd/Makefile b/regress/usr.sbin/ldapd/Makefile
index 55cf66f618b..8db4dba6acc 100644
--- a/regress/usr.sbin/ldapd/Makefile
+++ b/regress/usr.sbin/ldapd/Makefile
@@ -6,27 +6,7 @@ DIT2=dc=bar,dc=quux
 NLV=0.65
 CLEANFILES=ldapd.pid log ldapd1.conf ${DIT}_indx.db ${DIT}_data.db ${DIT2}_indx.db ${DIT2}_data.db
 
-# Needs p5-ldap and openldap (client)
-
-PERL_REQUIRE != perl -Mstrict -Mwarnings -e ' \
-    eval { require Net::LDAP } or print $@; \
-'
-.if ! empty (PERL_REQUIRE)
-regress:
- @echo "${PERL_REQUIRE}"
- @echo install package p5-ldap
- @echo SKIPPED
-.endif
-
-.if ! (make(clean) || make(cleandir) || make(obj))
-LDAP_DEP != ldapsearch -VV 2>/dev/null ; echo $?
-.endif
-.if ("${LDAP_DEP}" != 0)
-regress:
- @echo openldap-client must be installed
- @echo SKIPPED
-.endif
-
+PKG_REQUIRED += p5-ldap openldap-client--
 REGRESS_TARGETS = connect import perl purge #cpan
 
 bootstrap:
diff --git a/regress/usr.sbin/ospfd/Makefile b/regress/usr.sbin/ospfd/Makefile
index b829bbdc296..65cc7300307 100644
--- a/regress/usr.sbin/ospfd/Makefile
+++ b/regress/usr.sbin/ospfd/Makefile
@@ -4,21 +4,8 @@
 # p5-AnyEvent provide framework for multiple event loops
 # p5-Hash-Merge merge associative arrays
 # p5-YAML YAML ain't a markup language
-#
-# Check wether all required perl packages are installed.  If some
-# are missing print a warning and skip the tests, but do not fail.
-
-PERL_REQUIRE != perl -Mstrict -Mwarnings -e ' \
-    eval { require AnyEvent } or print $@; \
-    eval { require Hash::Merge } or print $@; \
-    eval { require YAML } or print $@; \
-'
-.if ! empty (PERL_REQUIRE)
-regress:
- @echo "${PERL_REQUIRE}"
- @echo install these perl packages for additional tests
- @echo SKIPPED
-.endif
+
+PKG_REQUIRED += p5-AnyEvent p5-Hash-Merge p5-YAML
 
 # Fill out these variables with your own system parameters
 # You need a tap device and an unused /24 IPv4 network.
diff --git a/regress/usr.sbin/relayd/Makefile b/regress/usr.sbin/relayd/Makefile
index 7f9106d9f92..c3c846f943d 100644
--- a/regress/usr.sbin/relayd/Makefile
+++ b/regress/usr.sbin/relayd/Makefile
@@ -8,17 +8,7 @@
 # Check wether all required perl packages are installed.  If some
 # are missing print a warning and skip the tests, but do not fail.
 
-PERL_REQUIRE != perl -Mstrict -Mwarnings -e ' \
-    eval { require IO::Socket::INET6 } or print $@; \
-    eval { require Socket6 } or print $@; \
-    eval { require IO::Socket::SSL } or print $@; \
-'
-.if ! empty (PERL_REQUIRE)
-regress:
- @echo "${PERL_REQUIRE}"
- @echo install these perl packages for additional tests
- @echo SKIPPED
-.endif
+PKG_REQUIRED += p5-IO-Socket-INET6 p5-Socket6 p5-IO-Socket-SSL
 
 .if make (regress) || make (all)
 .BEGIN:
diff --git a/regress/usr.sbin/snmpd/Makefile b/regress/usr.sbin/snmpd/Makefile
index f2c6622c074..a604f6bef2a 100644
--- a/regress/usr.sbin/snmpd/Makefile
+++ b/regress/usr.sbin/snmpd/Makefile
@@ -1,18 +1,9 @@
 # $OpenBSD: Makefile,v 1.1 2017/08/11 17:45:02 rob Exp $
 # Regress tests for snmpd
 
+PKG_REQUIRED += net-snmp
 REGRESS_TARGETS = run-regress-snmpd
 
-# Needs netsnmp
-
-NETSNMP_DEP != which snmpset >/dev/null 2>&1 ; echo $?
-
-.if ("${NETSNMP_DEP}" !=0)
-run-regress-snmpd:
- @echo install netsnmp
- @echo SKIPPED
-.endif
-
 run-regress-snmpd:
  env OBJDIR=${.OBJDIR} ${SUDO} sh ${.CURDIR}/snmpd.sh
 
diff --git a/regress/usr.sbin/switchd/Makefile b/regress/usr.sbin/switchd/Makefile
index 76c47af0fdd..ce58ca65c71 100644
--- a/regress/usr.sbin/switchd/Makefile
+++ b/regress/usr.sbin/switchd/Makefile
@@ -4,21 +4,8 @@
 # p5-Net-Pcap Perl interface for libpcap
 # p5-NetPacket Perl interface for packet encoding/decoding
 # p5-Crypt-Random To fill payloads with weak random data
-#
-# Check wether all required perl packages are installed.  If some
-# are missing print a warning and skip the tests, but do not fail.
-
-PERL_REQUIRE != perl -Mstrict -Mwarnings -e ' \
-    eval { require NetPacket::Ethernet } or print $@; \
-    eval { require Net::Pcap } or print $@; \
-    eval { require Crypt::Random } or print $@; \
-'
-.if ! empty (PERL_REQUIRE)
-regress:
- @echo "${PERL_REQUIRE}"
- @echo install these perl packages for additional tests
- @echo SKIPPED
-.endif
+
+PKG_REQUIRED += p5-Net-Pcap p5-NetPacket p5-Crypt-Random
 
 # Automatically generate regress targets from test cases in directory.
 
diff --git a/regress/usr.sbin/syslogd/Makefile b/regress/usr.sbin/syslogd/Makefile
index 7b33571f60d..27b9f6431c5 100644
--- a/regress/usr.sbin/syslogd/Makefile
+++ b/regress/usr.sbin/syslogd/Makefile
@@ -8,22 +8,8 @@
 #
 # This package enables additional interoperability tests
 # rsyslog syslog daemon supporting databases, TCP, SSL, RELP
-#
-# Check wether all required perl packages are installed.  If some
-# are missing print a warning and skip the tests, but do not fail.
-
-PERL_REQUIRE != perl -Mstrict -Mwarnings -e ' \
-    eval { require IO::Socket::INET6 } or print $@; \
-    eval { require Socket6 } or print $@; \
-    eval { require IO::Socket::SSL } or print $@; \
-    eval { require BSD::Resource } or print $@; \
-'
-.if ! empty (PERL_REQUIRE)
-regress:
- @echo "${PERL_REQUIRE}"
- @echo install these perl packages for additional tests
- @echo SKIPPED
-.endif
+
+PKG_REQUIRED += p5-IO-Socket-INET6 p5-Socket6 p5-IO-Socket-SSL p5-BSD-Resource
 
 # Automatically generate regress targets from test cases in directory.
 
diff --git a/share/man/man5/bsd.regress.mk.5 b/share/man/man5/bsd.regress.mk.5
index bbd49058a47..d53c5aa42a0 100644
--- a/share/man/man5/bsd.regress.mk.5
+++ b/share/man/man5/bsd.regress.mk.5
@@ -66,6 +66,8 @@ then a failure is logged, otherwise the test is marked as a success.
 .El
 .Sh VARIABLES
 .Bl -tag -width Ds
+.It Ev PKG_REQUIRED
+List of packages required to run tests.
 .It Ev REGRESS_FAIL_EARLY
 If this variable is set to anything but
 .Dq no ,
diff --git a/share/mk/bsd.regress.mk b/share/mk/bsd.regress.mk
index 0b8aa4c30dc..9b8c7f59082 100644
--- a/share/mk/bsd.regress.mk
+++ b/share/mk/bsd.regress.mk
@@ -3,6 +3,7 @@
 
 # No man pages for regression tests.
 NOMAN=
+PKG_ADD= /usr/sbin/pkg_add
 
 # No installation.
 install:
@@ -33,6 +34,16 @@ ${_REGRESS_NEW}:=${${_REGRESS_OLD}}
 .  endif
 .endfor
 
+.if defined(PKG_REQUIRED)
+.  for _p in ${PKG_REQUIRED}
+PREREQ != ${PKG_ADD} ${_p} >/dev/null 2>&1 ; echo $?
+.if ("${PREREQ}" !=0)
+prereq:
+ @echo ${_p} not installed
+.endif
+.  endfor
+.endif
+
 # XXX - Need full path to REGRESS_LOG, otherwise there will be much pain.
 REGRESS_LOG?=/dev/null
 REGRESS_SKIP_TARGETS?=
@@ -65,7 +76,7 @@ _SKIP_FAIL=
 _SKIP_FAIL=-
 .endif
 
-.if defined(REGRESS_ROOT_TARGETS)
+.if defined(REGRESS_ROOT_TARGETS) || defined(PKG_REQUIRED)
 _ROOTUSER!=id -g
 SUDO?=
 .  if (${_ROOTUSER} != 0) && empty(SUDO)

Sergey