]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/makefs/tests/makefs_tests_common.sh
MFV r362565:
[FreeBSD/FreeBSD.git] / usr.sbin / makefs / tests / makefs_tests_common.sh
1 #
2 # Copyright 2015 EMC Corp.
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
8 #
9 # * Redistributions of source code must retain the above copyright
10 #   notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright
12 #   notice, this list of conditions and the following disclaimer in the
13 #   documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #
27 # $FreeBSD$
28 #
29
30 KB=1024
31 : ${TMPDIR=/tmp}
32 DEFAULT_MTREE_KEYWORDS="type,mode,gid,uid,size,link,time"
33 TEST_IMAGE="$TMPDIR/test.img"
34 TEST_INPUTS_DIR="$TMPDIR/inputs"
35 TEST_MD_DEVICE_FILE="$TMPDIR/md.output"
36 TEST_MOUNT_DIR="$TMPDIR/mnt"
37 TEST_SPEC_FILE="$TMPDIR/mtree.spec"
38
39 check_image_contents()
40 {
41         local directories=$TEST_INPUTS_DIR
42         local excludes mtree_excludes_arg mtree_file
43         local mtree_keywords="$DEFAULT_MTREE_KEYWORDS"
44
45         while getopts "d:f:m:X:" flag; do
46                 case "$flag" in
47                 d)
48                         directories="$directories $OPTARG"
49                         ;;
50                 f)
51                         mtree_file=$OPTARG
52                         ;;
53                 m)
54                         mtree_keywords=$OPTARG
55                         ;;
56                 X)
57                         excludes="$excludes $OPTARG"
58                         ;;
59                 *)
60                         echo "usage: check_image_contents [-d directory ...] [-f mtree-file] [-m mtree-keywords] [-X exclude]"
61                         atf_fail "unhandled option: $flag"
62                         ;;
63                 esac
64         done
65
66         if [ -n "$excludes" ]; then
67                 echo "$excludes" | tr ' ' '\n' > excludes.txt
68                 mtree_excludes_arg="-X excludes.txt"
69         fi
70
71         if [ -z "$mtree_file" ]; then
72                 mtree_file=input_spec.mtree
73                 for directory in $directories; do
74                         mtree -c -k $mtree_keywords -p $directory $mtree_excludes_arg
75                 done > $mtree_file
76         fi
77
78         echo "<---- Input spec BEGIN ---->"
79         cat $mtree_file
80         echo "<---- Input spec END ---->"
81         atf_check -e empty -o empty -s exit:0 \
82             mtree -UW -f $mtree_file \
83                 -p $TEST_MOUNT_DIR \
84                 $mtree_excludes_arg
85 }
86
87 create_test_dirs()
88 {
89         atf_check -e empty -s exit:0 mkdir -m 0777 -p $TEST_MOUNT_DIR
90         atf_check -e empty -s exit:0 mkdir -m 0777 -p $TEST_INPUTS_DIR
91 }
92
93 create_test_inputs()
94 {
95         create_test_dirs
96
97         cd $TEST_INPUTS_DIR
98
99         atf_check -e empty -s exit:0 mkdir -m 0755 -p a/b/1
100         atf_check -e empty -s exit:0 ln -s a/b c
101         atf_check -e empty -s exit:0 touch d
102         atf_check -e empty -s exit:0 ln d e
103         atf_check -e empty -s exit:0 touch .f
104         atf_check -e empty -s exit:0 mkdir .g
105         # XXX: fifos on the filesystem don't match fifos created by makefs for
106         # some odd reason.
107         #atf_check -e empty -s exit:0 mkfifo h
108         atf_check -e ignore -s exit:0 dd if=/dev/zero of=i count=1000 bs=1
109         atf_check -e empty -s exit:0 touch klmn
110         atf_check -e empty -s exit:0 touch opqr
111         atf_check -e empty -s exit:0 touch stuv
112         atf_check -e empty -s exit:0 install -m 0755 /dev/null wxyz
113         atf_check -e empty -s exit:0 touch 0b00000001
114         atf_check -e empty -s exit:0 touch 0b00000010
115         atf_check -e empty -s exit:0 touch 0b00000011
116         atf_check -e empty -s exit:0 touch 0b00000100
117         atf_check -e empty -s exit:0 touch 0b00000101
118         atf_check -e empty -s exit:0 touch 0b00000110
119         atf_check -e empty -s exit:0 touch 0b00000111
120         atf_check -e empty -s exit:0 touch 0b00001000
121         atf_check -e empty -s exit:0 touch 0b00001001
122         atf_check -e empty -s exit:0 touch 0b00001010
123         atf_check -e empty -s exit:0 touch 0b00001011
124         atf_check -e empty -s exit:0 touch 0b00001100
125         atf_check -e empty -s exit:0 touch 0b00001101
126         atf_check -e empty -s exit:0 touch 0b00001110
127
128         for filesize in 1 512 $(( 2 * $KB )) $(( 10 * $KB )) $(( 512 * $KB )); \
129         do
130                 atf_check -e ignore -o empty -s exit:0 \
131                     dd if=/dev/zero of=${filesize}.file bs=1 \
132                     count=1 oseek=${filesize} conv=sparse
133                 files="${files} ${filesize}.file"
134         done
135
136         cd -
137 }
138
139 mount_image()
140 {
141         atf_check -e empty -o save:$TEST_MD_DEVICE_FILE -s exit:0 \
142             mdconfig -a -f $TEST_IMAGE
143         atf_check -e empty -o empty -s exit:0 \
144             $MOUNT /dev/$(cat $TEST_MD_DEVICE_FILE) $TEST_MOUNT_DIR
145 }
146