xref: /freebsd/sbin/sysctl/tests/sysctl_test.sh (revision 0c428864495af9dc7d2af4d0a5ae21732af9c739)
1f126d349SKirk McKusick# Copyright (c) 2022 Yoshihiro Ota <ota@j.email.ne.jp>
2f126d349SKirk McKusick#
3f126d349SKirk McKusick# Redistribution and use in source and binary forms, with or without
4f126d349SKirk McKusick# modification, are permitted provided that the following conditions
5f126d349SKirk McKusick# are met:
6f126d349SKirk McKusick# 1. Redistributions of source code must retain the above copyright
7f126d349SKirk McKusick#    notice, this list of conditions and the following disclaimer.
8f126d349SKirk McKusick# 2. Redistributions in binary form must reproduce the above copyright
9f126d349SKirk McKusick#    notice, this list of conditions and the following disclaimer in the
10f126d349SKirk McKusick#    documentation and/or other materials provided with the distribution.
11f126d349SKirk McKusick#
12f126d349SKirk McKusick# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13f126d349SKirk McKusick# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14f126d349SKirk McKusick# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15f126d349SKirk McKusick# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16f126d349SKirk McKusick# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17f126d349SKirk McKusick# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18f126d349SKirk McKusick# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19f126d349SKirk McKusick# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20f126d349SKirk McKusick# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21f126d349SKirk McKusick# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22f126d349SKirk McKusick# SUCH DAMAGE.
23f126d349SKirk McKusick
24f126d349SKirk McKusicksysctl_name="kern.ostype"
25f126d349SKirk McKusicksysctl_value="FreeBSD"
26f126d349SKirk McKusicksysctl_type="string"
27f126d349SKirk McKusicksysctl_description="Operating system type"
28f126d349SKirk McKusick
29f126d349SKirk McKusickatf_test_case sysctl_by_name
30f126d349SKirk McKusicksysctl_by_name_head()
31f126d349SKirk McKusick{
32f126d349SKirk McKusick	atf_set "descr" "Verify name without any arguments"
33f126d349SKirk McKusick}
34f126d349SKirk McKusicksysctl_by_name_body()
35f126d349SKirk McKusick{
36f126d349SKirk McKusick	atf_check -o "inline:${sysctl_name}: ${sysctl_value}\n" sysctl ${sysctl_name}
37f126d349SKirk McKusick}
38f126d349SKirk McKusick
39f126d349SKirk McKusick
40f126d349SKirk McKusickatf_test_case sysctl_nflag
41*0c428864SKyle Evanssysctl_nflag_head()
42f126d349SKirk McKusick{
43f126d349SKirk McKusick	atf_set "descr" "Verify -n argument"
44f126d349SKirk McKusick}
45f126d349SKirk McKusicksysctl_nflag_body()
46f126d349SKirk McKusick{
47f126d349SKirk McKusick	atf_check -o "inline:${sysctl_value}\n" sysctl -n ${sysctl_name}
48f126d349SKirk McKusick}
49f126d349SKirk McKusick
50f126d349SKirk McKusick
51f126d349SKirk McKusickatf_test_case sysctl_eflag
52*0c428864SKyle Evanssysctl_eflag_head()
53f126d349SKirk McKusick{
54f126d349SKirk McKusick	atf_set "descr" "Verify -e argument"
55f126d349SKirk McKusick}
56f126d349SKirk McKusicksysctl_eflag_body()
57f126d349SKirk McKusick{
58f126d349SKirk McKusick	atf_check -o "inline:${sysctl_name}=${sysctl_value}\n" sysctl -e ${sysctl_name}
59f126d349SKirk McKusick}
60f126d349SKirk McKusick
61f126d349SKirk McKusick
62f126d349SKirk McKusickatf_test_case sysctl_tflag
63*0c428864SKyle Evanssysctl_tflag_head()
64f126d349SKirk McKusick{
65f126d349SKirk McKusick	atf_set "descr" "Verify -t argument"
66f126d349SKirk McKusick}
67f126d349SKirk McKusicksysctl_tflag_body()
68f126d349SKirk McKusick{
69f126d349SKirk McKusick	atf_check -o "inline:${sysctl_name}: ${sysctl_type}\n" sysctl -t ${sysctl_name}
70f126d349SKirk McKusick}
71f126d349SKirk McKusick
72f126d349SKirk McKusick
73f126d349SKirk McKusickatf_test_case sysctl_dflag
74*0c428864SKyle Evanssysctl_dflag_head()
75f126d349SKirk McKusick{
76f126d349SKirk McKusick	atf_set "descr" "Verify -d argument"
77f126d349SKirk McKusick}
78f126d349SKirk McKusicksysctl_dflag_body()
79f126d349SKirk McKusick{
80f126d349SKirk McKusick	atf_check -o "inline:${sysctl_name}: ${sysctl_description}\n" sysctl -d ${sysctl_name}
81f126d349SKirk McKusick}
82f126d349SKirk McKusick
83f126d349SKirk McKusick
84f126d349SKirk McKusickatf_test_case sysctl_tflag_dflag
85*0c428864SKyle Evanssysctl_tflag_dflag_head()
86f126d349SKirk McKusick{
87f126d349SKirk McKusick	atf_set "descr" "Verify -t -d arguments"
88f126d349SKirk McKusick}
89f126d349SKirk McKusicksysctl_tflag_dflag_body()
90f126d349SKirk McKusick{
91f126d349SKirk McKusick	atf_check -o "inline:${sysctl_name}: ${sysctl_type}: ${sysctl_description}\n" sysctl -t -d ${sysctl_name}
92f126d349SKirk McKusick	atf_check -o "inline:${sysctl_name}: ${sysctl_type}: ${sysctl_description}\n" sysctl -d -t ${sysctl_name}
93f126d349SKirk McKusick}
94f126d349SKirk McKusick
95f126d349SKirk McKusick
96f126d349SKirk McKusickatf_test_case sysctl_nflag_tflag_dflag
97*0c428864SKyle Evanssysctl_nflag_tflag_dflag_head()
98f126d349SKirk McKusick{
99f126d349SKirk McKusick	atf_set "descr" "Verify -n -t -d arguments"
100f126d349SKirk McKusick}
101f126d349SKirk McKusicksysctl_nflag_tflag_dflag_body()
102f126d349SKirk McKusick{
103f126d349SKirk McKusick	atf_check -o "inline:${sysctl_type}: ${sysctl_description}\n" sysctl -n -t -d ${sysctl_name}
104f126d349SKirk McKusick}
105f126d349SKirk McKusick
106f126d349SKirk McKusick
107f126d349SKirk McKusickatf_init_test_cases()
108f126d349SKirk McKusick{
109f126d349SKirk McKusick	atf_add_test_case sysctl_by_name
110f126d349SKirk McKusick	atf_add_test_case sysctl_nflag
111f126d349SKirk McKusick	atf_add_test_case sysctl_eflag
112f126d349SKirk McKusick	atf_add_test_case sysctl_tflag
113f126d349SKirk McKusick	atf_add_test_case sysctl_dflag
114f126d349SKirk McKusick	atf_add_test_case sysctl_tflag_dflag
115f126d349SKirk McKusick	atf_add_test_case sysctl_nflag_tflag_dflag
116f126d349SKirk McKusick}
117