git: 0ae114f07f5a - releng/15.1 - lockf: Test that lockf does not spin on fd

From: Colin Percival <cperciva_at_FreeBSD.org>
Date: Wed, 06 May 2026 16:30:36 UTC
The branch releng/15.1 has been updated by cperciva:

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

commit 0ae114f07f5a8d6048459f8dc37ed4132b02dcc9
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-05-03 15:35:15 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2026-05-06 16:30:21 +0000

    lockf: Test that lockf does not spin on fd
    
    Approved by:    re (cperciva)
    PR:             294832
    MFC after:      1 week
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D56723
    
    (cherry picked from commit 0733afdb4dad58cfe7ad7f5994e26bf148d78199)
    (cherry picked from commit 8e5f92b6b22c82af1192575781788eb2c8fed448)
---
 usr.bin/lockf/tests/lockf_test.sh | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/usr.bin/lockf/tests/lockf_test.sh b/usr.bin/lockf/tests/lockf_test.sh
index 823b5673a176..16ee5a03bb9e 100644
--- a/usr.bin/lockf/tests/lockf_test.sh
+++ b/usr.bin/lockf/tests/lockf_test.sh
@@ -177,6 +177,23 @@ fdlock_body()
 	atf_check test "$status2" -eq 0
 }
 
+atf_test_case fdlockspin
+fdlockspin_head()
+{
+	atf_set "descr" "Don't spin when locking a file descriptor"
+}
+fdlockspin_body()
+{
+	# Start background locker and give it time to get settled
+	lockf foo sleep 2 & sleep 1
+	# Start foreground locker in fdlock mode
+	atf_check ktrace -tc lockf -t 3 0 <foo
+	# Background locker quit and foreground locker succeeded
+	atf_check -o save:trace kdump -tc
+	# Check how many times foreground locker called flock()
+	atf_check -o inline:"2\n" egrep -c 'CALL +flock' trace
+}
+
 atf_test_case keep
 keep_body()
 {
@@ -334,6 +351,7 @@ atf_init_test_cases()
 	atf_add_test_case basic
 	atf_add_test_case bubble_error
 	atf_add_test_case fdlock
+	atf_add_test_case fdlockspin
 	atf_add_test_case keep
 	atf_add_test_case needfile
 	atf_add_test_case termchild