Home | History | Annotate | Line # | Download | only in tmpfs
      1  1.8    rillig # $NetBSD: t_times.sh,v 1.8 2024/04/28 07:27:41 rillig 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.8    rillig 	atf_check -s exit: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.6  riastrad 	[ ${ost_birthtime} -eq ${ost_atime} ] || \
     44  1.6  riastrad 	    atf_fail "Incorrect atime: ${ost_birthtime} != ${ost_atime}"
     45  1.6  riastrad 	[ ${ost_birthtime} -eq ${ost_ctime} ] || \
     46  1.6  riastrad 	    atf_fail "Incorrect ctime: ${ost_birthtime} != ${ost_ctime}"
     47  1.6  riastrad 	[ ${ost_birthtime} -eq ${ost_mtime} ] || \
     48  1.6  riastrad 	    atf_fail "Incorrect mtime: ${ost_birthtime} != ${ost_mtime}"
     49  1.1      jmmv 
     50  1.1      jmmv 	sleep 1
     51  1.8    rillig 	atf_check -s exit:0 -o empty -e empty cat a
     52  1.1      jmmv 	eval $(stat -s a) || atf_fail "stat failed"
     53  1.6  riastrad 	[ ${st_atime} -gt ${ost_atime} ] || \
     54  1.6  riastrad 	    atf_fail "Incorrect atime: ${st_atime} <= ${ost_atime}"
     55  1.6  riastrad 	[ ${st_ctime} -eq ${ost_ctime} ] || \
     56  1.6  riastrad 	    atf_fail "Incorrect ctime: ${st_ctime} != ${ost_ctime}"
     57  1.6  riastrad 	[ ${st_mtime} -eq ${ost_mtime} ] || \
     58  1.6  riastrad 	    atf_fail "Incorrect mtime: ${st_mtime} != ${ost_mtime}"
     59  1.1      jmmv 
     60  1.1      jmmv 	sleep 1
     61  1.1      jmmv 	echo foo >a || atf_fail "Write failed"
     62  1.1      jmmv 	eval $(stat -s a) || atf_fail "stat failed"
     63  1.6  riastrad 	[ ${st_atime} -gt ${ost_atime} ] || \
     64  1.6  riastrad 	    atf_fail "Incorrect atime: ${st_atime} <= ${ost_atime}"
     65  1.6  riastrad 	[ ${st_ctime} -gt ${ost_ctime} ] || \
     66  1.6  riastrad 	    atf_fail "Incorrect ctime: ${st_ctime} <= ${ost_ctime}"
     67  1.6  riastrad 	[ ${st_mtime} -gt ${ost_mtime} ] || \
     68  1.6  riastrad 	    atf_fail "Incorrect mtime: ${st_mtime} <= ${ost_mtime}"
     69  1.1      jmmv 
     70  1.1      jmmv 	test_unmount
     71  1.1      jmmv }
     72  1.1      jmmv 
     73  1.1      jmmv atf_test_case non_empty
     74  1.1      jmmv non_empty_head() {
     75  1.1      jmmv 	atf_set "descr" "Tests that creating a non-empty file and later" \
     76  1.1      jmmv 	                "manipulating it updates times correctly"
     77  1.1      jmmv 	atf_set "require.user" "root"
     78  1.1      jmmv }
     79  1.1      jmmv non_empty_body() {
     80  1.1      jmmv 	test_mount
     81  1.1      jmmv 
     82  1.1      jmmv 	echo foo >b || atf_fail "Non-empty creation failed"
     83  1.1      jmmv 	eval $(stat -s b | sed -e 's|st_|ost_|g') || atf_fail "stat failed"
     84  1.1      jmmv 
     85  1.1      jmmv 	sleep 1
     86  1.8    rillig 	atf_check -s exit:0 -o inline:"foo\n" -e empty cat b
     87  1.1      jmmv 	eval $(stat -s b) || atf_fail "stat failed"
     88  1.6  riastrad 	[ ${st_atime} -gt ${ost_atime} ] || \
     89  1.6  riastrad 	    atf_fail "Incorrect atime: ${st_atime} <= ${ost_atime}"
     90  1.6  riastrad 	[ ${st_ctime} -eq ${ost_ctime} ] || \
     91  1.6  riastrad 	    atf_fail "Incorrect ctime: ${st_ctime} != ${ost_ctime}"
     92  1.6  riastrad 	[ ${st_mtime} -eq ${ost_mtime} ] || \
     93  1.6  riastrad 	    atf_fail "Incorrect mtime: ${st_mtime} != ${ost_mtime}"
     94  1.1      jmmv 
     95  1.1      jmmv 	test_unmount
     96  1.1      jmmv }
     97  1.1      jmmv 
     98  1.1      jmmv atf_test_case link
     99  1.1      jmmv link_head() {
    100  1.1      jmmv 	atf_set "descr" "Tests that linking to an existing file updates" \
    101  1.1      jmmv 	                "times correctly"
    102  1.1      jmmv 	atf_set "require.user" "root"
    103  1.1      jmmv }
    104  1.1      jmmv link_body() {
    105  1.1      jmmv 	test_mount
    106  1.1      jmmv 
    107  1.1      jmmv 	echo foo >c || atf_fail "Non-empty creation failed"
    108  1.1      jmmv 	eval $(stat -s c | sed -e 's|st_|ost_|g') || atf_fail "stat failed"
    109  1.1      jmmv 
    110  1.1      jmmv 	sleep 1
    111  1.8    rillig 	atf_check -s exit:0 -o empty -e empty ln c d
    112  1.1      jmmv 	eval $(stat -s c) || atf_fail "stat failed"
    113  1.6  riastrad 	[ ${st_atime} -eq ${ost_atime} ] || \
    114  1.6  riastrad 	    atf_fail "Incorrect atime: ${st_atime} != ${ost_atime}"
    115  1.6  riastrad 	[ ${st_ctime} -gt ${ost_ctime} ] || \
    116  1.6  riastrad 	    atf_fail "Incorrect ctime: ${st_ctime} <= ${ost_ctime}"
    117  1.6  riastrad 	[ ${st_mtime} -eq ${ost_mtime} ] || \
    118  1.6  riastrad 	    atf_fail "Incorrect mtime: ${st_mtime} != ${ost_mtime}"
    119  1.1      jmmv 
    120  1.1      jmmv 	test_unmount
    121  1.1      jmmv }
    122  1.1      jmmv 
    123  1.1      jmmv atf_test_case rename
    124  1.1      jmmv rename_head() {
    125  1.1      jmmv 	atf_set "descr" "Tests that renaming an existing file updates" \
    126  1.1      jmmv 	                "times correctly"
    127  1.1      jmmv 	atf_set "require.user" "root"
    128  1.1      jmmv }
    129  1.1      jmmv rename_body() {
    130  1.1      jmmv 	test_mount
    131  1.1      jmmv 
    132  1.8    rillig 	atf_check -s exit:0 -o empty -e empty mkdir e
    133  1.1      jmmv 	echo foo >e/a || atf_fail "Creation failed"
    134  1.1      jmmv 	eval $(stat -s e | sed -e 's|st_|dost_|g') || atf_fail "stat failed"
    135  1.1      jmmv 	eval $(stat -s e/a | sed -e 's|st_|ost_|g') || atf_fail "stat failed"
    136  1.1      jmmv 	sleep 1
    137  1.8    rillig 	atf_check -s exit:0 -o empty -e empty mv e/a e/b
    138  1.1      jmmv 	eval $(stat -s e | sed -e 's|st_|dst_|g') || atf_fail "stat failed"
    139  1.1      jmmv 	eval $(stat -s e/b) || atf_fail "stat failed"
    140  1.6  riastrad 	[ ${st_atime} -eq ${ost_atime} ] || \
    141  1.6  riastrad 	    atf_fail "Incorrect atime: ${st_atime} != ${ost_atime}"
    142  1.6  riastrad 	[ ${st_ctime} -gt ${ost_ctime} ] || \
    143  1.6  riastrad 	    atf_fail "Incorrect ctime: ${st_ctime} <= ${ost_ctime}"
    144  1.6  riastrad 	[ ${st_mtime} -eq ${ost_mtime} ] || \
    145  1.6  riastrad 	    atf_fail "Incorrect mtime: ${st_mtime} != ${ost_mtime}"
    146  1.6  riastrad 	[ ${dst_mtime} -gt ${dost_mtime} ] || \
    147  1.6  riastrad 	    atf_fail "Incorrect mtime: ${dst_mtime} <= ${dost_mtime}"
    148  1.1      jmmv 
    149  1.1      jmmv 	test_unmount
    150  1.1      jmmv }
    151  1.1      jmmv 
    152  1.1      jmmv atf_init_test_cases() {
    153  1.1      jmmv 	. $(atf_get_srcdir)/../h_funcs.subr
    154  1.1      jmmv 	. $(atf_get_srcdir)/h_funcs.subr
    155  1.1      jmmv 
    156  1.1      jmmv 	atf_add_test_case empty
    157  1.1      jmmv 	atf_add_test_case non_empty
    158  1.1      jmmv 	atf_add_test_case link
    159  1.1      jmmv 	atf_add_test_case rename
    160  1.1      jmmv }
    161