From d6797009f8e316e5dc778d42db609f7bd81225ee Mon Sep 17 00:00:00 2001 From: David Steele Date: Tue, 13 Jul 2021 11:13:57 -0400 Subject: [PATCH] Add ioFdReadNewOpen() and ioFdWriteNewOpen(). These functions construct and open in one call, which allows them to be used as function parameters. --- src/command/local/local.c | 9 ++-- src/command/remote/remote.c | 9 ++-- src/common/exec.c | 8 ++- src/common/io/fdRead.h | 9 ++++ src/common/io/fdWrite.h | 9 ++++ src/common/io/socket/session.c | 8 +-- test/src/common/harnessProtocol.c | 36 +++++--------- test/src/module/command/archiveGetTest.c | 12 ++--- test/src/module/command/archivePushTest.c | 12 ++--- test/src/module/command/controlTest.c | 47 ++++++------------ test/src/module/command/localTest.c | 10 ++-- test/src/module/command/remoteTest.c | 59 +++++++++++------------ test/src/module/common/ioTest.c | 6 +-- test/src/module/config/protocolTest.c | 19 +++----- test/src/module/db/dbTest.c | 26 +++++----- test/src/module/performance/storageTest.c | 20 +++----- test/src/module/protocol/protocolTest.c | 52 +++++++++----------- 17 files changed, 150 insertions(+), 201 deletions(-) diff --git a/src/command/local/local.c b/src/command/local/local.c index 7579e1f01..2060a134e 100644 --- a/src/command/local/local.c +++ b/src/command/local/local.c @@ -38,12 +38,9 @@ cmdLocal(int fdRead, int fdWrite) MEM_CONTEXT_TEMP_BEGIN() { String *name = strNewFmt(PROTOCOL_SERVICE_LOCAL "-%s", strZ(cfgOptionDisplay(cfgOptProcess))); - IoRead *read = ioFdReadNew(name, fdRead, cfgOptionUInt64(cfgOptProtocolTimeout)); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(name, fdWrite, cfgOptionUInt64(cfgOptProtocolTimeout)); - ioWriteOpen(write); - - ProtocolServer *server = protocolServerNew(name, PROTOCOL_SERVICE_LOCAL_STR, read, write); + ProtocolServer *server = protocolServerNew( + name, PROTOCOL_SERVICE_LOCAL_STR, ioFdReadNewOpen(name, fdRead, cfgOptionUInt64(cfgOptProtocolTimeout)), + ioFdWriteNewOpen(name, fdWrite, cfgOptionUInt64(cfgOptProtocolTimeout))); protocolServerProcess( server, cfgCommandJobRetry(), commandLocalHandlerList, PROTOCOL_SERVER_HANDLER_LIST_SIZE(commandLocalHandlerList)); } diff --git a/src/command/remote/remote.c b/src/command/remote/remote.c index d725de713..f6d4fb9b4 100644 --- a/src/command/remote/remote.c +++ b/src/command/remote/remote.c @@ -36,12 +36,9 @@ cmdRemote(int fdRead, int fdWrite) MEM_CONTEXT_TEMP_BEGIN() { String *name = strNewFmt(PROTOCOL_SERVICE_REMOTE "-%s", strZ(cfgOptionDisplay(cfgOptProcess))); - IoRead *read = ioFdReadNew(name, fdRead, cfgOptionUInt64(cfgOptProtocolTimeout)); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(name, fdWrite, cfgOptionUInt64(cfgOptProtocolTimeout)); - ioWriteOpen(write); - - ProtocolServer *server = protocolServerNew(name, PROTOCOL_SERVICE_REMOTE_STR, read, write); + ProtocolServer *server = protocolServerNew( + name, PROTOCOL_SERVICE_REMOTE_STR, ioFdReadNewOpen(name, fdRead, cfgOptionUInt64(cfgOptProtocolTimeout)), + ioFdWriteNewOpen(name, fdWrite, cfgOptionUInt64(cfgOptProtocolTimeout))); // Acquire a lock if this command needs one. We'll use the noop that is always sent from the client right after the // handshake to return an error. We can't take a lock earlier than this because we want the error to go back through the diff --git a/src/common/exec.c b/src/common/exec.c index 7e06af647..e4da33bae 100644 --- a/src/common/exec.c +++ b/src/common/exec.c @@ -183,9 +183,8 @@ execCheck(Exec *this) if (WIFEXITED(processStatus)) { // Get data from stderr to help diagnose the problem - IoRead *ioReadError = ioFdReadNew(strNewFmt("%s error", strZ(this->name)), this->fdError, 0); - ioReadOpen(ioReadError); - String *errorStr = strTrim(strNewBuf(ioReadBuf(ioReadError))); + String *errorStr = strTrim( + strNewBuf(ioReadBuf(ioFdReadNewOpen(strNewFmt("%s error", strZ(this->name)), this->fdError, 0)))); // Throw the error with as much information as is available THROWP_FMT( @@ -361,8 +360,7 @@ execOpen(Exec *this) // Assign file descriptors to io interfaces this->ioReadFd = ioFdReadNew(strNewFmt("%s read", strZ(this->name)), this->fdRead, this->timeout); - this->ioWriteFd = ioFdWriteNew(strNewFmt("%s write", strZ(this->name)), this->fdWrite, this->timeout); - ioWriteOpen(this->ioWriteFd); + this->ioWriteFd = ioFdWriteNewOpen(strNewFmt("%s write", strZ(this->name)), this->fdWrite, this->timeout); // Create wrapper interfaces that check process state this->pub.ioReadExec = ioReadNewP(this, .block = true, .read = execRead, .eof = execEof, .fd = execFdRead); diff --git a/src/common/io/fdRead.h b/src/common/io/fdRead.h index f7f587061..02f9f1bae 100644 --- a/src/common/io/fdRead.h +++ b/src/common/io/fdRead.h @@ -14,4 +14,13 @@ Constructors ***********************************************************************************************************************************/ IoRead *ioFdReadNew(const String *name, int fd, TimeMSec timeout); +// Construct and open read fd +__attribute__((always_inline)) static inline IoRead * +ioFdReadNewOpen(const String *const name, const int fd, const TimeMSec timeout) +{ + IoRead *const result = ioFdReadNew(name, fd, timeout); + ioReadOpen(result); + return result; +} + #endif diff --git a/src/common/io/fdWrite.h b/src/common/io/fdWrite.h index 9118fe4a0..a369e7883 100644 --- a/src/common/io/fdWrite.h +++ b/src/common/io/fdWrite.h @@ -14,6 +14,15 @@ Constructors ***********************************************************************************************************************************/ IoWrite *ioFdWriteNew(const String *name, int fd, TimeMSec timeout); +// Construct and open write fd +__attribute__((always_inline)) static inline IoWrite * +ioFdWriteNewOpen(const String *const name, const int fd, const TimeMSec timeout) +{ + IoWrite *const result = ioFdWriteNew(name, fd, timeout); + ioWriteOpen(result); + return result; +} + /*********************************************************************************************************************************** Helper functions ***********************************************************************************************************************************/ diff --git a/src/common/io/socket/session.c b/src/common/io/socket/session.c index f94ba4321..85a8bf8c9 100644 --- a/src/common/io/socket/session.c +++ b/src/common/io/socket/session.c @@ -193,16 +193,12 @@ sckSessionNew(IoSessionRole role, int fd, const String *host, unsigned int port, .host = strDup(host), .port = port, .timeout = timeout, - .read = ioFdReadNew(name, fd, timeout), - .write = ioFdWriteNew(name, fd, timeout), + .read = ioFdReadNewOpen(name, fd, timeout), + .write = ioFdWriteNewOpen(name, fd, timeout), }; strFree(name); - // Open read/write io - ioReadOpen(driver->read); - ioWriteOpen(driver->write); - // Ensure file descriptor is closed memContextCallbackSet(driver->memContext, sckSessionFreeResource, driver); diff --git a/test/src/common/harnessProtocol.c b/test/src/common/harnessProtocol.c index 2a9fb28ab..bd8e6bf7f 100644 --- a/test/src/common/harnessProtocol.c +++ b/test/src/common/harnessProtocol.c @@ -73,12 +73,9 @@ protocolLocalExec( // Run server with provided handlers String *name = strNewFmt(PROTOCOL_SERVICE_LOCAL "-shim-%u", processId); - IoRead *read = ioFdReadNew(name, pipeWrite[0], 5000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(name, pipeRead[1], 5000); - ioWriteOpen(write); - - ProtocolServer *server = protocolServerNew(name, PROTOCOL_SERVICE_LOCAL_STR, read, write); + ProtocolServer *server = protocolServerNew( + name, PROTOCOL_SERVICE_LOCAL_STR, ioFdReadNewOpen(name, pipeWrite[0], 5000), + ioFdWriteNewOpen(name, pipeRead[1], 5000)); protocolServerProcess(server, NULL, hrnProtocolStatic.localHandlerList, hrnProtocolStatic.localHandlerListSize); // Exit when done @@ -90,13 +87,10 @@ protocolLocalExec( close(pipeWrite[0]); // Create protocol object - IoRead *read = ioFdReadNew(strNewFmt(PROTOCOL_SERVICE_LOCAL "-%u shim protocol read", processId), pipeRead[0], 5000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(strNewFmt(PROTOCOL_SERVICE_LOCAL "-%u shim protocol write", processId), pipeWrite[1], 5000); - ioWriteOpen(write); - helper->client = protocolClientNew( - strNewFmt(PROTOCOL_SERVICE_LOCAL "-%u shim protocol", processId), PROTOCOL_SERVICE_LOCAL_STR, read, write); + strNewFmt(PROTOCOL_SERVICE_LOCAL "-%u shim protocol", processId), PROTOCOL_SERVICE_LOCAL_STR, + ioFdReadNewOpen(strNewFmt(PROTOCOL_SERVICE_LOCAL "-%u shim protocol read", processId), pipeRead[0], 5000), + ioFdWriteNewOpen(strNewFmt(PROTOCOL_SERVICE_LOCAL "-%u shim protocol write", processId), pipeWrite[1], 5000)); FUNCTION_LOG_RETURN_VOID(); } @@ -169,12 +163,9 @@ protocolRemoteExec( // Run server with provided handlers String *name = strNewFmt(PROTOCOL_SERVICE_REMOTE "-shim-%u", processId); - IoRead *read = ioFdReadNew(name, pipeWrite[0], 5000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(name, pipeRead[1], 5000); - ioWriteOpen(write); - - ProtocolServer *server = protocolServerNew(name, PROTOCOL_SERVICE_REMOTE_STR, read, write); + ProtocolServer *server = protocolServerNew( + name, PROTOCOL_SERVICE_REMOTE_STR, ioFdReadNewOpen(name, pipeWrite[0], 5000), + ioFdWriteNewOpen(name, pipeRead[1], 5000)); protocolServerProcess(server, NULL, hrnProtocolStatic.remoteHandlerList, hrnProtocolStatic.remoteHandlerListSize); // Put an end message here to sync with the client to ensure that coverage data is written before exiting @@ -189,13 +180,10 @@ protocolRemoteExec( close(pipeWrite[0]); // Create protocol object - IoRead *read = ioFdReadNew(strNewFmt(PROTOCOL_SERVICE_REMOTE "-%u shim protocol read", processId), pipeRead[0], 5000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(strNewFmt(PROTOCOL_SERVICE_REMOTE "-%u shim protocol write", processId), pipeWrite[1], 5000); - ioWriteOpen(write); - helper->client = protocolClientNew( - strNewFmt(PROTOCOL_SERVICE_REMOTE "-%u shim protocol", processId), PROTOCOL_SERVICE_REMOTE_STR, read, write); + strNewFmt(PROTOCOL_SERVICE_REMOTE "-%u shim protocol", processId), PROTOCOL_SERVICE_REMOTE_STR, + ioFdReadNewOpen(strNewFmt(PROTOCOL_SERVICE_REMOTE "-%u shim protocol read", processId), pipeRead[0], 5000), + ioFdWriteNewOpen(strNewFmt(PROTOCOL_SERVICE_REMOTE "-%u shim protocol write", processId), pipeWrite[1], 5000)); FUNCTION_LOG_RETURN_VOID(); } diff --git a/test/src/module/command/archiveGetTest.c b/test/src/module/command/archiveGetTest.c index d7ea72d91..ba22c0014 100644 --- a/test/src/module/command/archiveGetTest.c +++ b/test/src/module/command/archiveGetTest.c @@ -735,10 +735,8 @@ testRun(void) { HARNESS_FORK_CHILD_BEGIN(0, true) { - IoRead *read = ioFdReadNew(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000); - ioWriteOpen(write); + IoRead *read = ioFdReadNewOpen(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000); + IoWrite *write = ioFdWriteNewOpen(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000); TEST_RESULT_VOID( lockAcquire( @@ -757,10 +755,8 @@ testRun(void) HARNESS_FORK_PARENT_BEGIN() { - IoRead *read = ioFdReadNew(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000); - ioWriteOpen(write); + IoRead *read = ioFdReadNewOpen(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); + IoWrite *write = ioFdWriteNewOpen(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000); // Wait for the child to acquire the lock ioReadLine(read); diff --git a/test/src/module/command/archivePushTest.c b/test/src/module/command/archivePushTest.c index eeaeaa242..45ab8b21c 100644 --- a/test/src/module/command/archivePushTest.c +++ b/test/src/module/command/archivePushTest.c @@ -713,10 +713,8 @@ testRun(void) { HARNESS_FORK_CHILD_BEGIN(0, true) { - IoRead *read = ioFdReadNew(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000); - ioWriteOpen(write); + IoRead *read = ioFdReadNewOpen(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000); + IoWrite *write = ioFdWriteNewOpen(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000); lockAcquire( cfgOptionStr(cfgOptLockPath), cfgOptionStr(cfgOptStanza), STRDEF("555-fefefefe"), cfgLockType(), 30000, true); @@ -732,10 +730,8 @@ testRun(void) HARNESS_FORK_PARENT_BEGIN() { - IoRead *read = ioFdReadNew(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000); - ioWriteOpen(write); + IoRead *read = ioFdReadNewOpen(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); + IoWrite *write = ioFdWriteNewOpen(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000); // Wait for the child to acquire the lock ioReadLine(read); diff --git a/test/src/module/command/controlTest.c b/test/src/module/command/controlTest.c index f7fa1102d..f6b283672 100644 --- a/test/src/module/command/controlTest.c +++ b/test/src/module/command/controlTest.c @@ -164,10 +164,8 @@ testRun(void) { HARNESS_FORK_CHILD_BEGIN(0, true) { - IoRead *read = ioFdReadNew(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000); - ioWriteOpen(write); + IoRead *read = ioFdReadNewOpen(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000); + IoWrite *write = ioFdWriteNewOpen(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000); int lockFd = open(HRN_PATH "/lock/empty" LOCK_FILE_EXT, O_RDONLY, 0); TEST_RESULT_BOOL(lockFd != -1, true, "file descriptor acquired"); @@ -187,10 +185,8 @@ testRun(void) HARNESS_FORK_PARENT_BEGIN() { - IoRead *read = ioFdReadNew(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000); - ioWriteOpen(write); + IoRead *read = ioFdReadNewOpen(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); + IoWrite *write = ioFdWriteNewOpen(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000); // Wait for the child to acquire the lock ioReadLine(read); @@ -218,10 +214,8 @@ testRun(void) { HARNESS_FORK_CHILD_BEGIN(0, true) { - IoRead *read = ioFdReadNew(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000); - ioWriteOpen(write); + IoRead *read = ioFdReadNewOpen(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000); + IoWrite *write = ioFdWriteNewOpen(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000); int lockFd = open(HRN_PATH "/lock/empty" LOCK_FILE_EXT, O_RDONLY, 0); TEST_RESULT_BOOL(lockFd != -1, true, "file descriptor acquired"); @@ -241,10 +235,8 @@ testRun(void) HARNESS_FORK_PARENT_BEGIN() { - IoRead *read = ioFdReadNew(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000); - ioWriteOpen(write); + IoRead *read = ioFdReadNewOpen(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); + IoWrite *write = ioFdWriteNewOpen(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000); // Wait for the child to acquire the lock ioReadLine(read); @@ -270,10 +262,8 @@ testRun(void) { HARNESS_FORK_CHILD_BEGIN(0, true) { - IoRead *read = ioFdReadNew(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000); - ioWriteOpen(write); + IoRead *read = ioFdReadNewOpen(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000); + IoWrite *write = ioFdWriteNewOpen(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000); TEST_RESULT_BOOL( lockAcquire(STRDEF(HRN_PATH "/lock"), cfgOptionStr(cfgOptStanza), cfgOptionStr(cfgOptExecId), 0, 30000, true), @@ -290,10 +280,7 @@ testRun(void) HARNESS_FORK_PARENT_BEGIN() { - IoRead *read = ioFdReadNew(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000); - ioWriteOpen(write); + IoRead *read = ioFdReadNewOpen(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); // Wait for the child to acquire the lock ioReadLine(read); @@ -317,10 +304,8 @@ testRun(void) { HARNESS_FORK_CHILD_BEGIN(0, true) { - IoRead *read = ioFdReadNew(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000); - ioWriteOpen(write); + IoRead *read = ioFdReadNewOpen(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000); + IoWrite *write = ioFdWriteNewOpen(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000); int lockFd = open(HRN_PATH "/lock/badpid" LOCK_FILE_EXT, O_RDONLY, 0); TEST_RESULT_BOOL(lockFd != -1, true, "file descriptor acquired"); @@ -341,10 +326,8 @@ testRun(void) HARNESS_FORK_PARENT_BEGIN() { - IoRead *read = ioFdReadNew(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000); - ioWriteOpen(write); + IoRead *read = ioFdReadNewOpen(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); + IoWrite *write = ioFdWriteNewOpen(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000); // Wait for the child to acquire the lock ioReadLine(read); diff --git a/test/src/module/command/localTest.c b/test/src/module/command/localTest.c index 37d3315ed..50d0b770c 100644 --- a/test/src/module/command/localTest.c +++ b/test/src/module/command/localTest.c @@ -43,12 +43,10 @@ testRun(void) HARNESS_FORK_PARENT_BEGIN() { - IoRead *read = ioFdReadNew(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000); - ioWriteOpen(write); - - ProtocolClient *client = protocolClientNew(STRDEF("test"), PROTOCOL_SERVICE_LOCAL_STR, read, write); + ProtocolClient *client = protocolClientNew( + STRDEF("test"), PROTOCOL_SERVICE_LOCAL_STR, + ioFdReadNewOpen(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000), + ioFdWriteNewOpen(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000)); protocolClientNoOp(client); protocolClientFree(client); } diff --git a/test/src/module/command/remoteTest.c b/test/src/module/command/remoteTest.c index ecd575ade..d2c9bcf5d 100644 --- a/test/src/module/command/remoteTest.c +++ b/test/src/module/command/remoteTest.c @@ -43,12 +43,10 @@ testRun(void) HARNESS_FORK_PARENT_BEGIN() { - IoRead *read = ioFdReadNew(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000); - ioWriteOpen(write); - - ProtocolClient *client = protocolClientNew(STRDEF("test"), PROTOCOL_SERVICE_REMOTE_STR, read, write); + ProtocolClient *client = protocolClientNew( + STRDEF("test"), PROTOCOL_SERVICE_REMOTE_STR, + ioFdReadNewOpen(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000), + ioFdWriteNewOpen(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000)); protocolClientNoOp(client); protocolClientFree(client); } @@ -77,13 +75,13 @@ testRun(void) HARNESS_FORK_PARENT_BEGIN() { - IoRead *read = ioFdReadNew(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000); - ioWriteOpen(write); - ProtocolClient *client = NULL; - TEST_ASSIGN(client, protocolClientNew(STRDEF("test"), PROTOCOL_SERVICE_REMOTE_STR, read, write), "create client"); + TEST_ASSIGN( + client, + protocolClientNew(STRDEF("test"), PROTOCOL_SERVICE_REMOTE_STR, + ioFdReadNewOpen(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000), + ioFdWriteNewOpen(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000)), + "create client"); protocolClientNoOp(client); protocolClientFree(client); } @@ -111,14 +109,12 @@ testRun(void) HARNESS_FORK_PARENT_BEGIN() { - IoRead *read = ioFdReadNew(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000); - ioWriteOpen(write); - TEST_ERROR( - protocolClientNew(STRDEF("test"), PROTOCOL_SERVICE_REMOTE_STR, read, write), PathCreateError, - "raised from test: unable to create path '/bogus': [13] Permission denied"); + protocolClientNew( + STRDEF("test"), PROTOCOL_SERVICE_REMOTE_STR, + ioFdReadNewOpen(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000), + ioFdWriteNewOpen(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000)), + PathCreateError, "raised from test: unable to create path '/bogus': [13] Permission denied"); } HARNESS_FORK_PARENT_END(); } @@ -144,13 +140,14 @@ testRun(void) HARNESS_FORK_PARENT_BEGIN() { - IoRead *read = ioFdReadNew(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000); - ioWriteOpen(write); - ProtocolClient *client = NULL; - TEST_ASSIGN(client, protocolClientNew(STRDEF("test"), PROTOCOL_SERVICE_REMOTE_STR, read, write), "create client"); + TEST_ASSIGN( + client, + protocolClientNew( + STRDEF("test"), PROTOCOL_SERVICE_REMOTE_STR, + ioFdReadNewOpen(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000), + ioFdWriteNewOpen(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000)), + "create client"); protocolClientNoOp(client); TEST_RESULT_BOOL( @@ -182,16 +179,14 @@ testRun(void) HARNESS_FORK_PARENT_BEGIN() { - IoRead *read = ioFdReadNew(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000); - ioWriteOpen(write); - storagePutP(storageNewWriteP(hrnStorage, STRDEF("lock/all" STOP_FILE_EXT)), NULL); TEST_ERROR( - protocolClientNew(STRDEF("test"), PROTOCOL_SERVICE_REMOTE_STR, read, write), StopError, - "raised from test: stop file exists for all stanzas"); + protocolClientNew( + STRDEF("test"), PROTOCOL_SERVICE_REMOTE_STR, + ioFdReadNewOpen(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000), + ioFdWriteNewOpen(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000)), + StopError, "raised from test: stop file exists for all stanzas"); storageRemoveP(hrnStorage, STRDEF("lock/all" STOP_FILE_EXT)); } diff --git a/test/src/module/common/ioTest.c b/test/src/module/common/ioTest.c index 2c4ccdc89..cde66f26e 100644 --- a/test/src/module/common/ioTest.c +++ b/test/src/module/common/ioTest.c @@ -543,8 +543,7 @@ testRun(void) { IoWrite *write = NULL; - TEST_ASSIGN(write, ioFdWriteNew(STRDEF("write test"), HARNESS_FORK_CHILD_WRITE(), 1000), "move write"); - ioWriteOpen(write); + TEST_ASSIGN(write, ioFdWriteNewOpen(STRDEF("write test"), HARNESS_FORK_CHILD_WRITE(), 1000), "move write"); TEST_RESULT_BOOL(ioWriteReadyP(write), true, "write is ready"); TEST_RESULT_INT(ioWriteFd(write), ((IoFdWrite *)write->driver)->fd, "check write fd"); @@ -568,9 +567,8 @@ testRun(void) HARNESS_FORK_PARENT_BEGIN() { - IoRead *read = ioFdReadNew(STRDEF("read test"), HARNESS_FORK_PARENT_READ_PROCESS(0), 1000); + IoRead *read = ioFdReadNewOpen(STRDEF("read test"), HARNESS_FORK_PARENT_READ_PROCESS(0), 1000); - ioReadOpen(read); TEST_RESULT_INT(ioReadFd(read), ((IoFdRead *)ioReadDriver(read))->fd, "check fd"); TEST_RESULT_PTR(ioReadInterface(read), &read->pub.interface, "check interface"); TEST_RESULT_PTR(ioReadDriver(read), read->pub.driver, "check driver"); diff --git a/test/src/module/config/protocolTest.c b/test/src/module/config/protocolTest.c index 8ae8d57c3..fa91ba60e 100644 --- a/test/src/module/config/protocolTest.c +++ b/test/src/module/config/protocolTest.c @@ -24,11 +24,6 @@ testRun(void) { HARNESS_FORK_CHILD_BEGIN(0, true) { - IoRead *read = ioFdReadNew(STRDEF("client read"), HARNESS_FORK_CHILD_READ(), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("client write"), HARNESS_FORK_CHILD_WRITE(), 2000); - ioWriteOpen(write); - StringList *argList = strLstNew(); strLstAddZ(argList, "--stanza=test1"); hrnCfgArgRawZ(argList, cfgOptPgPath, "/path/to/pg"); @@ -36,7 +31,9 @@ testRun(void) strLstAddZ(argList, "--repo1-host-user=repo-host-user"); HRN_CFG_LOAD(cfgCmdArchiveGet, argList); - ProtocolServer *server = protocolServerNew(STRDEF("test"), STRDEF("config"), read, write); + ProtocolServer *server = protocolServerNew( + STRDEF("test"), STRDEF("config"), ioFdReadNewOpen(STRDEF("client read"), HARNESS_FORK_CHILD_READ(), 2000), + ioFdWriteNewOpen(STRDEF("client write"), HARNESS_FORK_CHILD_WRITE(), 2000)); static const ProtocolServerHandler commandHandler[] = {PROTOCOL_SERVER_HANDLER_OPTION_LIST}; protocolServerProcess(server, NULL, commandHandler, PROTOCOL_SERVER_HANDLER_LIST_SIZE(commandHandler)); @@ -45,12 +42,10 @@ testRun(void) HARNESS_FORK_PARENT_BEGIN() { - IoRead *read = ioFdReadNew(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000); - ioWriteOpen(write); - - ProtocolClient *client = protocolClientNew(STRDEF("test"), STRDEF("config"), read, write); + ProtocolClient *client = protocolClientNew( + STRDEF("test"), STRDEF("config"), + ioFdReadNewOpen(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000), + ioFdWriteNewOpen(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000)); VariantList *list = varLstNew(); varLstAdd(list, varNewStr(STRDEF("repo1-host"))); diff --git a/test/src/module/db/dbTest.c b/test/src/module/db/dbTest.c index c7f485ae0..2781aefd1 100644 --- a/test/src/module/db/dbTest.c +++ b/test/src/module/db/dbTest.c @@ -63,11 +63,6 @@ testRun(void) { HARNESS_FORK_CHILD_BEGIN(0, true) { - IoRead *read = ioFdReadNew(STRDEF("client read"), HARNESS_FORK_CHILD_READ(), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("client write"), HARNESS_FORK_CHILD_WRITE(), 2000); - ioWriteOpen(write); - // Set options StringList *argList = strLstNew(); strLstAddZ(argList, "--stanza=test1"); @@ -99,7 +94,13 @@ testRun(void) // Create server ProtocolServer *server = NULL; - TEST_ASSIGN(server, protocolServerNew(STRDEF("db test server"), STRDEF("test"), read, write), "create server"); + TEST_ASSIGN( + server, + protocolServerNew( + STRDEF("db test server"), STRDEF("test"), + ioFdReadNewOpen(STRDEF("client read"), HARNESS_FORK_CHILD_READ(), 2000), + ioFdWriteNewOpen(STRDEF("client write"), HARNESS_FORK_CHILD_WRITE(), 2000)), + "create server"); static const ProtocolServerHandler commandHandler[] = {PROTOCOL_SERVER_HANDLER_DB_LIST}; @@ -112,16 +113,17 @@ testRun(void) HARNESS_FORK_PARENT_BEGIN() { - IoRead *read = ioFdReadNew(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000); - ioWriteOpen(write); - // Create client ProtocolClient *client = NULL; Db *db = NULL; - TEST_ASSIGN(client, protocolClientNew(STRDEF("db test client"), STRDEF("test"), read, write), "create client"); + TEST_ASSIGN( + client, + protocolClientNew( + STRDEF("db test client"), STRDEF("test"), + ioFdReadNewOpen(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000), + ioFdWriteNewOpen(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000)), + "create client"); TRY_BEGIN() { diff --git a/test/src/module/performance/storageTest.c b/test/src/module/performance/storageTest.c index 7b652b747..c08246ed0 100644 --- a/test/src/module/performance/storageTest.c +++ b/test/src/module/performance/storageTest.c @@ -172,12 +172,10 @@ testRun(void) strIdFromZ(stringIdBit6, "test"), STRDEF("/"), 0, 0, false, NULL, &driver, driver.interface); // Setup handler for remote storage protocol - IoRead *read = ioFdReadNew(STRDEF("storage server read"), HARNESS_FORK_CHILD_READ(), 60000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("storage server write"), HARNESS_FORK_CHILD_WRITE(), 1000); - ioWriteOpen(write); - - ProtocolServer *server = protocolServerNew(STRDEF("storage test server"), STRDEF("test"), read, write); + ProtocolServer *server = protocolServerNew( + STRDEF("storage test server"), STRDEF("test"), + ioFdReadNewOpen(STRDEF("storage server read"), HARNESS_FORK_CHILD_READ(), 60000), + ioFdWriteNewOpen(STRDEF("storage server write"), HARNESS_FORK_CHILD_WRITE(), 1000)); static const ProtocolServerHandler commandHandler[] = {PROTOCOL_SERVER_HANDLER_STORAGE_REMOTE_LIST}; protocolServerProcess(server, NULL, commandHandler, PROTOCOL_SERVER_HANDLER_LIST_SIZE(commandHandler)); @@ -188,12 +186,10 @@ testRun(void) HARNESS_FORK_PARENT_BEGIN() { // Create client - IoRead *read = ioFdReadNew(STRDEF("storage client read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 60000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("storage client write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 1000); - ioWriteOpen(write); - - ProtocolClient *client = protocolClientNew(STRDEF("storage test client"), STRDEF("test"), read, write); + ProtocolClient *client = protocolClientNew( + STRDEF("storage test client"), STRDEF("test"), + ioFdReadNewOpen(STRDEF("storage client read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 60000), + ioFdWriteNewOpen(STRDEF("storage client write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 1000)); // Create remote storage Storage *storageRemote = storageRemoteNew( diff --git a/test/src/module/protocol/protocolTest.c b/test/src/module/protocol/protocolTest.c index fb55322cd..e75e3d304 100644 --- a/test/src/module/protocol/protocolTest.c +++ b/test/src/module/protocol/protocolTest.c @@ -437,10 +437,8 @@ testRun(void) { HARNESS_FORK_CHILD_BEGIN(0, true) { - IoRead *read = ioFdReadNew(STRDEF("server read"), HARNESS_FORK_CHILD_READ(), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("server write"), HARNESS_FORK_CHILD_WRITE(), 2000); - ioWriteOpen(write); + IoRead *read = ioFdReadNewOpen(STRDEF("server read"), HARNESS_FORK_CHILD_READ(), 2000); + IoWrite *write = ioFdWriteNewOpen(STRDEF("server write"), HARNESS_FORK_CHILD_WRITE(), 2000); // Various bogus greetings // ----------------------------------------------------------------------------------------------------------------- @@ -494,10 +492,8 @@ testRun(void) HARNESS_FORK_PARENT_BEGIN() { - IoRead *read = ioFdReadNew(STRDEF("client read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("client write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000); - ioWriteOpen(write); + IoRead *read = ioFdReadNewOpen(STRDEF("client read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000); + IoWrite *write = ioFdWriteNewOpen(STRDEF("client write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000); // ----------------------------------------------------------------------------------------------------------------- TEST_TITLE("bogus greetings"); @@ -665,13 +661,14 @@ testRun(void) // Local 1 HARNESS_FORK_CHILD_BEGIN(0, true) { - IoRead *read = ioFdReadNew(STRDEF("local server 1 read"), HARNESS_FORK_CHILD_READ(), 10000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("local server 1 write"), HARNESS_FORK_CHILD_WRITE(), 2000); - ioWriteOpen(write); - ProtocolServer *server = NULL; - TEST_ASSIGN(server, protocolServerNew(STRDEF("local server 1"), STRDEF("test"), read, write), "local server 1"); + TEST_ASSIGN( + server, + protocolServerNew( + STRDEF("local server 1"), STRDEF("test"), + ioFdReadNewOpen(STRDEF("local server 1 read"), HARNESS_FORK_CHILD_READ(), 10000), + ioFdWriteNewOpen(STRDEF("local server 1 write"), HARNESS_FORK_CHILD_WRITE(), 2000)), + "local server 1"); TEST_RESULT_UINT(protocolServerCommandGet(server).id, PROTOCOL_COMMAND_NOOP, "noop command get"); TEST_RESULT_VOID(protocolServerDataEndPut(server), "data end put"); @@ -692,13 +689,14 @@ testRun(void) // Local 2 HARNESS_FORK_CHILD_BEGIN(0, true) { - IoRead *read = ioFdReadNew(STRDEF("local server 2 read"), HARNESS_FORK_CHILD_READ(), 10000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew(STRDEF("local server 2 write"), HARNESS_FORK_CHILD_WRITE(), 2000); - ioWriteOpen(write); - ProtocolServer *server = NULL; - TEST_ASSIGN(server, protocolServerNew(STRDEF("local server 2"), STRDEF("test"), read, write), "local server 2"); + TEST_ASSIGN( + server, + protocolServerNew( + STRDEF("local server 2"), STRDEF("test"), + ioFdReadNewOpen(STRDEF("local server 2 read"), HARNESS_FORK_CHILD_READ(), 10000), + ioFdWriteNewOpen(STRDEF("local server 2 write"), HARNESS_FORK_CHILD_WRITE(), 2000)), + "local server 2"); TEST_RESULT_UINT(protocolServerCommandGet(server).id, PROTOCOL_COMMAND_NOOP, "noop command get"); TEST_RESULT_VOID(protocolServerDataEndPut(server), "data end put"); @@ -733,16 +731,14 @@ testRun(void) for (unsigned int clientIdx = 0; clientIdx < clientTotal; clientIdx++) { - IoRead *read = ioFdReadNew( - strNewFmt("local client %u read", clientIdx), HARNESS_FORK_PARENT_READ_PROCESS(clientIdx), 2000); - ioReadOpen(read); - IoWrite *write = ioFdWriteNew( - strNewFmt("local client %u write", clientIdx), HARNESS_FORK_PARENT_WRITE_PROCESS(clientIdx), 2000); - ioWriteOpen(write); - TEST_ASSIGN( client[clientIdx], - protocolClientNew(strNewFmt("local client %u", clientIdx), STRDEF("test"), read, write), + protocolClientNew( + strNewFmt("local client %u", clientIdx), STRDEF("test"), + ioFdReadNewOpen( + strNewFmt("local client %u read", clientIdx), HARNESS_FORK_PARENT_READ_PROCESS(clientIdx), 2000), + ioFdWriteNewOpen( + strNewFmt("local client %u write", clientIdx), HARNESS_FORK_PARENT_WRITE_PROCESS(clientIdx), 2000)), strZ(strNewFmt("local client %u new", clientIdx))); TEST_RESULT_VOID( protocolParallelClientAdd(parallel, client[clientIdx]), strZ(strNewFmt("local client %u add", clientIdx)));