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) 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib
33. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib
34
35#
36# DESCRIPTION:
37# Verify "-d <n>" can work with other options
38#
39# STRATEGY:
40# 1. Create pool, filesystem, dataset, volume, snapshot, and bookmark.
41# 2. Getting an -d option, other options and properties random combination.
42# 3. Using the combination as the parameters of 'zfs get' to check the
43# command line return value.
44#
45
46verify_runnable "both"
47
48set -A options " " "-r" "-H" "-p" "-rHp" "-o name" \
49	"-s local,default,temporary,inherited,none" \
50	"-o name -s local,default,temporary,inherited,none" \
51	"-rHp -o name -s local,default,temporary,inherited,none"
52
53set -A props type used available creation volsize referenced compressratio \
54	mounted origin recordsize quota reservation mountpoint sharenfs \
55	checksum compression atime devices exec readonly setuid zoned snapdir \
56	aclmode aclinherit canmount primarycache secondarycache \
57	usedbychildren usedbydataset usedbyrefreservation usedbysnapshots \
58	userquota@root groupquota@root userused@root groupused@root
59
60zfs upgrade -v > /dev/null 2>&1
61if [[ $? -eq 0 ]]; then
62	set -A all_props ${all_props[*]} version
63fi
64
65set -A dataset $TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \
66	$TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP
67
68set -A bookmark_props creation
69set -A bookmark $TESTPOOL/$TESTFS#$TESTBKMARK $TESTPOOL/$TESTVOL#$TESTBKMARK
70
71log_assert "Verify '-d <n>' can work with other options"
72log_onexit cleanup
73
74# Create volume and filesystem's snapshot
75create_snapshot $TESTPOOL/$TESTFS $TESTSNAP
76create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP
77
78# Create filesystem and volume's bookmark
79create_bookmark $TESTPOOL/$TESTFS $TESTSNAP $TESTBKMARK
80create_bookmark $TESTPOOL/$TESTVOL $TESTSNAP $TESTBKMARK
81
82typeset -i opt_numb=16
83typeset -i prop_numb=16
84typeset -i i=0
85typeset -i item=0
86typeset -i depth_item=0
87
88for dst in ${dataset[@]}; do
89	(( i=0 ))
90	while (( i < opt_numb )); do
91		(( item = $RANDOM % ${#options[@]} ))
92		(( depth_item = $RANDOM % ${#depth_options[@]} ))
93		for prop in $(gen_option_str "${props[*]}" "" "," $prop_numb)
94		do
95			log_must eval "zfs get -${depth_options[depth_item]} ${options[item]} $prop $dst > /dev/null 2>&1"
96		done
97		(( i += 1 ))
98	done
99done
100
101for dst in ${bookmark[@]}; do
102	(( i=0 ))
103	while (( i < opt_numb )); do
104		(( item = $RANDOM % ${#options[@]} ))
105		(( depth_item = $RANDOM % ${#depth_options[@]} ))
106		log_must eval "zfs get -${depth_options[depth_item]} ${options[item]} $bookmark_props $dst > /dev/null 2>&1"
107		(( i += 1 ))
108	done
109done
110
111log_pass "Verify '-d <n>' can work with other options"
112
113