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