xref: /freebsd/usr.bin/getconf/tests/getconf_test.sh (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
1#
2# Copyright (c) 2017 Dell EMC
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1. Redistributions of source code must retain the above copyright
9#    notice, this list of conditions and the following disclaimer.
10# 2. Redistributions in binary form must reproduce the above copyright
11#    notice, this list of conditions and the following disclaimer in the
12#    documentation and/or other materials provided with the distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24# SUCH DAMAGE.
25#
26
27POSITIVE_EXP_EXPR_RE='match:[1-9][0-9]*'
28
29POSIX_CONSTANTS="ARG_MAX PAGESIZE"
30POSIX_PATH_CONSTANTS="NAME_MAX PATH_MAX"
31SUPPORTED_32BIT_PROGRAM_ENVS="POSIX_V6_ILP32_OFFBIG"
32SUPPORTED_64BIT_PROGRAM_ENVS="POSIX_V6_LP64_OFF64"
33UNAVAILABLE_PROGRAM_ENVS="I_AM_BOGUS"
34UNSUPPORTED_32BIT_PROGRAM_ENVS="POSIX_V6_LP64_OFF64"
35UNSUPPORTED_64BIT_PROGRAM_ENVS="POSIX_V6_ILP32_OFFBIG"
36
37XOPEN_CONSTANTS=
38
39# XXX: hardcoded sysexits
40EX_USAGE=64
41EX_UNAVAILABLE=69
42
43set_program_environments()
44{
45	atf_check -o save:arch_type.out $(atf_get_srcdir)/arch_type
46	arch_type=$(cat arch_type.out)
47	case "$arch_type" in
48	ILP32|LP32)
49		SUPPORTED_PROGRAM_ENVS="$SUPPORTED_PROGRAM_ENVS $SUPPORTED_32BIT_PROGRAM_ENVS"
50		UNSUPPORTED_PROGRAM_ENVS="$UNSUPPORTED_PROGRAM_ENVS $UNSUPPORTED_32BIT_PROGRAM_ENVS"
51		;;
52	LP64)
53		SUPPORTED_PROGRAM_ENVS="$SUPPORTED_PROGRAM_ENVS $SUPPORTED_64BIT_PROGRAM_ENVS"
54		UNSUPPORTED_PROGRAM_ENVS="$UNSUPPORTED_PROGRAM_ENVS $UNSUPPORTED_64BIT_PROGRAM_ENVS"
55		;;
56	*)
57		atf_fail "arch_type output unexpected: $arch_type"
58		;;
59	esac
60}
61
62atf_test_case no_programming_environment
63no_programming_environment_head()
64{
65	atf_set	"descr" "Test some POSIX constants as a positive functional test"
66}
67
68no_programming_environment_body()
69{
70	for var in $POSIX_CONSTANTS; do
71		atf_check -o "$POSITIVE_EXP_EXPR_RE" getconf $var
72	done
73	for var in $POSIX_PATH_CONSTANTS; do
74		atf_check -o "$POSITIVE_EXP_EXPR_RE" getconf $var .
75	done
76}
77
78atf_test_case programming_environment
79programming_environment_head()
80{
81	atf_set	"descr" "Test some constants with specific programming environments"
82}
83
84programming_environment_body()
85{
86	set_program_environments
87
88	for prog_env in ${SUPPORTED_PROGRAM_ENVS}; do
89		for var in $POSIX_CONSTANTS; do
90			atf_check -o "$POSITIVE_EXP_EXPR_RE" \
91			    getconf -v $prog_env $var
92		done
93	done
94}
95
96atf_test_case programming_environment_unsupported
97programming_environment_unsupported_head()
98{
99	atf_set	"descr" "Test for unsupported environments"
100}
101
102programming_environment_unsupported_body()
103{
104	set_program_environments
105
106	for prog_env in ${UNSUPPORTED_PROGRAM_ENVS}; do
107		for var in $POSIX_CONSTANTS; do
108			atf_check -e not-empty -s exit:$EX_UNAVAILABLE \
109			    getconf -v $prog_env $var
110		done
111	done
112}
113
114atf_init_test_cases()
115{
116	atf_add_test_case no_programming_environment
117	atf_add_test_case programming_environment
118	atf_add_test_case programming_environment_unsupported
119}
120