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