Home | History | Annotate | Line # | Download | only in tmpfs
t_times.sh revision 1.3
      1  1.3  jmmv # $NetBSD: t_times.sh,v 1.3 2009/01/19 07:15:46 jmmv Exp $
      2  1.1  jmmv #
      3  1.3  jmmv # Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
      4  1.1  jmmv # All rights reserved.
      5  1.1  jmmv #
      6  1.1  jmmv # Redistribution and use in source and binary forms, with or without
      7  1.1  jmmv # modification, are permitted provided that the following conditions
      8  1.1  jmmv # are met:
      9  1.1  jmmv # 1. Redistributions of source code must retain the above copyright
     10  1.1  jmmv #    notice, this list of conditions and the following disclaimer.
     11  1.1  jmmv # 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  jmmv #    notice, this list of conditions and the following disclaimer in the
     13  1.1  jmmv #    documentation and/or other materials provided with the distribution.
     14  1.1  jmmv #
     15  1.1  jmmv # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     16  1.1  jmmv # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17  1.1  jmmv # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18  1.1  jmmv # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     19  1.1  jmmv # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20  1.1  jmmv # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21  1.1  jmmv # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22  1.1  jmmv # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23  1.1  jmmv # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24  1.1  jmmv # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25  1.1  jmmv # POSSIBILITY OF SUCH DAMAGE.
     26  1.1  jmmv #
     27  1.1  jmmv 
     28  1.1  jmmv #
     29  1.1  jmmv # Verifies that node times are properly handled.
     30  1.1  jmmv #
     31  1.1  jmmv 
     32  1.1  jmmv atf_test_case empty
     33  1.1  jmmv empty_head() {
     34  1.1  jmmv 	atf_set "descr" "Tests that creating an empty file and later" \
     35  1.1  jmmv 	                "manipulating it updates times correctly"
     36  1.1  jmmv 	atf_set "require.user" "root"
     37  1.1  jmmv }
     38  1.1  jmmv empty_body() {
     39  1.1  jmmv 	test_mount
     40  1.1  jmmv 
     41  1.3  jmmv 	atf_check -s eq:0 -o empty -e empty touch a
     42  1.1  jmmv 	eval $(stat -s a | sed -e 's|st_|ost_|g') || atf_fail "stat failed"
     43  1.1  jmmv 	[ ${ost_birthtime} -eq ${ost_atime} ] || atf_fail "Incorrect atime"
     44  1.1  jmmv 	[ ${ost_birthtime} -eq ${ost_ctime} ] || atf_fail "Incorrect ctime"
     45  1.1  jmmv 	[ ${ost_birthtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime"
     46  1.1  jmmv 
     47  1.1  jmmv 	sleep 1
     48  1.3  jmmv 	atf_check -s eq:0 -o ignore -e empty cat a
     49  1.1  jmmv 	eval $(stat -s a) || atf_fail "stat failed"
     50  1.1  jmmv 	[ ${st_atime} -gt ${ost_atime} ] || atf_fail "Incorrect atime"
     51  1.1  jmmv 	[ ${st_ctime} -eq ${ost_ctime} ] || atf_fail "Incorrect ctime"
     52  1.1  jmmv 	[ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime"
     53  1.1  jmmv 
     54  1.1  jmmv 	sleep 1
     55  1.1  jmmv 	echo foo >a || atf_fail "Write failed"
     56  1.1  jmmv 	eval $(stat -s a) || atf_fail "stat failed"
     57  1.1  jmmv 	[ ${st_atime} -gt ${ost_atime} ] || atf_fail "Incorrect atime"
     58  1.1  jmmv 	[ ${st_ctime} -gt ${ost_ctime} ] || atf_fail "Incorrect ctime"
     59  1.1  jmmv 	[ ${st_mtime} -gt ${ost_mtime} ] || atf_fail "Incorrect mtime"
     60  1.1  jmmv 
     61  1.1  jmmv 	test_unmount
     62  1.1  jmmv }
     63  1.1  jmmv 
     64  1.1  jmmv atf_test_case non_empty
     65  1.1  jmmv non_empty_head() {
     66  1.1  jmmv 	atf_set "descr" "Tests that creating a non-empty file and later" \
     67  1.1  jmmv 	                "manipulating it updates times correctly"
     68  1.1  jmmv 	atf_set "require.user" "root"
     69  1.1  jmmv }
     70  1.1  jmmv non_empty_body() {
     71  1.1  jmmv 	test_mount
     72  1.1  jmmv 
     73  1.1  jmmv 	echo foo >b || atf_fail "Non-empty creation failed"
     74  1.1  jmmv 	eval $(stat -s b | sed -e 's|st_|ost_|g') || atf_fail "stat failed"
     75  1.1  jmmv 
     76  1.1  jmmv 	sleep 1
     77  1.3  jmmv 	atf_check -s eq:0 -o ignore -e empty cat b
     78  1.1  jmmv 	eval $(stat -s b) || atf_fail "stat failed"
     79  1.1  jmmv 	[ ${st_atime} -gt ${ost_atime} ] || atf_fail "Incorrect atime"
     80  1.1  jmmv 	[ ${st_ctime} -eq ${ost_ctime} ] || atf_fail "Incorrect ctime"
     81  1.1  jmmv 	[ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime"
     82  1.1  jmmv 
     83  1.1  jmmv 	test_unmount
     84  1.1  jmmv }
     85  1.1  jmmv 
     86  1.1  jmmv atf_test_case link
     87  1.1  jmmv link_head() {
     88  1.1  jmmv 	atf_set "descr" "Tests that linking to an existing file updates" \
     89  1.1  jmmv 	                "times correctly"
     90  1.1  jmmv 	atf_set "require.user" "root"
     91  1.1  jmmv }
     92  1.1  jmmv link_body() {
     93  1.1  jmmv 	test_mount
     94  1.1  jmmv 
     95  1.1  jmmv 	echo foo >c || atf_fail "Non-empty creation failed"
     96  1.1  jmmv 	eval $(stat -s c | sed -e 's|st_|ost_|g') || atf_fail "stat failed"
     97  1.1  jmmv 
     98  1.1  jmmv 	sleep 1
     99  1.3  jmmv 	atf_check -s eq:0 -o empty -e empty ln c d
    100  1.1  jmmv 	eval $(stat -s c) || atf_fail "stat failed"
    101  1.1  jmmv 	[ ${st_atime} -eq ${ost_atime} ] || atf_fail "Incorrect atime"
    102  1.1  jmmv 	[ ${st_ctime} -gt ${ost_ctime} ] || atf_fail "Incorrect ctime"
    103  1.1  jmmv 	[ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime"
    104  1.1  jmmv 
    105  1.1  jmmv 	test_unmount
    106  1.1  jmmv }
    107  1.1  jmmv 
    108  1.1  jmmv atf_test_case rename
    109  1.1  jmmv rename_head() {
    110  1.1  jmmv 	atf_set "descr" "Tests that renaming an existing file updates" \
    111  1.1  jmmv 	                "times correctly"
    112  1.1  jmmv 	atf_set "require.user" "root"
    113  1.1  jmmv }
    114  1.1  jmmv rename_body() {
    115  1.1  jmmv 	test_mount
    116  1.1  jmmv 
    117  1.3  jmmv 	atf_check -s eq:0 -o empty -e empty mkdir e
    118  1.1  jmmv 	echo foo >e/a || atf_fail "Creation failed"
    119  1.1  jmmv 	eval $(stat -s e | sed -e 's|st_|dost_|g') || atf_fail "stat failed"
    120  1.1  jmmv 	eval $(stat -s e/a | sed -e 's|st_|ost_|g') || atf_fail "stat failed"
    121  1.1  jmmv 	sleep 1
    122  1.3  jmmv 	atf_check -s eq:0 -o empty -e empty mv e/a e/b
    123  1.1  jmmv 	eval $(stat -s e | sed -e 's|st_|dst_|g') || atf_fail "stat failed"
    124  1.1  jmmv 	eval $(stat -s e/b) || atf_fail "stat failed"
    125  1.1  jmmv 	[ ${st_atime} -eq ${ost_atime} ] || atf_fail "Incorrect atime"
    126  1.1  jmmv 	[ ${st_ctime} -gt ${ost_ctime} ] || atf_fail "Incorrect ctime"
    127  1.1  jmmv 	[ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime"
    128  1.1  jmmv 	[ ${dst_mtime} -gt ${dost_mtime} ] || atf_fail "Incorrect mtime"
    129  1.1  jmmv 
    130  1.1  jmmv 	test_unmount
    131  1.1  jmmv }
    132  1.1  jmmv 
    133  1.1  jmmv atf_init_test_cases() {
    134  1.1  jmmv 	. $(atf_get_srcdir)/../h_funcs.subr
    135  1.1  jmmv 	. $(atf_get_srcdir)/h_funcs.subr
    136  1.1  jmmv 
    137  1.1  jmmv 	atf_add_test_case empty
    138  1.1  jmmv 	atf_add_test_case non_empty
    139  1.1  jmmv 	atf_add_test_case link
    140  1.1  jmmv 	atf_add_test_case rename
    141  1.1  jmmv }
    142