rm, du, chmod, chown, chgrp: use much less memory for large directories
[coreutils/ericb.git] / tests / ls / stat-free-color
blob1288560ff30649c9a179d5d32d19608b424ad715
1 #!/bin/sh
2 # Show that --color need not use stat, as long as we have d_type support.
4 # Copyright (C) 2011 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 <http://www.gnu.org/licenses/>.
19 . "${srcdir=.}/init.sh"; path_prepend_ ../src
20 print_ver_ ls
21 require_strace_ stat
22 require_dirent_d_type_
24 for i in 1 2 3; do
25 ln -s nowhere dangle-$i || framework_failure_
26 done
28 # Disable enough features via LS_COLORS so that ls --color
29 # can do its job without calling stat (other than the obligatory
30 # one-call-per-command-line argument).
31 cat <<EOF > color-without-stat || framework_failure_
32 RESET 0
33 DIR 01;34
34 LINK 01;36
35 FIFO 40;33
36 SOCK 01;35
37 DOOR 01;35
38 BLK 40;33;01
39 CHR 40;33;01
40 ORPHAN 00
41 SETUID 00
42 SETGID 00
43 CAPABILITY 00
44 STICKY_OTHER_WRITABLE 00
45 OTHER_WRITABLE 00
46 STICKY 00
47 EXEC 00
48 MULTIHARDLINK 00
49 EOF
50 eval $(dircolors -b color-without-stat)
52 # The system may perform additional stat-like calls before main.
53 # To avoid counting those, first get a baseline count by running
54 # ls with only the --help option. Then, compare that with the
55 # invocation under test.
56 strace -o log-help -e stat,lstat,stat64,lstat64 ls --help >/dev/null || fail=1
57 n_lines_help=$(wc -l < log-help)
59 strace -o log -e stat,lstat,stat64,lstat64 ls --color=always . || fail=1
60 n_lines=$(wc -l < log)
62 n_stat=$(expr $n_lines - $n_lines_help)
64 # Expect one or two stat calls.
65 case $n_stat in
66 1) ;;
67 *) fail=1; head -n30 log* ;;
68 esac
70 Exit $fail