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#
24# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26
27. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_list_d.kshlib
28. $STF_SUITE/tests/cli_user/cli_user.kshlib
29
30#################################################################################
31#
32# __stc_assertion_start
33#
34# ID: zfs_list_007_pos
35#
36# DESCRIPTION:
37#	'zfs list -d <n>' should get expected output.
38#
39# STRATEGY:
40#	1. 'zfs list -d <n>' to get the output.
41#	2. 'zfs list -r|egrep' to get the expected output.
42#	3. Compare the two outputs, they shoud be same.
43#
44# TESTABILITY: explicit
45#
46# TEST_AUTOMATION_LEVEL: automated
47#
48# CODING_STATUS: COMPLETED (2009-05-25)
49#
50# __stc_assertion_end
51#
52################################################################################
53
54verify_runnable "both"
55
56if ! zfs_get_list_d_supported ; then
57	log_unsupported "'zfs list -d' is not supported."
58fi
59
60set -A fs_type "all" "filesystem" "snapshot"
61if is_global_zone ; then
62	set -A fs_type ${fs_type[*]} "volume"
63fi
64
65function cleanup
66{
67	log_must $RM -f $DEPTH_OUTPUT
68	log_must $RM -f $EXPECT_OUTPUT
69}
70
71log_onexit cleanup
72log_assert "'zfs list -d <n>' should get expected output."
73
74mntpnt=$TMPDIR
75DEPTH_OUTPUT="$mntpnt/depth_output"
76EXPECT_OUTPUT="$mntpnt/expect_output"
77typeset -i old_val=0
78typeset -i j=0
79typeset -i fs=0
80typeset eg_opt="$DEPTH_FS"$
81for dp in ${depth_array[@]}; do
82	(( j=old_val+1 ))
83	while (( j<=dp && j<=MAX_DEPTH )); do
84		eg_opt="$eg_opt""|d""$j"$
85		(( j+=1 ))
86	done
87	(( fs=0 ))
88	while (( fs<${#fs_type[*]} )); do
89		if [[ "$dp" == "0" ]] && \
90		  [[ "${fs_type[$fs]}" == "volume" || "${fs_type[$fs]}" == "snapshot" ]]; then
91			log_must eval "run_unprivileged $ZFS list -H -d $dp -o name -t ${fs_type[$fs]} $DEPTH_FS > $DEPTH_OUTPUT"
92			[[ -s "$DEPTH_OUTPUT" ]] && \
93				log_fail "$DEPTH_OUTPUT should be null."
94			log_mustnot run_unprivileged $ZFS list -rH -o name -t ${fs_type[$fs]} $DEPTH_FS | $EGREP -e '$eg_opt'
95		else
96			log_must eval "run_unprivileged $ZFS list -H -d $dp -o name -t ${fs_type[$fs]} $DEPTH_FS > $DEPTH_OUTPUT"
97			log_must eval "run_unprivileged $ZFS list -rH -o name -t ${fs_type[$fs]} $DEPTH_FS | $EGREP -e '$eg_opt' > $EXPECT_OUTPUT"
98			log_must $DIFF $DEPTH_OUTPUT $EXPECT_OUTPUT
99		fi
100		(( fs+=1 ))
101	done
102	(( old_val=dp ))
103done
104
105log_pass "'zfs list -d <n>' should get expected output."
106
107