1 # Copyright (c) 2016 Alan Somers
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
7 # 1. Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # 2. Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution.
13 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 atf_test_case diskinfo cleanup
33 atf_set "descr" "gnop should preserve diskinfo's basic properties"
34 atf_set "require.user" "root"
40 atf_check gnop create /dev/${us}
41 md_secsize=$(diskinfo ${us} | cut -wf 2)
42 md_mediasize=$(diskinfo ${us} | cut -wf 3)
43 md_stripesize=$(diskinfo ${us} | cut -wf 5)
44 nop_secsize=$(diskinfo ${us}.nop | cut -wf 2)
45 nop_mediasize=$(diskinfo ${us}.nop | cut -wf 3)
46 nop_stripesize=$(diskinfo ${us}.nop | cut -wf 5)
47 atf_check_equal "$md_secsize" "$nop_secsize"
48 atf_check_equal "$md_mediasize" "$nop_mediasize"
49 atf_check_equal "$md_stripesize" "$nop_stripesize"
56 atf_test_case io cleanup
59 atf_set "descr" "I/O works on gnop devices"
60 atf_set "require.user" "root"
66 atf_check gnop create /dev/${us}
68 echo src >> $PLAINFILES
69 echo dst >> $PLAINFILES
70 dd if=/dev/random of=src bs=1m count=1 >/dev/null 2>&1
71 dd if=src of=/dev/${us}.nop bs=1m count=1 > /dev/null 2>&1
72 dd if=/dev/${us}.nop of=dst bs=1m count=1 > /dev/null 2>&1
74 atf_check_equal `md5 -q src` `md5 -q dst`
81 atf_test_case size cleanup
84 atf_set "descr" "Test gnop's -s option"
85 atf_set "require.user" "root"
91 for mediasize in 65536 524288 1048576; do
92 atf_check gnop create -s ${mediasize} /dev/${us}
93 gnop_mediasize=`diskinfo /dev/${us}.nop | cut -wf 3`
94 atf_check_equal "${mediasize}" "${gnop_mediasize}"
95 atf_check gnop destroy /dev/${us}.nop
97 # We shouldn't be able to extend the provider's size
98 atf_check -s not-exit:0 -e ignore gnop create -s 2097152 /dev/${us}
105 atf_test_case stripesize cleanup
108 atf_set "descr" "Test gnop's -p and -P options"
109 atf_set "require.user" "root"
115 for ss in 512 1024 2048 4096 8192; do
116 for sofs in `seq 0 512 ${ss}`; do
117 [ "$sofs" -eq "$ss" ] && continue
118 atf_check gnop create -p ${ss} -P ${sofs} /dev/${us}
119 gnop_ss=`diskinfo /dev/${us}.nop | cut -wf 5`
120 gnop_sofs=`diskinfo /dev/${us}.nop | cut -wf 6`
121 atf_check_equal "${ss}" "${gnop_ss}"
122 atf_check_equal "${sofs}" "${gnop_sofs}"
123 atf_check gnop destroy /dev/${us}.nop
132 atf_init_test_cases()
135 atf_add_test_case diskinfo
136 atf_add_test_case stripesize
137 atf_add_test_case size
144 md=$(mdconfig -a -t swap -s 1M) || atf_fail "mdconfig -a failed"
145 echo ${md} >> $MD_DEVS
151 if [ -f "$MD_DEVS" ]; then
152 while read test_md; do
153 gnop destroy -f ${test_md}.nop 2>/dev/null
154 mdconfig -d -u $test_md 2>/dev/null
159 if [ -f "$PLAINFILES" ]; then