1 #
   2 # CDDL HEADER START
   3 #
   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.
   7 #
   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.
  12 #
  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]
  18 #
  19 # CDDL HEADER END
  20 #
  21 
  22 #
  23 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24 # Use is subject to license terms.
  25 #
  26 
  27 #
  28 # Copyright (c) 2013 by Delphix. All rights reserved.
  29 #
  30 
  31 . $STF_SUITE/include/libtest.shlib
  32 
  33 #
  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
  37 #
  38 function verify_sort { # command list name
  39 
  40         # now verify we've sorted by creation date:
  41         typeset CMD=$1
  42         typeset list=$2
  43         typeset name=$3
  44 
  45         typeset -i RET=0
  46         typeset -i index=1
  47 
  48         # run the command to verify that it works
  49         log_must eval "$CMD > /dev/null"
  50 
  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
  64 
  65                         ((index = index + 1))
  66                 fi
  67         done
  68 
  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
  75 }
  76 
  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
  80 #
  81 function verify_reverse_sort { # command list name
  82 
  83         typeset CMD=$1
  84         typeset list=$2
  85         typeset name=$3
  86 
  87         # set our index to the be number of elements in the list
  88         typeset -i index=$($ECHO $list | $AWK '{print split($0,arr)}')
  89 
  90         log_note "Checking reverse sort by '$name'," \
  91                 "expecting the reverse of '$list'"
  92         log_must eval "$CMD > /dev/null"
  93 
  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
 107 
 108                         ((index = index - 1))
 109                 fi
 110         done
 111 
 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
 118 }