xref: /netbsd-src/tests/usr.bin/mtree/t_sets.sh (revision 2173c07c844454b066e4e45280874e88a0ba1745)
1*2173c07cSriastradh#	$NetBSD: t_sets.sh,v 1.9 2024/05/10 03:29:47 riastradh Exp $
200b317fcSriastradh#
300b317fcSriastradh# Copyright (c) 2024 The NetBSD Foundation, Inc.
400b317fcSriastradh# All rights reserved.
500b317fcSriastradh#
600b317fcSriastradh# Redistribution and use in source and binary forms, with or without
700b317fcSriastradh# modification, are permitted provided that the following conditions
800b317fcSriastradh# are met:
900b317fcSriastradh# 1. Redistributions of source code must retain the above copyright
1000b317fcSriastradh#    notice, this list of conditions and the following disclaimer.
1100b317fcSriastradh# 2. Redistributions in binary form must reproduce the above copyright
1200b317fcSriastradh#    notice, this list of conditions and the following disclaimer in the
1300b317fcSriastradh#    documentation and/or other materials provided with the distribution.
1400b317fcSriastradh#
1500b317fcSriastradh# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1600b317fcSriastradh# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1700b317fcSriastradh# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1800b317fcSriastradh# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1900b317fcSriastradh# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2000b317fcSriastradh# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2100b317fcSriastradh# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2200b317fcSriastradh# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2300b317fcSriastradh# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2400b317fcSriastradh# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2500b317fcSriastradh# POSSIBILITY OF SUCH DAMAGE.
2600b317fcSriastradh#
2700b317fcSriastradh
2800b317fcSriastradhcheck_mtree()
2900b317fcSriastradh{
3000b317fcSriastradh	local set=$1
3100b317fcSriastradh
3200b317fcSriastradh	cd /
33d8f5b04cSrillig	atf_check -o empty -s exit:0 \
3400b317fcSriastradh		mtree -e </etc/mtree/set."$set"
3500b317fcSriastradh}
3600b317fcSriastradh
3700b317fcSriastradhset_case()
3800b317fcSriastradh{
3900b317fcSriastradh	local set=$1
4000b317fcSriastradh
4100b317fcSriastradh	eval "set_${set}_head() { atf_set descr \"/etc/mtree/set.${set}\"; }"
4200b317fcSriastradh	eval "set_${set}_body() { check_mtree ${set}; }"
43cd71d518Sriastradh	eval "set_${set}_defined="
4400b317fcSriastradh}
4500b317fcSriastradh
4600b317fcSriastradhset_case base
47*2173c07cSriastradhset_case base32
48*2173c07cSriastradhset_case base64
4900b317fcSriastradhset_case comp
5000b317fcSriastradhset_case debug
51*2173c07cSriastradhset_case debug32
52*2173c07cSriastradhset_case debug64
5300b317fcSriastradhset_case dtb
5400b317fcSriastradh#set_case etc
5500b317fcSriastradhset_case games
5600b317fcSriastradhset_case gpufw
5700b317fcSriastradhset_case man
58ce6107daSmartinset_case manhtml
5900b317fcSriastradhset_case misc
6000b317fcSriastradhset_case modules
6100b317fcSriastradhset_case rescue
6200b317fcSriastradhset_case tests
6300b317fcSriastradhset_case text
6400b317fcSriastradhset_case xbase
6500b317fcSriastradhset_case xcomp
6600b317fcSriastradhset_case xdebug
6700b317fcSriastradh#set_case xetc
6800b317fcSriastradhset_case xfont
6900b317fcSriastradhset_case xserver
7000b317fcSriastradh
71cd71d518Sriastradhsets_unknown=
72cd71d518Sriastradh
73cd71d518Sriastradhsets_unknown_head()
74cd71d518Sriastradh{
75cd71d518Sriastradh	atf_set descr "Verify this tests lists all sets"
76cd71d518Sriastradh}
77cd71d518Sriastradhsets_unknown_body()
78cd71d518Sriastradh{
7992638538Sriastradh	test -z "$sets_unknown" || atf_fail "Unknown sets: ${sets_unknown}"
80cd71d518Sriastradh}
81cd71d518Sriastradh
8200b317fcSriastradhatf_init_test_cases()
8300b317fcSriastradh{
84cd71d518Sriastradh	local mtree set defined
85cd71d518Sriastradh
86cd71d518Sriastradh	atf_add_test_case sets_unknown
8700b317fcSriastradh
8800b317fcSriastradh	# base is always installed -- hard-code this in case we make a
8900b317fcSriastradh	# mistake with the automatic set detection.
9000b317fcSriastradh	atf_add_test_case set_base
9100b317fcSriastradh
9200b317fcSriastradh	# Test all of the sets that are installed, except for some
9300b317fcSriastradh	# special cases.
9400b317fcSriastradh	for mtree in /etc/mtree/set.*; do
9500b317fcSriastradh		set=${mtree#/etc/mtree/set.}
9600b317fcSriastradh		case $set in
9700b317fcSriastradh		base)	# Handled above already.
9800b317fcSriastradh			continue
9900b317fcSriastradh			;;
100e9be82c8Smartin		dtb)
101e9be82c8Smartin			# contents of this set go to the boot partition,
102e9be82c8Smartin			# which may not be mounted during normal operation
103e9be82c8Smartin			if [ ! -d /boot/dtb ]; then
104e9be82c8Smartin				continue;
105e9be82c8Smartin			fi
106e9be82c8Smartin			;;
10700b317fcSriastradh		etc|xetc)
10800b317fcSriastradh			# etc and xetc have files that may be modified
10900b317fcSriastradh			# on installation, and also contain log files,
11000b317fcSriastradh			# so let's skip them for now.
11100b317fcSriastradh			continue
11200b317fcSriastradh			;;
11300b317fcSriastradh		*)	;;
11400b317fcSriastradh		esac
115cd71d518Sriastradh
116cd71d518Sriastradh		# If we have a test for this set, add it.  Otherwise,
117cd71d518Sriastradh		# add it to the unknown list to make the test suite
118cd71d518Sriastradh		# fail.
119cd71d518Sriastradh		eval 'defined=${set_'"$set"'_defined+yes}'
120cd71d518Sriastradh		if [ -n "$defined" ]; then
12100b317fcSriastradh			atf_add_test_case set_"${set}"
122cd71d518Sriastradh		else
123cd71d518Sriastradh			sets_unknown="${sets_unknown}${sets_unknown:+ }${set}"
124cd71d518Sriastradh		fi
12500b317fcSriastradh	done
12600b317fcSriastradh}
127