7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / casenorm / casenorm.kshlib
blob273522406b6fcd0e31c3a760232417d9c285bc58
2 # This file and its contents are supplied under the terms of the
3 # Common Development and Distribution License ("CDDL"), version 1.0.
4 # You may only use this file in accordance with the terms of version
5 # 1.0 of the CDDL.
7 # A full copy of the text of the CDDL should have accompanied this
8 # source.  A copy of the CDDL is also available via the Internet at
9 # http://www.illumos.org/license/CDDL.
13 # Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
17 # Copyright (c) 2016 by Delphix. All rights reserved.
20 . $STF_SUITE/include/libtest.shlib
21 . $STF_SUITE/tests/functional/casenorm/casenorm.cfg
23 function create_testfs
25         typeset opts=$1
27         rm -rf $TESTDIR || log_unresolved Could not remove $TESTDIR
28         mkdir -p $TESTDIR || log_unresolved Could not create $TESTDIR
30         log_must zfs create $opts $TESTPOOL/$TESTFS
31         log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
34 function destroy_testfs
36         if datasetexists $TESTPOOL/$TESTFS ; then
37                 log_must zfs destroy -f $TESTPOOL/$TESTFS
38                 rm -rf $TESTDIR || log_unresolved Could not remove $TESTDIR
39         fi
42 function create_file
44         typeset name=$TESTDIR/$1
46         echo $name > $name
49 function delete_file
51         typeset name=$TESTDIR/$1
53         rm $name >/dev/null 2>&1
55         if [[ $? -ne 0 ]] ; then
56                 return 1
57         fi
59         if [[ -f $name ]] ; then
60                 return 2
61         fi
64 function lookup_file
66         typeset name=$1
68         zlook -l $TESTDIR $name >/dev/null 2>&1
71 function lookup_file_ci
73         typeset name=$1
75         zlook -il $TESTDIR $name >/dev/null 2>&1
78 function lookup_any
80         for name in $NAMES_ALL ; do
81                 lookup_file $name
82                 if [[ $? -eq 0 ]] ; then
83                         return 0
84                 fi
85         done
87         return 1
90 function switch_norm
92         typeset norm=$(get_norm $1)
94         if [[ $norm == "C" ]] ; then
95                 print "D"
96         else
97                 print "C"
98         fi
101 function get_norm
103         if [[ "${NAMES_C#*$1}" != "${NAMES_C}" ]] ; then
104                 print "C"
105         elif [[ "${NAMES_D#*$1}" != "${NAMES_D}" ]] ; then
106                 print "D"
107         else
108                 return 1
109         fi
112 function get_case
114         if [[ ${NAMES_UPPER#*$1} != ${NAMES_UPPER} ]] ; then
115                 print "UPPER"
116         elif [[ ${NAMES_LOWER#*$1} != ${NAMES_LOWER} ]] ; then
117                 print "LOWER"
118         elif [[ ${NAMES_ORIG#*$1} != ${NAMES_ORIG} ]] ; then
119                 print "ORIG"
120         else
121                 return 1
122         fi