The issue you're experiencing, where the stub WorkersPoolNext is reported as "never called," can be analyzed step by step based on the code snippets provided. Let's break down the relevant parts of your code and the relationship between them:
Code Breakdown
-
Function in Focus:
The relevant part of your main function involves WorkersPoolNext, which is called within a do...while loop until a non-NULL value is returned:
do {
identity = WorkersPoolNext(wlist, client_id, client_id_len, &identity_len);
} while (identity == NULL);
-
Test Case:
The test case calls FrontendManager(_wlist);, which presumably contains the code that calls FrontendReceive(...) and subsequently calls WorkersPoolNext(...).
-
Stubbing Mechanism:
You have registered a stub callback for WorkersPoolNext:
CPPTEST_REGISTER_STUB_CALLBACK("WorkersPoolNext", &CppTest_StubCallback_main_c_WorkersPoolNext_return_success_1);
In your stub callback, you're controlling what the stub returns based on the callNo.
-
Stub Implementation:
The stub CppTest_StubCallback_main_c_WorkersPoolNext_return_success_1 is designed to return NULL on the first call:
if(stubCallInfo->callNo == 1) {
* __return = NULL;
}
else {
uint8_t _test_data;
uint8_t* test_data = &_test_data;
* __return = test_data;
}
Potential Issues and Solutions
1. Call Count Configuration
The issue might relate to how your stub callback is counting calls. In the typical usage of stubs, callNo should be incremented each time the stub is called, but it's not shown in your callback logic whether callNo is properly incremented. If the callNo starts at 1 and only returns NULL for that call, the do...while loop in the main function will run indefinitely.
Solution: Ensure that callNo is appropriately managed (incremented) in your testing framework. If this is not explicitly handled, callNo could be incorrectly initialized or not incrementing, causing the stub to not behave as expected.
2. Stub Not Being Called at All
If callNo is correctly managed yet WorkersPoolNext is still not called, verify that the FrontendManager(_wlist) function is correctly implementing the logic to call FrontendReceive(...):
Solution:
- Use logging or breakpoints to ensure that
FrontendReceive is being executed.
- Make sure that
rx_data, client_id, and their lengths are set up correctly so that FrontendReceive returns true.
- Confirm that there are no early exits or returns in
FrontendReceive preventing the WorkersPoolNext call.
3. wlist Initialization
In your test, _wlist is initialized as:
zlist_t * _wlist = 0 ;
This means _wlist is a NULL pointer. If FrontendManager or any function it calls expects _wlist to be a valid pointer (and not NULL), it may lead to unexpected behavior or exits.
Solution: Ensure that _wlist is properly initialized prior to passing it into FrontendManager. This includes setting it to a valid allocated structure of type zlist_t.
Debugging Steps
-
Implement Logging: Inside FrontendManager, FrontendReceive, and WorkersPoolNext, add logging to trace if the functions are being invoked and what parameters they receive.
-
Validate Call Flow: Trace the flow from FrontendManager to see if it calls FrontendReceive and then proceeds to call WorkersPoolNext.
-
Check Parameter Values: Log the values passed to the functions, particularly the pointers and lengths that are critical in determining whether the inner logic is executing correctly.
By examining these components, you should be able to identify why WorkersPoolNext is not being called and address the issue accordingly.