tests: tee: avoid false failure due to fifo usage
[coreutils.git] / tests / ls / stat-free-color.sh
blobb02c06bb7fbcdc7e1f74f9c72b18f208c4154935
1 #!/bin/sh
2 # Show that --color need not use stat, as long as we have d_type support.
4 # Copyright (C) 2011-2023 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ ls
21 require_strace_ stat
22 require_dirent_d_type_
24 stats='stat'
25 # List of other _file name_ stat functions to increase coverage.
26 other_stats='statx lstat stat64 lstat64 newfstatat fstatat64'
27 for stat in $other_stats; do
28 strace -qe "$stat" true > /dev/null 2>&1 &&
29 stats="$stats,$stat"
30 done
32 # Disable enough features via LS_COLORS so that ls --color
33 # can do its job without calling stat (other than the obligatory
34 # one-call-per-command-line argument).
35 cat <<EOF > color-without-stat || framework_failure_
36 RESET 0
37 DIR 01;34
38 LINK 01;36
39 FIFO 40;33
40 SOCK 01;35
41 DOOR 01;35
42 BLK 40;33;01
43 CHR 40;33;01
44 ORPHAN 00
45 SETUID 00
46 SETGID 00
47 CAPABILITY 00
48 STICKY_OTHER_WRITABLE 00
49 OTHER_WRITABLE 00
50 STICKY 00
51 EXEC 00
52 MULTIHARDLINK 00
53 EOF
54 eval $(dircolors -b color-without-stat)
56 # The system may perform additional stat-like calls before main.
57 # Furthermore, underlying library functions may also implicitly
58 # add an extra stat call, e.g. opendir since glibc-2.21-360-g46f894d.
59 # Finally, ls(1) makes a stat call for stdout, but only in the case
60 # when there is something to output.
61 # To get the comparison right, first get a baseline count for running
62 # 'ls -a' with one empty directory argument. Then, compare that with
63 # the invocation under test.
64 mkdir d || framework_failure_
66 count_stats() { grep -vE '\+\+\+|ENOSYS|NOTSUP' "$1" | wc -l; }
67 strace -q -o log1 -e $stats ls -a --color=always d || fail=1
68 n_stat1=$(count_stats log1) || framework_failure_
70 test $n_stat1 = 0 \
71 && skip_ 'No stat calls recognized on this platform'
73 # Populate the test directory.
74 mkdir d/subdir \
75 && touch d/regf \
76 && ln d/regf d/hlink \
77 && ln -s regf d/slink \
78 && ln -s nowhere d/dangle \
79 || framework_failure_
81 # Invocation under test.
82 strace -q -o log2 -e $stats ls --color=always d || fail=1
83 n_stat2=$(count_stats log2) || framework_failure_
85 # Expect the same number of stat calls.
86 test $n_stat1 = $n_stat2 \
87 || { fail=1; head -n30 log*; }
89 Exit $fail