11.9Sriastrad#	$NetBSD: t_sets.sh,v 1.9 2024/05/10 03:29:47 riastradh Exp $
21.1Sriastrad#
31.1Sriastrad# Copyright (c) 2024 The NetBSD Foundation, Inc.
41.1Sriastrad# All rights reserved.
51.1Sriastrad#
61.1Sriastrad# Redistribution and use in source and binary forms, with or without
71.1Sriastrad# modification, are permitted provided that the following conditions
81.1Sriastrad# are met:
91.1Sriastrad# 1. Redistributions of source code must retain the above copyright
101.1Sriastrad#    notice, this list of conditions and the following disclaimer.
111.1Sriastrad# 2. Redistributions in binary form must reproduce the above copyright
121.1Sriastrad#    notice, this list of conditions and the following disclaimer in the
131.1Sriastrad#    documentation and/or other materials provided with the distribution.
141.1Sriastrad#
151.1Sriastrad# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
161.1Sriastrad# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
171.1Sriastrad# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
181.1Sriastrad# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
191.1Sriastrad# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
201.1Sriastrad# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
211.1Sriastrad# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
221.1Sriastrad# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
231.1Sriastrad# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
241.1Sriastrad# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
251.1Sriastrad# POSSIBILITY OF SUCH DAMAGE.
261.1Sriastrad#
271.1Sriastrad
281.1Sriastradcheck_mtree()
291.1Sriastrad{
301.1Sriastrad	local set=$1
311.1Sriastrad
321.1Sriastrad	cd /
331.5Srillig	atf_check -o empty -s exit:0 \
341.1Sriastrad		mtree -e </etc/mtree/set."$set"
351.1Sriastrad}
361.1Sriastrad
371.1Sriastradset_case()
381.1Sriastrad{
391.1Sriastrad	local set=$1
401.1Sriastrad
411.1Sriastrad	eval "set_${set}_head() { atf_set descr \"/etc/mtree/set.${set}\"; }"
421.1Sriastrad	eval "set_${set}_body() { check_mtree ${set}; }"
431.6Sriastrad	eval "set_${set}_defined="
441.1Sriastrad}
451.1Sriastrad
461.1Sriastradset_case base
471.9Sriastradset_case base32
481.9Sriastradset_case base64
491.1Sriastradset_case comp
501.1Sriastradset_case debug
511.9Sriastradset_case debug32
521.9Sriastradset_case debug64
531.1Sriastradset_case dtb
541.1Sriastrad#set_case etc
551.1Sriastradset_case games
561.1Sriastradset_case gpufw
571.1Sriastradset_case man
581.8Smartinset_case manhtml
591.1Sriastradset_case misc
601.1Sriastradset_case modules
611.1Sriastradset_case rescue
621.1Sriastradset_case tests
631.1Sriastradset_case text
641.1Sriastradset_case xbase
651.1Sriastradset_case xcomp
661.1Sriastradset_case xdebug
671.1Sriastrad#set_case xetc
681.1Sriastradset_case xfont
691.1Sriastradset_case xserver
701.1Sriastrad
711.6Sriastradsets_unknown=
721.6Sriastrad
731.6Sriastradsets_unknown_head()
741.6Sriastrad{
751.6Sriastrad	atf_set descr "Verify this tests lists all sets"
761.6Sriastrad}
771.6Sriastradsets_unknown_body()
781.6Sriastrad{
791.7Sriastrad	test -z "$sets_unknown" || atf_fail "Unknown sets: ${sets_unknown}"
801.6Sriastrad}
811.6Sriastrad
821.1Sriastradatf_init_test_cases()
831.1Sriastrad{
841.6Sriastrad	local mtree set defined
851.6Sriastrad
861.6Sriastrad	atf_add_test_case sets_unknown
871.1Sriastrad
881.1Sriastrad	# base is always installed -- hard-code this in case we make a
891.1Sriastrad	# mistake with the automatic set detection.
901.1Sriastrad	atf_add_test_case set_base
911.1Sriastrad
921.1Sriastrad	# Test all of the sets that are installed, except for some
931.1Sriastrad	# special cases.
941.1Sriastrad	for mtree in /etc/mtree/set.*; do
951.1Sriastrad		set=${mtree#/etc/mtree/set.}
961.1Sriastrad		case $set in
971.1Sriastrad		base)	# Handled above already.
981.1Sriastrad			continue
991.1Sriastrad			;;
1001.4Smartin		dtb)
1011.4Smartin			# contents of this set go to the boot partition,
1021.4Smartin			# which may not be mounted during normal operation
1031.4Smartin			if [ ! -d /boot/dtb ]; then
1041.4Smartin				continue;
1051.4Smartin			fi
1061.4Smartin			;;
1071.1Sriastrad		etc|xetc)
1081.1Sriastrad			# etc and xetc have files that may be modified
1091.1Sriastrad			# on installation, and also contain log files,
1101.1Sriastrad			# so let's skip them for now.
1111.1Sriastrad			continue
1121.1Sriastrad			;;
1131.1Sriastrad		*)	;;
1141.1Sriastrad		esac
1151.6Sriastrad
1161.6Sriastrad		# If we have a test for this set, add it.  Otherwise,
1171.6Sriastrad		# add it to the unknown list to make the test suite
1181.6Sriastrad		# fail.
1191.6Sriastrad		eval 'defined=${set_'"$set"'_defined+yes}'
1201.6Sriastrad		if [ -n "$defined" ]; then
1211.6Sriastrad			atf_add_test_case set_"${set}"
1221.6Sriastrad		else
1231.6Sriastrad			sets_unknown="${sets_unknown}${sets_unknown:+ }${set}"
1241.6Sriastrad		fi
1251.1Sriastrad	done
1261.1Sriastrad}
127