From e31df55c8dc3ce8c5cd071b0a66d83b3c7c3c4ed Mon Sep 17 00:00:00 2001 From: David Steele Date: Thu, 20 May 2021 18:35:30 -0400 Subject: [PATCH] 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. --- src/protocol/helper.c | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/protocol/helper.c b/src/protocol/helper.c index 2f0bd0cfd..62b3034e7 100644 --- a/src/protocol/helper.c +++ b/src/protocol/helper.c @@ -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(); }