1# SPDX-License-Identifier: CDDL-1.0 2# 3# This file and its contents are supplied under the terms of the 4# Common Development and Distribution License ("CDDL"), version 1.0. 5# You may only use this file in accordance with the terms of version 6# 1.0 of the CDDL. 7# 8# A full copy of the text of the CDDL should have accompanied this 9# source. A copy of the CDDL is also available via the Internet at 10# http://www.illumos.org/license/CDDL. 11# 12 13# 14# Copyright 2015 Nexenta Systems, Inc. All rights reserved. 15# 16 17# 18# Copyright (c) 2016 by Delphix. All rights reserved. 19# 20 21. $STF_SUITE/include/libtest.shlib 22. $STF_SUITE/tests/functional/casenorm/casenorm.cfg 23 24function create_testfs 25{ 26 typeset opts=$1 27 28 rm -rf $TESTDIR || log_unresolved Could not remove $TESTDIR 29 mkdir -p $TESTDIR || log_unresolved Could not create $TESTDIR 30 31 log_must zfs create $opts $TESTPOOL/$TESTFS 32 log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS 33} 34 35function destroy_testfs 36{ 37 if datasetexists $TESTPOOL/$TESTFS ; then 38 destroy_dataset $TESTPOOL/$TESTFS -f 39 rm -rf $TESTDIR || log_unresolved Could not remove $TESTDIR 40 fi 41} 42 43function create_file 44{ 45 typeset name=$TESTDIR/$1 46 47 echo $name > $name 48} 49 50function delete_file 51{ 52 typeset name=$TESTDIR/$1 53 54 rm $name >/dev/null 2>&1 || return 1 55 if [ -f $name ]; then 56 return 2 57 fi 58} 59 60function lookup_file 61{ 62 typeset name=$1 63 64 if is_illumos; then 65 zlook -l $TESTDIR $name >/dev/null 2>&1 66 else 67 test -f "${TESTDIR}/${name}" >/dev/null 2>&1 68 fi 69} 70 71function lookup_file_ci 72{ 73 typeset name=$1 74 75 if is_illumos; then 76 zlook -il $TESTDIR $name >/dev/null 2>&1 77 else 78 test -f "${TESTDIR}/${name}" >/dev/null 2>&1 79 fi 80} 81 82function lookup_any 83{ 84 for name in $NAMES_ALL ; do 85 lookup_file $name && return 86 done 87 88 return 1 89} 90 91function switch_norm 92{ 93 typeset norm=$(get_norm $1) 94 95 if [[ $norm == "C" ]] ; then 96 print "D" 97 else 98 print "C" 99 fi 100} 101 102function get_norm 103{ 104 if [[ "${NAMES_C#*$1}" != "${NAMES_C}" ]] ; then 105 print "C" 106 elif [[ "${NAMES_D#*$1}" != "${NAMES_D}" ]] ; then 107 print "D" 108 else 109 return 1 110 fi 111} 112 113function get_case 114{ 115 if [[ ${NAMES_UPPER#*$1} != ${NAMES_UPPER} ]] ; then 116 print "UPPER" 117 elif [[ ${NAMES_LOWER#*$1} != ${NAMES_LOWER} ]] ; then 118 print "LOWER" 119 elif [[ ${NAMES_ORIG#*$1} != ${NAMES_ORIG} ]] ; then 120 print "ORIG" 121 else 122 return 1 123 fi 124} 125