1# vim: filetype=sh
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 2008 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)zfs_list.kshlib	1.1	08/08/15 SMI"
30#
31
32. $STF_SUITE/include/libtest.kshlib
33
34#
35# A function that verifies sort order. It takes as input
36# a command, which gets executed. We then iterate over the results
37# comparing that the sort order passed in via the list
38#
39function verify_sort { # command list name
40
41	# now verify we've sorted by creation date:
42	typeset CMD=$1
43	typeset list=$2
44	typeset name=$3
45
46	typeset -i RET=0
47	typeset -i index=1
48
49	# run the command to verify that it works
50	log_must eval "$CMD > /dev/null"
51
52	# Now check the sort order
53	for dataset in $( $CMD )
54	do
55		ACTUAL=$(basename $dataset)
56		if [ "$dataset" != "$TESTPOOL/$TESTFS" ]
57		then
58			EXPECTED=$($ECHO $list | $AWK "{print \$$index}")
59		   	if [ "$ACTUAL" != "$EXPECTED" ]
60			then
61		      		log_note "WARNING:" \
62					"'$ACTUAL' does not equal '$EXPECTED'"
63				log_fail "ERROR: Sort by $name fails."
64			fi
65
66			((index = index + 1))
67		fi
68	done
69
70	# finally check to see if we have the expected number of elements
71	if [ $index -ne $($ECHO $list | $AWK '{print split($0,arr)+1}') ]
72	then
73		log_fail "Warning: " \
74			"unexpected number of filesystems found in list output!"
75	fi
76}
77
78# A function that verifies reverse sort order. It takes as input
79# a command, which gets executed. We then iterate over the results
80# comparing that the sort order passed in via the list
81#
82function verify_reverse_sort { # command list name
83
84	typeset CMD=$1
85	typeset list=$2
86	typeset name=$3
87
88	# set our index to the be number of elements in the list
89	typeset -i index=$($ECHO $list | $AWK '{print split($0,arr)}')
90
91	log_note "Checking reverse sort by '$name'," \
92		"expecting the reverse of '$list'"
93	log_must eval "$CMD > /dev/null"
94
95	for dataset in $( $CMD )
96	do
97		ACTUAL=$(basename $dataset)
98		if [ "$dataset" != "$TESTPOOL/$TESTFS" ]
99		then
100			EXPECTED=$($ECHO $list | $AWK "{print \$$index}")
101	   		if [ "$ACTUAL" != "$EXPECTED" ]
102			then
103		      		log_note "Warning:" \
104					"'$ACTUAL' does not equal to" \
105					"the reverse of '$EXPECTED'"
106				log_fail "ERROR: Reverse sort by '$name' fails."
107			fi
108
109			((index = index - 1))
110		fi
111	done
112
113 	# finally check to see if we have the expected number of elements
114	if [ $index -ne 0 ]
115	then
116		log_fail "Warning: " \
117			"unexpected number of filesystems found in list output!"
118	fi
119}
120