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