You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-13 01:00:23 +02:00
Ensure ASSERT() macro is always available in test modules.
Tests that run without DEBUG for performance did not have ASSERT() and were using CHECK() instead. Instead ensure that the ASSERT() macro is always available in tests.
This commit is contained in:
@ -96,6 +96,7 @@ unit:
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------------
|
||||
- name: assert-on
|
||||
feature: assert
|
||||
total: 1
|
||||
|
||||
coverage:
|
||||
|
@ -371,7 +371,7 @@ hrnLogReplace(void)
|
||||
int diff = (int)strSize(replace) - (int)strSize(match);
|
||||
|
||||
// Make sure we won't overflow the buffer
|
||||
CHECK((size_t)((int)strlen(harnessLogBuffer) + diff) < sizeof(harnessLogBuffer) - 1);
|
||||
ASSERT((size_t)((int)strlen(harnessLogBuffer) + diff) < sizeof(harnessLogBuffer) - 1);
|
||||
|
||||
// Move data from end of string enough to make room for the replacement and copy replacement
|
||||
memmove(end + diff, end, strlen(end) + 1);
|
||||
|
@ -6,6 +6,7 @@ C Test Harness
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/debug.h"
|
||||
#include "common/error.h"
|
||||
|
||||
@ -16,6 +17,21 @@ Constants
|
||||
***********************************************************************************************************************************/
|
||||
#define BOGUS_STR "BOGUS"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Make sure ASSERT() always exists for tests to use, even when DEBUG is disabled for performance
|
||||
***********************************************************************************************************************************/
|
||||
#ifdef HRN_FEATURE_ASSERT
|
||||
#undef ASSERT
|
||||
|
||||
#define ASSERT(condition) \
|
||||
do \
|
||||
{ \
|
||||
if (!(condition)) \
|
||||
THROW_FMT(AssertError, "assertion '%s' failed", #condition); \
|
||||
} \
|
||||
while (0)
|
||||
#endif
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Functions
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -149,7 +149,7 @@ testRun(void)
|
||||
TEST_TITLE_FMT("list %d million files", TEST_SCALE);
|
||||
|
||||
// One million files represents a fairly large cluster
|
||||
CHECK(TEST_SCALE <= 2000);
|
||||
ASSERT(TEST_SCALE <= 2000);
|
||||
uint64_t fileTotal = (uint64_t)1000000 * TEST_SCALE;
|
||||
|
||||
HRN_FORK_BEGIN(.timeout = 60000)
|
||||
@ -225,7 +225,7 @@ testRun(void)
|
||||
ioBufferSizeSet(4 * 1024 * 1024);
|
||||
|
||||
// 1MB is a fairly normal table size
|
||||
CHECK(TEST_SCALE <= 1024 * 1024 * 1024);
|
||||
ASSERT(TEST_SCALE <= 1024 * 1024 * 1024);
|
||||
uint64_t blockTotal = (uint64_t)1 * TEST_SCALE;
|
||||
|
||||
// Set iteration
|
||||
|
@ -155,7 +155,7 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("lstFind()"))
|
||||
{
|
||||
CHECK(TEST_SCALE <= 10000);
|
||||
ASSERT(TEST_SCALE <= 10000);
|
||||
int testMax = 100000 * (int)TEST_SCALE;
|
||||
|
||||
// Generate a large list of values (use int instead of string so there fewer allocations)
|
||||
@ -164,7 +164,7 @@ testRun(void)
|
||||
for (int listIdx = 0; listIdx < testMax; listIdx++)
|
||||
lstAdd(list, &listIdx);
|
||||
|
||||
CHECK(lstSize(list) == (unsigned int)testMax);
|
||||
ASSERT(lstSize(list) == (unsigned int)testMax);
|
||||
|
||||
TEST_LOG_FMT("generated %d item list", testMax);
|
||||
|
||||
@ -174,7 +174,7 @@ testRun(void)
|
||||
TimeMSec timeBegin = timeMSec();
|
||||
|
||||
for (int listIdx = 0; listIdx < testMax; listIdx++)
|
||||
CHECK(*(int *)lstFind(list, &listIdx) == listIdx);
|
||||
ASSERT(*(int *)lstFind(list, &listIdx) == listIdx);
|
||||
|
||||
TEST_LOG_FMT("asc search completed in %ums", (unsigned int)(timeMSec() - timeBegin));
|
||||
|
||||
@ -184,7 +184,7 @@ testRun(void)
|
||||
timeBegin = timeMSec();
|
||||
|
||||
for (int listIdx = 0; listIdx < testMax; listIdx++)
|
||||
CHECK(*(int *)lstFind(list, &listIdx) == listIdx);
|
||||
ASSERT(*(int *)lstFind(list, &listIdx) == listIdx);
|
||||
|
||||
TEST_LOG_FMT("desc search completed in %ums", (unsigned int)(timeMSec() - timeBegin));
|
||||
}
|
||||
@ -192,7 +192,7 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("lstRemoveIdx()"))
|
||||
{
|
||||
CHECK(TEST_SCALE <= 10000);
|
||||
ASSERT(TEST_SCALE <= 10000);
|
||||
int testMax = 1000000 * (int)TEST_SCALE;
|
||||
|
||||
// Generate a large list of values (use int instead of string so there fewer allocations)
|
||||
@ -201,7 +201,7 @@ testRun(void)
|
||||
for (int listIdx = 0; listIdx < testMax; listIdx++)
|
||||
lstAdd(list, &listIdx);
|
||||
|
||||
CHECK(lstSize(list) == (unsigned int)testMax);
|
||||
ASSERT(lstSize(list) == (unsigned int)testMax);
|
||||
|
||||
TEST_LOG_FMT("generated %d item list", testMax);
|
||||
|
||||
@ -213,13 +213,13 @@ testRun(void)
|
||||
|
||||
TEST_LOG_FMT("remove completed in %ums", (unsigned int)(timeMSec() - timeBegin));
|
||||
|
||||
CHECK(lstEmpty(list));
|
||||
ASSERT(lstEmpty(list));
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("iniLoad()"))
|
||||
{
|
||||
CHECK(TEST_SCALE <= 10000);
|
||||
ASSERT(TEST_SCALE <= 10000);
|
||||
|
||||
String *iniStr = strCatZ(strNew(), "[section1]\n");
|
||||
unsigned int iniMax = 100000 * (unsigned int)TEST_SCALE;
|
||||
@ -242,7 +242,7 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("manifestNewBuild()/manifestNewLoad()/manifestSave()"))
|
||||
{
|
||||
CHECK(TEST_SCALE <= 1000000);
|
||||
ASSERT(TEST_SCALE <= 1000000);
|
||||
|
||||
// Create a storage driver to test manifest build with an arbitrary number of files
|
||||
StorageTestManifestNewBuild driver =
|
||||
@ -314,7 +314,7 @@ testRun(void)
|
||||
for (unsigned int fileIdx = 0; fileIdx < manifestFileTotal(manifest); fileIdx++)
|
||||
{
|
||||
const ManifestFile *file = manifestFile(manifest, fileIdx);
|
||||
CHECK(file == manifestFileFind(manifest, file->name));
|
||||
ASSERT(file == manifestFileFind(manifest, file->name));
|
||||
}
|
||||
|
||||
TEST_LOG_FMT("completed in %ums", (unsigned int)(timeMSec() - timeBegin));
|
||||
@ -324,7 +324,7 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("statistics collector"))
|
||||
{
|
||||
CHECK(TEST_SCALE <= 1000000);
|
||||
ASSERT(TEST_SCALE <= 1000000);
|
||||
|
||||
// Setup a list of stats to use for testing
|
||||
#define TEST_STAT_TOTAL 100
|
||||
|
Reference in New Issue
Block a user