1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-30 05:39:12 +02:00

Remove comment formatting from TEST_*() macros.

Comment formatting was not used much but it incurred a heavy cost in each macro to process possible formatting.

Remove formatted comments where they did not contain valuable information and replace with strZ(strNewFmt()) otherwise.
This commit is contained in:
David Steele 2021-05-22 11:28:56 -04:00
parent b270253a69
commit a4f057bb70
12 changed files with 93 additions and 93 deletions

View File

@ -11,8 +11,8 @@ Write info to a file and add the checksum
***********************************************************************************************************************************/
#define HRN_INFO_PUT(storage, file, info, ...) \
TEST_RESULT_VOID( \
hrnStoragePut(storage, file, harnessInfoChecksumZ(info), (HrnStoragePutParam){VAR_PARAM_INIT, __VA_ARGS__}), "put info %s",\
hrnStoragePutLog(storage, file, LF_BUF, (HrnStoragePutParam){VAR_PARAM_INIT, __VA_ARGS__}))
hrnStoragePut(storage, file, harnessInfoChecksumZ(info), (HrnStoragePutParam){VAR_PARAM_INIT, __VA_ARGS__}), \
strZ(strNewFmt("put info %s", hrnStoragePutLog(storage, file, LF_BUF, (HrnStoragePutParam){VAR_PARAM_INIT, __VA_ARGS__}))))
/***********************************************************************************************************************************
Functions

View File

@ -14,7 +14,8 @@ Helper functions for testing storage and related functions.
Check file exists
***********************************************************************************************************************************/
#define TEST_STORAGE_EXISTS(storage, file) \
TEST_RESULT_BOOL(storageExistsP(storage, STR(file)), true, "file exists '%s'", strZ(storagePathP(storage, STR(file))))
TEST_RESULT_BOOL( \
storageExistsP(storage, STR(file)), true, strZ(strNewFmt("file exists '%s'", strZ(storagePathP(storage, STR(file))))))
/***********************************************************************************************************************************
Get a file and test it against the specified content
@ -79,8 +80,8 @@ typedef struct HrnStoragePutParam
#define HRN_STORAGE_PUT(storage, file, buffer, ...) \
TEST_RESULT_VOID( \
hrnStoragePut(storage, file, buffer, (HrnStoragePutParam){VAR_PARAM_INIT, __VA_ARGS__}), "put file %s", \
hrnStoragePutLog(storage, file, buffer, (HrnStoragePutParam){VAR_PARAM_INIT, __VA_ARGS__}))
hrnStoragePut(storage, file, buffer, (HrnStoragePutParam){VAR_PARAM_INIT, __VA_ARGS__}), \
strZ(strNewFmt("put file %s", hrnStoragePutLog(storage, file, buffer, (HrnStoragePutParam){VAR_PARAM_INIT, __VA_ARGS__}))))
#define HRN_STORAGE_PUT_EMPTY(storage, file, ...) \
HRN_STORAGE_PUT(storage, file, NULL, __VA_ARGS__)
@ -95,8 +96,9 @@ const char *hrnStoragePutLog(const Storage *storage, const char *file, const Buf
Remove a file and error if it does not exist
***********************************************************************************************************************************/
#define TEST_STORAGE_REMOVE(storage, path) \
TEST_RESULT_VOID(storageRemoveP(storage, STR(path), .errorOnMissing = true), "remove file '%s'", \
strZ(storagePathP(storage, STR(path))))
TEST_RESULT_VOID( \
storageRemoveP(storage, STR(path), .errorOnMissing = true), \
strZ(strNewFmt("remove file '%s'", strZ(storagePathP(storage, STR(path))))))
/***********************************************************************************************************************************
Change the time of a path/file

View File

@ -103,18 +103,17 @@ Test error with a formatted expected message
/***********************************************************************************************************************************
Output information about the test
***********************************************************************************************************************************/
#define TEST_RESULT_INFO(...) \
#define TEST_RESULT_INFO(comment) \
hrnTestLogPrefix(__LINE__, true); \
printf(__VA_ARGS__); \
printf("\n"); \
puts(comment); \
fflush(stdout);
/***********************************************************************************************************************************
Test that a void statement returns and does not throw an error
***********************************************************************************************************************************/
#define TEST_RESULT_VOID(statement, ...) \
#define TEST_RESULT_VOID(statement, comment) \
{ \
TEST_RESULT_INFO(__VA_ARGS__); \
TEST_RESULT_INFO(comment); \
hrnTestResultBegin(#statement, __LINE__, false); \
statement; \
hrnTestResultEnd(); \
@ -123,9 +122,9 @@ Test that a void statement returns and does not throw an error
/***********************************************************************************************************************************
Test that a statement does not error and assign it to the specified variable if not
***********************************************************************************************************************************/
#define TEST_ASSIGN(lValue, statement, ...) \
#define TEST_ASSIGN(lValue, statement, comment) \
{ \
TEST_RESULT_INFO(__VA_ARGS__); \
TEST_RESULT_INFO(comment); \
hrnTestResultBegin(#statement, __LINE__, true); \
lValue = statement; \
hrnTestResultEnd(); \
@ -134,48 +133,48 @@ Test that a statement does not error and assign it to the specified variable if
/***********************************************************************************************************************************
Macros to compare results of common data types
***********************************************************************************************************************************/
#define TEST_RESULT_BOOL_PARAM(statement, expected, ...) \
#define TEST_RESULT_BOOL_PARAM(statement, expected, comment) \
do \
{ \
TEST_RESULT_INFO(__VA_ARGS__); \
TEST_RESULT_INFO(comment); \
hrnTestResultBegin(#statement, __LINE__, true); \
hrnTestResultBool(statement, expected); \
} \
while (0)
#define TEST_RESULT_BOOL(statement, expected, ...) \
TEST_RESULT_BOOL_PARAM(statement, expected, __VA_ARGS__)
#define TEST_RESULT_BOOL(statement, expected, comment) \
TEST_RESULT_BOOL_PARAM(statement, expected, comment)
#define TEST_RESULT_DOUBLE_PARAM(statement, expected, ...) \
#define TEST_RESULT_DOUBLE_PARAM(statement, expected, comment) \
do \
{ \
TEST_RESULT_INFO(__VA_ARGS__); \
TEST_RESULT_INFO(comment); \
hrnTestResultBegin(#statement, __LINE__, true); \
hrnTestResultDouble(statement, expected); \
} \
while (0)
#define TEST_RESULT_DOUBLE(statement, expected, ...) \
TEST_RESULT_DOUBLE_PARAM(statement, expected, __VA_ARGS__)
#define TEST_RESULT_DOUBLE(statement, expected, comment) \
TEST_RESULT_DOUBLE_PARAM(statement, expected, comment)
#define TEST_RESULT_INT_PARAM(statement, expected, operation, ...) \
#define TEST_RESULT_INT_PARAM(statement, expected, operation, comment) \
do \
{ \
TEST_RESULT_INFO(__VA_ARGS__); \
TEST_RESULT_INFO(comment); \
hrnTestResultBegin(#statement, __LINE__, true); \
hrnTestResultInt64(statement, expected, operation); \
} \
while (0)
#define TEST_RESULT_INT(statement, expected, ...) \
TEST_RESULT_INT_PARAM(statement, expected, harnessTestResultOperationEq, __VA_ARGS__)
#define TEST_RESULT_INT_NE(statement, expected, ...) \
TEST_RESULT_INT_PARAM(statement, expected, harnessTestResultOperationNe, __VA_ARGS__)
#define TEST_RESULT_INT(statement, expected, comment) \
TEST_RESULT_INT_PARAM(statement, expected, harnessTestResultOperationEq, comment)
#define TEST_RESULT_INT_NE(statement, expected, comment) \
TEST_RESULT_INT_PARAM(statement, expected, harnessTestResultOperationNe, comment)
#define TEST_RESULT_PTR_PARAM(statement, expected, operation, ...) \
#define TEST_RESULT_PTR_PARAM(statement, expected, operation, comment) \
do \
{ \
TEST_RESULT_INFO(__VA_ARGS__); \
TEST_RESULT_INFO(comment); \
hrnTestResultBegin(#statement, __LINE__, true); \
hrnTestResultPtr(statement, expected, operation); \
} \
@ -183,72 +182,72 @@ Macros to compare results of common data types
// Compare raw pointers. When checking for NULL use the type-specific macro when available, e.g. TEST_RESULT_STR(). This is more
// type-safe and makes it clearer what is being tested.
#define TEST_RESULT_PTR(statement, expected, ...) \
TEST_RESULT_PTR_PARAM(statement, expected, harnessTestResultOperationEq, __VA_ARGS__)
#define TEST_RESULT_PTR_NE(statement, expected, ...) \
TEST_RESULT_PTR_PARAM(statement, expected, harnessTestResultOperationNe, __VA_ARGS__)
#define TEST_RESULT_PTR(statement, expected, comment) \
TEST_RESULT_PTR_PARAM(statement, expected, harnessTestResultOperationEq, comment)
#define TEST_RESULT_PTR_NE(statement, expected, comment) \
TEST_RESULT_PTR_PARAM(statement, expected, harnessTestResultOperationNe, comment)
#define TEST_RESULT_Z_PARAM(statement, expected, operation, ...) \
#define TEST_RESULT_Z_PARAM(statement, expected, operation, comment) \
do \
{ \
TEST_RESULT_INFO(__VA_ARGS__); \
TEST_RESULT_INFO(comment); \
hrnTestResultBegin(#statement, __LINE__, true); \
hrnTestResultZ(statement, expected, operation); \
} \
while (0)
#define TEST_RESULT_Z(statement, expected, ...) \
TEST_RESULT_Z_PARAM(statement, expected, harnessTestResultOperationEq, __VA_ARGS__)
#define TEST_RESULT_Z_NE(statement, expected, ...) \
TEST_RESULT_Z_PARAM(statement, expected, harnessTestResultOperationNe, __VA_ARGS__)
#define TEST_RESULT_Z(statement, expected, comment) \
TEST_RESULT_Z_PARAM(statement, expected, harnessTestResultOperationEq, comment)
#define TEST_RESULT_Z_NE(statement, expected, comment) \
TEST_RESULT_Z_PARAM(statement, expected, harnessTestResultOperationNe, comment)
#define TEST_RESULT_STR(statement, resultExpected, ...) \
TEST_RESULT_Z(strZNull(statement), strZNull(resultExpected), __VA_ARGS__)
#define TEST_RESULT_STR_Z(statement, resultExpected, ...) \
TEST_RESULT_Z(strZNull(statement), resultExpected, __VA_ARGS__)
#define TEST_RESULT_STR_KEYRPL(statement, resultExpected, ...) \
TEST_RESULT_Z(strZNull(statement), strZ(resultExpected), __VA_ARGS__)
#define TEST_RESULT_STR_Z_KEYRPL(statement, resultExpected, ...) \
TEST_RESULT_Z(strZNull(statement), resultExpected, __VA_ARGS__)
#define TEST_RESULT_Z_STR(statement, resultExpected, ...) \
TEST_RESULT_Z(statement, strZNull(resultExpected), __VA_ARGS__)
#define TEST_RESULT_STR(statement, resultExpected, comment) \
TEST_RESULT_Z(strZNull(statement), strZNull(resultExpected), comment)
#define TEST_RESULT_STR_Z(statement, resultExpected, comment) \
TEST_RESULT_Z(strZNull(statement), resultExpected, comment)
#define TEST_RESULT_STR_KEYRPL(statement, resultExpected, comment) \
TEST_RESULT_Z(strZNull(statement), strZ(resultExpected), comment)
#define TEST_RESULT_STR_Z_KEYRPL(statement, resultExpected, comment) \
TEST_RESULT_Z(strZNull(statement), resultExpected, comment)
#define TEST_RESULT_Z_STR(statement, resultExpected, comment) \
TEST_RESULT_Z(statement, strZNull(resultExpected), comment)
// Compare a string list to a \n delimited string
#define TEST_RESULT_STRLST_Z(statement, resultExpected, ...) \
#define TEST_RESULT_STRLST_Z(statement, resultExpected, comment) \
do \
{ \
TEST_RESULT_INFO(__VA_ARGS__); \
TEST_RESULT_INFO(comment); \
hrnTestResultBegin(#statement, __LINE__, true); \
hrnTestResultStringList(statement, resultExpected, harnessTestResultOperationEq); \
} \
while (0)
#define TEST_RESULT_STRLST_STR(statement, resultExpected, ...) \
TEST_RESULT_STRLST_Z(statement, strZNull(resultExpected), __VA_ARGS__)
#define TEST_RESULT_STRLST_STR(statement, resultExpected, comment) \
TEST_RESULT_STRLST_Z(statement, strZNull(resultExpected), comment)
#define TEST_RESULT_UINT_PARAM(statement, expected, operation, ...) \
#define TEST_RESULT_UINT_PARAM(statement, expected, operation, comment) \
do \
{ \
TEST_RESULT_INFO(__VA_ARGS__); \
TEST_RESULT_INFO(comment); \
hrnTestResultBegin(#statement, __LINE__, true); \
hrnTestResultUInt64(statement, expected, operation); \
} \
while (0)
#define TEST_RESULT_UINT(statement, expected, ...) \
TEST_RESULT_UINT_PARAM(statement, expected, harnessTestResultOperationEq, __VA_ARGS__)
#define TEST_RESULT_UINT(statement, expected, comment) \
TEST_RESULT_UINT_PARAM(statement, expected, harnessTestResultOperationEq, comment)
#define TEST_RESULT_UINT_INT_PARAM(statement, expected, operation, ...) \
#define TEST_RESULT_UINT_INT_PARAM(statement, expected, operation, comment) \
do \
{ \
TEST_RESULT_INFO(__VA_ARGS__); \
TEST_RESULT_INFO(comment); \
hrnTestResultBegin(#statement, __LINE__, true); \
hrnTestResultUInt64Int64(statement, expected, operation); \
} \
while (0)
#define TEST_RESULT_UINT_INT(statement, expected, ...) \
TEST_RESULT_UINT_INT_PARAM(statement, expected, harnessTestResultOperationEq, __VA_ARGS__)
#define TEST_RESULT_UINT_INT(statement, expected, comment) \
TEST_RESULT_UINT_INT_PARAM(statement, expected, harnessTestResultOperationEq, comment)
/***********************************************************************************************************************************
Test system calls

View File

@ -182,7 +182,7 @@ testRun(void)
TEST_RESULT_BOOL(
regExpMatchOne(
STRDEF("^20[0-9]{2}\\-[0-1][0-9]\\-[0-3][0-9] [0-2][0-9]\\:[0-5][0-9]\\:[0-5][0-9]\\.[0-9]{3}$"), logTime),
true, "check timestamp format: %s", strZ(logTime));
true, "check timestamp format");
// Redirect output to files
const char *const stdoutFile = TEST_PATH "/stdout.log";

View File

@ -325,7 +325,7 @@ testRun(void)
{
memContext = MEM_CONTEXT_NEW();
TEST_RESULT_PTR(memContext, memContextCurrent(), "new mem context is current");
TEST_RESULT_Z(memContextName(memContext), memContextTestName, "context is now '%s'", memContextTestName);
TEST_RESULT_Z(memContextName(memContext), memContextTestName, "check context name");
}
MEM_CONTEXT_NEW_END();
@ -344,7 +344,7 @@ testRun(void)
MEM_CONTEXT_NEW_BEGIN(memContextTestName)
{
memContext = MEM_CONTEXT_NEW();
TEST_RESULT_Z(memContextName(memContext), memContextTestName, "context is now '%s'", memContextTestName);
TEST_RESULT_Z(memContextName(memContext), memContextTestName, "check mem context name");
THROW(AssertError, "create failed");
}
MEM_CONTEXT_NEW_END();

View File

@ -86,7 +86,9 @@ testRun(void)
// Add ints to the list
for (int listIdx = 1; listIdx <= LIST_INITIAL_SIZE; listIdx++)
TEST_RESULT_VOID(lstAdd(list, &listIdx), "add item %d", listIdx);
{
TEST_RESULT_VOID(lstAdd(list, &listIdx), strZ(strNewFmt("add item %d", listIdx)));
}
lstMove(list, memContextPrior());
}
@ -94,7 +96,7 @@ testRun(void)
// Insert an int at the beginning
int insertIdx = 0;
TEST_RESULT_INT(*(int *)lstInsert(list, 0, &insertIdx), 0, "insert item %d", insertIdx);
TEST_RESULT_INT(*(int *)lstInsert(list, 0, &insertIdx), 0, strZ(strNewFmt("insert item %d", insertIdx)));
// Check the size
TEST_RESULT_INT(lstSize(list), 9, "list size");
@ -104,7 +106,7 @@ testRun(void)
for (unsigned int listIdx = 0; listIdx < lstSize(list); listIdx++)
{
int *item = lstGet(list, listIdx);
TEST_RESULT_INT(*item, listIdx, "check item %u", listIdx);
TEST_RESULT_INT(*item, listIdx, strZ(strNewFmt("check item %u", listIdx)));
}
// Remove first item
@ -115,7 +117,7 @@ testRun(void)
{
int *item = listIdx == lstSize(list) - 1 ? lstGetLast(list) : lstGet(list, listIdx);
TEST_RESULT_INT(*item, listIdx + 1, "check item %u", listIdx);
TEST_RESULT_INT(*item, listIdx + 1, strZ(strNewFmt("check item %u", listIdx)));
}
// -------------------------------------------------------------------------------------------------------------------------
@ -127,7 +129,7 @@ testRun(void)
for (int listIdx = 0; listIdx < 8; listIdx++)
{
int item = listIdx + 9;
TEST_RESULT_VOID(lstAdd(list, &item), "add item %d", item);
TEST_RESULT_VOID(lstAdd(list, &item), strZ(strNewFmt("add item %d", item)));
}
TEST_RESULT_UINT(lstSize(list), list->listSizeMax, "size equals max size");
@ -139,7 +141,7 @@ testRun(void)
for (unsigned int listIdx = 0; listIdx < lstSize(list); listIdx++)
{
int *item = lstGet(list, listIdx);
TEST_RESULT_INT(*item, listIdx + 1, "check item %u", listIdx);
TEST_RESULT_INT(*item, listIdx + 1, strZ(strNewFmt("check item %u", listIdx)));
}
TEST_ERROR(lstGet(list, lstSize(list)), AssertError, "cannot get index 15 from list with 15 value(s)");

View File

@ -227,7 +227,7 @@ testRun(void)
while (pckReadNext(packRead))
{
TEST_RESULT_UINT(pckReadU64P(packRead, .id = pckReadId(packRead)), value, "read %u", value);
TEST_RESULT_UINT(pckReadU64P(packRead, .id = pckReadId(packRead)), value, strZ(strNewFmt("read %u", value)));
value++;
}

View File

@ -325,7 +325,8 @@ testRun(void)
else
{
TEST_RESULT_STR(
strLstAdd(list, strNewFmt("STR%02d", listIdx)), strNewFmt("STR%02d", listIdx), "add item %d", listIdx);
strLstAdd(list, strNewFmt("STR%02d", listIdx)), strNewFmt("STR%02d", listIdx),
strZ(strNewFmt("add item %d", listIdx)));
}
}
@ -344,9 +345,7 @@ testRun(void)
TEST_RESULT_STR(strLstGet(list, listIdx), NULL, "check null item");
}
else
{
TEST_RESULT_STR(strLstGet(list, listIdx), strNewFmt("STR%02u", listIdx), "check item %u", listIdx);
}
TEST_RESULT_STR(strLstGet(list, listIdx), strNewFmt("STR%02u", listIdx), strZ(strNewFmt("check item %u", listIdx)));
}
TEST_RESULT_VOID(strLstFree(list), "free string list");
@ -418,7 +417,7 @@ testRun(void)
}
else
{
TEST_RESULT_Z_STR(szList[listIdx], strNewFmt("STR%02u", listIdx), "check item %u", listIdx);
TEST_RESULT_Z_STR(szList[listIdx], strNewFmt("STR%02u", listIdx), strZ(strNewFmt("check item %u", listIdx)));
}
}

View File

@ -23,12 +23,12 @@ testOptionFind(const char *optionName, unsigned int optionId, unsigned int optio
{
CfgParseOptionResult option = cfgParseOptionP(STR(optionName));
TEST_RESULT_BOOL(option.found, true, "check %s found", optionName);
TEST_RESULT_UINT(option.id, optionId, "check %s id %u", optionName, optionId);
TEST_RESULT_UINT(option.keyIdx, optionKeyIdx, "check %s key idx %u", optionName, optionKeyIdx);
TEST_RESULT_BOOL(option.negate, negate, "check %s negate %d", optionName, negate);
TEST_RESULT_BOOL(option.reset, reset, "check %s reset %d", optionName, reset);
TEST_RESULT_BOOL(option.deprecated, deprecated, "check %s deprecated %d", optionName, deprecated);
TEST_RESULT_BOOL(option.found, true, strZ(strNewFmt("check %s found", optionName)));
TEST_RESULT_UINT(option.id, optionId, strZ(strNewFmt("check %s id %u", optionName, optionId)));
TEST_RESULT_UINT(option.keyIdx, optionKeyIdx, strZ(strNewFmt("check %s key idx %u", optionName, optionKeyIdx)));
TEST_RESULT_BOOL(option.negate, negate, strZ(strNewFmt("check %s negate %d", optionName, negate)));
TEST_RESULT_BOOL(option.reset, reset, strZ(strNewFmt("check %s reset %d", optionName, reset)));
TEST_RESULT_BOOL(option.deprecated, deprecated, strZ(strNewFmt("check %s deprecated %d", optionName, deprecated)));
}
/***********************************************************************************************************************************

View File

@ -203,8 +203,7 @@ testRun(void)
// Storage info list
TEST_RESULT_VOID(
storageInfoListP(storageRemote, NULL, storageTestDummyInfoListCallback, NULL),
"list %" PRIu64 " remote files", fileTotal);
storageInfoListP(storageRemote, NULL, storageTestDummyInfoListCallback, NULL), "list remote files");
TEST_LOG_FMT("list transferred in %ums", (unsigned int)(timeMSec() - timeBegin));

View File

@ -265,9 +265,7 @@ testRun(void)
MEM_CONTEXT_BEGIN(testContext)
{
TEST_ASSIGN(
manifest, manifestNewBuild(storagePg, PG_VERSION_91, 999999999, false, false, NULL, NULL),
"build with %" PRIu64 " files", driver.fileTotal);
TEST_ASSIGN(manifest, manifestNewBuild(storagePg, PG_VERSION_91, 999999999, false, false, NULL, NULL), "build files");
}
MEM_CONTEXT_END();
@ -356,8 +354,8 @@ testRun(void)
for (unsigned int statIdx = 0; statIdx < TEST_STAT_TOTAL; statIdx++)
{
TEST_RESULT_UINT(
varUInt64(kvGet(varKv(kvGet(statKv, VARSTR(statList[statIdx]))), STAT_VALUE_TOTAL_VAR)), runTotal, "check stat %u",
statIdx);
varUInt64(kvGet(varKv(kvGet(statKv, VARSTR(statList[statIdx]))), STAT_VALUE_TOTAL_VAR)), runTotal,
strZ(strNewFmt("check stat %u", statIdx)));
}
}

View File

@ -864,8 +864,9 @@ testRun(void)
TEST_ASSIGN(
client[clientIdx],
protocolClientNew(strNewFmt("test client %u", clientIdx), STRDEF("test"), read, write),
"create client %u", clientIdx);
TEST_RESULT_VOID(protocolParallelClientAdd(parallel, client[clientIdx]), "add client %u", clientIdx);
strZ(strNewFmt("create client %u", clientIdx)));
TEST_RESULT_VOID(
protocolParallelClientAdd(parallel, client[clientIdx]), strZ(strNewFmt("add client %u", clientIdx)));
}
// Attempt to add client without an fd
@ -963,7 +964,7 @@ testRun(void)
TEST_TITLE("free clients");
for (unsigned int clientIdx = 0; clientIdx < clientTotal; clientIdx++)
TEST_RESULT_VOID(protocolClientFree(client[clientIdx]), "free client %u", clientIdx);
TEST_RESULT_VOID(protocolClientFree(client[clientIdx]), strZ(strNewFmt("free client %u", clientIdx)));
}
HARNESS_FORK_PARENT_END();
}