Factor local process exec out of protocolLocalGet().
This allows protocolLocalExec() to be shimmed, which means the local can be run as a child of the test process, simplifying coverage testing.
@@ -171,6 +171,36 @@ protocolLocalParam(ProtocolStorageType protocolStorageType, unsigned int hostIdx
}
/**********************************************************************************************************************************/
+// Helper to execute the local process. This is a separate function solely so that it can be shimmed during testing.
+static void
+protocolLocalExec(
+ ProtocolHelperClient *helper, ProtocolStorageType protocolStorageType, unsigned int hostIdx, unsigned int processId)
+{
+ FUNCTION_TEST_BEGIN();
+ FUNCTION_TEST_PARAM_P(VOID, helper);
+ FUNCTION_TEST_PARAM(ENUM, protocolStorageType);
+ FUNCTION_TEST_PARAM(UINT, hostIdx);
+ FUNCTION_TEST_PARAM(UINT, processId);
+ FUNCTION_TEST_END();
+
+ ASSERT(helper != NULL);
+
+ // Execute the protocol command
+ helper->exec = execNew(
+ cfgExe(), protocolLocalParam(protocolStorageType, hostIdx, processId),
+ strNewFmt(PROTOCOL_SERVICE_LOCAL "-%u process", processId), cfgOptionUInt64(cfgOptProtocolTimeout));
+ execOpen(helper->exec);
+
+ // Create protocol object
+ helper->client = protocolClientNew(
+ strNewFmt(PROTOCOL_SERVICE_LOCAL "-%u protocol", processId),
+ PROTOCOL_SERVICE_LOCAL_STR, execIoRead(helper->exec), execIoWrite(helper->exec));
+
+ protocolClientMove(helper->client, execMemContext(helper->exec));
+
+ FUNCTION_TEST_RETURN_VOID();
+}
+
ProtocolClient *
protocolLocalGet(ProtocolStorageType protocolStorageType, unsigned int hostIdx, unsigned int processId)
{
@@ -205,18 +235,7 @@ protocolLocalGet(ProtocolStorageType protocolStorageType, unsigned int hostIdx,
{
MEM_CONTEXT_BEGIN(protocolHelper.memContext)
{
- // Execute the protocol command
- protocolHelperClient->exec = execNew(
- cfgExe(), protocolLocalParam(protocolStorageType, hostIdx, processId),
- strNewFmt(PROTOCOL_SERVICE_LOCAL "-%u process", processId), cfgOptionUInt64(cfgOptProtocolTimeout));
- execOpen(protocolHelperClient->exec);
-
- // Create protocol object
- protocolHelperClient->client = protocolClientNew(
- strNewFmt(PROTOCOL_SERVICE_LOCAL "-%u protocol", processId),
- PROTOCOL_SERVICE_LOCAL_STR, execIoRead(protocolHelperClient->exec), execIoWrite(protocolHelperClient->exec));
-
- protocolClientMove(protocolHelperClient->client, execMemContext(protocolHelperClient->exec));
+ protocolLocalExec(protocolHelperClient, protocolStorageType, hostIdx, processId);
}
MEM_CONTEXT_END();
}
