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#
24# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27# ident	"@(#)zfs_send_002_pos.ksh	1.2	07/01/09 SMI"
28#
29
30. $STF_SUITE/tests/cli_root/cli_common.kshlib
31
32#################################################################################
33#
34# __stc_assertion_start
35#
36# ID: zfs_send_002_pos
37#
38# DESCRIPTION:
39#	Verify 'zfs send' can generate valid streams with a property setup.
40#
41# STRATEGY:
42#	1. Setup property for filesystem
43#	2. Fill in some data into filesystem
44#	3. Create a full send streams
45#	4. Receive the send stream
46#	5. Verify the receive result
47#
48# TESTABILITY: explicit
49#
50# TEST_AUTOMATION_LEVEL: automated
51#
52# CODING_STATUS: COMPLETED (2006-07-11)
53#
54# __stc_assertion_end
55#
56################################################################################
57
58verify_runnable "both"
59
60function cleanup
61{
62	snapexists $snap && \
63		log_must $ZFS destroy $snap
64
65	datasetexists $ctr && \
66		log_must $ZFS destroy -r $ctr
67
68	[[ -e $origfile ]] && \
69		log_must $RM -f $origfile
70
71	[[ -e $stream ]] && \
72		log_must $RM -f $stream
73}
74
75function do_testing # <prop> <prop_value>
76{
77	typeset property=$1
78	typeset prop_val=$2
79
80	log_must $ZFS set $property=$prop_val $fs
81	log_must $FILE_WRITE -o create -f $origfile -b $BLOCK_SIZE -c $WRITE_COUNT
82	log_must $ZFS snapshot $snap
83	$ZFS send $snap > $stream
84	(( $? != 0 )) && \
85		log_fail "'$ZFS send' fails to create send streams."
86	$ZFS receive -d $ctr <$stream
87	(( $? != 0 )) && \
88		log_fail "'$ZFS receive' fails to receive send streams."
89
90	#verify receive result
91	! datasetexists $rstfs && \
92		log_fail "'$ZFS receive' fails to restore $rstfs"
93	! snapexists $rstfssnap && \
94		log_fail "'$ZFS receive' fails to restore $rstfssnap"
95	if [[ ! -e $rstfile ]] || [[ ! -e $rstsnapfile ]]; then
96		log_fail " Data lost after receiving stream"
97	fi
98
99	compare_cksum $origfile $rstfile
100	compare_cksum $origsnapfile $rstsnapfile
101
102	#Destroy datasets and stream for next testing
103	log_must $ZFS destroy $snap
104	if is_global_zone ; then
105		log_must $ZFS destroy -r $rstfs
106	else
107		log_must $ZFS destroy -r $ds_path
108	fi
109	log_must $RM -f $stream
110}
111
112log_assert "Verify 'zfs send' generates valid streams with a property setup"
113log_onexit cleanup
114
115fs=$TESTPOOL/$TESTFS
116snap=$fs@$TESTSNAP
117ctr=$TESTPOOL/$TESTCTR
118if is_global_zone; then
119	rstfs=$ctr/$TESTFS
120else
121	ds_path=$ctr/${ZONE_CTR}0
122	rstfs=$ds_path/$TESTFS
123fi
124rstfssnap=$rstfs@$TESTSNAP
125snapdir="$(get_snapdir_name)/$TESTSNAP"
126origfile=$TESTDIR/$TESTFILE1
127rstfile=/$rstfs/$TESTFILE1
128origsnapfile=$TESTDIR/$snapdir/$TESTFILE1
129rstsnapfile=/$rstfs/$snapdir/$TESTFILE1
130stream=$TMPDIR/streamfile.${TESTCASE_ID}
131
132set -A props "compression" "checksum" "recordsize"
133set -A propval "on lzjb" "on fletcher2 fletcher4 sha256" \
134	"512 1k 4k 8k 16k 32k 64k 128k"
135
136#Create a dataset to receive the send stream
137log_must $ZFS create $ctr
138
139typeset -i i=0
140while (( i < ${#props[*]} ))
141do
142	for value in ${propval[i]}
143	do
144		do_testing ${props[i]} $value
145	done
146
147	(( i = i + 1 ))
148done
149
150log_pass "'zfs send' generates streams with a property setup as expected."
151