t_times.sh revision 272343
1272343Sngie# $NetBSD: t_times.sh,v 1.5 2010/11/07 17:51:18 jmmv Exp $ 2272343Sngie# 3272343Sngie# Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc. 4272343Sngie# All rights reserved. 5272343Sngie# 6272343Sngie# Redistribution and use in source and binary forms, with or without 7272343Sngie# modification, are permitted provided that the following conditions 8272343Sngie# are met: 9272343Sngie# 1. Redistributions of source code must retain the above copyright 10272343Sngie# notice, this list of conditions and the following disclaimer. 11272343Sngie# 2. Redistributions in binary form must reproduce the above copyright 12272343Sngie# notice, this list of conditions and the following disclaimer in the 13272343Sngie# documentation and/or other materials provided with the distribution. 14272343Sngie# 15272343Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16272343Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17272343Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18272343Sngie# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19272343Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20272343Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21272343Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22272343Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23272343Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24272343Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25272343Sngie# POSSIBILITY OF SUCH DAMAGE. 26272343Sngie# 27272343Sngie 28272343Sngie# 29272343Sngie# Verifies that node times are properly handled. 30272343Sngie# 31272343Sngie 32272343Sngieatf_test_case empty 33272343Sngieempty_head() { 34272343Sngie atf_set "descr" "Tests that creating an empty file and later" \ 35272343Sngie "manipulating it updates times correctly" 36272343Sngie atf_set "require.user" "root" 37272343Sngie} 38272343Sngieempty_body() { 39272343Sngie test_mount 40272343Sngie 41272343Sngie atf_check -s eq:0 -o empty -e empty touch a 42272343Sngie eval $(stat -s a | sed -e 's|st_|ost_|g') || atf_fail "stat failed" 43272343Sngie [ ${ost_birthtime} -eq ${ost_atime} ] || atf_fail "Incorrect atime" 44272343Sngie [ ${ost_birthtime} -eq ${ost_ctime} ] || atf_fail "Incorrect ctime" 45272343Sngie [ ${ost_birthtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime" 46272343Sngie 47272343Sngie sleep 1 48272343Sngie atf_check -s eq:0 -o ignore -e empty cat a 49272343Sngie eval $(stat -s a) || atf_fail "stat failed" 50272343Sngie [ ${st_atime} -gt ${ost_atime} ] || atf_fail "Incorrect atime" 51272343Sngie [ ${st_ctime} -eq ${ost_ctime} ] || atf_fail "Incorrect ctime" 52272343Sngie [ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime" 53272343Sngie 54272343Sngie sleep 1 55272343Sngie echo foo >a || atf_fail "Write failed" 56272343Sngie eval $(stat -s a) || atf_fail "stat failed" 57272343Sngie [ ${st_atime} -gt ${ost_atime} ] || atf_fail "Incorrect atime" 58272343Sngie [ ${st_ctime} -gt ${ost_ctime} ] || atf_fail "Incorrect ctime" 59272343Sngie [ ${st_mtime} -gt ${ost_mtime} ] || atf_fail "Incorrect mtime" 60272343Sngie 61272343Sngie test_unmount 62272343Sngie} 63272343Sngie 64272343Sngieatf_test_case non_empty 65272343Sngienon_empty_head() { 66272343Sngie atf_set "descr" "Tests that creating a non-empty file and later" \ 67272343Sngie "manipulating it updates times correctly" 68272343Sngie atf_set "require.user" "root" 69272343Sngie} 70272343Sngienon_empty_body() { 71272343Sngie test_mount 72272343Sngie 73272343Sngie echo foo >b || atf_fail "Non-empty creation failed" 74272343Sngie eval $(stat -s b | sed -e 's|st_|ost_|g') || atf_fail "stat failed" 75272343Sngie 76272343Sngie sleep 1 77272343Sngie atf_check -s eq:0 -o ignore -e empty cat b 78272343Sngie eval $(stat -s b) || atf_fail "stat failed" 79272343Sngie [ ${st_atime} -gt ${ost_atime} ] || atf_fail "Incorrect atime" 80272343Sngie [ ${st_ctime} -eq ${ost_ctime} ] || atf_fail "Incorrect ctime" 81272343Sngie [ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime" 82272343Sngie 83272343Sngie test_unmount 84272343Sngie} 85272343Sngie 86272343Sngieatf_test_case link 87272343Sngielink_head() { 88272343Sngie atf_set "descr" "Tests that linking to an existing file updates" \ 89272343Sngie "times correctly" 90272343Sngie atf_set "require.user" "root" 91272343Sngie} 92272343Sngielink_body() { 93272343Sngie test_mount 94272343Sngie 95272343Sngie echo foo >c || atf_fail "Non-empty creation failed" 96272343Sngie eval $(stat -s c | sed -e 's|st_|ost_|g') || atf_fail "stat failed" 97272343Sngie 98272343Sngie sleep 1 99272343Sngie atf_check -s eq:0 -o empty -e empty ln c d 100272343Sngie eval $(stat -s c) || atf_fail "stat failed" 101272343Sngie [ ${st_atime} -eq ${ost_atime} ] || atf_fail "Incorrect atime" 102272343Sngie [ ${st_ctime} -gt ${ost_ctime} ] || atf_fail "Incorrect ctime" 103272343Sngie [ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime" 104272343Sngie 105272343Sngie test_unmount 106272343Sngie} 107272343Sngie 108272343Sngieatf_test_case rename 109272343Sngierename_head() { 110272343Sngie atf_set "descr" "Tests that renaming an existing file updates" \ 111272343Sngie "times correctly" 112272343Sngie atf_set "require.user" "root" 113272343Sngie} 114272343Sngierename_body() { 115272343Sngie test_mount 116272343Sngie 117272343Sngie atf_check -s eq:0 -o empty -e empty mkdir e 118272343Sngie echo foo >e/a || atf_fail "Creation failed" 119272343Sngie eval $(stat -s e | sed -e 's|st_|dost_|g') || atf_fail "stat failed" 120272343Sngie eval $(stat -s e/a | sed -e 's|st_|ost_|g') || atf_fail "stat failed" 121272343Sngie sleep 1 122272343Sngie atf_check -s eq:0 -o empty -e empty mv e/a e/b 123272343Sngie eval $(stat -s e | sed -e 's|st_|dst_|g') || atf_fail "stat failed" 124272343Sngie eval $(stat -s e/b) || atf_fail "stat failed" 125272343Sngie [ ${st_atime} -eq ${ost_atime} ] || atf_fail "Incorrect atime" 126272343Sngie [ ${st_ctime} -gt ${ost_ctime} ] || atf_fail "Incorrect ctime" 127272343Sngie [ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime" 128272343Sngie [ ${dst_mtime} -gt ${dost_mtime} ] || atf_fail "Incorrect mtime" 129272343Sngie 130272343Sngie test_unmount 131272343Sngie} 132272343Sngie 133272343Sngieatf_init_test_cases() { 134272343Sngie . $(atf_get_srcdir)/../h_funcs.subr 135272343Sngie . $(atf_get_srcdir)/h_funcs.subr 136272343Sngie 137272343Sngie atf_add_test_case empty 138272343Sngie atf_add_test_case non_empty 139272343Sngie atf_add_test_case link 140272343Sngie atf_add_test_case rename 141272343Sngie} 142