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_common.kshlib
28. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_list_d.kshlib
29. $STF_SUITE/tests/userquota/userquota_common.kshlib
30
31###############################################################################
32#
33# __stc_assertion_start
34#
35# ID: zfs_get_001_pos
36#
37# DESCRIPTION:
38# Setting the valid option and properties, 'zfs get' should return the
39# correct property value.
40#
41# STRATEGY:
42# 1. Create pool, filesystem, volume and snapshot.
43# 2. Setting valid parameter, 'zfs get' should succeed.
44# 3. Compare the output property name with the original input property.
45#
46# TESTABILITY: explicit
47#
48# TEST_AUTOMATION_LEVEL: automated
49#
50# CODING_STATUS: COMPLETED (2005-07-04)
51#
52# __stc_assertion_end
53#
54################################################################################
55
56verify_runnable "both"
57
58set -A options "" "-p" "-r" "-H"
59if zfs_get_list_d_supported ; then
60	typeset -i i=${#options[*]}
61	typeset -i j=0
62	while (( j<${#depth_options[*]} ));
63	do
64		options[$i]=-"${depth_options[$j]}"
65		(( j+=1 ))
66		(( i+=1 ))
67	done
68fi
69
70set -A zfs_props type used available creation volsize referenced \
71	compressratio mounted origin recordsize quota reservation mountpoint \
72	sharenfs checksum compression atime devices exec readonly setuid \
73	snapdir aclmode aclinherit canmount primarycache secondarycache \
74	usedbychildren usedbydataset usedbyrefreservation usedbysnapshots
75
76
77$ZFS upgrade -v > /dev/null 2>&1
78if [[ $? -eq 0 ]]; then
79	set -A zfs_props ${zfs_props[*]} version
80fi
81
82if is_userquota_supported; then
83	set -A  userquota_props userquota@root groupquota@root \
84		userused@root groupused@root
85fi
86
87set -A all_props --  "${zfs_props[@]}" "${userquota_props[@]}"
88
89set -A dataset $TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \
90	$TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP
91
92#
93# According to dataset and option, checking if 'zfs get' return correct
94# property information.
95#
96# $1 dataset
97# $2 properties which are expected to output into $TESTDIR/$TESTFILE0
98# $3 option
99#
100function check_return_value
101{
102	typeset dst=$1
103	typeset props=$2
104	typeset opt=$3
105	typeset -i found=0
106	typeset p
107
108	for p in $props; do
109		found=0
110
111		while read line; do
112			typeset item
113			item=$($ECHO $line | $AWK '{print $2}' 2>&1)
114
115			if [[ $item == $p ]]; then
116				(( found += 1 ))
117				break
118			fi
119		done < $TESTDIR/$TESTFILE0
120
121		if (( found == 0 )); then
122			log_fail "'zfs get $opt $props $dst' return " \
123				"error message.'$p' haven't been found."
124		fi
125	done
126
127	log_note "SUCCESS: '$ZFS get $opt $prop $dst'."
128}
129
130log_assert "Setting the valid options and properties 'zfs get' should return " \
131	"the correct property value."
132log_onexit cleanup
133
134# Create filesystem and volume's snapshot
135create_snapshot $TESTPOOL/$TESTFS $TESTSNAP
136create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP
137
138typeset -i i=0
139while (( i < ${#dataset[@]} )); do
140	for opt in "${options[@]}"; do
141		for prop in ${all_props[@]}; do
142			eval "$ZFS get $opt $prop ${dataset[i]} > \
143				$TESTDIR/$TESTFILE0"
144			ret=$?
145			if [[ $ret != 0 ]]; then
146				log_fail "$ZFS get returned: $ret"
147			fi
148			check_return_value ${dataset[i]} "$prop" "$opt"
149		done
150	done
151	(( i += 1 ))
152done
153
154log_pass "Setting the valid options to dataset, it should succeed and return " \
155	"valid value. 'zfs get' pass."
156