17bdfc3b7SEnji Cooper# 27bdfc3b7SEnji Cooper# Copyright 2015 EMC Corp. 37bdfc3b7SEnji Cooper# All rights reserved. 47bdfc3b7SEnji Cooper# 57bdfc3b7SEnji Cooper# Redistribution and use in source and binary forms, with or without 67bdfc3b7SEnji Cooper# modification, are permitted provided that the following conditions are 77bdfc3b7SEnji Cooper# met: 87bdfc3b7SEnji Cooper# 97bdfc3b7SEnji Cooper# * Redistributions of source code must retain the above copyright 107bdfc3b7SEnji Cooper# notice, this list of conditions and the following disclaimer. 117bdfc3b7SEnji Cooper# * Redistributions in binary form must reproduce the above copyright 127bdfc3b7SEnji Cooper# notice, this list of conditions and the following disclaimer in the 137bdfc3b7SEnji Cooper# documentation and/or other materials provided with the distribution. 147bdfc3b7SEnji Cooper# 157bdfc3b7SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 167bdfc3b7SEnji Cooper# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 177bdfc3b7SEnji Cooper# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 187bdfc3b7SEnji Cooper# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 197bdfc3b7SEnji Cooper# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 207bdfc3b7SEnji Cooper# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 217bdfc3b7SEnji Cooper# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 227bdfc3b7SEnji Cooper# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 237bdfc3b7SEnji Cooper# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 247bdfc3b7SEnji Cooper# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 257bdfc3b7SEnji Cooper# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 267bdfc3b7SEnji Cooper 2766845bf5SEnji CooperKB=1024 28fc2b0536SEnji Cooper: ${TMPDIR=/tmp} 29*286258a9SEd MasteDEFAULT_MTREE_KEYWORDS="type,mode,gid,uid,size,link,time" 30fc2b0536SEnji CooperTEST_IMAGE="$TMPDIR/test.img" 31fc2b0536SEnji CooperTEST_INPUTS_DIR="$TMPDIR/inputs" 32fc2b0536SEnji CooperTEST_MD_DEVICE_FILE="$TMPDIR/md.output" 33fc2b0536SEnji CooperTEST_MOUNT_DIR="$TMPDIR/mnt" 34fc2b0536SEnji CooperTEST_SPEC_FILE="$TMPDIR/mtree.spec" 35fc2b0536SEnji Cooper 36fc2b0536SEnji Coopercheck_image_contents() 37fc2b0536SEnji Cooper{ 38fc2b0536SEnji Cooper local directories=$TEST_INPUTS_DIR 39fc2b0536SEnji Cooper local excludes mtree_excludes_arg mtree_file 40c213f0dbSEnji Cooper local mtree_keywords="$DEFAULT_MTREE_KEYWORDS" 41fc2b0536SEnji Cooper 42fc2b0536SEnji Cooper while getopts "d:f:m:X:" flag; do 43fc2b0536SEnji Cooper case "$flag" in 44fc2b0536SEnji Cooper d) 45fc2b0536SEnji Cooper directories="$directories $OPTARG" 46fc2b0536SEnji Cooper ;; 47fc2b0536SEnji Cooper f) 48fc2b0536SEnji Cooper mtree_file=$OPTARG 49fc2b0536SEnji Cooper ;; 50fc2b0536SEnji Cooper m) 51fc2b0536SEnji Cooper mtree_keywords=$OPTARG 52fc2b0536SEnji Cooper ;; 53fc2b0536SEnji Cooper X) 54fc2b0536SEnji Cooper excludes="$excludes $OPTARG" 55fc2b0536SEnji Cooper ;; 56fc2b0536SEnji Cooper *) 57fc2b0536SEnji Cooper echo "usage: check_image_contents [-d directory ...] [-f mtree-file] [-m mtree-keywords] [-X exclude]" 58fc2b0536SEnji Cooper atf_fail "unhandled option: $flag" 59fc2b0536SEnji Cooper ;; 60fc2b0536SEnji Cooper esac 61fc2b0536SEnji Cooper done 62fc2b0536SEnji Cooper 63fc2b0536SEnji Cooper if [ -n "$excludes" ]; then 64fc2b0536SEnji Cooper echo "$excludes" | tr ' ' '\n' > excludes.txt 65fc2b0536SEnji Cooper mtree_excludes_arg="-X excludes.txt" 66fc2b0536SEnji Cooper fi 67fc2b0536SEnji Cooper 68fc2b0536SEnji Cooper if [ -z "$mtree_file" ]; then 69fc2b0536SEnji Cooper mtree_file=input_spec.mtree 70fc2b0536SEnji Cooper for directory in $directories; do 71fc2b0536SEnji Cooper mtree -c -k $mtree_keywords -p $directory $mtree_excludes_arg 72fc2b0536SEnji Cooper done > $mtree_file 73fc2b0536SEnji Cooper fi 74fc2b0536SEnji Cooper 75fc2b0536SEnji Cooper echo "<---- Input spec BEGIN ---->" 76fc2b0536SEnji Cooper cat $mtree_file 77fc2b0536SEnji Cooper echo "<---- Input spec END ---->" 78fc2b0536SEnji Cooper atf_check -e empty -o empty -s exit:0 \ 79fc2b0536SEnji Cooper mtree -UW -f $mtree_file \ 80fc2b0536SEnji Cooper -p $TEST_MOUNT_DIR \ 81fc2b0536SEnji Cooper $mtree_excludes_arg 82fc2b0536SEnji Cooper} 837bdfc3b7SEnji Cooper 8466845bf5SEnji Coopercreate_test_dirs() 857bdfc3b7SEnji Cooper{ 867bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 mkdir -m 0777 -p $TEST_MOUNT_DIR 877bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 mkdir -m 0777 -p $TEST_INPUTS_DIR 887bdfc3b7SEnji Cooper} 897bdfc3b7SEnji Cooper 907bdfc3b7SEnji Coopercreate_test_inputs() 917bdfc3b7SEnji Cooper{ 9266845bf5SEnji Cooper create_test_dirs 9366845bf5SEnji Cooper 9466845bf5SEnji Cooper cd $TEST_INPUTS_DIR 957bdfc3b7SEnji Cooper 967bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 mkdir -m 0755 -p a/b/1 977bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 ln -s a/b c 987bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 touch d 997bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 ln d e 1007bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 touch .f 1017bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 mkdir .g 10266845bf5SEnji Cooper # XXX: fifos on the filesystem don't match fifos created by makefs for 10366845bf5SEnji Cooper # some odd reason. 10466845bf5SEnji Cooper #atf_check -e empty -s exit:0 mkfifo h 1057bdfc3b7SEnji Cooper atf_check -e ignore -s exit:0 dd if=/dev/zero of=i count=1000 bs=1 1067bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 touch klmn 1077bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 touch opqr 1087bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 touch stuv 1097bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 install -m 0755 /dev/null wxyz 1107bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 touch 0b00000001 1117bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 touch 0b00000010 1127bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 touch 0b00000011 1137bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 touch 0b00000100 1147bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 touch 0b00000101 1157bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 touch 0b00000110 1167bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 touch 0b00000111 1177bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 touch 0b00001000 1187bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 touch 0b00001001 1197bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 touch 0b00001010 1207bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 touch 0b00001011 1217bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 touch 0b00001100 1227bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 touch 0b00001101 1237bdfc3b7SEnji Cooper atf_check -e empty -s exit:0 touch 0b00001110 12466845bf5SEnji Cooper 12566845bf5SEnji Cooper for filesize in 1 512 $(( 2 * $KB )) $(( 10 * $KB )) $(( 512 * $KB )); \ 12666845bf5SEnji Cooper do 12766845bf5SEnji Cooper atf_check -e ignore -o empty -s exit:0 \ 12866845bf5SEnji Cooper dd if=/dev/zero of=${filesize}.file bs=1 \ 12966845bf5SEnji Cooper count=1 oseek=${filesize} conv=sparse 13066845bf5SEnji Cooper files="${files} ${filesize}.file" 13166845bf5SEnji Cooper done 13266845bf5SEnji Cooper 13366845bf5SEnji Cooper cd - 1347bdfc3b7SEnji Cooper} 135fc2b0536SEnji Cooper 136fc2b0536SEnji Coopermount_image() 137fc2b0536SEnji Cooper{ 138fc2b0536SEnji Cooper atf_check -e empty -o save:$TEST_MD_DEVICE_FILE -s exit:0 \ 139fc2b0536SEnji Cooper mdconfig -a -f $TEST_IMAGE 140fc2b0536SEnji Cooper atf_check -e empty -o empty -s exit:0 \ 141fc2b0536SEnji Cooper $MOUNT /dev/$(cat $TEST_MD_DEVICE_FILE) $TEST_MOUNT_DIR 142fc2b0536SEnji Cooper} 143fc2b0536SEnji Cooper 144