Update ZTS to work on FreeBSD
[freebsd.git] / tests / zfs-tests / tests / functional / cli_root / zpool_add / add_prop_ashift.ksh
1 #!/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2017, loli10K. All rights reserved.
25 #
26
27 . $STF_SUITE/include/libtest.shlib
28 . $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
29
30 #
31 # DESCRIPTION:
32 #       'zpool add' should use the ashift pool property value as default.
33 #
34 # STRATEGY:
35 #       1. Create a pool with default values.
36 #       2. Verify 'zpool add' uses the ashift pool property value when adding
37 #          a new device.
38 #       3. Verify the default ashift value can still be overridden by manually
39 #          specifying '-o ashift=<n>' from the command line.
40 #
41
42 verify_runnable "global"
43
44 function cleanup
45 {
46         poolexists $TESTPOOL && destroy_pool $TESTPOOL
47         log_must rm -f $disk1 $disk2
48 }
49
50 log_assert "'zpool add' uses the ashift pool property value as default."
51 log_onexit cleanup
52
53 disk1=$TEST_BASE_DIR/$FILEDISK0
54 disk2=$TEST_BASE_DIR/$FILEDISK1
55 log_must mkfile $SIZE $disk1
56 log_must mkfile $SIZE $disk2
57
58 typeset ashifts=("9" "10" "11" "12" "13" "14" "15" "16")
59 for ashift in ${ashifts[@]}
60 do
61         log_must zpool create -o ashift=$ashift $TESTPOOL $disk1
62         log_must zpool add $TESTPOOL $disk2
63         verify_ashift $disk2 $ashift
64         if [[ $? -ne 0 ]]
65         then
66                 log_fail "Device was added without setting ashift value to "\
67                     "$ashift"
68         fi
69         # clean things for the next run
70         log_must zpool destroy $TESTPOOL
71         log_must zpool labelclear $disk1
72         log_must zpool labelclear $disk2
73 done
74
75 for ashift in ${ashifts[@]}
76 do
77         for cmdval in ${ashifts[@]}
78         do
79                 log_must zpool create -o ashift=$ashift $TESTPOOL $disk1
80                 log_must zpool add -o ashift=$cmdval $TESTPOOL $disk2
81                 verify_ashift $disk2 $cmdval
82                 if [[ $? -ne 0 ]]
83                 then
84                         log_fail "Device was added without setting ashift " \
85                             "value to $cmdval"
86                 fi
87                 # clean things for the next run
88                 log_must zpool destroy $TESTPOOL
89                 log_must zpool labelclear $disk1
90                 log_must zpool labelclear $disk2
91         done
92 done
93
94 log_pass "'zpool add' uses the ashift pool property value."