|WARNING| [v2,4/4] test/cfgfile: test for long lines in file
dpdklab at iol.unh.edu
dpdklab at iol.unh.edu
Mon Aug 17 17:17:59 CEST 2026
Test-Label: ai-code-review
Test-Status: WARNING
https://dpdk.org/patch/167875
_AI Code Review_
=== Patch Review: series.patch (via Claude) ===
Review date: 2026-08-17
# Review of DPDK Patch Series: test/cfgfile improvements
## Patch 1/4: test/cfgfile: improve coverage for listing APIs
### Errors
None identified.
### Warnings
None identified.
### Info
The patch adds comprehensive test coverage for section and entry listing APIs with proper sentinel verification. The test correctly validates:
- Section count and listing
- Entry counts per section
- Index-based access
- Proper bounds checking with sentinel values
## Patch 2/4: test/cfgfile: validate config creation APIs
### Errors
1. **Resource leak on test failure path** (line 209-210):
```c
cfgfile = rte_cfgfile_create(0);
TEST_ASSERT_NOT_NULL(cfgfile, "Failed to create cfgfile");
```
If any subsequent `TEST_ASSERT*` macro fails before `rte_cfgfile_close()` at line 232, the cfgfile handle leaks. The `TEST_ASSERT*` macros return immediately on failure without cleanup.
**Fix**: Add cleanup path using a label or restructure to ensure `rte_cfgfile_close()` is called on all paths:
```c
cfgfile = rte_cfgfile_create(0);
if (cfgfile == NULL) {
printf("Failed to create cfgfile\n");
return -1;
}
/* ... test operations ... */
ret = rte_cfgfile_close(cfgfile);
TEST_ASSERT_SUCCESS(ret, "Failed to close created cfgfile");
```
Or add explicit cleanup before each early return.
2. **Resource leak on test failure path** (line 235-236):
```c
loaded = rte_cfgfile_load(filename, 0);
TEST_ASSERT_NOT_NULL(loaded, "Failed to load saved cfgfile");
```
Same issue: if any subsequent assertion fails before `rte_cfgfile_close(loaded)` at line 258, the loaded cfgfile handle leaks.
**Fix**: Similar to above - ensure cleanup on all paths.
3. **Temporary file not removed on early failure** (line 226-227):
```c
ret = make_tmp_file(filename, "create_save", "");
TEST_ASSERT_SUCCESS(ret, "Failed to make temporary output file");
```
If this assertion fails or any assertion between file creation and `remove(filename)` at line 261 fails, the temporary file is left behind.
**Fix**: Consider adding cleanup in a way that ensures file removal, or accept that test framework cleanup handles temp files.
### Warnings
None beyond the errors above.
## Patch 3/4: test/cfgfile: verify file modification API
### Errors
1. **Resource leak on test failure path** (line 503-504):
```c
cfgfile = rte_cfgfile_load(filename, 0);
TEST_ASSERT_NOT_NULL(cfgfile, "Failed to load config file");
```
If any subsequent `TEST_ASSERT*` fails before `rte_cfgfile_close()` at line 528, the cfgfile handle leaks.
**Fix**: Ensure cleanup on all exit paths.
2. **Resource leak on test failure path** (line 532-533):
```c
loaded = rte_cfgfile_load(filename, 0);
TEST_ASSERT_NOT_NULL(loaded, "Failed to reload saved cfgfile");
```
Same leak pattern if assertions fail before `rte_cfgfile_close(loaded)` at line 538.
**Fix**: Add cleanup path.
3. **Temporary file not removed on early failure** (line 499-500):
Similar to Patch 2, temporary file may be left behind on early test failure.
### Warnings
None beyond the errors above.
## Patch 4/4: test/cfgfile: test for long lines in file
### Errors
None identified. This test correctly expects failure and does not create a cfgfile handle that needs cleanup.
### Warnings
None identified.
---
## Summary
**Primary Issue**: All three test functions that create or load cfgfile handles (patches 2 and 3) have **resource leak bugs** on error paths. The `TEST_ASSERT*` macros return immediately on failure, bypassing the cleanup code (`rte_cfgfile_close()` and `remove()`). This violates the guideline requirement to trace all error paths and verify resources are released.
**Recommended Pattern**: Use a common cleanup pattern for tests that allocate resources:
```c
static int
test_cfgfile_example(void)
{
struct rte_cfgfile *cfgfile = NULL;
struct rte_cfgfile *loaded = NULL;
char filename[PATH_MAX];
int ret = -1;
/* Create temp file */
if (make_tmp_file(filename, "name", content) != 0)
goto cleanup;
/* Allocate resources */
cfgfile = rte_cfgfile_create(0);
if (cfgfile == NULL)
goto cleanup;
/* Test operations - can now use goto cleanup on failure */
if (rte_cfgfile_add_section(cfgfile, "section1") != 0)
goto cleanup;
/* ... more tests ... */
loaded = rte_cfgfile_load(filename, 0);
if (loaded == NULL)
goto cleanup;
/* ... validation ... */
ret = 0; /* Success */
cleanup:
if (loaded != NULL)
rte_cfgfile_close(loaded);
if (cfgfile != NULL)
rte_cfgfile_close(cfgfile);
remove(filename); /* Safe even if file doesn't exist */
return ret;
}
```
This ensures all resources are properly freed regardless of which test step fails.
More information about the test-report
mailing list