fs/test: Fix fd management and formatting issues #3374
Draft
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.
Note: Please adhere to Contributing Guidelines.
Summary
This commit improves the filesystem test suite by addressing both functional and code quality issues:
Removes unnecessary test_state structure usage for tracking file descriptors
Adds missing close(newfd) call in fs_dup_test.c to prevent file descriptor leaks
Simplifies test code by eliminating redundant fd tracking that could lead to incorrect resource management
2. Code Quality and Formatting (Commit 3022918)
Corrects variable naming: writen → written in fs_fsync_test.c
Fixes comment typos: "wirte" → "write", "befor" → "before"
Corrects error message spelling: "descrepancy" → "discrepancy" (7 occurrences)
Impact
Users: No impact on end users; changes are limited to test infrastructure.
Build Process: No changes to build configuration or dependencies.
Testing: Affects 12 filesystem test case files in cases:
Modified for fd management: fs_dup_test.c, fs_file_get_test.c, fs_poll_test.c, fs_readdir_test.c, fs_seek_test.c, fs_truncate_test.c, fs_unlink_test.c, fs_write_test.c
Modified for formatting: fs_fsync_test.c, fs_readdir_test.c, fs_rename_test.c, fs_stream_test.c
Code Quality: Ensures proper file descriptor cleanup, improves readability, and passes static analysis checks.
Testing
cmocka -s cmocka_fs_test -t test_nuttx_fs_dup01
[==========] nuttx_fs_test_suites: Running 1 test(s).
[ RUN ] test_nuttx_fs_dup01
INFO: lstat /tmp/CM_fs_testdir errno 2
[ OK ] test_nuttx_fs_dup01
[==========] nuttx_fs_test_suites: 1 test(s) run.
[ PASSED ] 1 test(s).
Cmocka Test Completed.
cmocka -s cmocka_fs_test -t test_nuttx_fs_file_get01
[==========] nuttx_fs_test_suites: Running 1 test(s).
[ RUN ] test_nuttx_fs_file_get01
INFO: lstat /tmp/CM_fs_testdir errno 2
[ OK ] test_nuttx_fs_file_get01
[==========] nuttx_fs_test_suites: 1 test(s) run.
[ PASSED ] 1 test(s).
Cmocka Test Completed.
cmocka -s cmocka_fs_test -t test_nuttx_fs_poll01
[==========] nuttx_fs_test_suites: Running 1 test(s).
[ RUN ] test_nuttx_fs_poll01
INFO: lstat /tmp/CM_fs_testdir errno 2
[ OK ] test_nuttx_fs_poll01
[==========] nuttx_fs_test_suites: 1 test(s) run.
[ PASSED ] 1 test(s).
Cmocka Test Completed.
cmocka -s cmocka_fs_test -t test_nuttx_fs_readdir01
[==========] nuttx_fs_test_suites: Running 1 test(s).
[ RUN ] test_nuttx_fs_readdir01
INFO: lstat /tmp/CM_fs_testdir errno 2
[ OK ] test_nuttx_fs_readdir01
[==========] nuttx_fs_test_suites: 1 test(s) run.
[ PASSED ] 1 test(s).
Cmocka Test Completed.
cmocka -s cmocka_fs_test -t test_nuttx_fs_seek01
[==========] nuttx_fs_test_suites: Running 1 test(s).
[ RUN ] test_nuttx_fs_seek01
INFO: lstat /tmp/CM_fs_testdir errno 2
[ OK ] test_nuttx_fs_seek01
[==========] nuttx_fs_test_suites: 1 test(s) run.
[ PASSED ] 1 test(s).
Cmocka Test Completed.
cmocka -s cmocka_fs_test -t test_nuttx_fs_seek02
[==========] nuttx_fs_test_suites: Running 1 test(s).
[ RUN ] test_nuttx_fs_seek02
INFO: lstat /tmp/CM_fs_testdir errno 2
[ OK ] test_nuttx_fs_seek02
[==========] nuttx_fs_test_suites: 1 test(s) run.
[ PASSED ] 1 test(s).
Cmocka Test Completed.
cmocka -s cmocka_fs_test -t test_nuttx_fs_truncate01
[==========] nuttx_fs_test_suites: Running 1 test(s).
[ RUN ] test_nuttx_fs_truncate01
INFO: lstat /tmp/CM_fs_testdir errno 2
[ OK ] test_nuttx_fs_truncate01
[==========] nuttx_fs_test_suites: 1 test(s) run.
[ PASSED ] 1 test(s).
Cmocka Test Completed.
cmocka -s cmocka_fs_test -t test_nuttx_fs_unlink01
[==========] nuttx_fs_test_suites: Running 1 test(s).
[ RUN ] test_nuttx_fs_unlink01
INFO: lstat /tmp/CM_fs_testdir errno 2
[ OK ] test_nuttx_fs_unlink01
[==========] nuttx_fs_test_suites: 1 test(s) run.
[ PASSED ] 1 test(s).
Cmocka Test Completed.
cmocka -s cmocka_fs_test -t test_nuttx_fs_write02
[==========] nuttx_fs_test_suites: Running 1 test(s).
[ RUN ] test_nuttx_fs_write02
INFO: lstat /tmp/CM_fs_testdir errno 2
[ OK ] test_nuttx_fs_write02
[==========] nuttx_fs_test_suites: 1 test(s) run.
[ PASSED ] 1 test(s).
Cmocka Test Completed.
cmocka -s cmocka_fs_test -t test_nuttx_fs_write03
[==========] nuttx_fs_test_suites: Running 1 test(s).
[ RUN ] test_nuttx_fs_write03
INFO: lstat /tmp/CM_fs_testdir errno 2
[ OK ] test_nuttx_fs_write03
[==========] nuttx_fs_test_suites: 1 test(s) run.
[ PASSED ] 1 test(s).
Cmocka Test Completed.