1 # $NetBSD: t_times.sh,v 1.5 2010/11/07 17:51:18 jmmv Exp $
3 # Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
29 # Verifies that node times are properly handled.
34 atf_set
"descr" "Tests that creating an empty file and later" \
35 "manipulating it updates times correctly"
36 atf_set
"require.user" "root"
41 atf_check
-s eq
:0 -o empty
-e empty
touch a
42 eval $
(stat
-s a |
sed -e 's|st_|ost_|g') || atf_fail
"stat failed"
43 [ ${ost_birthtime} -eq ${ost_atime} ] || atf_fail
"Incorrect atime"
44 [ ${ost_birthtime} -eq ${ost_ctime} ] || atf_fail
"Incorrect ctime"
45 [ ${ost_birthtime} -eq ${ost_mtime} ] || atf_fail
"Incorrect mtime"
48 atf_check
-s eq
:0 -o ignore
-e empty
cat a
49 eval $
(stat
-s a
) || atf_fail
"stat failed"
50 [ ${st_atime} -gt ${ost_atime} ] || atf_fail
"Incorrect atime"
51 [ ${st_ctime} -eq ${ost_ctime} ] || atf_fail
"Incorrect ctime"
52 [ ${st_mtime} -eq ${ost_mtime} ] || atf_fail
"Incorrect mtime"
55 echo foo
>a || atf_fail
"Write failed"
56 eval $
(stat
-s a
) || atf_fail
"stat failed"
57 [ ${st_atime} -gt ${ost_atime} ] || atf_fail
"Incorrect atime"
58 [ ${st_ctime} -gt ${ost_ctime} ] || atf_fail
"Incorrect ctime"
59 [ ${st_mtime} -gt ${ost_mtime} ] || atf_fail
"Incorrect mtime"
64 atf_test_case non_empty
66 atf_set
"descr" "Tests that creating a non-empty file and later" \
67 "manipulating it updates times correctly"
68 atf_set
"require.user" "root"
73 echo foo
>b || atf_fail
"Non-empty creation failed"
74 eval $
(stat
-s b |
sed -e 's|st_|ost_|g') || atf_fail
"stat failed"
77 atf_check
-s eq
:0 -o ignore
-e empty
cat b
78 eval $
(stat
-s b
) || atf_fail
"stat failed"
79 [ ${st_atime} -gt ${ost_atime} ] || atf_fail
"Incorrect atime"
80 [ ${st_ctime} -eq ${ost_ctime} ] || atf_fail
"Incorrect ctime"
81 [ ${st_mtime} -eq ${ost_mtime} ] || atf_fail
"Incorrect mtime"
88 atf_set
"descr" "Tests that linking to an existing file updates" \
90 atf_set
"require.user" "root"
95 echo foo
>c || atf_fail
"Non-empty creation failed"
96 eval $
(stat
-s c |
sed -e 's|st_|ost_|g') || atf_fail
"stat failed"
99 atf_check
-s eq
:0 -o empty
-e empty
ln c d
100 eval $
(stat
-s c
) || atf_fail
"stat failed"
101 [ ${st_atime} -eq ${ost_atime} ] || atf_fail
"Incorrect atime"
102 [ ${st_ctime} -gt ${ost_ctime} ] || atf_fail
"Incorrect ctime"
103 [ ${st_mtime} -eq ${ost_mtime} ] || atf_fail
"Incorrect mtime"
110 atf_set
"descr" "Tests that renaming an existing file updates" \
112 atf_set
"require.user" "root"
117 atf_check
-s eq
:0 -o empty
-e empty mkdir e
118 echo foo
>e
/a || atf_fail
"Creation failed"
119 eval $
(stat
-s e |
sed -e 's|st_|dost_|g') || atf_fail
"stat failed"
120 eval $
(stat
-s e
/a |
sed -e 's|st_|ost_|g') || atf_fail
"stat failed"
122 atf_check
-s eq
:0 -o empty
-e empty
mv e
/a e
/b
123 eval $
(stat
-s e |
sed -e 's|st_|dst_|g') || atf_fail
"stat failed"
124 eval $
(stat
-s e
/b
) || atf_fail
"stat failed"
125 [ ${st_atime} -eq ${ost_atime} ] || atf_fail
"Incorrect atime"
126 [ ${st_ctime} -gt ${ost_ctime} ] || atf_fail
"Incorrect ctime"
127 [ ${st_mtime} -eq ${ost_mtime} ] || atf_fail
"Incorrect mtime"
128 [ ${dst_mtime} -gt ${dost_mtime} ] || atf_fail
"Incorrect mtime"
133 atf_init_test_cases
() {
134 . $
(atf_get_srcdir
)/..
/h_funcs.subr
135 . $
(atf_get_srcdir
)/h_funcs.subr
137 atf_add_test_case empty
138 atf_add_test_case non_empty
139 atf_add_test_case link
140 atf_add_test_case rename