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# $FreeBSD$
24
25#
26# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)zfs_list_002_pos.ksh	1.6	08/11/03 SMI"
30#
31. $STF_SUITE/tests/cli_user/zfs_list/zfs_list.kshlib
32. $STF_SUITE/tests/cli_user/cli_user.kshlib
33
34################################################################################
35#
36# __stc_assertion_start
37#
38# ID: zfs_list_002_pos
39#
40# DESCRIPTION:
41# The sort functionality in 'zfs list' works as expected.
42#
43# STRATEGY:
44# 1. Using several zfs datasets with names, creation dates, checksum options
45# 2. Sort the datasets by name, checksum options, creation date.
46# 3. Verify that the datasets are sorted correctly.
47#
48# TESTABILITY: explicit
49#
50# TEST_AUTOMATION_LEVEL: automated
51#
52# CODING_STATUS: COMPLETED (2006-09-08)
53#
54# __stc_assertion_end
55#
56################################################################################
57
58verify_runnable "both"
59
60# datasets ordered by name
61fs_name="Apple Banana Carrot Orange apple banana carrot"
62vol_name="Apple-vol Banana-vol Carrot-vol Orange-vol apple-vol"
63vol_name="$vol_name banana-vol carrot-vol"
64if is_global_zone ; then
65	snap_name="Apple-vol@snap Apple@snap Banana-vol@snap Banana@snap"
66	snap_name="$snap_name Carrot-vol@snap Carrot@snap Orange-vol@snap Orange@snap"
67	snap_name="$snap_name apple-vol@snap apple@snap banana-vol@snap banana@snap"
68	snap_name="$snap_name carrot-vol@snap carrot@snap"
69else
70	snap_name="Apple@snap Banana@snap"
71	snap_name="$snap_name Carrot@snap Orange@snap"
72	snap_name="$snap_name apple@snap banana@snap"
73	snap_name="$snap_name carrot@snap"
74fi
75
76fs_creation=$fs_name
77vol_creation=$vol_name
78if is_global_zone ; then
79	snap_creation="Apple@snap Apple-vol@snap Banana@snap Banana-vol@snap"
80	snap_creation="$snap_creation Carrot@snap Carrot-vol@snap Orange@snap Orange-vol@snap"
81	snap_creation="$snap_creation apple@snap apple-vol@snap banana@snap banana-vol@snap"
82	snap_creation="$snap_creation carrot@snap carrot-vol@snap"
83else
84	snap_creation="Apple@snap Banana@snap"
85	snap_creation="$snap_creation Carrot@snap Orange@snap"
86	snap_creation="$snap_creation apple@snap banana@snap"
87	snap_creation="$snap_creation carrot@snap"
88fi
89
90#
91# datsets ordered by checksum options (note, Orange, Carrot & Banana have the
92# same checksum options, so ZFS should revert to sorting them alphabetically by
93# name)
94#
95fs_cksum="carrot apple banana Apple Banana Carrot Orange"
96vol_cksum="carrot-vol apple-vol banana-vol Apple-vol Banana-vol"
97vol_cksum="$vol_cksum Carrot-vol Orange-vol"
98snap_cksum=$snap_creation
99
100fs_rev_cksum="carrot apple banana Apple Orange Carrot Banana"
101vol_rev_cksum="carrot-vol apple-vol banana-vol Apple-vol Orange-vol"
102vol_rev_cksum="$vol_rev_cksum Carrot-vol Banana-vol"
103
104log_assert "The sort functionality in 'zfs list' works as expected."
105
106#
107# we must be in the C locale here, as running in other locales
108# will make zfs use that locale's sort order.
109#
110LC_ALL=C; export LC_ALL
111
112# sort by creation
113verify_sort \
114	"run_unprivileged $ZFS list -H -r -o name -s creation -t filesystem $TESTPOOL/$TESTFS" \
115	"$fs_creation" "creation date"
116if is_global_zone ; then
117	verify_sort \
118	"run_unprivileged $ZFS list -H -r -o name -s creation -t volume $TESTPOOL/$TESTFS" \
119	"$vol_creation" "creation date"
120fi
121verify_sort \
122	"run_unprivileged $ZFS list -H -r -o name -s creation -t snapshot $TESTPOOL/$TESTFS" \
123	"$snap_creation" "creation date"
124
125# sort by checksum
126verify_sort \
127	"run_unprivileged $ZFS list -H -r -o name -s checksum -t filesystem $TESTPOOL/$TESTFS" \
128	"$fs_cksum" "checksum"
129if is_global_zone ; then
130	verify_sort \
131	"run_unprivileged $ZFS list -H -r -o name -s checksum -t volume $TESTPOOL/$TESTFS" \
132	"$vol_cksum" "checksum"
133fi
134verify_sort \
135	"run_unprivileged $ZFS list -H -r -o name -s checksum -t snapshot $TESTPOOL/$TESTFS" \
136	"$snap_cksum" "checksum"
137verify_sort \
138	"run_unprivileged $ZFS list -H -r -o name -S checksum -t snapshot $TESTPOOL/$TESTFS" \
139	"$snap_cksum" "checksum"
140
141# sort by name
142verify_sort \
143	"run_unprivileged $ZFS list -H -r -o name -s name -t filesystem $TESTPOOL/$TESTFS" \
144	"$fs_name" "name"
145if is_global_zone ; then
146	verify_sort \
147	"run_unprivileged $ZFS list -H -r -o name -s name -t volume $TESTPOOL/$TESTFS" \
148	"$vol_name" "name"
149fi
150verify_sort \
151	"run_unprivileged $ZFS list -H -r -o name -s name -t snapshot $TESTPOOL/$TESTFS" \
152	"$snap_name" "name"
153
154# reverse sort by creation
155verify_reverse_sort \
156	"run_unprivileged $ZFS list -H -r -o name -S creation -t filesystem $TESTPOOL/$TESTFS" \
157	"$fs_creation" "creation date"
158if is_global_zone ; then
159	verify_reverse_sort \
160	"run_unprivileged $ZFS list -H -r -o name -S creation -t volume $TESTPOOL/$TESTFS" \
161	"$vol_creation" "creation date"
162fi
163verify_reverse_sort \
164	"run_unprivileged $ZFS list -H -r -o name -S creation -t snapshot $TESTPOOL/$TESTFS" \
165	"$snap_creation" "creation date"
166
167# reverse sort by checksum
168verify_reverse_sort \
169	"run_unprivileged $ZFS list -H -r -o name -S checksum -t filesystem $TESTPOOL/$TESTFS" \
170	"$fs_rev_cksum" "checksum"
171if is_global_zone ; then
172	verify_reverse_sort \
173	"run_unprivileged $ZFS list -H -r -o name -S checksum -t volume $TESTPOOL/$TESTFS" \
174	"$vol_rev_cksum" "checksum"
175fi
176
177# reverse sort by name
178verify_reverse_sort \
179	"run_unprivileged $ZFS list -H -r -o name -S name -t filesystem $TESTPOOL/$TESTFS"\
180	"$fs_name" "name"
181if is_global_zone ; then
182	verify_reverse_sort \
183	"run_unprivileged $ZFS list -H -r -o name -S name -t volume $TESTPOOL/$TESTFS"\
184	"$vol_name" "name"
185fi
186verify_reverse_sort \
187	"run_unprivileged $ZFS list -H -r -o name -S name -t snapshot $TESTPOOL/$TESTFS"\
188	"$snap_name" "name"
189
190log_pass "The sort functionality in 'zfs list' works as expected."
191