casaroli opened a new pull request, #4017: URL: https://github.com/apache/nuttx-apps/pull/4017
depends-on: apache/nuttx/pull/21651 ## 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, with `fcntl(F_SETLKW)`, `flock(LOCK_EX)` and `lockf(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 for `fcntl()`. The test also checks that `F_SETLK`, `flock(LOCK_EX | LOCK_NB)` and `lockf(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_FILELOCK` is off by default, as the other tests in testing/fs, and depends on `FS_LOCK_BUCKET_SIZE > 0`, `!DISABLE_PTHREAD` and `!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/lock` on a tmpfs, nuttx master 80a052ff9cc vs master + apache/nuttx#21651, apps master ee3d67104 + this PR, `CONFIG_FS_LOCK_BUCKET_SIZE=16`, `EXTRAFLAGS="-Wno-cpp -Werror"`: | Configuration | nuttx master | with apache/nuttx#21651 | ostest | |---|---|---|---| | qemu-armv8a:knsh (kernel, arm64, QEMU HVF), make | 6 errors | 0 errors | status 0 (both) | | qemu-armv8a:nsh (flat, arm64, QEMU HVF), make | 6 errors | 0 errors | status 0 (both) | | mps2-an500:knsh (protected, Cortex-M7, QEMU TCG), make | 6 errors | 0 errors | status 0 (both) | | qemu-armv8a:nsh (flat), CMake | not run | 0 errors | status 0 | On master `fcntl(F_SETLKW)`, `flock(LOCK_EX)` and `lockf(F_LOCK)` all return 0 after 2001 ms, when the main thread unlocks: the handler ran, but the wait went on (`eintr` and `early` fail for each call). With the fix each call returns -1 with EINTR after about 301 ms. The `busy`, `handler` and `wait` checks pass with both. The builds have no warnings. `tools/checkpatch.sh -c -u -m -g origin/master..HEAD` passes. Not run: SMP, other architectures. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
