generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 453
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 453
6 #
7 # Create a directory with multiple filenames that all appear the same
8 # (in unicode, anyway) but point to different inodes.  In theory all
9 # Linux filesystems should allow this (filenames are a sequence of
10 # arbitrary bytes) even if the user implications are horrifying.
11 #
12 . ./common/preamble
13 _begin_fstest auto quick dir
14
15 # Import common functions.
16
17 _require_scratch
18 _require_names_are_bytes
19
20 echo "Format and mount"
21 _scratch_mkfs > $seqres.full 2>&1
22 _scratch_mount >> $seqres.full 2>&1
23
24 testdir="${SCRATCH_MNT}/test-${seq}"
25 mkdir $testdir
26
27 hexbytes() {
28         echo -n "$1" | od -tx1 -w99999 | head -n1 | sed -e 's/^0* //g'
29 }
30
31 setf() {
32         key="$(echo -e "$1")"
33         value="$2"
34
35         echo "${value}" > "${testdir}/${key}"
36         echo "Storing ${key} ($(hexbytes "${key}")) -> ${value}" >> $seqres.full
37 }
38
39 setd() {
40         key="$(echo -e "$1")"
41         value="$2"
42
43         mkdir -p "${testdir}/${key}"
44         echo "${value}" > "${testdir}/${key}/value"
45         echo "Storing ${key} ($(hexbytes "${key}")) -> ${value}" >> $seqres.full
46 }
47
48 testf() {
49         key="$(echo -e "$1")"
50         value="$2"
51         fname="${testdir}/${key}"
52
53         echo "Testing ${key} ($(hexbytes "${key}")) -> ${value}" >> $seqres.full
54
55         if [ ! -e "${fname}" ]; then
56                 echo "Key ${key} does not exist for ${value} test??"
57                 return
58         fi
59
60         actual_value="$(cat "${fname}")"
61         if [ "${actual_value}" != "${value}" ]; then
62                 echo "Key ${key} has value ${value}, expected ${actual_value}."
63         fi
64 }
65
66 testd() {
67         key="$(echo -e "$1")"
68         value="$2"
69         fname="${testdir}/${key}/value"
70
71         echo "Testing ${key} ($(hexbytes "${key}")) -> ${value}" >> $seqres.full
72
73         if [ ! -e "${fname}" ]; then
74                 echo "Key ${key} does not exist for ${value} test??"
75                 return
76         fi
77
78         actual_value="$(cat "${fname}")"
79         if [ "${actual_value}" != "${value}" ]; then
80                 echo "Key ${key} has value ${value}, expected ${actual_value}."
81         fi
82 }
83
84 filter_scrub() {
85         grep 'Unicode' | sed -e 's/^.*Duplicate/Duplicate/g'
86 }
87
88 echo "Create files"
89 # These two render the same
90 setf "french_caf\xc3\xa9.txt" "NFC"
91 setf "french_cafe\xcc\x81.txt" "NFD"
92
93 # These two may have different widths
94 setf "chinese_\xef\xbd\xb6.txt" "NFKC1"
95 setf "chinese_\xe3\x82\xab.txt" "NFKC2"
96
97 # Same point, different byte representations in NFC/NFD/NFKC/NFKD
98 setf "greek_\xcf\x93.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFC"
99 setf "greek_\xcf\x92\xcc\x81.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFD"
100 setf "greek_\xce\x8e.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFKC"
101 setf "greek_\xce\xa5\xcc\x81.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFKD"
102
103 # Arabic code point can expand into a muuuch longer series
104 setf "arabic_\xef\xb7\xba.txt" "ARABIC LIGATURE SALLALLAHOU ALAYHE WASALLAM, NFC"
105 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"
106
107 # Fake slash?
108 setf "urk\xc0\xafmoo" "FAKESLASH"
109
110 # Emoji: octopus butterfly owl giraffe
111 setf "emoji_\xf0\x9f\xa6\x91\xf0\x9f\xa6\x8b\xf0\x9f\xa6\x89\xf0\x9f\xa6\x92.txt" "octopus butterfly owl giraffe emoji"
112
113 # Line draw characters, because why not?
114 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"
115
116 # unicode rtl widgets too...
117 setf "moo\xe2\x80\xaegnp.txt" "Well say hello,"
118 setf "mootxt.png" "Harvey"
119
120 # mixed-script confusables
121 setf "mixed_t\xce\xbfp.txt" "greek omicron instead of o"
122 setf "mixed_top.txt" "greek omicron instead of o"
123
124 # single-script spoofing
125 setf "hyphens_a\xe2\x80\x90b.txt" "hyphens"
126 setf "hyphens_a-b.txt" "hyphens"
127
128 setf "dz_digraph_dze.txt" "d-z digraph"
129 setf "dz_digraph_\xca\xa3e.txt" "d-z digraph"
130
131 # inadequate rendering
132 setf "inadequate_al.txt" "is it l or is it 1"
133 setf "inadequate_a1.txt" "is it l or is it 1"
134
135 # symbols
136 setf "prohibition_Rs.txt" "rupee symbol"
137 setf "prohibition_\xe2\x82\xa8.txt" "rupee symbol"
138
139 # zero width joiners
140 setf "zerojoin_moocow.txt" "zero width joiners"
141 setf "zerojoin_moo\xe2\x80\x8dcow.txt" "zero width joiners"
142
143 # combining marks
144 setf "combmark_\xe1\x80\x9c\xe1\x80\xad\xe1\x80\xaf.txt" "combining marks"
145 setf "combmark_\xe1\x80\x9c\xe1\x80\xaf\xe1\x80\xad.txt" "combining marks"
146
147 # fake dotdot entry
148 setd ".\xe2\x80\x8d" "zero width joiners in dot entry"
149 setd "..\xe2\x80\x8d" "zero width joiners in dotdot entry"
150
151 ls -la $testdir >> $seqres.full
152
153 echo "Test files"
154 testf "french_caf\xc3\xa9.txt" "NFC"
155 testf "french_cafe\xcc\x81.txt" "NFD"
156
157 testf "chinese_\xef\xbd\xb6.txt" "NFKC1"
158 testf "chinese_\xe3\x82\xab.txt" "NFKC2"
159
160 testf "greek_\xcf\x93.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFC"
161 testf "greek_\xcf\x92\xcc\x81.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFD"
162 testf "greek_\xce\x8e.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFKC"
163 testf "greek_\xce\xa5\xcc\x81.txt" "GREEK UPSILON WITH ACUTE AND HOOK SYMBOL, NFKD"
164
165 testf "arabic_\xef\xb7\xba.txt" "ARABIC LIGATURE SALLALLAHOU ALAYHE WASALLAM, NFC"
166 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"
167
168 testf "urk\xc0\xafmoo" "FAKESLASH"
169
170 testf "emoji_\xf0\x9f\xa6\x91\xf0\x9f\xa6\x8b\xf0\x9f\xa6\x89\xf0\x9f\xa6\x92.txt" "octopus butterfly owl giraffe emoji"
171
172 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"
173
174 testf "moo\xe2\x80\xaegnp.txt" "Well say hello,"
175 testf "mootxt.png" "Harvey"
176
177 testf "mixed_t\xce\xbfp.txt" "greek omicron instead of o"
178 testf "mixed_top.txt" "greek omicron instead of o"
179
180 testf "hyphens_a\xe2\x80\x90b.txt" "hyphens"
181 testf "hyphens_a-b.txt" "hyphens"
182
183 testf "dz_digraph_dze.txt" "d-z digraph"
184 testf "dz_digraph_\xca\xa3e.txt" "d-z digraph"
185
186 testf "inadequate_al.txt" "is it l or is it 1"
187 testf "inadequate_a1.txt" "is it l or is it 1"
188
189 testf "prohibition_Rs.txt" "rupee symbol"
190 testf "prohibition_\xe2\x82\xa8.txt" "rupee symbol"
191
192 testf "zerojoin_moocow.txt" "zero width joiners"
193 testf "zerojoin_moo\xe2\x80\x8dcow.txt" "zero width joiners"
194
195 testf "combmark_\xe1\x80\x9c\xe1\x80\xad\xe1\x80\xaf.txt" "combining marks"
196 testf "combmark_\xe1\x80\x9c\xe1\x80\xaf\xe1\x80\xad.txt" "combining marks"
197
198 testd ".\xe2\x80\x8d" "zero width joiners in dot entry"
199 testd "..\xe2\x80\x8d" "zero width joiners in dotdot entry"
200
201 echo "Uniqueness of inodes?"
202 stat -c '%i' "${testdir}/"* | sort | uniq -c | while read nr inum; do
203         if [ "${nr}" -gt 1 ]; then
204                 echo "${nr} ${inum}"
205         fi
206 done
207
208 echo "Test XFS online scrub, if applicable"
209
210 if _check_xfs_scrub_does_unicode "$SCRATCH_MNT" "$SCRATCH_DEV"; then
211         output="$(LC_ALL="C.UTF-8" ${XFS_SCRUB_PROG} -v -n "${SCRATCH_MNT}" 2>&1 | filter_scrub)"
212         echo "${output}" | grep -q "french_" || echo "No complaints about french e accent?"
213         echo "${output}" | grep -q "greek_" || echo "No complaints about greek letter mess?"
214         echo "${output}" | grep -q "arabic_" || echo "No complaints about arabic expanded string?"
215         echo "${output}" | grep -q "mixed_" || echo "No complaints about mixed script confusables?"
216         echo "${output}" | grep -q "hyphens_" || echo "No complaints about hyphenation confusables?"
217         echo "${output}" | grep -q "dz_digraph_" || echo "No complaints about single script confusables?"
218         echo "${output}" | grep -q "inadequate_" || echo "No complaints about inadequate rendering confusables?"
219         echo "${output}" | grep -q "prohibition_" || echo "No complaints about prohibited sequence confusables?"
220         echo "${output}" | grep -q "zerojoin_" || echo "No complaints about zero-width join confusables?"
221         echo "Actual xfs_scrub output:" >> $seqres.full
222         echo "${output}" >> $seqres.full
223 fi
224
225 # success, all done
226 status=0
227 exit