1170809Sdelphij#!/bin/sh
2170809Sdelphij#
3170809Sdelphij# $NetBSD: t_times,v 1.6 2006/11/09 16:20:06 jmmv Exp $
4170809Sdelphij#
5170809Sdelphij# Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
6170809Sdelphij# All rights reserved.
7170809Sdelphij#
8170809Sdelphij# This code is derived from software contributed to The NetBSD Foundation
9170809Sdelphij# by Julio M. Merino Vidal, developed as part of Google's Summer of Code
10170809Sdelphij# 2005 program.
11170809Sdelphij#
12170809Sdelphij# Redistribution and use in source and binary forms, with or without
13170809Sdelphij# modification, are permitted provided that the following conditions
14170809Sdelphij# are met:
15170809Sdelphij# 1. Redistributions of source code must retain the above copyright
16170809Sdelphij#    notice, this list of conditions and the following disclaimer.
17170809Sdelphij# 2. Redistributions in binary form must reproduce the above copyright
18170809Sdelphij#    notice, this list of conditions and the following disclaimer in the
19170809Sdelphij#    documentation and/or other materials provided with the distribution.
20170809Sdelphij#
21170809Sdelphij# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22170809Sdelphij# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23170809Sdelphij# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24170809Sdelphij# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25170809Sdelphij# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26170809Sdelphij# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27170809Sdelphij# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28170809Sdelphij# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29170809Sdelphij# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30170809Sdelphij# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31170809Sdelphij# POSSIBILITY OF SUCH DAMAGE.
32170809Sdelphij#
33170809Sdelphij# $FreeBSD$
34170809Sdelphij#
35170809Sdelphij
36170809Sdelphij#
37170809Sdelphij# Verifies that node times are properly handled.
38170809Sdelphij#
39170809Sdelphij
40170809Sdelphijtest_run() {
41170809Sdelphij	test_mount
42170809Sdelphij
43170809Sdelphij	test_name "Creation of empty file"
44170809Sdelphij	touch a || die
45170809Sdelphij	eval $(stat -s a | sed -e 's|st_|ost_|g') || die
46170809Sdelphij	[ ${ost_birthtime} -eq ${ost_atime} ] || die
47170809Sdelphij	[ ${ost_birthtime} -eq ${ost_ctime} ] || die
48170809Sdelphij	[ ${ost_birthtime} -eq ${ost_mtime} ] || die
49170809Sdelphij
50170809Sdelphij	test_name "Read of empty file"
51170809Sdelphij	sleep 1
52170809Sdelphij	cat a >/dev/null || die
53170809Sdelphij	eval $(stat -s a) || die
54170809Sdelphij	[ ${st_atime} -gt ${ost_atime} ] || die
55170809Sdelphij	[ ${st_ctime} -eq ${ost_ctime} ] || die
56170809Sdelphij	[ ${st_mtime} -eq ${ost_mtime} ] || die
57170809Sdelphij
58170809Sdelphij	test_name "Write to (and extension of) empty file"
59170809Sdelphij	sleep 1
60170809Sdelphij	echo foo >a || die
61170809Sdelphij	eval $(stat -s a) || die
62170809Sdelphij	[ ${st_atime} -gt ${ost_atime} ] || die
63170809Sdelphij	[ ${st_ctime} -gt ${ost_ctime} ] || die
64170809Sdelphij	[ ${st_mtime} -gt ${ost_mtime} ] || die
65170809Sdelphij
66170809Sdelphij	test_name "Creation of non-empty file"
67170809Sdelphij	echo foo >b || die
68170809Sdelphij	eval $(stat -s b | sed -e 's|st_|ost_|g') || die
69170809Sdelphij
70170809Sdelphij	test_name "Read of non-empty file"
71170809Sdelphij	sleep 1
72170809Sdelphij	cat b >/dev/null || die
73170809Sdelphij	eval $(stat -s b) || die
74170809Sdelphij	[ ${st_atime} -gt ${ost_atime} ] || die
75170809Sdelphij	[ ${st_ctime} -eq ${ost_ctime} ] || die
76170809Sdelphij	[ ${st_mtime} -eq ${ost_mtime} ] || die
77170809Sdelphij
78170809Sdelphij	test_name "Creation of non-empty file"
79170809Sdelphij	echo foo >c || die
80170809Sdelphij	eval $(stat -s c | sed -e 's|st_|ost_|g') || die
81170809Sdelphij
82170809Sdelphij	test_name "New link to non-empty file"
83170809Sdelphij	sleep 1
84170809Sdelphij	ln c d || die
85170809Sdelphij	eval $(stat -s c) || die
86170809Sdelphij	[ ${st_atime} -eq ${ost_atime} ] || die
87170809Sdelphij	[ ${st_ctime} -gt ${ost_ctime} ] || die
88170809Sdelphij	[ ${st_mtime} -eq ${ost_mtime} ] || die
89170809Sdelphij
90170809Sdelphij	test_name "File renaming does not change times"
91170809Sdelphij	mkdir e || die
92170809Sdelphij	echo foo >e/a || die
93170809Sdelphij	eval $(stat -s e | sed -e 's|st_|dost_|g') || die
94170809Sdelphij	eval $(stat -s e/a | sed -e 's|st_|ost_|g') || die
95170809Sdelphij	sleep 1
96170809Sdelphij	mv e/a e/b || die
97170809Sdelphij	eval $(stat -s e | sed -e 's|st_|dst_|g') || die
98170809Sdelphij	eval $(stat -s e/b) || die
99170809Sdelphij	[ ${st_atime} -eq ${ost_atime} ] || die
100170809Sdelphij	[ ${st_ctime} -gt ${ost_ctime} ] || die
101170809Sdelphij	[ ${st_mtime} -eq ${ost_mtime} ] || die
102170809Sdelphij	[ ${dst_mtime} -gt ${dost_mtime} ] || die
103170809Sdelphij
104170809Sdelphij	test_unmount
105170809Sdelphij}
106170809Sdelphij
107170809Sdelphij. ${SUBRDIR}/h_funcs.subr
108