xref: /freebsd/usr.sbin/makefs/tests/makefs_tests_common.sh (revision 286258a9a0e39cfce79d3b072a665b88bfb422c7)
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#
277bdfc3b7SEnji Cooper# $FreeBSD$
287bdfc3b7SEnji Cooper#
297bdfc3b7SEnji Cooper
3066845bf5SEnji CooperKB=1024
31fc2b0536SEnji Cooper: ${TMPDIR=/tmp}
32*286258a9SEd MasteDEFAULT_MTREE_KEYWORDS="type,mode,gid,uid,size,link,time"
33fc2b0536SEnji CooperTEST_IMAGE="$TMPDIR/test.img"
34fc2b0536SEnji CooperTEST_INPUTS_DIR="$TMPDIR/inputs"
35fc2b0536SEnji CooperTEST_MD_DEVICE_FILE="$TMPDIR/md.output"
36fc2b0536SEnji CooperTEST_MOUNT_DIR="$TMPDIR/mnt"
37fc2b0536SEnji CooperTEST_SPEC_FILE="$TMPDIR/mtree.spec"
38fc2b0536SEnji Cooper
39fc2b0536SEnji Coopercheck_image_contents()
40fc2b0536SEnji Cooper{
41fc2b0536SEnji Cooper	local directories=$TEST_INPUTS_DIR
42fc2b0536SEnji Cooper	local excludes mtree_excludes_arg mtree_file
43c213f0dbSEnji Cooper	local mtree_keywords="$DEFAULT_MTREE_KEYWORDS"
44fc2b0536SEnji Cooper
45fc2b0536SEnji Cooper	while getopts "d:f:m:X:" flag; do
46fc2b0536SEnji Cooper		case "$flag" in
47fc2b0536SEnji Cooper		d)
48fc2b0536SEnji Cooper			directories="$directories $OPTARG"
49fc2b0536SEnji Cooper			;;
50fc2b0536SEnji Cooper		f)
51fc2b0536SEnji Cooper			mtree_file=$OPTARG
52fc2b0536SEnji Cooper			;;
53fc2b0536SEnji Cooper		m)
54fc2b0536SEnji Cooper			mtree_keywords=$OPTARG
55fc2b0536SEnji Cooper			;;
56fc2b0536SEnji Cooper		X)
57fc2b0536SEnji Cooper			excludes="$excludes $OPTARG"
58fc2b0536SEnji Cooper			;;
59fc2b0536SEnji Cooper		*)
60fc2b0536SEnji Cooper			echo "usage: check_image_contents [-d directory ...] [-f mtree-file] [-m mtree-keywords] [-X exclude]"
61fc2b0536SEnji Cooper			atf_fail "unhandled option: $flag"
62fc2b0536SEnji Cooper			;;
63fc2b0536SEnji Cooper		esac
64fc2b0536SEnji Cooper	done
65fc2b0536SEnji Cooper
66fc2b0536SEnji Cooper	if [ -n "$excludes" ]; then
67fc2b0536SEnji Cooper		echo "$excludes" | tr ' ' '\n' > excludes.txt
68fc2b0536SEnji Cooper		mtree_excludes_arg="-X excludes.txt"
69fc2b0536SEnji Cooper	fi
70fc2b0536SEnji Cooper
71fc2b0536SEnji Cooper	if [ -z "$mtree_file" ]; then
72fc2b0536SEnji Cooper		mtree_file=input_spec.mtree
73fc2b0536SEnji Cooper		for directory in $directories; do
74fc2b0536SEnji Cooper			mtree -c -k $mtree_keywords -p $directory $mtree_excludes_arg
75fc2b0536SEnji Cooper		done > $mtree_file
76fc2b0536SEnji Cooper	fi
77fc2b0536SEnji Cooper
78fc2b0536SEnji Cooper	echo "<---- Input spec BEGIN ---->"
79fc2b0536SEnji Cooper	cat $mtree_file
80fc2b0536SEnji Cooper	echo "<---- Input spec END ---->"
81fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 \
82fc2b0536SEnji Cooper	    mtree -UW -f $mtree_file \
83fc2b0536SEnji Cooper		-p $TEST_MOUNT_DIR \
84fc2b0536SEnji Cooper		$mtree_excludes_arg
85fc2b0536SEnji Cooper}
867bdfc3b7SEnji Cooper
8766845bf5SEnji Coopercreate_test_dirs()
887bdfc3b7SEnji Cooper{
897bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 mkdir -m 0777 -p $TEST_MOUNT_DIR
907bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 mkdir -m 0777 -p $TEST_INPUTS_DIR
917bdfc3b7SEnji Cooper}
927bdfc3b7SEnji Cooper
937bdfc3b7SEnji Coopercreate_test_inputs()
947bdfc3b7SEnji Cooper{
9566845bf5SEnji Cooper	create_test_dirs
9666845bf5SEnji Cooper
9766845bf5SEnji Cooper	cd $TEST_INPUTS_DIR
987bdfc3b7SEnji Cooper
997bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 mkdir -m 0755 -p a/b/1
1007bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 ln -s a/b c
1017bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 touch d
1027bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 ln d e
1037bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 touch .f
1047bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 mkdir .g
10566845bf5SEnji Cooper	# XXX: fifos on the filesystem don't match fifos created by makefs for
10666845bf5SEnji Cooper	# some odd reason.
10766845bf5SEnji Cooper	#atf_check -e empty -s exit:0 mkfifo h
1087bdfc3b7SEnji Cooper	atf_check -e ignore -s exit:0 dd if=/dev/zero of=i count=1000 bs=1
1097bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 touch klmn
1107bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 touch opqr
1117bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 touch stuv
1127bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 install -m 0755 /dev/null wxyz
1137bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 touch 0b00000001
1147bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 touch 0b00000010
1157bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 touch 0b00000011
1167bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 touch 0b00000100
1177bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 touch 0b00000101
1187bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 touch 0b00000110
1197bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 touch 0b00000111
1207bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 touch 0b00001000
1217bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 touch 0b00001001
1227bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 touch 0b00001010
1237bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 touch 0b00001011
1247bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 touch 0b00001100
1257bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 touch 0b00001101
1267bdfc3b7SEnji Cooper	atf_check -e empty -s exit:0 touch 0b00001110
12766845bf5SEnji Cooper
12866845bf5SEnji Cooper	for filesize in 1 512 $(( 2 * $KB )) $(( 10 * $KB )) $(( 512 * $KB )); \
12966845bf5SEnji Cooper	do
13066845bf5SEnji Cooper		atf_check -e ignore -o empty -s exit:0 \
13166845bf5SEnji Cooper		    dd if=/dev/zero of=${filesize}.file bs=1 \
13266845bf5SEnji Cooper		    count=1 oseek=${filesize} conv=sparse
13366845bf5SEnji Cooper		files="${files} ${filesize}.file"
13466845bf5SEnji Cooper	done
13566845bf5SEnji Cooper
13666845bf5SEnji Cooper	cd -
1377bdfc3b7SEnji Cooper}
138fc2b0536SEnji Cooper
139fc2b0536SEnji Coopermount_image()
140fc2b0536SEnji Cooper{
141fc2b0536SEnji Cooper	atf_check -e empty -o save:$TEST_MD_DEVICE_FILE -s exit:0 \
142fc2b0536SEnji Cooper	    mdconfig -a -f $TEST_IMAGE
143fc2b0536SEnji Cooper	atf_check -e empty -o empty -s exit:0 \
144fc2b0536SEnji Cooper	    $MOUNT /dev/$(cat $TEST_MD_DEVICE_FILE) $TEST_MOUNT_DIR
145fc2b0536SEnji Cooper}
146fc2b0536SEnji Cooper
147