build: ensure make-prime-list doesn't access out of bounds memory
[platform/upstream/coreutils.git] / tests / misc / stat-birthtime.sh
1 #!/bin/sh
2 # ensure that stat attempts birthtime access
3
4 # Copyright (C) 2010-2013 Free Software Foundation, Inc.
5
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.
10
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.
15
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/>.
18
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ stat
21
22 # Whether birthtime is supported or not, it better not change even when
23 # [acm]time are modified.  :)
24 touch a || fail=1
25 btime=$(stat --format %W a) || fail=1
26 atime=$(stat --format %X a) || fail=1
27 mtime=$(stat --format %Y a) || fail=1
28 ctime=$(stat --format %Z a) || fail=1
29
30 # Wait up to 2.17s for timestamps to change.
31 # ----------------------------------------
32 # iterations   file system resolution  e.g.
33 # ----------------------------------------
34 # 1            nano or micro second    ext4
35 # 4            1 second                ext3
36 # 5            2 second                FAT
37 # ----------------------------------------
38 check_timestamps_updated()
39 {
40   local delay="$1"
41   sleep $delay
42   touch a || fail=1
43
44   test "x$btime" = x$(stat --format %W a) &&
45   test "x$atime" != x$(stat --format %X a) &&
46   test "x$mtime" != x$(stat --format %Y a) &&
47   test "x$ctime" != x$(stat --format %Z a)
48 }
49 retry_delay_ check_timestamps_updated .07 5 || fail=1
50
51 Exit $fail