#1# SPDX-License-Identifier: BSD-2-Clause2#3# Copyright (c) 2024 Rubicon Communications, LLC (Netgate)4#5# Redistribution and use in source and binary forms, with or without6# modification, are permitted provided that the following conditions7# are met:8# 1. Redistributions of source code must retain the above copyright9# notice, this list of conditions and the following disclaimer.10# 2. Redistributions in binary form must reproduce the above copyright11# notice, this list of conditions and the following disclaimer in the12# documentation and/or other materials provided with the distribution.13#14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24# SUCH DAMAGE.2526. $(atf_get_srcdir)/utils.subr2728atf_test_case "basic" "cleanup"29basic_head()30{31atf_set descr 'Test setting and retrieving debug level'32atf_set require.user root33}3435basic_body()36{37pft_init3839vnet_mkjail debug40atf_check -s exit:0 -e ignore \41jexec debug pfctl -x loud4243atf_check -s exit:0 -o match:'Debug: Loud' \44jexec debug pfctl -si45}4647basic_cleanup()48{49pft_cleanup50}5152atf_test_case "reset" "cleanup"53reset_head()54{55atf_set descr 'Test resetting debug level'56atf_set require.user root57}5859reset_body()60{61pft_init6263vnet_mkjail debug6465# Default is Urgent66atf_check -s exit:0 -o match:'Debug: Urgent' \67jexec debug pfctl -sa68state_limit=$(jexec debug pfctl -sa | grep 'states.*hard limit' | awk '{ print $4; }')6970# Change defaults71pft_set_rules debug \72"set limit states 42"73atf_check -s exit:0 -e ignore \74jexec debug pfctl -x loud7576atf_check -s exit:0 -o match:'Debug: Loud' \77jexec debug pfctl -sa78new_state_limit=$(jexec debug pfctl -sa | grep 'states.*hard limit' | awk '{ print $4; }')79if [ $state_limit -eq $new_state_limit ]; then80jexec debug pfctl -sa81atf_fail "Failed to change state limit"82fi8384# Reset85atf_check -s exit:0 -o ignore -e ignore \86jexec debug pfctl -FR87atf_check -s exit:0 -o match:'Debug: Urgent' \88jexec debug pfctl -sa89new_state_limit=$(jexec debug pfctl -sa | grep 'states.*hard limit' | awk '{ print $4; }')90if [ $state_limit -ne $new_state_limit ]; then91jexec debug pfctl -sa92atf_fail "Failed to reset state limit"93fi94}9596reset_cleanup()97{98pft_cleanup99}100101atf_init_test_cases()102{103atf_add_test_case "basic"104atf_add_test_case "reset"105}106107108