git: e069c451f85e - stable/14 - tmpfs: Improve file time tests.

From: Dag-Erling Smørgrav <des_at_FreeBSD.org>
Date: Tue, 09 Apr 2024 08:49:51 UTC
The branch stable/14 has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=e069c451f85e5a28f83bf4fba3b668777d2f9193

commit e069c451f85e5a28f83bf4fba3b668777d2f9193
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2024-04-04 13:40:47 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2024-04-09 08:36:04 +0000

    tmpfs: Improve file time tests.
    
    * The empty test case no longer fails because 89f1dcb3eb46 causes empty
      files to bypass the bug.
    * The bug still exists, so add a test case which exercises it.
    * While here, tighten up some of the checks.
    
    A similar patch has been submitted upstream.
    
    PR:             274615
    X-MFC-With:     89f1dcb3eb46
    Sponsored by:   Juniper Networks, Inc.
    Sponsored by:   Klara, Inc.
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D44609
    
    (cherry picked from commit 8311bc5f17dec348749f763b82dfe2737bc53cd7)
---
 contrib/netbsd-tests/fs/tmpfs/t_times.sh | 38 +++++++++++++++++++++++++++-----
 1 file changed, 32 insertions(+), 6 deletions(-)

diff --git a/contrib/netbsd-tests/fs/tmpfs/t_times.sh b/contrib/netbsd-tests/fs/tmpfs/t_times.sh
index f7676814fa71..2d8eb6f67aa0 100755
--- a/contrib/netbsd-tests/fs/tmpfs/t_times.sh
+++ b/contrib/netbsd-tests/fs/tmpfs/t_times.sh
@@ -36,10 +36,6 @@ empty_head() {
 	atf_set "require.user" "root"
 }
 empty_body() {
-	# Begin FreeBSD
-	atf_expect_fail "Incorrect atime on FreeBSD: PR274615"
-	# End FreeBSD
-
 	test_mount
 
 	atf_check -s eq:0 -o empty -e empty touch a
@@ -49,13 +45,14 @@ empty_body() {
 	[ ${ost_birthtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime"
 
 	sleep 1
-	atf_check -s eq:0 -o ignore -e empty cat a
+	atf_check -s eq:0 -o empty -e empty cat a
 	eval $(stat -s a) || atf_fail "stat failed"
 	[ ${st_atime} -gt ${ost_atime} ] || atf_fail "Incorrect atime"
 	[ ${st_ctime} -eq ${ost_ctime} ] || atf_fail "Incorrect ctime"
 	[ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime"
 
 	sleep 1
+	ost_atime=${st_atime}
 	echo foo >a || atf_fail "Write failed"
 	eval $(stat -s a) || atf_fail "stat failed"
 	[ ${st_atime} -gt ${ost_atime} ] || atf_fail "Incorrect atime"
@@ -65,6 +62,34 @@ empty_body() {
 	test_unmount
 }
 
+atf_test_case holey
+holey_head() {
+	atf_set "descr" "Tests that creating a file consisting entirely" \
+		        "of a hole and later" \
+	                "manipulating it updates times correctly"
+	atf_set "require.user" "root"
+}
+holey_body() {
+	atf_expect_fail "https://bugs.freebsd.org/274615"
+
+	test_mount
+
+	atf_check -s eq:0 -o empty -e empty truncate -s 8k a
+	eval $(stat -s a | sed -e 's|st_|ost_|g') || atf_fail "stat failed"
+	[ ${ost_birthtime} -eq ${ost_atime} ] || atf_fail "Incorrect atime"
+	[ ${ost_birthtime} -eq ${ost_ctime} ] || atf_fail "Incorrect ctime"
+	[ ${ost_birthtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime"
+
+	sleep 1
+	atf_check -s eq:0 -o ignore -e empty cat a
+	eval $(stat -s a) || atf_fail "stat failed"
+	[ ${st_atime} -gt ${ost_atime} ] || atf_fail "Incorrect atime"
+	[ ${st_ctime} -eq ${ost_ctime} ] || atf_fail "Incorrect ctime"
+	[ ${st_mtime} -eq ${ost_mtime} ] || atf_fail "Incorrect mtime"
+
+	test_unmount
+}
+
 atf_test_case non_empty
 non_empty_head() {
 	atf_set "descr" "Tests that creating a non-empty file and later" \
@@ -78,7 +103,7 @@ non_empty_body() {
 	eval $(stat -s b | sed -e 's|st_|ost_|g') || atf_fail "stat failed"
 
 	sleep 1
-	atf_check -s eq:0 -o ignore -e empty cat b
+	atf_check -s eq:0 -o inline:"foo\n" -e empty cat b
 	eval $(stat -s b) || atf_fail "stat failed"
 	[ ${st_atime} -gt ${ost_atime} ] || atf_fail "Incorrect atime"
 	[ ${st_ctime} -eq ${ost_ctime} ] || atf_fail "Incorrect ctime"
@@ -139,6 +164,7 @@ atf_init_test_cases() {
 	. $(atf_get_srcdir)/h_funcs.subr
 
 	atf_add_test_case empty
+	atf_add_test_case holey
 	atf_add_test_case non_empty
 	atf_add_test_case link
 	atf_add_test_case rename