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