Repository navigation
testing/fs/filelock: Add a test for a signal during a file lock wait - #4017
Merged
Merged
Conversation
A thread waits for a file lock that the main thread holds, with fcntl(F_SETLKW), flock(LOCK_EX) and lockf(F_LOCK). A signal to the thread must end the wait with EINTR before the lock is free, as POSIX asks for fcntl(). The test also checks that the calls that do not wait fail on a held lock, and that a wait without a signal gets the lock after the unlock. The main thread always unlocks, so the test does not hang. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
xiaoxiang781216
approved these changes
Nov 11, 2026
xiaoxiang781216
marked this pull request as ready for review
November 11, 2026 01:45
🔗 Cross-repo PR dependenciesThe read-only Build run reported the following dependent PR(s) and fetched head SHA(s):
CI run: https://github.com/apache/nuttx-apps/actions/runs/42941207688 |
acassis
approved these changes
Nov 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
No test in nuttx-apps covers a wait for a file lock. This PR adds
testing/fs/filelock. A thread waits for a write lock that the main thread holds, withfcntl(F_SETLKW),flock(LOCK_EX)andlockf(F_LOCK). A signal to the thread (pthread_sigqueue(), a handler without SA_RESTART) must end the wait with EINTR before the lock is free, as POSIX asks forfcntl(). The test also checks thatF_SETLK,flock(LOCK_EX | LOCK_NB)andlockf(F_TLOCK)fail on a held lock, and that a wait without a signal gets the lock after the unlock.The main thread always unlocks after 2 seconds, so the test fails and does not hang when the signal does not end the wait. The program prints PASS or FAIL for each of the 13 checks and returns the number of errors.
Impact
Test only. The new option
TESTING_FILELOCKis off by default, as the other tests in testing/fs, and depends onFS_LOCK_BUCKET_SIZE > 0,!DISABLE_PTHREADand!DISABLE_ALL_SIGNALS. No defconfig sets it, so CI does not build or run it. The argument is the lock file (default/tmp/filelock.lck); its file system must support F_GETPATH (tmpfs, FAT, littlefs, v9fs, hostfs, ...).The cmocka fs tests are not a good place for this case: the configurations that enable them (rv-virt:citest, sim:citest) have
FS_LOCK_BUCKET_SIZE=0, so the case would be compiled out there too.Testing
filelock /lk/lockon a tmpfs, nuttx master 80a052ff9cc vs master + apache/nuttx#21651, apps master ee3d671 + this PR,CONFIG_FS_LOCK_BUCKET_SIZE=16,EXTRAFLAGS="-Wno-cpp -Werror":On master
fcntl(F_SETLKW),flock(LOCK_EX)andlockf(F_LOCK)all return 0 after 2001 ms, when the main thread unlocks: the handler ran, but the wait went on (eintrandearlyfail for each call). With the fix each call returns -1 with EINTR after about 301 ms. Thebusy,handlerandwaitchecks pass with both. The builds have no warnings.tools/checkpatch.sh -c -u -m -g origin/master..HEADpasses.Not run: SMP, other architectures.