1289694Sngie# 2289694Sngie# Copyright 2015 EMC Corp. 3289694Sngie# All rights reserved. 4289694Sngie# 5289694Sngie# Redistribution and use in source and binary forms, with or without 6289694Sngie# modification, are permitted provided that the following conditions are 7289694Sngie# met: 8289694Sngie# 9289694Sngie# * Redistributions of source code must retain the above copyright 10289694Sngie# notice, this list of conditions and the following disclaimer. 11289694Sngie# * Redistributions in binary form must reproduce the above copyright 12289694Sngie# notice, this list of conditions and the following disclaimer in the 13289694Sngie# documentation and/or other materials provided with the distribution. 14289694Sngie# 15289694Sngie# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16289694Sngie# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17289694Sngie# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18289694Sngie# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19289694Sngie# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20289694Sngie# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21289694Sngie# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22289694Sngie# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23289694Sngie# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24289694Sngie# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25289694Sngie# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26289694Sngie# 27289694Sngie# $FreeBSD: releng/11.0/usr.sbin/makefs/tests/makefs_tests_common.sh 290267 2015-11-02 10:08:00Z ngie $ 28289694Sngie# 29289694Sngie 30289743SngieKB=1024 31289897Sngie: ${TMPDIR=/tmp} 32290267Sngie# TODO: add mtree `time` support; get a lot of errors like this right now when 33290267Sngie# passing generating disk images with keyword mtree support, like: 34290267Sngie# 35290267Sngie# `[...]/mtree.spec:8: error: time: invalid value '1446458503'` 36290267Sngie# 37290267Sngie#DEFAULT_MTREE_KEYWORDS="type,mode,gid,uid,size,link,time" 38290267SngieDEFAULT_MTREE_KEYWORDS="type,mode,gid,uid,size,link" 39289897SngieTEST_IMAGE="$TMPDIR/test.img" 40289897SngieTEST_INPUTS_DIR="$TMPDIR/inputs" 41289897SngieTEST_MD_DEVICE_FILE="$TMPDIR/md.output" 42289897SngieTEST_MOUNT_DIR="$TMPDIR/mnt" 43289897SngieTEST_SPEC_FILE="$TMPDIR/mtree.spec" 44289694Sngie 45289897Sngiecheck_image_contents() 46289897Sngie{ 47289897Sngie local directories=$TEST_INPUTS_DIR 48289897Sngie local excludes mtree_excludes_arg mtree_file 49290267Sngie local mtree_keywords="$DEFAULT_MTREE_KEYWORDS" 50289897Sngie 51289897Sngie while getopts "d:f:m:X:" flag; do 52289897Sngie case "$flag" in 53289897Sngie d) 54289897Sngie directories="$directories $OPTARG" 55289897Sngie ;; 56289897Sngie f) 57289897Sngie mtree_file=$OPTARG 58289897Sngie ;; 59289897Sngie m) 60289897Sngie mtree_keywords=$OPTARG 61289897Sngie ;; 62289897Sngie X) 63289897Sngie excludes="$excludes $OPTARG" 64289897Sngie ;; 65289897Sngie *) 66289897Sngie echo "usage: check_image_contents [-d directory ...] [-f mtree-file] [-m mtree-keywords] [-X exclude]" 67289897Sngie atf_fail "unhandled option: $flag" 68289897Sngie ;; 69289897Sngie esac 70289897Sngie done 71289897Sngie 72289897Sngie if [ -n "$excludes" ]; then 73289897Sngie echo "$excludes" | tr ' ' '\n' > excludes.txt 74289897Sngie mtree_excludes_arg="-X excludes.txt" 75289897Sngie fi 76289897Sngie 77289897Sngie if [ -z "$mtree_file" ]; then 78289897Sngie mtree_file=input_spec.mtree 79289897Sngie for directory in $directories; do 80289897Sngie mtree -c -k $mtree_keywords -p $directory $mtree_excludes_arg 81289897Sngie done > $mtree_file 82289897Sngie fi 83289897Sngie 84289897Sngie echo "<---- Input spec BEGIN ---->" 85289897Sngie cat $mtree_file 86289897Sngie echo "<---- Input spec END ---->" 87289897Sngie atf_check -e empty -o empty -s exit:0 \ 88289897Sngie mtree -UW -f $mtree_file \ 89289897Sngie -p $TEST_MOUNT_DIR \ 90289897Sngie $mtree_excludes_arg 91289897Sngie} 92289897Sngie 93289743Sngiecreate_test_dirs() 94289694Sngie{ 95289694Sngie atf_check -e empty -s exit:0 mkdir -m 0777 -p $TEST_MOUNT_DIR 96289694Sngie atf_check -e empty -s exit:0 mkdir -m 0777 -p $TEST_INPUTS_DIR 97289694Sngie} 98289694Sngie 99289694Sngiecreate_test_inputs() 100289694Sngie{ 101289743Sngie create_test_dirs 102289694Sngie 103289743Sngie cd $TEST_INPUTS_DIR 104289743Sngie 105289694Sngie atf_check -e empty -s exit:0 mkdir -m 0755 -p a/b/1 106289694Sngie atf_check -e empty -s exit:0 ln -s a/b c 107289694Sngie atf_check -e empty -s exit:0 touch d 108289694Sngie atf_check -e empty -s exit:0 ln d e 109289694Sngie atf_check -e empty -s exit:0 touch .f 110289694Sngie atf_check -e empty -s exit:0 mkdir .g 111289743Sngie # XXX: fifos on the filesystem don't match fifos created by makefs for 112289743Sngie # some odd reason. 113289743Sngie #atf_check -e empty -s exit:0 mkfifo h 114289694Sngie atf_check -e ignore -s exit:0 dd if=/dev/zero of=i count=1000 bs=1 115289694Sngie atf_check -e empty -s exit:0 touch klmn 116289694Sngie atf_check -e empty -s exit:0 touch opqr 117289694Sngie atf_check -e empty -s exit:0 touch stuv 118289694Sngie atf_check -e empty -s exit:0 install -m 0755 /dev/null wxyz 119289694Sngie atf_check -e empty -s exit:0 touch 0b00000001 120289694Sngie atf_check -e empty -s exit:0 touch 0b00000010 121289694Sngie atf_check -e empty -s exit:0 touch 0b00000011 122289694Sngie atf_check -e empty -s exit:0 touch 0b00000100 123289694Sngie atf_check -e empty -s exit:0 touch 0b00000101 124289694Sngie atf_check -e empty -s exit:0 touch 0b00000110 125289694Sngie atf_check -e empty -s exit:0 touch 0b00000111 126289694Sngie atf_check -e empty -s exit:0 touch 0b00001000 127289694Sngie atf_check -e empty -s exit:0 touch 0b00001001 128289694Sngie atf_check -e empty -s exit:0 touch 0b00001010 129289694Sngie atf_check -e empty -s exit:0 touch 0b00001011 130289694Sngie atf_check -e empty -s exit:0 touch 0b00001100 131289694Sngie atf_check -e empty -s exit:0 touch 0b00001101 132289694Sngie atf_check -e empty -s exit:0 touch 0b00001110 133289743Sngie 134289743Sngie for filesize in 1 512 $(( 2 * $KB )) $(( 10 * $KB )) $(( 512 * $KB )); \ 135289743Sngie do 136289743Sngie atf_check -e ignore -o empty -s exit:0 \ 137289743Sngie dd if=/dev/zero of=${filesize}.file bs=1 \ 138289743Sngie count=1 oseek=${filesize} conv=sparse 139289743Sngie files="${files} ${filesize}.file" 140289743Sngie done 141289743Sngie 142289743Sngie cd - 143289694Sngie} 144289897Sngie 145289897Sngiemount_image() 146289897Sngie{ 147289897Sngie atf_check -e empty -o save:$TEST_MD_DEVICE_FILE -s exit:0 \ 148289897Sngie mdconfig -a -f $TEST_IMAGE 149289897Sngie atf_check -e empty -o empty -s exit:0 \ 150289897Sngie $MOUNT /dev/$(cat $TEST_MD_DEVICE_FILE) $TEST_MOUNT_DIR 151289897Sngie} 152289897Sngie 153