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