1# vim: filetype=sh
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	"@(#)cli_common.kshlib	1.2	07/01/09 SMI"
28#
29
30. $STF_SUITE/include/libtest.kshlib
31
32#
33# Get the checksum and size of the file.
34#
35function get_cksum # <file path>
36{
37	return $($CKSUM $1 | $AWK '{print $1 $2}')
38}
39
40#
41# Compare the check sum of target files with the original file
42#
43
44function compare_cksum #<orig_data> <target_data1>...<target_datan>
45{
46	typeset orig_data=$1
47	typeset orig_sum=$(get_cksum $orig_data)
48	typeset target_sum=""
49	typeset bad_data_list=""
50	typeset -i bad_count=0
51
52	shift
53	for data in $@; do
54		if [[ ! -e $data ]]; then
55			bad_data_list="$bad_data_list $data"
56			(( bad_count +=1 ))
57			continue
58		fi
59
60		target_sum=$(get_cksum $data)
61		if [[ $target_sum != $orig_sum ]]; then
62			bad_data_list="$bad_data_list $data"
63			(( bad_count +=1 ))
64		fi
65	done
66
67	[[ $bad_data_list != "" ]] && \
68		log_fail "Data corruptions appear during send->receive." \
69			"There are total $bad_count corruptions. They are:\n"\
70			"$bad_data_list"
71}
72
73#
74# Check the received dataset exists or not
75#
76function receive_check #<dataset1>...<datasetn>
77{
78	typeset bad_rst_tgts=""
79
80	for dataset in $@; do
81		! datasetexists $dataset && \
82			bad_rst_tgts="$bad_rst_tgts $dataset"
83	done
84
85	if [[ $bad_rst_tgts != "" ]]; then
86		log_fail "Restoring fails. The specified datasets"\
87			"$bad_rst_tgts are not being received."
88	fi
89}
90