xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/casenorm/casenorm.kshlib (revision 7f11fd00fc23e2af7ae21cc8837a2b86380dcfa7)
1#
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.
6#
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.
10#
11
12#
13# Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
14#
15
16. $STF_SUITE/include/libtest.shlib
17. $STF_SUITE/tests/functional/casenorm/casenorm.cfg
18
19function create_testfs
20{
21	typeset opts=$1
22
23	$RM -rf $TESTDIR || log_unresolved Could not remove $TESTDIR
24	$MKDIR -p $TESTDIR || log_unresolved Could not create $TESTDIR
25
26	log_must $ZFS create $opts $TESTPOOL/$TESTFS
27	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
28}
29
30function destroy_testfs
31{
32	if datasetexists $TESTPOOL/$TESTFS ; then
33		log_must $ZFS destroy -f $TESTPOOL/$TESTFS
34		$RM -rf $TESTDIR || log_unresolved Could not remove $TESTDIR
35	fi
36}
37
38function create_file
39{
40	typeset name=$TESTDIR/$1
41
42	$ECHO $name > $name
43}
44
45function delete_file
46{
47	typeset name=$TESTDIR/$1
48
49	$RM $name >/dev/null 2>&1
50
51	if [[ $? -ne 0 ]] ; then
52		return 1
53	fi
54
55	if [[ -f $name ]] ; then
56		return 2
57	fi
58}
59
60function lookup_file
61{
62	typeset name=$1
63
64	$ZLOOK -l $TESTDIR $name >/dev/null 2>&1
65}
66
67function lookup_file_ci
68{
69	typeset name=$1
70
71	$ZLOOK -il $TESTDIR $name >/dev/null 2>&1
72}
73
74function lookup_any
75{
76	for name in $NAMES_ALL ; do
77		lookup_file $name
78		if [[ $? -eq 0 ]] ; then
79			return 0
80		fi
81	done
82
83	return 1
84}
85
86function switch_norm
87{
88	typeset norm=$(get_norm $1)
89
90	if [[ $norm == "C" ]] ; then
91		print "D"
92	else
93		print "C"
94	fi
95}
96
97function get_norm
98{
99	if [[ "${NAMES_C#*$1}" != "${NAMES_C}" ]] ; then
100		print "C"
101	elif [[ "${NAMES_D#*$1}" != "${NAMES_D}" ]] ; then
102		print "D"
103	else
104		return 1
105	fi
106}
107
108function get_case
109{
110	if [[ ${NAMES_UPPER#*$1} != ${NAMES_UPPER} ]] ; then
111		print "UPPER"
112	elif [[ ${NAMES_LOWER#*$1} != ${NAMES_LOWER} ]] ; then
113		print "LOWER"
114	elif [[ ${NAMES_ORIG#*$1} != ${NAMES_ORIG} ]] ; then
115		print "ORIG"
116	else
117		return 1
118	fi
119}
120