xfs/504: Add scratch_mount before checking for xfs_scrub unicode support
[xfstests-dev.git] / tests / xfs / 504
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0+
3 # Copyright (c) 2019, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 504
6 #
7 # Create a filesystem label with emoji and confusing unicode characters
8 # to make sure that these special things actually work on xfs.  In
9 # theory it should allow this (labels are a sequence of arbitrary bytes)
10 # even if the user implications are horrifying.
11 #
12 . ./common/preamble
13 _begin_fstest auto quick mkfs label
14
15 # Import common functions.
16 . ./common/filter
17
18 _supported_fs xfs
19 _require_scratch_nocheck
20 _require_xfs_io_command 'label'
21
22 echo "Silence is golden."
23
24 _scratch_mkfs > /dev/null
25 _scratch_mount
26 want_scrub=
27 _check_xfs_scrub_does_unicode "$SCRATCH_MNT" "$SCRATCH_DEV" && want_scrub=yes
28 _scratch_unmount
29
30 filter_scrub() {
31         grep 'Unicode' | sed -e 's/^.*Duplicate/Duplicate/g'
32 }
33
34 maybe_scrub() {
35         test "$want_scrub" = "yes" || return
36
37         output="$(LC_ALL="C.UTF-8" ${XFS_SCRUB_PROG} -v -n "${SCRATCH_MNT}" 2>&1)"
38         echo "xfs_scrub output:" >> $seqres.full
39         echo "$output" >> $seqres.full
40         echo "$output" >> $tmp.scrub
41 }
42
43 testlabel() {
44         local label="$(echo -e "$1")"
45         local expected_label="label = \"$label\""
46
47         echo "Formatting label '$1'." >> $seqres.full
48         # First, let's see if we can recover the label when we set it
49         # with mkfs.
50         _scratch_mkfs -L "$label" >> $seqres.full 2>&1
51         _scratch_mount >> $seqres.full 2>&1
52         blkid -s LABEL $SCRATCH_DEV | _filter_scratch | sed -e "s/ $//g" >> $seqres.full
53         blkid -d -s LABEL $SCRATCH_DEV | _filter_scratch | sed -e "s/ $//g" >> $seqres.full
54
55         # Did it actually stick?
56         local actual_label="$($XFS_IO_PROG -c label $SCRATCH_MNT)"
57         echo "$actual_label" >> $seqres.full
58
59         if [ "${actual_label}" != "${expected_label}" ]; then
60                 echo "Saw '${expected_label}', expected '${actual_label}'."
61         fi
62         maybe_scrub
63         _scratch_unmount
64
65         # Now let's try setting the label online to see what happens.
66         echo "Setting label '$1'." >> $seqres.full
67         _scratch_mkfs >> $seqres.full 2>&1
68         _scratch_mount >> $seqres.full 2>&1
69         $XFS_IO_PROG -c "label -s $label" $SCRATCH_MNT >> $seqres.full
70         blkid -s LABEL $SCRATCH_DEV | _filter_scratch | sed -e "s/ $//g" >> $seqres.full
71         blkid -d -s LABEL $SCRATCH_DEV | _filter_scratch | sed -e "s/ $//g" >> $seqres.full
72         _scratch_cycle_mount
73
74         # Did it actually stick?
75         local actual_label="$($XFS_IO_PROG -c label $SCRATCH_MNT)"
76         echo "$actual_label" >> $seqres.full
77
78         if [ "${actual_label}" != "${expected_label}" ]; then
79                 echo "Saw '${expected_label}'; expected '${actual_label}'."
80         fi
81         maybe_scrub
82         _scratch_unmount
83 }
84
85 # Simple test
86 testlabel "simple"
87
88 # Two different renderings of the same label
89 testlabel "caf\xc3\xa9.fs"
90 testlabel "cafe\xcc\x81.fs"
91
92 # Arabic code point can expand into a muuuch longer series
93 testlabel "xfs_\xef\xb7\xba.fs"
94
95 # Fake slash?
96 testlabel "urk\xc0\xafmoo"
97
98 # Emoji: octopus butterfly owl giraffe
99 testlabel "\xf0\x9f\xa6\x91\xf0\x9f\xa6\x8b\xf0\x9f\xa6\x89"
100
101 # unicode rtl widgets too...
102 testlabel "mo\xe2\x80\xaegnp.txt"
103 testlabel "motxt.png"
104
105 # mixed-script confusables
106 testlabel "mixed_t\xce\xbfp"
107 testlabel "mixed_top"
108
109 # single-script spoofing
110 testlabel "a\xe2\x80\x90b.fs"
111 testlabel "a-b.fs"
112
113 testlabel "dz_dze.fs"
114 testlabel "dz_\xca\xa3e.fs"
115
116 # symbols
117 testlabel "_Rs.fs"
118 testlabel "_\xe2\x82\xa8.fs"
119
120 # zero width joiners
121 testlabel "moocow.fs"
122 testlabel "moo\xe2\x80\x8dcow.fs"
123
124 # combining marks
125 testlabel "\xe1\x80\x9c\xe1\x80\xad\xe1\x80\xaf.fs"
126 testlabel "\xe1\x80\x9c\xe1\x80\xaf\xe1\x80\xad.fs"
127
128 # fake dotdot entry
129 testlabel ".\xe2\x80\x8d"
130 testlabel "..\xe2\x80\x8d"
131
132 # Did scrub choke on anything?
133 if [ "$want_scrub" = "yes" ]; then
134         grep -q "^Warning.*gnp.txt.*suspicious text direction" $tmp.scrub || \
135                 echo "No complaints about direction overrides?"
136         grep -q "^Warning.*control characters" $tmp.scrub || \
137                 echo "No complaints about control characters?"
138 fi
139
140 # success, all done
141 status=0
142 exit