1# 2# SPDX-License-Identifier: BSD-2-Clause 3# 4# Copyright (c) 2022 Yoshihiro Ota <ota@j.email.ne.jp> 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# 27 28sysctl_name="kern.ostype" 29sysctl_value="FreeBSD" 30sysctl_type="string" 31sysctl_description="Operating system type" 32 33atf_test_case sysctl_aflag 34sysctl_aflag_head() 35{ 36 atf_set "descr" "Exercise all sysctl handlers" 37} 38sysctl_aflag_body() 39{ 40 # Avoid using atf_check here since sysctl -ao generates tons of 41 # output and it would all otherwise be saved. 42 sysctl -ao >/dev/null 2>stderr 43 if [ $? -ne 0 ]; then 44 atf_fail "sysctl -ao failed" 45 elif [ -s stderr ]; then 46 cat stderr 47 atf_fail "sysctl -ao printed to stderr" 48 fi 49} 50 51 52atf_test_case sysctl_aflag_jail 53sysctl_aflag_jail_head() 54{ 55 atf_set "descr" "Exercise all sysctl handlers in a jail" 56 atf_set "require.user" "root" 57} 58sysctl_aflag_jail_body() 59{ 60 local jail 61 62 jail=sysctl_test_aflag_jail 63 64 # Avoid using atf_check here since sysctl -ao generates tons of 65 # output and it would all otherwise be saved. 66 jail -c name=$jail command=sysctl -ao >/dev/null 2>stderr 67 if [ $? -ne 0 ]; then 68 atf_fail "sysctl -ao failed" 69 elif [ -s stderr ]; then 70 cat stderr 71 atf_fail "sysctl -ao printed to stderr" 72 fi 73 74 jail -c name=$jail vnet command=sysctl -ao >/dev/null 2>stderr 75 if [ $? -ne 0 ]; then 76 atf_fail "sysctl -ao failed" 77 elif [ -s stderr ]; then 78 cat stderr 79 atf_fail "sysctl -ao printed to stderr" 80 fi 81} 82 83 84atf_test_case sysctl_by_name 85sysctl_by_name_head() 86{ 87 atf_set "descr" "Verify name without any arguments" 88} 89sysctl_by_name_body() 90{ 91 atf_check -o "inline:${sysctl_name}: ${sysctl_value}\n" sysctl ${sysctl_name} 92} 93 94 95atf_test_case sysctl_nflag 96sysctl_nflag_head() 97{ 98 atf_set "descr" "Verify -n argument" 99} 100sysctl_nflag_body() 101{ 102 atf_check -o "inline:${sysctl_value}\n" sysctl -n ${sysctl_name} 103} 104 105 106atf_test_case sysctl_eflag 107sysctl_eflag_head() 108{ 109 atf_set "descr" "Verify -e argument" 110} 111sysctl_eflag_body() 112{ 113 atf_check -o "inline:${sysctl_name}=${sysctl_value}\n" sysctl -e ${sysctl_name} 114} 115 116 117atf_test_case sysctl_tflag 118sysctl_tflag_head() 119{ 120 atf_set "descr" "Verify -t argument" 121} 122sysctl_tflag_body() 123{ 124 atf_check -o "inline:${sysctl_name}: ${sysctl_type}\n" sysctl -t ${sysctl_name} 125} 126 127 128atf_test_case sysctl_dflag 129sysctl_dflag_head() 130{ 131 atf_set "descr" "Verify -d argument" 132} 133sysctl_dflag_body() 134{ 135 atf_check -o "inline:${sysctl_name}: ${sysctl_description}\n" sysctl -d ${sysctl_name} 136} 137 138 139atf_test_case sysctl_tflag_dflag 140sysctl_tflag_dflag_head() 141{ 142 atf_set "descr" "Verify -t -d arguments" 143} 144sysctl_tflag_dflag_body() 145{ 146 atf_check -o "inline:${sysctl_name}: ${sysctl_type}: ${sysctl_description}\n" sysctl -t -d ${sysctl_name} 147 atf_check -o "inline:${sysctl_name}: ${sysctl_type}: ${sysctl_description}\n" sysctl -d -t ${sysctl_name} 148} 149 150 151atf_test_case sysctl_nflag_tflag_dflag 152sysctl_nflag_tflag_dflag_head() 153{ 154 atf_set "descr" "Verify -n -t -d arguments" 155} 156sysctl_nflag_tflag_dflag_body() 157{ 158 atf_check -o "inline:${sysctl_type}: ${sysctl_description}\n" sysctl -n -t -d ${sysctl_name} 159} 160 161 162atf_init_test_cases() 163{ 164 atf_add_test_case sysctl_aflag 165 atf_add_test_case sysctl_aflag_jail 166 atf_add_test_case sysctl_by_name 167 atf_add_test_case sysctl_nflag 168 atf_add_test_case sysctl_eflag 169 atf_add_test_case sysctl_tflag 170 atf_add_test_case sysctl_dflag 171 atf_add_test_case sysctl_tflag_dflag 172 atf_add_test_case sysctl_nflag_tflag_dflag 173} 174