]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/netbsd-tests/fs/tmpfs/t_times.sh
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / netbsd-tests / fs / tmpfs / t_times.sh
1 # $NetBSD: t_times.sh,v 1.5 2010/11/07 17:51:18 jmmv Exp $
2 #
3 # Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
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.
14 #
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.
26 #
27
28 #
29 # Verifies that node times are properly handled.
30 #
31
32 atf_test_case empty
33 empty_head() {
34         atf_set "descr" "Tests that creating an empty file and later" \
35                         "manipulating it updates times correctly"
36         atf_set "require.user" "root"
37 }
38 empty_body() {
39         test_mount
40
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"
46
47         sleep 1
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"
53
54         sleep 1
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"
60
61         test_unmount
62 }
63
64 atf_test_case non_empty
65 non_empty_head() {
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"
69 }
70 non_empty_body() {
71         test_mount
72
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"
75
76         sleep 1
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"
82
83         test_unmount
84 }
85
86 atf_test_case link
87 link_head() {
88         atf_set "descr" "Tests that linking to an existing file updates" \
89                         "times correctly"
90         atf_set "require.user" "root"
91 }
92 link_body() {
93         test_mount
94
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"
97
98         sleep 1
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"
104
105         test_unmount
106 }
107
108 atf_test_case rename
109 rename_head() {
110         atf_set "descr" "Tests that renaming an existing file updates" \
111                         "times correctly"
112         atf_set "require.user" "root"
113 }
114 rename_body() {
115         test_mount
116
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"
121         sleep 1
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"
129
130         test_unmount
131 }
132
133 atf_init_test_cases() {
134         . $(atf_get_srcdir)/../h_funcs.subr
135         . $(atf_get_srcdir)/h_funcs.subr
136
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
141 }