t_npf.sh revision 1.8
11.8Sriastrad# $NetBSD: t_npf.sh,v 1.8 2025/04/18 20:06:39 riastradh Exp $
21.1Smartin#
31.1Smartin# Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
41.1Smartin# All rights reserved.
51.1Smartin#
61.1Smartin# Redistribution and use in source and binary forms, with or without
71.1Smartin# modification, are permitted provided that the following conditions
81.1Smartin# are met:
91.1Smartin# 1. Redistributions of source code must retain the above copyright
101.1Smartin#    notice, this list of conditions and the following disclaimer.
111.1Smartin# 2. Redistributions in binary form must reproduce the above copyright
121.1Smartin#    notice, this list of conditions and the following disclaimer in the
131.1Smartin#    documentation and/or other materials provided with the distribution.
141.1Smartin#
151.1Smartin# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
161.1Smartin# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
171.1Smartin# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
181.1Smartin# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
191.1Smartin# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
201.1Smartin# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
211.1Smartin# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
221.1Smartin# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
231.1Smartin# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
241.1Smartin# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
251.1Smartin# POSSIBILITY OF SUCH DAMAGE.
261.1Smartin#
271.1Smartin
281.1Smartinrun_test()
291.1Smartin{
301.1Smartin	local name="${1}"
311.1Smartin
321.4Smartin	atf_check -o ignore -e ignore npfctl debug -c "$(atf_get_srcdir)/npftest.conf" -o ./npf.plist
331.1Smartin	atf_check -o ignore npftest -c npf.plist -T "${name}"
341.1Smartin}
351.1Smartin
361.8Sriastradcleanup()
371.8Sriastrad{
381.8Sriastrad
391.8Sriastrad	if [ -f npftest.core ]; then
401.8Sriastrad		gdb -batch -ex bt npftest npftest.core
411.8Sriastrad		# Extract kernel logs including a panic message
421.8Sriastrad		strings npftest.core |grep -E '^\[.+\] '
431.8Sriastrad	fi
441.8Sriastrad}
451.8Sriastrad
461.1Smartinadd_test()
471.1Smartin{
481.1Smartin	local name="${1}"; shift
491.1Smartin	local desc="${*}";
501.1Smartin
511.8Sriastrad	atf_test_case "npf_${name}" cleanup
521.3Sozaki	eval "npf_${name}_head() {
531.3Sozaki			atf_set descr \"${desc}\"
541.3Sozaki			atf_set require.progs npfctl npftest
551.3Sozaki		}
561.3Sozaki	    npf_${name}_body() {
571.3Sozaki			run_test ${name}
581.8Sriastrad		}
591.8Sriastrad	    npf_${name}_cleanup() {
601.8Sriastrad			cleanup
611.1Smartin		}"
621.1Smartin	atf_add_test_case "npf_${name}"
631.1Smartin}
641.1Smartin
651.1Smartinatf_init_test_cases()
661.1Smartin{
671.1Smartin	LIST=/tmp/t_npf.$$
681.1Smartin	trap "rm -f $LIST" EXIT
691.1Smartin
701.2Smartin	sh -ec 'npftest -L || printf "dummy\tnone\n"' > $LIST 2>/dev/null
711.1Smartin
721.1Smartin	while read tag desc
731.1Smartin	do
741.1Smartin		add_test "${tag}" "${desc}"
751.1Smartin	done < $LIST
761.1Smartin}
77