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# ident	"@(#)zvol_swap_001_pos.ksh	1.3	08/05/14 SMI"
27#
28# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
29# Use is subject to license terms.
30#
31
32. $STF_SUITE/include/libtest.kshlib
33. $STF_SUITE/tests/zvol/zvol_common.kshlib
34
35###############################################################################
36#
37# __stc_assertion_start
38#
39# ID: zvol_swap_001_pos
40#
41# DESCRIPTION:
42# Verify that a zvol can be used as a swap device
43#
44# STRATEGY:
45# 1. Create a pool
46# 2. Create a zvol volume
47# 3. Use zvol as swap space
48# 4. Create a file under $TMPDIR
49#
50# TESTABILITY: explicit
51#
52# TEST_AUTOMATION_LEVEL: automated
53#
54# CODING_STATUS: COMPLETED (2005-07-04)
55#
56# __stc_assertion_end
57#
58################################################################################
59
60verify_runnable "global"
61
62function cleanup
63{
64	$RM -rf $TMPDIR/$TESTFILE
65
66	if is_swap_inuse $voldev ; then
67		log_must $SWAP -d $voldev
68	fi
69}
70
71log_assert "Verify that a zvol can be used as a swap device"
72
73log_onexit cleanup
74
75test_requires SWAP
76
77voldev=/dev/zvol/$TESTPOOL/$TESTVOL
78log_note "Add zvol volume as swap space"
79log_must $SWAP -a $voldev
80
81log_note "Create a file under $TMPDIR"
82log_must $FILE_WRITE -o create -f $TMPDIR/$TESTFILE \
83    -b $BLOCKSZ -c $NUM_WRITES -d $DATA
84
85[[ ! -f $TMPDIR/$TESTFILE ]] &&
86    log_fail "Unable to create file under $TMPDIR"
87
88filesize=`$LS -l $TMPDIR/$TESTFILE | $AWK '{print $5}'`
89tf_size=$(( BLOCKSZ * NUM_WRITES ))
90(( $tf_size != $filesize )) &&
91    log_fail "testfile is ($filesize bytes), expected ($tf_size bytes)"
92
93log_pass "Successfully added a zvol to swap area."
94