testing/fs: fix fd close issues and optimize test execution time #3383
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
This PR contains a series of fixes and improvements to the file system test cases in [fs]
fdcheck: fix fd close in other thread (34d2d3ebd1b)
Fix file descriptor leak issue where fd was stored in test_state for deferred close, but could fail when CONFIG_FDCHECK is enabled because fd cannot be closed in a different thread.
Modified test cases to close fd directly within the same test function instead of relying on teardown function.
Affected files: fs_creat_test.c, fs_dup2_test.c, fs_eventfd_test.c, fs_fcntl_test.c, fs_fstat_test.c, fs_fstatfs_test.c, fs_fsync_test.c, fs_open_test.c, fs_pread_test.c, fs_pwrite_test.c, fs_read_test.c, fs_readlink_test.c, fs_stat_test.c, fs_write_test.c
eventfd_test: avoid the orphan Thread (b4c00e9a57a)
Replace sleep() with pthread_join() to properly wait for the child thread to finish, avoiding orphan threads.
Change sleep(1) to usleep(1000) to reduce test time while maintaining synchronization.
Fix loop iteration count mismatch between reader thread (6 iterations) and writer (5 iterations).
fs/test: remove the usleep of eventfd read to solve the question of sem wait (74dda2d1b88)
Remove unnecessary usleep(1000) in the read thread of eventfd test.
The eventfd read operation will block and wait for data naturally via semaphore, no additional delay is needed.
testing/fs: reduce the test time of fs test (eb1d9a48c94)
Reduce TEST_NUM from 1000 to 100 in fs_opendir_test.c
Reduce loop count from 100 to 30 in fs_stream_test.c
These changes significantly reduce test execution time while still maintaining adequate test coverage.
Impact
Users: No impact on end users. These changes only affect test cases.
Build process: No impact.
Compatibility: Improves compatibility with CONFIG_FDCHECK enabled configurations.
Testing: Tests run faster and more reliably, especially when fdcheck is enabled.
Testing
cmocka -s cmocka_fs_test -t test_nuttx_fs_creat01 [PASSED]
cmocka -s cmocka_fs_test -t test_nuttx_fs_fcntl01 [PASSED]
cmocka -s cmocka_fs_test -t test_nuttx_fs_fstat01 [PASSED]
cmocka -s cmocka_fs_test -t test_nuttx_fs_fstatfs01 [PASSED]
cmocka -s cmocka_fs_test -t test_nuttx_fs_fsync01 [PASSED]
cmocka -s cmocka_fs_test -t test_nuttx_fs_open01 [PASSED]
cmocka -s cmocka_fs_test -t test_nuttx_fs_pread01 [PASSED]
cmocka -s cmocka_fs_test -t test_nuttx_fs_pwrite01 [PASSED]
cmocka -s cmocka_fs_test -t test_nuttx_fs_readlink01 [PASSED]
cmocka -s cmocka_fs_test -t test_nuttx_fs_write01 [PASSED]
cmocka -s cmocka_fs_test -t test_nuttx_fs_eventfd [PASSED]
cmocka -s cmocka_fs_test -t test_nuttx_fs_opendir02 [PASSED]
cmocka -s cmocka_fs_test -t test_nuttx_fs_stream02 [PASSED]
cmocka -s cmocka_fs_test -t test_nuttx_fs_read01 [PASSED]
cmocka -s cmocka_fs_test -t test_nuttx_fs_stat01 [PASSED]