Tests - Fix compile warnings in cpp_api unit_tests - #508
Conversation
|
Resolves #497 |
There was a problem hiding this comment.
Pull request overview
This PR targets build cleanliness for the C++ API unit tests by removing/handling constructs that trigger compiler warnings (unused variables and ignored [[nodiscard]] HIP API results), plus a small .gitignore update for an additional build directory.
Changes:
- Stop capturing return values from several
rocalTensor*reduction calls where the return was not used. - Replace ignored
hipMalloc/hipFreeresults withcheck_hip(...)to satisfy[[nodiscard]]and fail fast on HIP errors. - Add
build_verify/to.gitignore.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/cpp_api/unit_tests/unit_tests.cpp | Removes/handles unused values and HIP [[nodiscard]] warnings; adds a small HIP error-check helper. |
| .gitignore | Ignores build_verify/ build output directory. |
Suppressed comments (2)
tests/cpp_api/unit_tests/unit_tests.cpp:1244
indexis still never read: it is only incremented and not used anywhere else in this file (even underENABLE_OPENCV), so OpenCV-enabled builds will continue to emit-Wunused-but-set-variable. Remove the unused counter entirely (or actually use it).
#if ENABLE_OPENCV
int index = 0;
#endif
tests/cpp_api/unit_tests/unit_tests.cpp:1249
- This
index++is part of an unused counter and triggers-Wunused-but-set-variablewhenENABLE_OPENCVis on. If the counter is not used (it isn't elsewhere in this file), delete the increment block.
while (rocalGetRemainingImages(handle) >= input_batch_size) {
#if ENABLE_OPENCV
index++;
#endif
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
|
||
| // Get output matched indices | ||
| if (enable_iou_matcher) { | ||
| rocalGetMatchedIndices(handle); // TODO - To verify the output |
There was a problem hiding this comment.
For consistency with above copilot comment consider adding (void)rocalGetMatchedIndices(handle)
| auto tensor_max = rocalTensorMax(handle, input, false, ROCAL_NONE, ROCAL_UINT8); | ||
| rocalTensorSum(handle, input, false, ROCAL_NONE, ROCAL_FP32); | ||
| rocalTensorMin(handle, input, false, ROCAL_NONE, ROCAL_UINT8); | ||
| rocalTensorMax(handle, input, false, ROCAL_NONE, ROCAL_UINT8); |
There was a problem hiding this comment.
I think this test case for sum, min and max is flawed. We need to verify the output of these functions here.
| int w = rocalGetOutputWidth(handle); | ||
| int output_color_format = rocalGetOutputColorFormat(handle); | ||
| auto last_batch_padded_size = rocalGetLastBatchPaddedSize(handle); | ||
| rocalGetLastBatchPaddedSize(handle); |
There was a problem hiding this comment.
Also here. Add code to verify output
|
@levxn -- please address the review comments |
Motivation
Fixes #497: Compile warnings in tests/cpp_api/unit_tests/unit_tests.cpp
Technical Details
Removed unused variable captures for
rocalTensorSum,rocalTensorMin,rocalTensorMax,rocalTensorStdDev, androcalGetLastBatchPaddedSizecalls that were made purely for side effects but whose return values were never used or asserted on. Removed the unused loopindexvariable that was declared and incremented but never read. Explicitly discarded thehipError_treturn values of thehipMalloc/hipFreecalls (now[[nodiscard]]in current HIP headers) using(void)casts, since these test-only allocations were not being checked for failure.Affected file:
tests/cpp_api/unit_tests/unit_tests.cpp(lines 1190-1194, 1220, 1235, 1434-1462).Test Plan
Built
unit_testsfrom a clean configure with the HIP backend enabled, across all GPU targets, to confirm the warning count drops to zero:Test Result
Before fix: 14 warnings generated per compile target (
gfx...,host) — 4 unused-variable warnings, 8 hipMalloc/hipFree nodiscard warnings, 1 last_batch_padded_size unused-variable warning and 1 index set but unused warning.After fix: 0 warnings generated across all three compile passes (
gfx...,host);unit_testsbuilds and links cleanly.