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