xref: /freebsd/contrib/netbsd-tests/fs/tmpfs/t_times.sh (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
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	# Begin FreeBSD
40	atf_expect_fail "Incorrect atime on FreeBSD: PR274615"
41	# End FreeBSD
42
43	test_mount
44
45	atf_check -s eq:0 -o empty -e empty touch a
46	eval $(stat -s a | sed -e 's|st_|ost_|g') || atf_fail "stat failed"
47	[ ${ost_birthtime} -eq ${ost_atime} ] || atf_fail "Incorrect atime"
48	[ ${ost_birthtime} -eq ${ost_ctime} ] || atf_fail "Incorrect ctime"
49	[ ${ost_birthtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime"
50
51	sleep 1
52	atf_check -s eq:0 -o ignore -e empty cat a
53	eval $(stat -s a) || atf_fail "stat failed"
54	[ ${st_atime} -gt ${ost_atime} ] || atf_fail "Incorrect atime"
55	[ ${st_ctime} -eq ${ost_ctime} ] || atf_fail "Incorrect ctime"
56	[ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime"
57
58	sleep 1
59	echo foo >a || atf_fail "Write failed"
60	eval $(stat -s a) || atf_fail "stat failed"
61	[ ${st_atime} -gt ${ost_atime} ] || atf_fail "Incorrect atime"
62	[ ${st_ctime} -gt ${ost_ctime} ] || atf_fail "Incorrect ctime"
63	[ ${st_mtime} -gt ${ost_mtime} ] || atf_fail "Incorrect mtime"
64
65	test_unmount
66}
67
68atf_test_case non_empty
69non_empty_head() {
70	atf_set "descr" "Tests that creating a non-empty file and later" \
71	                "manipulating it updates times correctly"
72	atf_set "require.user" "root"
73}
74non_empty_body() {
75	test_mount
76
77	echo foo >b || atf_fail "Non-empty creation failed"
78	eval $(stat -s b | sed -e 's|st_|ost_|g') || atf_fail "stat failed"
79
80	sleep 1
81	atf_check -s eq:0 -o ignore -e empty cat b
82	eval $(stat -s b) || atf_fail "stat failed"
83	[ ${st_atime} -gt ${ost_atime} ] || atf_fail "Incorrect atime"
84	[ ${st_ctime} -eq ${ost_ctime} ] || atf_fail "Incorrect ctime"
85	[ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime"
86
87	test_unmount
88}
89
90atf_test_case link
91link_head() {
92	atf_set "descr" "Tests that linking to an existing file updates" \
93	                "times correctly"
94	atf_set "require.user" "root"
95}
96link_body() {
97	test_mount
98
99	echo foo >c || atf_fail "Non-empty creation failed"
100	eval $(stat -s c | sed -e 's|st_|ost_|g') || atf_fail "stat failed"
101
102	sleep 1
103	atf_check -s eq:0 -o empty -e empty ln c d
104	eval $(stat -s c) || atf_fail "stat failed"
105	[ ${st_atime} -eq ${ost_atime} ] || atf_fail "Incorrect atime"
106	[ ${st_ctime} -gt ${ost_ctime} ] || atf_fail "Incorrect ctime"
107	[ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime"
108
109	test_unmount
110}
111
112atf_test_case rename
113rename_head() {
114	atf_set "descr" "Tests that renaming an existing file updates" \
115	                "times correctly"
116	atf_set "require.user" "root"
117}
118rename_body() {
119	test_mount
120
121	atf_check -s eq:0 -o empty -e empty mkdir e
122	echo foo >e/a || atf_fail "Creation failed"
123	eval $(stat -s e | sed -e 's|st_|dost_|g') || atf_fail "stat failed"
124	eval $(stat -s e/a | sed -e 's|st_|ost_|g') || atf_fail "stat failed"
125	sleep 1
126	atf_check -s eq:0 -o empty -e empty mv e/a e/b
127	eval $(stat -s e | sed -e 's|st_|dst_|g') || atf_fail "stat failed"
128	eval $(stat -s e/b) || atf_fail "stat failed"
129	[ ${st_atime} -eq ${ost_atime} ] || atf_fail "Incorrect atime"
130	[ ${st_ctime} -gt ${ost_ctime} ] || atf_fail "Incorrect ctime"
131	[ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime"
132	[ ${dst_mtime} -gt ${dost_mtime} ] || atf_fail "Incorrect mtime"
133
134	test_unmount
135}
136
137atf_init_test_cases() {
138	. $(atf_get_srcdir)/../h_funcs.subr
139	. $(atf_get_srcdir)/h_funcs.subr
140
141	atf_add_test_case empty
142	atf_add_test_case non_empty
143	atf_add_test_case link
144	atf_add_test_case rename
145}
146