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 2009 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 
  28 #
  29 # Copyright (c) 2013 by Delphix. All rights reserved.
  30 #
  31 
  32 . $STF_SUITE/include/libtest.shlib
  33 . $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib
  34 
  35 #
  36 # DESCRIPTION:
  37 # Executing well-formed 'zfs list' commands should return success.
  38 #
  39 # STRATEGY:
  40 # 1. Create an array of valid options.
  41 # 2. Execute each element in the array.
  42 # 3. Verify success is returned.
  43 #
  44 
  45 verify_runnable "both"
  46 
  47 set -A args "list" "list -r" "list -H" \
  48         "list $TESTPOOL/$TESTFS" \
  49         "list -r $TESTPOOL/$TESTFS" "list -H $TESTPOOL/$TESTFS" \
  50         "list -rH $TESTPOOL/$TESTFS" "list -Hr $TESTPOOL/$TESTFS" \
  51         "list -o name $TESTPOOL/$TESTFS" "list -r -o name $TESTPOOL/$TESTFS" \
  52         "list -H -o name $TESTPOOL/$TESTFS" "list -rH -o name $TESTPOOL/$TESTFS" \
  53         "list -Hr -o name $TESTPOOL/$TESTFS"
  54 
  55 set -A d_args " " "-r" "-H" \
  56         "$TESTPOOL/$TESTFS" \
  57         "-r $TESTPOOL/$TESTFS" "-H $TESTPOOL/$TESTFS" \
  58         "-rH $TESTPOOL/$TESTFS" "-Hr $TESTPOOL/$TESTFS" \
  59         "-o name $TESTPOOL/$TESTFS" "-r -o name $TESTPOOL/$TESTFS" \
  60         "-H -o name $TESTPOOL/$TESTFS" "-rH -o name $TESTPOOL/$TESTFS" \
  61         "-Hr -o name $TESTPOOL/$TESTFS"
  62 
  63 typeset -i m=${#args[*]}
  64 typeset -i n=0
  65 typeset -i k=0
  66 while (( n<${#depth_options[*]} ));
  67 do
  68         (( k=0 ))
  69         while (( k<${#d_args[*]} ));
  70         do
  71                 args[$m]="list"" -${depth_options[$n]}"" ${d_args[$k]}"
  72                 (( k+=1 ))
  73                 (( m+=1 ))
  74         done
  75         (( n+=1 ))
  76 done
  77 
  78 set -A pathargs "list -r $TESTDIR" "list -H $TESTDIR" \
  79         "list -r ./../$TESTDIR" "list -H ./../$TESTDIR"
  80 
  81 set -A d_pathargs " $TESTDIR" "-r $TESTDIR" "-H $TESTDIR" \
  82         "-r ./../$TESTDIR" "-H ./../$TESTDIR"
  83 
  84 (( m=${#pathargs[*]} ))
  85 (( n=0 ))
  86 (( k=0 ))
  87 while (( n<${#depth_options[*]} ));
  88 do
  89         (( k=0 ))
  90         while (( k<${#d_pathargs[*]} ));
  91         do
  92                 pathargs[$m]="list"" -${depth_options[$n]}"" ${d_pathargs[$k]}"
  93                 (( k+=1 ))
  94                 (( m+=1 ))
  95         done
  96         (( n+=1 ))
  97 done
  98 
  99 log_assert "Verify 'zfs list [-rH] [-o property[,prop]*] [fs|clct|vol]'."
 100 
 101 typeset -i i=0
 102 while [[ $i -lt ${#args[*]} ]]; do
 103         log_must eval "$ZFS ${args[i]} > /dev/null"
 104         ((i = i + 1))
 105 done
 106 
 107 # Verify 'zfs list <path>' will succeed on absolute or relative path.
 108 
 109 cd /tmp
 110 typeset -i i=0
 111 while [[ $i -lt ${#pathargs[*]} ]]; do
 112         log_must eval "$ZFS ${pathargs[i]} > /dev/null"
 113         ((i = i + 1))
 114 done
 115 
 116 log_pass "The sub-command 'list' succeeds as non-root."