generic: try various unicode normalization games
[xfstests-dev.git] / tests / generic / 453
1 #! /bin/bash
2 # FS QA Test No. 453
3 #
4 # Create a directory with multiple filenames that all appear the same
5 # (in unicode, anyway) but point to different inodes.  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
43 _supported_os Linux
44 _require_scratch
45
46 echo "Format and mount"
47 _scratch_mkfs > $seqres.full 2>&1
48 _scratch_mount >> $seqres.full 2>&1
49
50 testdir="${SCRATCH_MNT}/test-${seq}"
51 mkdir $testdir
52
53 hexbytes() {
54         echo -n "$1" | od -tx1 -w99999 | head -n1 | sed -e 's/^0* //g'
55 }
56
57 setf() {
58         key="$(echo -e "$1")"
59         value="$2"
60
61         echo "${value}" > "${testdir}/${key}"
62         echo "Storing ${key} ($(hexbytes "${key}")) -> ${value}" >> $seqres.full
63 }
64
65 testf() {
66         key="$(echo -e "$1")"
67         value="$2"
68         fname="${testdir}/${key}"
69
70         echo "Testing ${key} ($(hexbytes "${key}")) -> ${value}" >> $seqres.full
71
72         if [ ! -e "${fname}" ]; then
73                 echo "Key ${key} does not exist for ${value} test??"
74                 return
75         fi
76
77         actual_value="$(cat "${fname}")"
78         if [ "${actual_value}" != "${value}" ]; then
79                 echo "Key ${key} has value ${value}, expected ${actual_value}."
80         fi
81 }
82
83 filter_scrub() {
84         grep 'Unicode' | sed -e 's/^.*Duplicate/Duplicate/g'
85 }
86
87 echo "Create files"
88 # These two render the same
89 setf "french_caf\xc3\xa9.txt" "NFC"
90 setf "french_cafe\xcc\x81.txt" "NFD"
91
92 # These two may have different widths
93 setf "chinese_\xef\xbd\xb6.txt" "NFKC1"
94 setf "chinese_\xe3\x82\xab.txt" "NFKC2"
95
96 # Same point, different byte representations in NFC/NFD/NFKC/NFKD
97 setf "greek_\xcf\x93.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFC"
98 setf "greek_\xcf\x92\xcc\x81.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFD"
99 setf "greek_\xce\x8e.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFKC"
100 setf "greek_\xce\xa5\xcc\x81.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFKD"
101
102 # Arabic code point can expand into a muuuch longer series
103 setf "arabic_\xef\xb7\xba.txt" "ARABIC LIGATURE SALLALLAHOU ALAYHE WASALLAM, NFC"
104 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"
105
106 # Fake slash?
107 setf "urk\xc0\xafmoo" "FAKESLASH"
108
109 ls -la $testdir >> $seqres.full
110
111 echo "Test files"
112 testf "french_caf\xc3\xa9.txt" "NFC"
113 testf "french_cafe\xcc\x81.txt" "NFD"
114
115 testf "chinese_\xef\xbd\xb6.txt" "NFKC1"
116 testf "chinese_\xe3\x82\xab.txt" "NFKC2"
117
118 testf "greek_\xcf\x93.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFC"
119 testf "greek_\xcf\x92\xcc\x81.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFD"
120 testf "greek_\xce\x8e.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFKC"
121 testf "greek_\xce\xa5\xcc\x81.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFKD"
122
123 testf "arabic_\xef\xb7\xba.txt" "ARABIC LIGATURE SALLALLAHOU ALAYHE WASALLAM, NFC"
124 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"
125
126 testf "urk\xc0\xafmoo" "FAKESLASH"
127
128 echo "Uniqueness of inodes?"
129 stat -c '%i' "${testdir}/"* | sort | uniq -c | while read nr inum; do
130         if [ "${nr}" -gt 1 ]; then
131                 echo "${nr} ${inum}"
132         fi
133 done
134
135 echo "Test XFS online scrub, if applicable"
136
137 # Only run this on xfs if xfs_scrub is available and has the unicode checker
138 check_xfs_scrub() {
139         # Ignore non-XFS fs or no scrub program...
140         if [ "${FSTYP}" != "xfs" ] || [ ! -x "${XFS_SCRUB_PROG}" ]; then
141                 return 1
142         fi
143
144         # We only care if xfs_scrub has unicode string support...
145         if ! type ldd > /dev/null 2>&1 || \
146            ! ldd "${XFS_SCRUB_PROG}" | grep -q libunistring; then
147                 return 1
148         fi
149
150         # Does the ioctl work?
151         if $XFS_IO_PROG -x -c "scrub test 0" $SCRATCH_MNT 2>&1 | \
152            grep -q "Inappropriate ioctl"; then
153                 return 1
154         fi
155
156         return 0
157 }
158
159 if check_xfs_scrub; then
160         output="$(${XFS_SCRUB_PROG} -n "${SCRATCH_MNT}" 2>&1 | filter_scrub)"
161         echo "${output}" | grep -q "french_" || echo "No complaints about french e accent?"
162         echo "${output}" | grep -q "chinese_" || echo "No complaints about chinese width-different?"
163         echo "${output}" | grep -q "greek_" || echo "No complaints about greek letter mess?"
164         echo "${output}" | grep -q "arabic_" || echo "No complaints about arabic expanded string?"
165         echo "Actual xfs_scrub output:" >> $seqres.full
166         echo "${output}" >> $seqres.full
167 fi
168
169 # success, all done
170 status=0
171 exit