xref: /freebsd/contrib/netbsd-tests/fs/tmpfs/t_times.sh (revision a0ca4af9455b844c5e094fc1b09b1390ffa979fc)
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
32atf_test_case empty
33empty_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}
38empty_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 empty -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	ost_atime=${st_atime}
56	echo foo >a || atf_fail "Write failed"
57	eval $(stat -s a) || atf_fail "stat failed"
58	[ ${st_atime} -gt ${ost_atime} ] || atf_fail "Incorrect atime"
59	[ ${st_ctime} -gt ${ost_ctime} ] || atf_fail "Incorrect ctime"
60	[ ${st_mtime} -gt ${ost_mtime} ] || atf_fail "Incorrect mtime"
61
62	test_unmount
63}
64
65atf_test_case holey
66holey_head() {
67	atf_set "descr" "Tests that creating a file consisting entirely" \
68		        "of a hole and later" \
69	                "manipulating it updates times correctly"
70	atf_set "require.user" "root"
71}
72holey_body() {
73	test_mount
74
75	atf_check -s eq:0 -o empty -e empty truncate -s 8k a
76	eval $(stat -s a | sed -e 's|st_|ost_|g') || atf_fail "stat failed"
77	[ ${ost_birthtime} -eq ${ost_atime} ] || atf_fail "Incorrect atime"
78	[ ${ost_birthtime} -eq ${ost_ctime} ] || atf_fail "Incorrect ctime"
79	[ ${ost_birthtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime"
80
81	sleep 1
82	atf_check -s eq:0 -o ignore -e empty cat a
83	eval $(stat -s a) || atf_fail "stat failed"
84	[ ${st_atime} -gt ${ost_atime} ] || atf_fail "Incorrect atime"
85	[ ${st_ctime} -eq ${ost_ctime} ] || atf_fail "Incorrect ctime"
86	[ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime"
87
88	test_unmount
89}
90
91atf_test_case non_empty
92non_empty_head() {
93	atf_set "descr" "Tests that creating a non-empty file and later" \
94	                "manipulating it updates times correctly"
95	atf_set "require.user" "root"
96}
97non_empty_body() {
98	test_mount
99
100	echo foo >b || atf_fail "Non-empty creation failed"
101	eval $(stat -s b | sed -e 's|st_|ost_|g') || atf_fail "stat failed"
102
103	sleep 1
104	atf_check -s eq:0 -o inline:"foo\n" -e empty cat b
105	eval $(stat -s b) || atf_fail "stat failed"
106	[ ${st_atime} -gt ${ost_atime} ] || atf_fail "Incorrect atime"
107	[ ${st_ctime} -eq ${ost_ctime} ] || atf_fail "Incorrect ctime"
108	[ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime"
109
110	test_unmount
111}
112
113atf_test_case link
114link_head() {
115	atf_set "descr" "Tests that linking to an existing file updates" \
116	                "times correctly"
117	atf_set "require.user" "root"
118}
119link_body() {
120	test_mount
121
122	echo foo >c || atf_fail "Non-empty creation failed"
123	eval $(stat -s c | sed -e 's|st_|ost_|g') || atf_fail "stat failed"
124
125	sleep 1
126	atf_check -s eq:0 -o empty -e empty ln c d
127	eval $(stat -s c) || atf_fail "stat failed"
128	[ ${st_atime} -eq ${ost_atime} ] || atf_fail "Incorrect atime"
129	[ ${st_ctime} -gt ${ost_ctime} ] || atf_fail "Incorrect ctime"
130	[ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime"
131
132	test_unmount
133}
134
135atf_test_case rename
136rename_head() {
137	atf_set "descr" "Tests that renaming an existing file updates" \
138	                "times correctly"
139	atf_set "require.user" "root"
140}
141rename_body() {
142	test_mount
143
144	atf_check -s eq:0 -o empty -e empty mkdir e
145	echo foo >e/a || atf_fail "Creation failed"
146	eval $(stat -s e | sed -e 's|st_|dost_|g') || atf_fail "stat failed"
147	eval $(stat -s e/a | sed -e 's|st_|ost_|g') || atf_fail "stat failed"
148	sleep 1
149	atf_check -s eq:0 -o empty -e empty mv e/a e/b
150	eval $(stat -s e | sed -e 's|st_|dst_|g') || atf_fail "stat failed"
151	eval $(stat -s e/b) || atf_fail "stat failed"
152	[ ${st_atime} -eq ${ost_atime} ] || atf_fail "Incorrect atime"
153	[ ${st_ctime} -gt ${ost_ctime} ] || atf_fail "Incorrect ctime"
154	[ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime"
155	[ ${dst_mtime} -gt ${dost_mtime} ] || atf_fail "Incorrect mtime"
156
157	test_unmount
158}
159
160atf_init_test_cases() {
161	. $(atf_get_srcdir)/../h_funcs.subr
162	. $(atf_get_srcdir)/h_funcs.subr
163
164	atf_add_test_case empty
165	atf_add_test_case holey
166	atf_add_test_case non_empty
167	atf_add_test_case link
168	atf_add_test_case rename
169}
170