makefs_tests_common.sh revision 290267
1226586Sdim# 2226586Sdim# Copyright 2015 EMC Corp. 3226586Sdim# All rights reserved. 4226586Sdim# 5226586Sdim# Redistribution and use in source and binary forms, with or without 6226586Sdim# modification, are permitted provided that the following conditions are 7226586Sdim# met: 8226586Sdim# 9226586Sdim# * Redistributions of source code must retain the above copyright 10226586Sdim# notice, this list of conditions and the following disclaimer. 11226586Sdim# * Redistributions in binary form must reproduce the above copyright 12226586Sdim# notice, this list of conditions and the following disclaimer in the 13226586Sdim# documentation and/or other materials provided with the distribution. 14226586Sdim# 15226586Sdim# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16226586Sdim# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17226586Sdim# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18226586Sdim# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19226586Sdim# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20226586Sdim# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21226586Sdim# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22226586Sdim# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23226586Sdim# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24226586Sdim# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25226586Sdim# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26226586Sdim# 27226586Sdim# $FreeBSD: head/usr.sbin/makefs/tests/makefs_tests_common.sh 290267 2015-11-02 10:08:00Z ngie $ 28226586Sdim# 29226586Sdim 30226586SdimKB=1024 31226586Sdim: ${TMPDIR=/tmp} 32226586Sdim# TODO: add mtree `time` support; get a lot of errors like this right now when 33226586Sdim# passing generating disk images with keyword mtree support, like: 34226586Sdim# 35226586Sdim# `[...]/mtree.spec:8: error: time: invalid value '1446458503'` 36226586Sdim# 37226586Sdim#DEFAULT_MTREE_KEYWORDS="type,mode,gid,uid,size,link,time" 38226586SdimDEFAULT_MTREE_KEYWORDS="type,mode,gid,uid,size,link" 39226586SdimTEST_IMAGE="$TMPDIR/test.img" 40226586SdimTEST_INPUTS_DIR="$TMPDIR/inputs" 41226586SdimTEST_MD_DEVICE_FILE="$TMPDIR/md.output" 42226586SdimTEST_MOUNT_DIR="$TMPDIR/mnt" 43226586SdimTEST_SPEC_FILE="$TMPDIR/mtree.spec" 44226586Sdim 45226586Sdimcheck_image_contents() 46226586Sdim{ 47226586Sdim local directories=$TEST_INPUTS_DIR 48226586Sdim local excludes mtree_excludes_arg mtree_file 49226586Sdim local mtree_keywords="$DEFAULT_MTREE_KEYWORDS" 50226586Sdim 51226586Sdim while getopts "d:f:m:X:" flag; do 52226586Sdim case "$flag" in 53226586Sdim d) 54226586Sdim directories="$directories $OPTARG" 55226586Sdim ;; 56226586Sdim f) 57226586Sdim mtree_file=$OPTARG 58226586Sdim ;; 59226586Sdim m) 60226586Sdim mtree_keywords=$OPTARG 61226586Sdim ;; 62226586Sdim X) 63226586Sdim excludes="$excludes $OPTARG" 64226586Sdim ;; 65226586Sdim *) 66226586Sdim echo "usage: check_image_contents [-d directory ...] [-f mtree-file] [-m mtree-keywords] [-X exclude]" 67226586Sdim atf_fail "unhandled option: $flag" 68226586Sdim ;; 69226586Sdim esac 70226586Sdim done 71226586Sdim 72226586Sdim if [ -n "$excludes" ]; then 73226586Sdim echo "$excludes" | tr ' ' '\n' > excludes.txt 74226586Sdim mtree_excludes_arg="-X excludes.txt" 75226586Sdim fi 76226586Sdim 77226586Sdim if [ -z "$mtree_file" ]; then 78226586Sdim mtree_file=input_spec.mtree 79226586Sdim for directory in $directories; do 80226586Sdim mtree -c -k $mtree_keywords -p $directory $mtree_excludes_arg 81226586Sdim done > $mtree_file 82226586Sdim fi 83226586Sdim 84226586Sdim echo "<---- Input spec BEGIN ---->" 85226586Sdim cat $mtree_file 86226586Sdim echo "<---- Input spec END ---->" 87226586Sdim atf_check -e empty -o empty -s exit:0 \ 88226586Sdim mtree -UW -f $mtree_file \ 89226586Sdim -p $TEST_MOUNT_DIR \ 90226586Sdim $mtree_excludes_arg 91226586Sdim} 92226586Sdim 93226586Sdimcreate_test_dirs() 94226586Sdim{ 95226586Sdim atf_check -e empty -s exit:0 mkdir -m 0777 -p $TEST_MOUNT_DIR 96226586Sdim atf_check -e empty -s exit:0 mkdir -m 0777 -p $TEST_INPUTS_DIR 97226586Sdim} 98226586Sdim 99226586Sdimcreate_test_inputs() 100226586Sdim{ 101226586Sdim create_test_dirs 102226586Sdim 103226586Sdim cd $TEST_INPUTS_DIR 104226586Sdim 105226586Sdim atf_check -e empty -s exit:0 mkdir -m 0755 -p a/b/1 106226586Sdim atf_check -e empty -s exit:0 ln -s a/b c 107226586Sdim atf_check -e empty -s exit:0 touch d 108226586Sdim atf_check -e empty -s exit:0 ln d e 109226586Sdim atf_check -e empty -s exit:0 touch .f 110226586Sdim atf_check -e empty -s exit:0 mkdir .g 111226586Sdim # XXX: fifos on the filesystem don't match fifos created by makefs for 112226586Sdim # some odd reason. 113226586Sdim #atf_check -e empty -s exit:0 mkfifo h 114226586Sdim atf_check -e ignore -s exit:0 dd if=/dev/zero of=i count=1000 bs=1 115226586Sdim atf_check -e empty -s exit:0 touch klmn 116226586Sdim atf_check -e empty -s exit:0 touch opqr 117226586Sdim atf_check -e empty -s exit:0 touch stuv 118226586Sdim atf_check -e empty -s exit:0 install -m 0755 /dev/null wxyz 119226586Sdim atf_check -e empty -s exit:0 touch 0b00000001 120226586Sdim atf_check -e empty -s exit:0 touch 0b00000010 121226586Sdim atf_check -e empty -s exit:0 touch 0b00000011 122226586Sdim atf_check -e empty -s exit:0 touch 0b00000100 123226586Sdim atf_check -e empty -s exit:0 touch 0b00000101 124226586Sdim atf_check -e empty -s exit:0 touch 0b00000110 125226586Sdim atf_check -e empty -s exit:0 touch 0b00000111 126226586Sdim atf_check -e empty -s exit:0 touch 0b00001000 127226586Sdim atf_check -e empty -s exit:0 touch 0b00001001 128226586Sdim atf_check -e empty -s exit:0 touch 0b00001010 129226586Sdim atf_check -e empty -s exit:0 touch 0b00001011 130226586Sdim atf_check -e empty -s exit:0 touch 0b00001100 131226586Sdim atf_check -e empty -s exit:0 touch 0b00001101 132226586Sdim atf_check -e empty -s exit:0 touch 0b00001110 133226586Sdim 134226586Sdim for filesize in 1 512 $(( 2 * $KB )) $(( 10 * $KB )) $(( 512 * $KB )); \ 135226586Sdim do 136226586Sdim atf_check -e ignore -o empty -s exit:0 \ 137226586Sdim dd if=/dev/zero of=${filesize}.file bs=1 \ 138226586Sdim count=1 oseek=${filesize} conv=sparse 139226586Sdim files="${files} ${filesize}.file" 140226586Sdim done 141226586Sdim 142226586Sdim cd - 143226586Sdim} 144226586Sdim 145226586Sdimmount_image() 146226586Sdim{ 147226586Sdim atf_check -e empty -o save:$TEST_MD_DEVICE_FILE -s exit:0 \ 148226586Sdim mdconfig -a -f $TEST_IMAGE 149226586Sdim atf_check -e empty -o empty -s exit:0 \ 150226586Sdim $MOUNT /dev/$(cat $TEST_MD_DEVICE_FILE) $TEST_MOUNT_DIR 151226586Sdim} 152226586Sdim 153226586Sdim