From nobody Thu Jul 10 17:54:33 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4bdMtK6CKXz61LZr; Thu, 10 Jul 2025 17:54:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bdMtK3LQNz3Jp3; Thu, 10 Jul 2025 17:54:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1752170073; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RHHVb6UyXOvk88J5+yo0jZ1TmfGbT0Q+B2h6xV/WYto=; b=ajs1MgD22vHdMwrjnHzy3eVdT/WUDM/SfCoJwheJ1orS9Ldmv2Kz9t1crUNtC4Z0/RIVC0 ARmQp1J8CgyYtrf9u5bkZ5qgvGFmnFcy1sOtGj/4gIUZ9nlOIoNDho4tPevYedIE/uAWob z1uuUhR8b9EBlZ8trkvhldPA5IxXzi0jAT6qgd9AVm2tDx8CyDNEp08X+CLZiSK8j9PQZw f9GZRAsPQ0dZy5njmgPSjbv4H9zQ6m7yFZSzK+cKBKPsN+j+T0NgqtKpN1g8GyCiOOOMNb jHxf84GvrpdDJJueDRuuE5TdceP8LCLDNyRA4xbgrtrAbgfZnbV/c0kwsoc+5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1752170073; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RHHVb6UyXOvk88J5+yo0jZ1TmfGbT0Q+B2h6xV/WYto=; b=Urtt6bYShRbsNZv9ThApqkt2ULhmsG7XZ9vsGj3opKoMWMwHr8mGYK/hdcvA9syDmNU+3k tS9i7d2FT7LPBtdXNbt8tGBC0qjgoQv4KlrRQ5W4pTnkKsOiqmvp7IY7QFvRWW1ylPIBAV dioJyJ4MUQT1oGIlIm7Au+2hTOKv1Pe/QbKxG9/6smmZ43OUR7zUVqvkKetSHHGXJTJ5pU zRHzJF4soUEOIg0/tOpcDkVawWWL6LtsFT5cip4cGvsfnaVbIw2uCaa5Aix65Zn8WDDi24 Ox6l/Z9U351GDP7HwZs9bTFq72d2fim3g9UmaNNvflzvLDuO5kLqCI9Wfip3Dg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1752170073; a=rsa-sha256; cv=none; b=h7LAGem9QoAGffz4vP3BoIwP3toGup+NoammMF+TNAPGLoCqJRK8k4g6tEz7zAM8/aam5B kehI+LFXOwBzp52WRe7Md73mvyg36Sxi7HSh0QQMkS5kVCxdMEM6lbY0QBeUdjZWHSNliz YgLSm1wB/aIG4Hk26GJ4MeY01QPi41OV/yzu+vruwB0VaF7cfRn34gmuSeCt4T9bWuzEAo K2KL3T46hfqwad9t0vRah7rIh+OhBR95eDEL0fmaJcfRXudSw2D3WgngOPDv+ToVx3pOFe ab/+TECfPaTHzvPacDUY92EysHc0iIpmqHGZGWRmX2Gi0ZxXOoN1j8bhVZVxIw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4bdMtK2xzsz1H7x; Thu, 10 Jul 2025 17:54:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 56AHsXF3072142; Thu, 10 Jul 2025 17:54:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 56AHsXt4072139; Thu, 10 Jul 2025 17:54:33 GMT (envelope-from git) Date: Thu, 10 Jul 2025 17:54:33 GMT Message-Id: <202507101754.56AHsXt4072139@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: c82203e65d08 - main - lockf: tests: add tests for the -p and -T features List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c82203e65d08036d25ed117f2617ef4ad07d6f97 Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=c82203e65d08036d25ed117f2617ef4ad07d6f97 commit c82203e65d08036d25ed117f2617ef4ad07d6f97 Author: Kyle Evans AuthorDate: 2025-06-24 23:04:11 +0000 Commit: Kyle Evans CommitDate: 2025-07-10 17:54:20 +0000 lockf: tests: add tests for the -p and -T features Reviewed by: des Differential Revision: https://reviews.freebsd.org/D51026 --- usr.bin/lockf/tests/lockf_test.sh | 95 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/usr.bin/lockf/tests/lockf_test.sh b/usr.bin/lockf/tests/lockf_test.sh index 0cdf7dae6f57..823b5673a176 100644 --- a/usr.bin/lockf/tests/lockf_test.sh +++ b/usr.bin/lockf/tests/lockf_test.sh @@ -31,6 +31,24 @@ : ${EX_CANTCREAT:=73} : ${EX_TEMPFAIL:=75} +waitlock() +{ + local cur lockfile tmo + + lockfile="$1" + + cur=0 + tmo=20 + + while [ "$cur" -lt "$tmo" -a ! -f "$lockfile" ]; do + sleep 0.1 + cur=$((cur + 1)) + done + + atf_check_not_equal "$cur" "$tmo" +} + + atf_test_case badargs badargs_body() { @@ -196,6 +214,52 @@ needfile_body() atf_check test "$tpass" -lt 10 } +atf_test_case termchild +termchild_body() +{ + lockf -kp testlock sleep 30 & + lpid=$! + + waitlock testlock + + atf_check -o file:testlock pgrep -F testlock + + start=$(date +"%s") + atf_check kill -TERM "$lpid" + wait "$lpid" + end=$(date +"%s") + elapsed=$((end - start)) + + if [ "$elapsed" -gt 5 ]; then + atf_fail "lockf seems to have dodged the SIGTERM ($elapsed passed)" + fi + + # We didn't start lockf with -T this time, so the process should not + # have been terminated. + atf_check -o file:testlock pgrep -F testlock + + lockf -kpT testlock sleep 30 & + lpid=$! + + waitlock testlock + + atf_check -o file:testlock pgrep -F testlock + + start=$(date +"%s") + atf_check kill -TERM "$lpid" + wait "$lpid" + end=$(date +"%s") + elapsed=$((end - start)) + + if [ "$elapsed" -gt 5 ]; then + atf_fail "lockf -T seems to have dodged the SIGTERM ($elapsed passed)" + fi + + # This time, it should have terminated (notably much earlier than our + # 30 second timeout). + atf_check -o empty -e not-empty -s not-exit:0 pgrep -F testlock +} + atf_test_case timeout timeout_body() { @@ -219,6 +283,34 @@ timeout_body() wait "$lpid" || true } +atf_test_case writepid +writepid_body() +{ + lockf -p "testlock" sleep 10 & + lpid=$! + + waitlock "testlock" + + atf_check test -s testlock + atf_check -o file:testlock pgrep -F testlock + atf_check -o file:testlock pgrep -F testlock -fx "sleep 10" + atf_check pkill -TERM -F testlock + + wait + + atf_check test ! -f testlock +} + +atf_test_case writepid_keep +writepid_keep_body() +{ + # Check that we'll clobber any existing contents (a pid, usually) + # once we acquire the lock. + jot -b A -s "" 64 > testlock + atf_check lockf -kp testlock sleep 0 + atf_check -o not-match:"A" cat testlock +} + atf_test_case wrlock wrlock_head() { @@ -244,6 +336,9 @@ atf_init_test_cases() atf_add_test_case fdlock atf_add_test_case keep atf_add_test_case needfile + atf_add_test_case termchild atf_add_test_case timeout + atf_add_test_case writepid + atf_add_test_case writepid_keep atf_add_test_case wrlock }