check: exit with exit code 1 after printing the usage message
[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 want_scrub=
25 _check_xfs_scrub_does_unicode "$SCRATCH_MNT" "$SCRATCH_DEV" && want_scrub=yes
26
27 filter_scrub() {
28         grep 'Unicode' | sed -e 's/^.*Duplicate/Duplicate/g'
29 }
30
31 maybe_scrub() {
32         test "$want_scrub" = "yes" || return
33
34         output="$(LC_ALL="C.UTF-8" ${XFS_SCRUB_PROG} -v -n "${SCRATCH_MNT}" 2>&1)"
35         echo "xfs_scrub output:" >> $seqres.full
36         echo "$output" >> $seqres.full
37         echo "$output" >> $tmp.scrub
38 }
39
40 testlabel() {
41         local label="$(echo -e "$1")"
42         local expected_label="label = \"$label\""
43
44         echo "Formatting label '$1'." >> $seqres.full
45         # First, let's see if we can recover the label when we set it
46         # with mkfs.
47         _scratch_mkfs -L "$label" >> $seqres.full 2>&1
48         _scratch_mount >> $seqres.full 2>&1
49         blkid -s LABEL $SCRATCH_DEV | _filter_scratch | sed -e "s/ $//g" >> $seqres.full
50         blkid -d -s LABEL $SCRATCH_DEV | _filter_scratch | sed -e "s/ $//g" >> $seqres.full
51
52         # Did it actually stick?
53         local actual_label="$($XFS_IO_PROG -c label $SCRATCH_MNT)"
54         echo "$actual_label" >> $seqres.full
55
56         if [ "${actual_label}" != "${expected_label}" ]; then
57                 echo "Saw '${expected_label}', expected '${actual_label}'."
58         fi
59         maybe_scrub
60         _scratch_unmount
61
62         # Now let's try setting the label online to see what happens.
63         echo "Setting label '$1'." >> $seqres.full
64         _scratch_mkfs >> $seqres.full 2>&1
65         _scratch_mount >> $seqres.full 2>&1
66         $XFS_IO_PROG -c "label -s $label" $SCRATCH_MNT >> $seqres.full
67         blkid -s LABEL $SCRATCH_DEV | _filter_scratch | sed -e "s/ $//g" >> $seqres.full
68         blkid -d -s LABEL $SCRATCH_DEV | _filter_scratch | sed -e "s/ $//g" >> $seqres.full
69         _scratch_cycle_mount
70
71         # Did it actually stick?
72         local actual_label="$($XFS_IO_PROG -c label $SCRATCH_MNT)"
73         echo "$actual_label" >> $seqres.full
74
75         if [ "${actual_label}" != "${expected_label}" ]; then
76                 echo "Saw '${expected_label}'; expected '${actual_label}'."
77         fi
78         maybe_scrub
79         _scratch_unmount
80 }
81
82 # Simple test
83 testlabel "simple"
84
85 # Two different renderings of the same label
86 testlabel "caf\xc3\xa9.fs"
87 testlabel "cafe\xcc\x81.fs"
88
89 # Arabic code point can expand into a muuuch longer series
90 testlabel "xfs_\xef\xb7\xba.fs"
91
92 # Fake slash?
93 testlabel "urk\xc0\xafmoo"
94
95 # Emoji: octopus butterfly owl giraffe
96 testlabel "\xf0\x9f\xa6\x91\xf0\x9f\xa6\x8b\xf0\x9f\xa6\x89"
97
98 # unicode rtl widgets too...
99 testlabel "mo\xe2\x80\xaegnp.txt"
100 testlabel "motxt.png"
101
102 # mixed-script confusables
103 testlabel "mixed_t\xce\xbfp"
104 testlabel "mixed_top"
105
106 # single-script spoofing
107 testlabel "a\xe2\x80\x90b.fs"
108 testlabel "a-b.fs"
109
110 testlabel "dz_dze.fs"
111 testlabel "dz_\xca\xa3e.fs"
112
113 # symbols
114 testlabel "_Rs.fs"
115 testlabel "_\xe2\x82\xa8.fs"
116
117 # zero width joiners
118 testlabel "moocow.fs"
119 testlabel "moo\xe2\x80\x8dcow.fs"
120
121 # combining marks
122 testlabel "\xe1\x80\x9c\xe1\x80\xad\xe1\x80\xaf.fs"
123 testlabel "\xe1\x80\x9c\xe1\x80\xaf\xe1\x80\xad.fs"
124
125 # fake dotdot entry
126 testlabel ".\xe2\x80\x8d"
127 testlabel "..\xe2\x80\x8d"
128
129 # Did scrub choke on anything?
130 if [ "$want_scrub" = "yes" ]; then
131         grep -q "^Warning.*gnp.txt.*suspicious text direction" $tmp.scrub || \
132                 echo "No complaints about direction overrides?"
133         grep -q "^Warning.*control characters" $tmp.scrub || \
134                 echo "No complaints about control characters?"
135 fi
136
137 # success, all done
138 status=0
139 exit