maint: post-release administrivia
[coreutils.git] / tests / ls / getxattr-speedup.sh
blob4fde11550645333eec649323a98edfaffe9fa8f2
1 #!/bin/sh
2 # Show that we've eliminated most of ls' failing getxattr syscalls,
3 # regardless of how many files are in a directory we list.
4 # This test is skipped on systems that lack LD_PRELOAD support; that's fine.
5 # Similarly, on a system that lacks getxattr altogether, skipping it is fine.
7 # Copyright (C) 2012-2024 Free Software Foundation, Inc.
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <https://www.gnu.org/licenses/>.
22 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
23 print_ver_ ls
24 require_gcc_shared_
26 # Replace each getxattr and lgetxattr call with a call to these stubs.
27 # Count those and write the total number of calls to the file "x"
28 # via a global destructor.
29 cat > k.c <<'EOF' || framework_failure_
30 #include <errno.h>
31 #include <stdio.h>
32 #include <sys/types.h>
34 static unsigned long int n_calls;
36 static void __attribute__ ((destructor))
37 print_call_count (void)
39 FILE *fp = fopen ("x", "w"); if (!fp) return;
40 fprintf (fp, "%lu\n", n_calls); fclose (fp);
43 static ssize_t incr () { ++n_calls; errno = ENOTSUP; return -1; }
44 ssize_t getxattr (const char *path, const char *name, void *value, size_t size)
45 { return incr (); }
46 ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size)
47 { return incr (); }
48 EOF
50 # Then compile/link it:
51 gcc_shared_ k.c k.so \
52 || framework_failure_ 'failed to build shared library'
54 # Create a few files:
55 seq 20 | xargs touch || framework_failure_
57 # Finally, run the test:
58 LD_PRELOAD=$LD_PRELOAD:./k.so ls --color=always -l . || fail=1
60 test -f x || skip_ "internal test failure: maybe LD_PRELOAD doesn't work?"
62 # Ensure that there were no more than 3 *getxattr calls.
63 n_calls=$(cat x)
64 test "$n_calls" -le 3 || fail=1
66 Exit $fail