xref: /freebsd/sys/contrib/openzfs/tests/zfs-tests/tests/functional/casenorm/casenorm.kshlib (revision 716fd348e01c5f2ba125f878a634a753436c2994)
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#
17# Copyright (c) 2016 by Delphix. All rights reserved.
18#
19
20. $STF_SUITE/include/libtest.shlib
21. $STF_SUITE/tests/functional/casenorm/casenorm.cfg
22
23function create_testfs
24{
25	typeset opts=$1
26
27	rm -rf $TESTDIR || log_unresolved Could not remove $TESTDIR
28	mkdir -p $TESTDIR || log_unresolved Could not create $TESTDIR
29
30	log_must zfs create $opts $TESTPOOL/$TESTFS
31	log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
32}
33
34function destroy_testfs
35{
36	if datasetexists $TESTPOOL/$TESTFS ; then
37		destroy_dataset $TESTPOOL/$TESTFS -f
38		rm -rf $TESTDIR || log_unresolved Could not remove $TESTDIR
39	fi
40}
41
42function create_file
43{
44	typeset name=$TESTDIR/$1
45
46	echo $name > $name
47}
48
49function delete_file
50{
51	typeset name=$TESTDIR/$1
52
53	rm $name >/dev/null 2>&1 || return 1
54	if [ -f $name ]; then
55		return 2
56	fi
57}
58
59function lookup_file
60{
61	typeset name=$1
62
63	if is_illumos; then
64		zlook -l $TESTDIR $name >/dev/null 2>&1
65	else
66		test -f "${TESTDIR}/${name}" >/dev/null 2>&1
67	fi
68}
69
70function lookup_file_ci
71{
72	typeset name=$1
73
74	if is_illumos; then
75		zlook -il $TESTDIR $name >/dev/null 2>&1
76	else
77		test -f "${TESTDIR}/${name}" >/dev/null 2>&1
78	fi
79}
80
81function lookup_any
82{
83	for name in $NAMES_ALL ; do
84		lookup_file $name && return
85	done
86
87	return 1
88}
89
90function switch_norm
91{
92	typeset norm=$(get_norm $1)
93
94	if [[ $norm == "C" ]] ; then
95		print "D"
96	else
97		print "C"
98	fi
99}
100
101function get_norm
102{
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
110}
111
112function get_case
113{
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
123}
124