1# $NetBSD: t_sets.sh,v 1.9 2024/05/10 03:29:47 riastradh Exp $ 2# 3# Copyright (c) 2024 The NetBSD Foundation, Inc. 4# All rights reserved. 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25# POSSIBILITY OF SUCH DAMAGE. 26# 27 28check_mtree() 29{ 30 local set=$1 31 32 cd / 33 atf_check -o empty -s exit:0 \ 34 mtree -e </etc/mtree/set."$set" 35} 36 37set_case() 38{ 39 local set=$1 40 41 eval "set_${set}_head() { atf_set descr \"/etc/mtree/set.${set}\"; }" 42 eval "set_${set}_body() { check_mtree ${set}; }" 43 eval "set_${set}_defined=" 44} 45 46set_case base 47set_case base32 48set_case base64 49set_case comp 50set_case debug 51set_case debug32 52set_case debug64 53set_case dtb 54#set_case etc 55set_case games 56set_case gpufw 57set_case man 58set_case manhtml 59set_case misc 60set_case modules 61set_case rescue 62set_case tests 63set_case text 64set_case xbase 65set_case xcomp 66set_case xdebug 67#set_case xetc 68set_case xfont 69set_case xserver 70 71sets_unknown= 72 73sets_unknown_head() 74{ 75 atf_set descr "Verify this tests lists all sets" 76} 77sets_unknown_body() 78{ 79 test -z "$sets_unknown" || atf_fail "Unknown sets: ${sets_unknown}" 80} 81 82atf_init_test_cases() 83{ 84 local mtree set defined 85 86 atf_add_test_case sets_unknown 87 88 # base is always installed -- hard-code this in case we make a 89 # mistake with the automatic set detection. 90 atf_add_test_case set_base 91 92 # Test all of the sets that are installed, except for some 93 # special cases. 94 for mtree in /etc/mtree/set.*; do 95 set=${mtree#/etc/mtree/set.} 96 case $set in 97 base) # Handled above already. 98 continue 99 ;; 100 dtb) 101 # contents of this set go to the boot partition, 102 # which may not be mounted during normal operation 103 if [ ! -d /boot/dtb ]; then 104 continue; 105 fi 106 ;; 107 etc|xetc) 108 # etc and xetc have files that may be modified 109 # on installation, and also contain log files, 110 # so let's skip them for now. 111 continue 112 ;; 113 *) ;; 114 esac 115 116 # If we have a test for this set, add it. Otherwise, 117 # add it to the unknown list to make the test suite 118 # fail. 119 eval 'defined=${set_'"$set"'_defined+yes}' 120 if [ -n "$defined" ]; then 121 atf_add_test_case set_"${set}" 122 else 123 sets_unknown="${sets_unknown}${sets_unknown:+ }${set}" 124 fi 125 done 126} 127