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 "@(#)zvol_swap_006_pos.ksh 1.4 08/05/14 SMI" 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_006_pos 40# 41# DESCRIPTION: 42# A volume can be add as several segments, but overlapping are not 43# allowed. 44# 45# STRATEGY: 46# 1. Figure out three groups swaplow and swaplen. 47# 2. Verify different volume segments can be added correctly. 48# 3. Verify overlapping swap volume are not allowed. 49# 50# TESTABILITY: explicit 51# 52# TEST_AUTOMATION_LEVEL: automated 53# 54# CODING_STATUS: COMPLETED (2006-12-13) 55# 56# __stc_assertion_end 57# 58################################################################################ 59 60verify_runnable "global" 61 62function cleanup 63{ 64 typeset -i i=0 65 66 while ((count > 0)); do 67 log_must $SWAP -d $swapname ${swap_opt[$i]} 68 69 ((i += 2)) 70 ((count -= 1)) 71 done 72} 73 74log_assert "Verify volume can be add as several segments, but overlapping " \ 75 "are not allowed." 76log_onexit cleanup 77 78test_requires SWAP 79 80typeset vol=$TESTPOOL/$TESTVOL 81typeset -i pageblocks volblocks 82((pageblocks = $($PAGESIZE) / 512)) 83((volblocks = $(get_prop volsize $vol) / 512)) 84 85log_note "Verify volume can be add as several segments." 86 87# 88# swaplow swaplen 89set -A swap_opt $((pageblocks)) \ 90 $((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) )) \ 91 $((volblocks / 3)) \ 92 $((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) )) \ 93 $((volblocks / 2)) \ 94 $((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) )) \ 95 $(((volblocks*2) / 3)) \ 96 $((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) )) 97 98swapname=/dev/zvol/$vol 99typeset -i i=0 count=0 100 101if is_swap_inuse $swapname ; then 102 log_must $SWAP -d $swapname 103fi 104 105while ((i < ${#swap_opt[@]})); do 106 log_must $SWAP -a $swapname ${swap_opt[$i]} ${swap_opt[((i+1))]} 107 108 ((i += 2)) 109 ((count += 1)) 110done 111 112log_note "Verify overlapping swap volume are not allowed" 113i=0 114while ((i < ${#swap_opt[@]})); do 115 log_mustnot $SWAP -a $swapname ${swap_opt[$i]} 116 117 ((i += 2)) 118done 119 120log_pass "Verify volume can be added as several segments passed." 121