generic/45[34]: test line draw characters in file/attr names
[xfstests-dev.git] / tests / generic / 454
1 #! /bin/bash
2 # FS QA Test No. 454
3 #
4 # Create xattrs with multiple keys that all appear the same
5 # (in unicode, anyway) but point to different values.  In theory all
6 # Linux filesystems should allow this (filenames are a sequence of
7 # arbitrary bytes) even if the user implications are horrifying.
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2017, Oracle and/or its affiliates.  All Rights Reserved.
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #-----------------------------------------------------------------------
25
26 seq=`basename "$0"`
27 seqres="$RESULT_DIR/$seq"
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1    # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37         rm -f $tmp.*
38 }
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/attr
43
44 _supported_os Linux
45 _require_scratch
46 _require_attrs
47
48 echo "Format and mount"
49 _scratch_mkfs > $seqres.full 2>&1
50 _scratch_mount >> $seqres.full 2>&1
51
52 testdir="${SCRATCH_MNT}/test-${seq}"
53 mkdir $testdir
54 testfile="${testdir}/attrfile"
55 touch "${testfile}"
56
57 hexbytes() {
58         echo -n "$1" | od -tx1 -w99999 | head -n1 | sed -e 's/^0* //g'
59 }
60
61 setf() {
62         key="$(echo -e "$1")"
63         value="$2"
64
65         $SETFATTR_PROG -n "user.${key}" -v "${value}" "${testfile}"
66         echo "Storing ${key} ($(hexbytes "${key}")) -> ${value}" >> $seqres.full
67 }
68
69 testf() {
70         key="$(echo -e "$1")"
71         value="$2"
72
73         echo "Testing ${key} ($(hexbytes "${key}")) -> ${value}" >> $seqres.full
74
75         actual_value="$($GETFATTR_PROG --absolute-names --only-values -n "user.${key}" "${testfile}")"
76         if [ "${actual_value}" != "${value}" ]; then
77                 echo "Key ${key} has value ${actual_value}, expected ${value}."
78         fi
79 }
80
81 filter_scrub() {
82         grep 'Unicode' | sed -e 's/^.*Duplicate/Duplicate/g'
83 }
84
85 echo "Create files"
86 # These two render the same
87 setf "french_caf\xc3\xa9.txt" "NFC"
88 setf "french_cafe\xcc\x81.txt" "NFD"
89
90 # These two may have different widths
91 setf "chinese_\xef\xbd\xb6.txt" "NFKC1"
92 setf "chinese_\xe3\x82\xab.txt" "NFKC2"
93
94 # Same point, different byte representations in NFC/NFD/NFKC/NFKD
95 setf "greek_\xcf\x93.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFC"
96 setf "greek_\xcf\x92\xcc\x81.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFD"
97 setf "greek_\xce\x8e.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFKC"
98 setf "greek_\xce\xa5\xcc\x81.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFKD"
99
100 # Arabic code point can expand into a muuuch longer series
101 setf "arabic_\xef\xb7\xba.txt" "ARABIC LIGATURE SALLALLAHOU ALAYHE WASALLAM, NFC"
102 setf "arabic_\xd8\xb5\xd9\x84\xd9\x89\x20\xd8\xa7\xd9\x84\xd9\x84\xd9\x87\x20\xd8\xb9\xd9\x84\xd9\x8a\xd9\x87\x20\xd9\x88\xd8\xb3\xd9\x84\xd9\x85.txt" "ARABIC LIGATURE SALLALLAHOU ALAYHE WASALLAM, NFKC"
103
104 # Fake slash?
105 setf "urk\xc0\xafmoo" "FAKESLASH"
106
107 # Emoji: octopus butterfly owl giraffe
108 setf "emoji_\xf0\x9f\xa6\x91\xf0\x9f\xa6\x8b\xf0\x9f\xa6\x89\xf0\x9f\xa6\x92.txt" "octopus butterfly owl giraffe emoji"
109
110 # Line draw characters, because why not?
111 setf "\x6c\x69\x6e\x65\x64\x72\x61\x77\x5f\x0a\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x97\x0a\xe2\x95\x91\x20\x6d\x65\x74\x61\x74\x61\x62\x6c\x65\x20\xe2\x95\x91\x0a\xe2\x95\x9f\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x95\xa2\x0a\xe2\x95\x91\x20\x5f\x5f\x69\x6e\x64\x65\x78\x20\x20\x20\xe2\x95\x91\x0a\xe2\x95\x9a\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d\x0a.txt" "ugly box because we can"
112
113 $GETFATTR_PROG --absolute-names -d "${testfile}" >> $seqres.full
114
115 echo "Test files"
116 testf "french_caf\xc3\xa9.txt" "NFC"
117 testf "french_cafe\xcc\x81.txt" "NFD"
118
119 testf "chinese_\xef\xbd\xb6.txt" "NFKC1"
120 testf "chinese_\xe3\x82\xab.txt" "NFKC2"
121
122 testf "greek_\xcf\x93.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFC"
123 testf "greek_\xcf\x92\xcc\x81.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFD"
124 testf "greek_\xce\x8e.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFKC"
125 testf "greek_\xce\xa5\xcc\x81.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFKD"
126
127 testf "arabic_\xef\xb7\xba.txt" "ARABIC LIGATURE SALLALLAHOU ALAYHE WASALLAM, NFC"
128 testf "arabic_\xd8\xb5\xd9\x84\xd9\x89\x20\xd8\xa7\xd9\x84\xd9\x84\xd9\x87\x20\xd8\xb9\xd9\x84\xd9\x8a\xd9\x87\x20\xd9\x88\xd8\xb3\xd9\x84\xd9\x85.txt" "ARABIC LIGATURE SALLALLAHOU ALAYHE WASALLAM, NFKC"
129
130 testf "urk\xc0\xafmoo" "FAKESLASH"
131
132 testf "emoji_\xf0\x9f\xa6\x91\xf0\x9f\xa6\x8b\xf0\x9f\xa6\x89\xf0\x9f\xa6\x92.txt" "octopus butterfly owl giraffe emoji"
133
134 testf "\x6c\x69\x6e\x65\x64\x72\x61\x77\x5f\x0a\xe2\x95\x94\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x97\x0a\xe2\x95\x91\x20\x6d\x65\x74\x61\x74\x61\x62\x6c\x65\x20\xe2\x95\x91\x0a\xe2\x95\x9f\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x95\xa2\x0a\xe2\x95\x91\x20\x5f\x5f\x69\x6e\x64\x65\x78\x20\x20\x20\xe2\x95\x91\x0a\xe2\x95\x9a\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x9d\x0a.txt" "ugly box because we can"
135
136 echo "Uniqueness of keys?"
137 crazy_keys="$($GETFATTR_PROG --absolute-names -d "${testfile}" | egrep -c '(french_|chinese_|greek_|arabic_|urk)')"
138 expected_keys=11
139 test "${crazy_keys}" -ne "${expected_keys}" && echo "Expected ${expected_keys} keys, saw ${crazy_keys}."
140
141 echo "Test XFS online scrub, if applicable"
142
143 # Only run this on xfs if xfs_scrub is available and has the unicode checker
144 check_xfs_scrub() {
145         [ "$FSTYP" == "xfs" ] || return 1
146         _supports_xfs_scrub "$SCRATCH_MNT" "$SCRATCH_DEV" || return 1
147
148         # We only care if xfs_scrub has unicode string support...
149         if ! type ldd > /dev/null 2>&1 || \
150            ! ldd "${XFS_SCRUB_PROG}" | grep -q libunistring; then
151                 return 1
152         fi
153
154         return 0
155 }
156
157 if check_xfs_scrub; then
158         output="$(LC_ALL="C.UTF-8" ${XFS_SCRUB_PROG} -n "${SCRATCH_MNT}" 2>&1 | filter_scrub)"
159         echo "${output}" | grep -q "french_" || echo "No complaints about french e accent?"
160         echo "${output}" | grep -q "chinese_" || echo "No complaints about chinese width-different?"
161         echo "${output}" | grep -q "greek_" || echo "No complaints about greek letter mess?"
162         echo "${output}" | grep -q "arabic_" || echo "No complaints about arabic expanded string?"
163         echo "Actual xfs_scrub output:" >> $seqres.full
164         echo "${output}" >> $seqres.full
165 fi
166
167 # success, all done
168 status=0
169 exit