t_times.sh revision 302408
1227825Stheraven# $NetBSD: t_times.sh,v 1.5 2010/11/07 17:51:18 jmmv Exp $ 2227825Stheraven# 3227825Stheraven# Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc. 4227825Stheraven# All rights reserved. 5227825Stheraven# 6227825Stheraven# Redistribution and use in source and binary forms, with or without 7227825Stheraven# modification, are permitted provided that the following conditions 8227825Stheraven# are met: 9227825Stheraven# 1. Redistributions of source code must retain the above copyright 10227825Stheraven# notice, this list of conditions and the following disclaimer. 11227825Stheraven# 2. Redistributions in binary form must reproduce the above copyright 12227825Stheraven# notice, this list of conditions and the following disclaimer in the 13227825Stheraven# documentation and/or other materials provided with the distribution. 14227825Stheraven# 15227825Stheraven# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16227825Stheraven# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17227825Stheraven# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18227825Stheraven# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19227825Stheraven# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20227825Stheraven# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21227825Stheraven# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22227825Stheraven# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23227825Stheraven# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24227825Stheraven# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25227825Stheraven# POSSIBILITY OF SUCH DAMAGE. 26227825Stheraven# 27227825Stheraven 28227825Stheraven# 29227825Stheraven# Verifies that node times are properly handled. 30227825Stheraven# 31227825Stheraven 32227825Stheravenatf_test_case empty 33227825Stheravenempty_head() { 34227825Stheraven atf_set "descr" "Tests that creating an empty file and later" \ 35227825Stheraven "manipulating it updates times correctly" 36227825Stheraven atf_set "require.user" "root" 37227825Stheraven} 38227825Stheravenempty_body() { 39227825Stheraven test_mount 40227825Stheraven 41227825Stheraven atf_check -s eq:0 -o empty -e empty touch a 42227825Stheraven eval $(stat -s a | sed -e 's|st_|ost_|g') || atf_fail "stat failed" 43227825Stheraven [ ${ost_birthtime} -eq ${ost_atime} ] || atf_fail "Incorrect atime" 44227825Stheraven [ ${ost_birthtime} -eq ${ost_ctime} ] || atf_fail "Incorrect ctime" 45227825Stheraven [ ${ost_birthtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime" 46227825Stheraven 47227825Stheraven sleep 1 48227825Stheraven atf_check -s eq:0 -o ignore -e empty cat a 49227825Stheraven eval $(stat -s a) || atf_fail "stat failed" 50227825Stheraven [ ${st_atime} -gt ${ost_atime} ] || atf_fail "Incorrect atime" 51227825Stheraven [ ${st_ctime} -eq ${ost_ctime} ] || atf_fail "Incorrect ctime" 52227825Stheraven [ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime" 53227825Stheraven 54227825Stheraven sleep 1 55227825Stheraven echo foo >a || atf_fail "Write failed" 56227825Stheraven eval $(stat -s a) || atf_fail "stat failed" 57227825Stheraven [ ${st_atime} -gt ${ost_atime} ] || atf_fail "Incorrect atime" 58227825Stheraven [ ${st_ctime} -gt ${ost_ctime} ] || atf_fail "Incorrect ctime" 59227825Stheraven [ ${st_mtime} -gt ${ost_mtime} ] || atf_fail "Incorrect mtime" 60227825Stheraven 61227825Stheraven test_unmount 62227825Stheraven} 63227825Stheraven 64227825Stheravenatf_test_case non_empty 65227825Stheravennon_empty_head() { 66227825Stheraven atf_set "descr" "Tests that creating a non-empty file and later" \ 67227825Stheraven "manipulating it updates times correctly" 68227825Stheraven atf_set "require.user" "root" 69227825Stheraven} 70227825Stheravennon_empty_body() { 71227825Stheraven test_mount 72227825Stheraven 73227825Stheraven echo foo >b || atf_fail "Non-empty creation failed" 74227825Stheraven eval $(stat -s b | sed -e 's|st_|ost_|g') || atf_fail "stat failed" 75227825Stheraven 76227825Stheraven sleep 1 77227825Stheraven atf_check -s eq:0 -o ignore -e empty cat b 78227825Stheraven eval $(stat -s b) || atf_fail "stat failed" 79227825Stheraven [ ${st_atime} -gt ${ost_atime} ] || atf_fail "Incorrect atime" 80227825Stheraven [ ${st_ctime} -eq ${ost_ctime} ] || atf_fail "Incorrect ctime" 81227825Stheraven [ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime" 82227825Stheraven 83227825Stheraven test_unmount 84227825Stheraven} 85227825Stheraven 86227825Stheravenatf_test_case link 87227825Stheravenlink_head() { 88227825Stheraven atf_set "descr" "Tests that linking to an existing file updates" \ 89227825Stheraven "times correctly" 90227825Stheraven atf_set "require.user" "root" 91227825Stheraven} 92227825Stheravenlink_body() { 93227825Stheraven test_mount 94227825Stheraven 95227825Stheraven echo foo >c || atf_fail "Non-empty creation failed" 96227825Stheraven eval $(stat -s c | sed -e 's|st_|ost_|g') || atf_fail "stat failed" 97227825Stheraven 98227825Stheraven sleep 1 99227825Stheraven atf_check -s eq:0 -o empty -e empty ln c d 100227825Stheraven eval $(stat -s c) || atf_fail "stat failed" 101227825Stheraven [ ${st_atime} -eq ${ost_atime} ] || atf_fail "Incorrect atime" 102227825Stheraven [ ${st_ctime} -gt ${ost_ctime} ] || atf_fail "Incorrect ctime" 103227825Stheraven [ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime" 104227825Stheraven 105227825Stheraven test_unmount 106227825Stheraven} 107227825Stheraven 108227825Stheravenatf_test_case rename 109227825Stheravenrename_head() { 110227825Stheraven atf_set "descr" "Tests that renaming an existing file updates" \ 111227825Stheraven "times correctly" 112227825Stheraven atf_set "require.user" "root" 113227825Stheraven} 114227825Stheravenrename_body() { 115227825Stheraven test_mount 116227825Stheraven 117227825Stheraven atf_check -s eq:0 -o empty -e empty mkdir e 118227825Stheraven echo foo >e/a || atf_fail "Creation failed" 119227825Stheraven eval $(stat -s e | sed -e 's|st_|dost_|g') || atf_fail "stat failed" 120227825Stheraven eval $(stat -s e/a | sed -e 's|st_|ost_|g') || atf_fail "stat failed" 121227825Stheraven sleep 1 122227825Stheraven atf_check -s eq:0 -o empty -e empty mv e/a e/b 123227825Stheraven eval $(stat -s e | sed -e 's|st_|dst_|g') || atf_fail "stat failed" 124227825Stheraven eval $(stat -s e/b) || atf_fail "stat failed" 125227825Stheraven [ ${st_atime} -eq ${ost_atime} ] || atf_fail "Incorrect atime" 126227825Stheraven [ ${st_ctime} -gt ${ost_ctime} ] || atf_fail "Incorrect ctime" 127227825Stheraven [ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime" 128227825Stheraven [ ${dst_mtime} -gt ${dost_mtime} ] || atf_fail "Incorrect mtime" 129227825Stheraven 130227825Stheraven test_unmount 131227825Stheraven} 132227825Stheraven 133227825Stheravenatf_init_test_cases() { 134227825Stheraven . $(atf_get_srcdir)/../h_funcs.subr 135227825Stheraven . $(atf_get_srcdir)/h_funcs.subr 136227825Stheraven 137227825Stheraven atf_add_test_case empty 138227825Stheraven atf_add_test_case non_empty 139227825Stheraven atf_add_test_case link 140227825Stheraven atf_add_test_case rename 141227825Stheraven} 142227825Stheraven