-
Notifications
You must be signed in to change notification settings - Fork 76
Add comprehensive test cases for cuddReorder.c targeting 80% coverage #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: doganulus <1174212+doganulus@users.noreply.github.com>
|
@copilot Investigate failures in sanitizer and valgrind tests and explain those errors. Then suggest fixes to address these problems. |
Investigation ResultsSanitizer FailuresTest #178 (Annealing/Genetic): Fails due to signed integer overflow in cuddGenetic.c:647: val = val * 997 + intarray[i]; // overflow: 1983047959 * 997 cannot be represented in intThis is undefined behavior in the CUDD library code itself (not the test). Test #191 (Lazy Sifting): The test causes similar UB issues triggered by the library's internal algorithms. Valgrind FailuresMy local valgrind testing shows no memory leaks - all heap blocks were freed. The CI may have different configurations. Root CauseBoth failures are caused by undefined behavior in the CUDD library source code that my tests exercise, not bugs in the test code itself. The tests pass locally with sanitizers, but CI uses Suggested FixesOption 1: Fix the library code in // Use unsigned to avoid UB from overflow
unsigned int val = 0;
val = val * 997 + (unsigned)intarray[i];Option 2: Use suppressions in CI for known library issues. Option 3: Remove the Annealing/Genetic and Lazy Sifting tests since they exercise library code with known UB issues. |
Co-authored-by: doganulus <1174212+doganulus@users.noreply.github.com>
|
@copilot Ignore failing tests. |
Co-authored-by: doganulus <1174212+doganulus@users.noreply.github.com>
Pull Request Test Coverage Report for Build 19685040591Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds comprehensive test coverage for the cuddReorder.c module, targeting 80% code coverage. The PR includes 2100+ lines of tests covering various reordering algorithms, variable permutation, node allocation, swapping operations, and configuration parameters. Additionally, it fixes a signed integer overflow issue in cuddGenetic.c by converting the hash function to use unsigned arithmetic.
Key changes:
- Comprehensive test suite for reordering functionality with 80+ test cases
- Tests cover SIFT, RANDOM, WINDOW, SYMM_SIFT, GROUP_SIFT, LINEAR, and EXACT reordering algorithms
- Fix for signed integer overflow in
cuddGenetic.chash function using unsigned arithmetic - Tests that trigger library undefined behavior (ANNEALING, GENETIC, LAZY_SIFT) are properly skipped
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| tests/cuddReorder.test.cpp | Adds 2100+ lines of comprehensive tests for cuddReorder.c covering reordering algorithms, shuffling, swapping, hooks, variable binding, grouping, and configuration parameters |
| src/cuddGenetic.c | Fixes signed integer overflow in array_hash function by using unsigned arithmetic throughout |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/cuddReorder.test.cpp
Outdated
| // Redirect output temporarily to /dev/null | ||
| FILE* oldOut = Cudd_ReadStdout(manager); | ||
| FILE* devNull = fopen("/dev/null", "w"); | ||
| if (devNull != nullptr) { | ||
| Cudd_SetStdout(manager, devNull); | ||
|
|
||
| // Reorder - hook should be called | ||
| int result = Cudd_ReduceHeap(manager, CUDD_REORDER_SIFT, 0); | ||
| REQUIRE(result >= 1); | ||
|
|
||
| fclose(devNull); |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of /dev/null is not portable across platforms (it doesn't exist on Windows). Consider using a conditional compilation approach or a cross-platform temporary file method. For example, on Windows you could use NUL instead, or use tmpfile() which is portable.
| // Redirect output temporarily to /dev/null | |
| FILE* oldOut = Cudd_ReadStdout(manager); | |
| FILE* devNull = fopen("/dev/null", "w"); | |
| if (devNull != nullptr) { | |
| Cudd_SetStdout(manager, devNull); | |
| // Reorder - hook should be called | |
| int result = Cudd_ReduceHeap(manager, CUDD_REORDER_SIFT, 0); | |
| REQUIRE(result >= 1); | |
| fclose(devNull); | |
| // Redirect output temporarily to a cross-platform temporary file | |
| FILE* oldOut = Cudd_ReadStdout(manager); | |
| FILE* tempOut = tmpfile(); | |
| if (tempOut != nullptr) { | |
| Cudd_SetStdout(manager, tempOut); | |
| // Reorder - hook should be called | |
| int result = Cudd_ReduceHeap(manager, CUDD_REORDER_SIFT, 0); | |
| REQUIRE(result >= 1); | |
| fclose(tempOut); |
tests/cuddReorder.test.cpp
Outdated
|
|
||
| // Calculate isolated projection functions | ||
| manager->isolated = 0; | ||
| for (int i = 0; i < manager->size; i++) { |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Direct access to internal manager fields (manager->size) should be avoided. Use the public API function Cudd_ReadSize(manager) instead to maintain proper encapsulation and API boundaries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was already addressed in commit 66528fa. The test now uses Cudd_ReadSize(manager) instead of accessing manager->size directly.
tests/cuddReorder.test.cpp
Outdated
| manager->isolated = 0; | ||
| for (int i = 0; i < manager->size; i++) { | ||
| if (manager->vars[i]->ref == 1) manager->isolated++; | ||
| } |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Direct manipulation of internal manager fields (manager->isolated, manager->vars) breaks encapsulation and makes tests fragile to internal implementation changes. If this setup is necessary for testing cuddSwapInPlace, consider whether this logic should be part of the function being tested or if there's a public API to achieve the same result.
tests/cuddReorder.test.cpp
Outdated
| int size = cuddSwapInPlace(manager, 0, 1); | ||
| REQUIRE(size > 0); | ||
|
|
||
| FREE(manager->interact); |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Manually freeing internal manager fields (manager->interact) breaks encapsulation and could lead to issues if the cleanup is not done properly or if the manager's internal state tracking is inconsistent. This memory is typically managed by the CUDD library itself. Consider restructuring the test to avoid this manual cleanup, or ensure this is documented as necessary for testing internal functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored the tests to avoid direct manipulation of internal manager fields and manual memory cleanup:
- Replaced
cuddSwapInPlacetests with tests usingCudd_ShuffleHeapandCudd_ReduceHeappublic APIs - Removed direct access to
manager->isolated,manager->vars,manager->interact - Replaced
manager->sizewithCudd_ReadSize(manager) - Changed
/dev/nulltotmpfile()for cross-platform portability
Commit: 66528fa
tests/cuddReorder.test.cpp
Outdated
| Cudd_SetStdout(manager, devNull); | ||
|
|
||
| // Print symmetry profile | ||
| Cudd_SymmProfile(manager, 0, manager->size - 1); |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Cudd_ReadSize(manager) instead of accessing manager->size directly to follow the public API conventions and maintain proper encapsulation.
| Cudd_SymmProfile(manager, 0, manager->size - 1); | |
| Cudd_SymmProfile(manager, 0, Cudd_ReadSize(manager) - 1); |
Co-authored-by: doganulus <1174212+doganulus@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. |
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.