7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / cli_user / zfs_list / zfs_list.kshlib
blob03c9d1f07a876f118352ce7ef3e474147c707ff7
2 # CDDL HEADER START
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
19 # CDDL HEADER END
23 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24 # Use is subject to license terms.
28 # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
31 . $STF_SUITE/include/libtest.shlib
34 # A function that verifies sort order. It takes as input
35 # a command, which gets executed. We then iterate over the results
36 # comparing that the sort order passed in via the list
38 function verify_sort { # command list name
40         # now verify we've sorted by creation date:
41         typeset CMD=$1
42         typeset list=$2
43         typeset name=$3
45         typeset -i RET=0
46         typeset -i index=1
48         # run the command to verify that it works
49         log_must eval "$CMD > /dev/null"
51         # Now check the sort order
52         for dataset in $( $CMD )
53         do
54                 ACTUAL=$(basename $dataset)
55                 if [ "$dataset" != "$TESTPOOL/$TESTFS" ]
56                 then
57                         EXPECTED=$(echo $list | awk "{print \$$index}")
58                         if [ "$ACTUAL" != "$EXPECTED" ]
59                         then
60                                 log_note "WARNING:" \
61                                         "'$ACTUAL' does not equal '$EXPECTED'"
62                                 log_fail "ERROR: Sort by $name fails."
63                         fi
65                         ((index = index + 1))
66                 fi
67         done
69         # finally check to see if we have the expected number of elements
70         if [ $index -ne $(echo $list | awk '{print split($0,arr)+1}') ]
71         then
72                 log_fail "Warning: " \
73                         "unexpected number of filesystems found in list output!"
74         fi
77 # A function that verifies reverse sort order. It takes as input
78 # a command, which gets executed. We then iterate over the results
79 # comparing that the sort order passed in via the list
81 function verify_reverse_sort { # command list name
83         typeset CMD=$1
84         typeset list=$2
85         typeset name=$3
87         # set our index to the be number of elements in the list
88         typeset -i index=$(echo $list | awk '{print split($0,arr)}')
90         log_note "Checking reverse sort by '$name'," \
91                 "expecting the reverse of '$list'"
92         log_must eval "$CMD > /dev/null"
94         for dataset in $( $CMD )
95         do
96                 ACTUAL=$(basename $dataset)
97                 if [ "$dataset" != "$TESTPOOL/$TESTFS" ]
98                 then
99                         EXPECTED=$(echo $list | awk "{print \$$index}")
100                         if [ "$ACTUAL" != "$EXPECTED" ]
101                         then
102                                 log_note "Warning:" \
103                                         "'$ACTUAL' does not equal to" \
104                                         "the reverse of '$EXPECTED'"
105                                 log_fail "ERROR: Reverse sort by '$name' fails."
106                         fi
108                         ((index = index - 1))
109                 fi
110         done
112         # finally check to see if we have the expected number of elements
113         if [ $index -ne 0 ]
114         then
115                 log_fail "Warning: " \
116                         "unexpected number of filesystems found in list output!"
117         fi