]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/sys/cddl/zfs/tests/pool_names/pool_names_002_neg.ksh
Merge compiler-rt trunk r351319, and resolve conflicts.
[FreeBSD/FreeBSD.git] / tests / sys / cddl / zfs / tests / pool_names / pool_names_002_neg.ksh
1 #!/usr/local/bin/ksh93 -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 # $FreeBSD$
24
25 #
26 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
27 # Use is subject to license terms.
28 #
29 # ident "@(#)pool_names_002_neg.ksh     1.4     08/11/03 SMI"
30 #
31
32 . $STF_SUITE/include/libtest.kshlib
33
34 ###############################################################################
35 #
36 # __stc_assertion_start
37 #
38 # ID: pool_names_002_neg
39 #
40 # DESCRIPTION:
41 #
42 # Ensure that a set of invalid names cannot be used to create pools.
43 #
44 # STRATEGY:
45 # 1) For each invalid character in the character set, try to create
46 # and destroy the pool. Verify it fails.
47 # 2) Given a list of invalid pool names, ensure the pools are not
48 # created.
49 #
50 # TESTABILITY: explicit
51 #
52 # TEST_AUTOMATION_LEVEL: automated
53 #
54 # CODING_STATUS: COMPLETED (2005-11-21)
55 #
56 # __stc_assertion_end
57 #
58 ################################################################################
59
60 verify_runnable "global"
61
62 log_assert "Ensure that a set of invalid names cannot be used to create pools."
63
64 # Global variable use to cleanup failures.
65 POOLNAME=""
66
67 function cleanup
68 {
69         destroy_pool $POOLNAME
70
71         if [[ -d $TESTDIR ]]; then
72                 log_must $RM -rf $TESTDIR
73         fi
74 }
75
76 log_onexit cleanup
77
78 if [[ ! -e $TESTDIR ]]; then
79         log_must $MKDIR $TESTDIR
80 fi
81
82 log_note "Ensure invalid characters fail"
83 for POOLNAME in "!" "\"" "#" "$" "%" "&" "'" "(" ")" \
84     "\*" "+" "," "-" "\." "/" "\\" \
85     ":" ";" "<" "=" ">" "\?" "@" \
86     "[" "]" "^" "_" "\`" "{" "|" "}" "~"
87 do
88         log_mustnot $ZPOOL create -m $TESTDIR $POOLNAME $DISK
89         if poolexists $POOLNAME; then
90                 log_fail "Unexpectedly created pool: '$POOLNAME'"
91         fi
92
93         log_mustnot $ZPOOL destroy $POOLNAME
94 done
95
96 # poolexists cannot be used to test pools with numeric names, because
97 # "zpool list" will interpret the name as a repeat interval and never return.
98 log_note "Ensure invalid characters fail"
99 for POOLNAME in 0 1 2 3 4 5 6 7 8 9 2222222222222222222
100 do
101         log_mustnot $ZPOOL create -m $TESTDIR $POOLNAME $DISK
102         log_mustnot $ZPOOL destroy $POOLNAME
103 done
104
105 log_note "Check that invalid octal values fail"
106 for oct in "\000" "\001" "\002" "\003" "\004" "\005" "\006" "\007" \
107     "\010" "\011" "\012" "\013" "\014" "\015" "\017" \
108     "\020" "\021" "\022" "\023" "\024" "\025" "\026" "\027" \
109     "\030" "\031" "\032" "\033" "\034" "\035" "\036" "\037" \
110     "\040" "\177"
111 do
112         # Be careful not to print the poolname, because it might be a terminal
113         # control character
114         POOLNAME=`eval "print x | tr 'x' '$oct'"`
115         $ZPOOL create -m $TESTDIR $POOLNAME $DISK > /dev/null 2>&1
116         if [ $? = 0 ]; then
117                 log_fail "Unexpectedly created pool: \"$oct\""
118         elif poolexists $POOLNAME; then
119                 log_fail "Unexpectedly created pool: \"$oct\""
120         fi
121
122         $ZPOOL destroy $POOLNAME > /dev/null 2>&1
123         if [ $? = 0 ]; then
124                 log_fail "Unexpectedly destroyed pool: \"$oct\""
125         fi
126 done
127
128 log_note "Verify invalid pool names fail"       
129 set -A POOLNAME "c0t0d0s0" "c0t0d0" "c0t0d19" "c0t50000E0108D279d0" \
130     "mirror" "raidz" ",," ",,,,,,,,,,,,,,,,,,,,,,,,," \
131     "mirror_pool" "raidz_pool" \
132     "mirror-pool" "raidz-pool" "spare" "spare_pool" \
133     "spare-pool" "raidz1-" "raidz2:" ":aaa" "-bbb" "_ccc" ".ddd"
134 POOLNAME[${#POOLNAME[@]}]='log'
135 typeset -i i=0
136 while ((i < ${#POOLNAME[@]})); do
137         log_mustnot $ZPOOL create -m $TESTDIR ${POOLNAME[$i]} $DISK
138         if poolexists ${POOLNAME[$i]}; then
139                 log_fail "Unexpectedly created pool: '${POOLNAME[$i]}'"
140         fi
141
142         log_mustnot $ZPOOL destroy ${POOLNAME[$i]}        
143
144         ((i += 1))
145 done
146
147 log_pass "Invalid names and characters were caught correctly"