7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / cli_root / cli_common.kshlib
blob4788de59866393eac58a000fbd71d69e403e05c0
2 # CDDL HEADER START
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
19 # CDDL HEADER END
23 # Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24 # Use is subject to license terms.
28 # Copyright (c) 2016 by Delphix. All rights reserved.
31 . $STF_SUITE/include/libtest.shlib
34 # Get the checksum and size of the file.
36 function get_cksum # <file path>
38         return $(cksum $1 | awk '{print $1 $2}')
42 # Compare the check sum of target files with the original file
45 function compare_cksum #<orig_data> <target_data1>...<target_datan>
47         typeset orig_data=$1
48         typeset orig_sum=$(get_cksum $orig_data)
49         typeset target_sum=""
50         typeset bad_data_list=""
51         typeset -i bad_count=0
53         shift
54         for data in $@; do
55                 if [[ ! -e $data ]]; then
56                         bad_data_list="$bad_data_list $data"
57                         (( bad_count +=1 ))
58                         continue
59                 fi
61                 target_sum=$(get_cksum $data)
62                 if [[ $target_sum != $orig_sum ]]; then
63                         bad_data_list="$bad_data_list $data"
64                         (( bad_count +=1 ))
65                 fi
66         done
68         [[ $bad_data_list != "" ]] && \
69                 log_fail "Data corruptions appear during send->receive." \
70                         "There are total $bad_count corruptions. They are:\n"\
71                         "$bad_data_list"
75 # Check the received dataset exists or not
77 function receive_check #<dataset1>...<datasetn>
79         typeset bad_rst_tgts=""
81         for dataset in $@; do
82                 ! datasetexists $dataset && \
83                         bad_rst_tgts="$bad_rst_tgts $dataset"
84         done
86         if [[ $bad_rst_tgts != "" ]]; then
87                 log_fail "Restoring fails. The specified datasets"\
88                         "$bad_rst_tgts are not being received."
89         fi