Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / ls / time-1
1 #!/bin/sh
2 # Test some of ls's sorting options.
3
4 # Copyright (C) 1998, 1999, 2000, 2001, 2004 Free Software Foundation,
5 # Inc.
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 # 02110-1301, USA.
21
22 if test "$VERBOSE" = yes; then
23   set -x
24   ls --version
25 fi
26
27 # Avoid any possible glitches due to daylight-saving changes near the
28 # time stamps used during the test.
29 TZ=UTC0
30 export TZ
31
32 # Avoid glitches due to the environment specifying `ls' styles.
33 unset QUOTING_STYLE
34 unset TIME_STYLE
35
36 tmp=t-ls.$$
37
38 framework_failure=0
39 mkdir $tmp || framework_failure=1
40 cd $tmp || framework_failure=1
41
42 t1='1998-01-15 21:00'
43 t2='1998-01-15 22:00'
44 t3='1998-01-15 23:00'
45
46 u1='1998-01-14 11:00'
47 u2='1998-01-14 12:00'
48 u3='1998-01-14 13:00'
49
50 touch -m -d "$t3" a || framework_failure=1
51 touch -m -d "$t2" b || framework_failure=1
52 touch -m -d "$t1" c || framework_failure=1
53
54 touch -a -d "$u3" c || framework_failure=1
55 touch -a -d "$u2" b || framework_failure=1
56 # Make sure A has ctime at least 1 second more recent than C's.
57 sleep 2
58 touch -a -d "$u1" a || framework_failure=1
59
60 fail=0
61
62 # A has ctime more recent than C.
63 set `ls -c a c`
64 test "$*" = 'a c' || fail=1
65
66 # Sleep so long in an attempt to avoid spurious failures
67 # due to NFS caching and/or clock skew.
68 sleep 2
69
70 # Create a link, updating c's ctime.
71 ln c d || framework_failure=1
72
73 # Before we go any further, verify that touch's -m option works.
74 set -- `ls --full -l a`
75 case "$*" in
76   *" $t3:00.000000000 +0000 a") ;;
77   *)
78   # This might be what's making HPUX 11 systems fail this test.
79   cat >&2 << EOF
80 A basic test of touch -m has just failed, so the subsequent
81 tests in this file will not be run.
82
83 In the output below, the date of last modification for \`a' should
84 have been $t3.
85 EOF
86   #`
87   ls --full -l a
88   framework_failure=1
89   ;;
90 esac
91
92 # Now test touch's -a option.
93 set -- `ls --full -lu a`
94 case "$*" in
95   *" $u1:00.000000000 +0000 a") ;;
96   *)
97   # This might be what's making HPUX 11 systems fail this test.
98   cat >&2 << EOF
99 A basic test of touch -a has just failed, so the subsequent
100 tests in this file will not be run.
101
102 In the output below, the date of last access for \`a' should
103 have been $u1.
104 EOF
105   ls --full -lu a
106   (exit 77); exit 77
107   ;;
108 esac
109
110 if test $framework_failure = 1; then
111   echo 'failure in testing framework'
112   exit 1
113 fi
114
115 set `ls -ut a b c`
116 test "$*" = 'c b a' && : || fail=1
117 test $fail = 1 && ls -l --full-time --time=access a b c
118
119 set `ls -t a b c`
120 test "$*" = 'a b c' && : || fail=1
121 test $fail = 1 && ls -l --full-time a b c
122
123 # Now, C should have ctime more recent than A.
124 set `ls -ct a c`
125 if test "$*" = 'c a'; then
126   : ok
127 else
128   # In spite of documentation, (e.g., stat(2)), neither link nor chmod
129   # update a file's st_ctime on SunOS4.1.4.
130   cat >&2 << \EOF
131 failed ls ctime test -- this failure is expected at least for SunOS4.1.4
132 and for tmpfs file systems on Solaris 5.5.1.
133
134 In the output below, `c' should have had a ctime more recent than
135 that of `a', but does not.
136 EOF
137   #'
138   ls -ctl --full-time a c
139   fail=1
140 fi
141
142 cd ..
143 rm -rf $tmp
144
145 exit $fail