1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-12 10:04:14 +02:00

Allow control version and WAL magic to be overridden in test harness.

This makes it easier to write tests for invalid control version/WAL magic.

Also add HRN_PG_WAL_TO_BUFFER() to simplify generation of WAL headers.
This commit is contained in:
David Steele 2023-03-04 12:50:02 +07:00
parent 1648c133d6
commit c656669ac2
7 changed files with 86 additions and 76 deletions

View File

@ -12,44 +12,44 @@ Harness for PostgreSQL Interface
Interface definition
***********************************************************************************************************************************/
uint32_t hrnPgInterfaceCatalogVersion093(void);
void hrnPgInterfaceControl093(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal093(PgWal pgWal, unsigned char *buffer);
void hrnPgInterfaceControl093(unsigned int controlVersion, PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal093(unsigned int magic, PgWal pgWal, unsigned char *buffer);
uint32_t hrnPgInterfaceCatalogVersion094(void);
void hrnPgInterfaceControl094(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal094(PgWal pgWal, unsigned char *buffer);
void hrnPgInterfaceControl094(unsigned int controlVersion, PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal094(unsigned int magic, PgWal pgWal, unsigned char *buffer);
uint32_t hrnPgInterfaceCatalogVersion095(void);
void hrnPgInterfaceControl095(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal095(PgWal pgWal, unsigned char *buffer);
void hrnPgInterfaceControl095(unsigned int controlVersion, PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal095(unsigned int magic, PgWal pgWal, unsigned char *buffer);
uint32_t hrnPgInterfaceCatalogVersion096(void);
void hrnPgInterfaceControl096(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal096(PgWal pgWal, unsigned char *buffer);
void hrnPgInterfaceControl096(unsigned int controlVersion, PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal096(unsigned int magic, PgWal pgWal, unsigned char *buffer);
uint32_t hrnPgInterfaceCatalogVersion100(void);
void hrnPgInterfaceControl100(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal100(PgWal pgWal, unsigned char *buffer);
void hrnPgInterfaceControl100(unsigned int controlVersion, PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal100(unsigned int magic, PgWal pgWal, unsigned char *buffer);
uint32_t hrnPgInterfaceCatalogVersion110(void);
void hrnPgInterfaceControl110(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal110(PgWal pgWal, unsigned char *buffer);
void hrnPgInterfaceControl110(unsigned int controlVersion, PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal110(unsigned int magic, PgWal pgWal, unsigned char *buffer);
uint32_t hrnPgInterfaceCatalogVersion120(void);
void hrnPgInterfaceControl120(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal120(PgWal pgWal, unsigned char *buffer);
void hrnPgInterfaceControl120(unsigned int controlVersion, PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal120(unsigned int magic, PgWal pgWal, unsigned char *buffer);
uint32_t hrnPgInterfaceCatalogVersion130(void);
void hrnPgInterfaceControl130(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal130(PgWal pgWal, unsigned char *buffer);
void hrnPgInterfaceControl130(unsigned int controlVersion, PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal130(unsigned int magic, PgWal pgWal, unsigned char *buffer);
uint32_t hrnPgInterfaceCatalogVersion140(void);
void hrnPgInterfaceControl140(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal140(PgWal pgWal, unsigned char *buffer);
void hrnPgInterfaceControl140(unsigned int controlVersion, PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal140(unsigned int magic, PgWal pgWal, unsigned char *buffer);
uint32_t hrnPgInterfaceCatalogVersion150(void);
void hrnPgInterfaceControl150(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal150(PgWal pgWal, unsigned char *buffer);
void hrnPgInterfaceControl150(unsigned int controlVersion, PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal150(unsigned int magic, PgWal pgWal, unsigned char *buffer);
typedef struct HrnPgInterface
{
@ -60,10 +60,10 @@ typedef struct HrnPgInterface
unsigned int (*catalogVersion)(void);
// Create pg_control
void (*control)(PgControl, unsigned char *);
void (*control)(unsigned int, PgControl, unsigned char *);
// Create WAL header
void (*wal)(PgWal, unsigned char *);
void (*wal)(unsigned int, PgWal, unsigned char *);
} HrnPgInterface;
static const HrnPgInterface hrnPgInterface[] =
@ -181,9 +181,10 @@ hrnPgCatalogVersion(unsigned int pgVersion)
/**********************************************************************************************************************************/
Buffer *
hrnPgControlToBuffer(PgControl pgControl)
hrnPgControlToBuffer(const unsigned int controlVersion, PgControl pgControl)
{
FUNCTION_HARNESS_BEGIN();
FUNCTION_HARNESS_PARAM(UINT, controlVersion);
FUNCTION_HARNESS_PARAM(PG_CONTROL, pgControl);
FUNCTION_HARNESS_END();
@ -204,18 +205,19 @@ hrnPgControlToBuffer(PgControl pgControl)
bufUsedSet(result, bufSize(result));
// Generate pg_control
hrnPgInterfaceVersion(pgControl.version)->control(pgControl, bufPtr(result));
hrnPgInterfaceVersion(pgControl.version)->control(controlVersion, pgControl, bufPtr(result));
FUNCTION_HARNESS_RETURN(BUFFER, result);
}
/**********************************************************************************************************************************/
void
hrnPgWalToBuffer(PgWal pgWal, Buffer *walBuffer)
hrnPgWalToBuffer(Buffer *const walBuffer, const unsigned int magic, PgWal pgWal)
{
FUNCTION_HARNESS_BEGIN();
FUNCTION_HARNESS_PARAM(PG_WAL, pgWal);
FUNCTION_HARNESS_PARAM(BUFFER, walBuffer);
FUNCTION_HARNESS_PARAM(UINT, magic);
FUNCTION_HARNESS_PARAM(PG_WAL, pgWal);
FUNCTION_HARNESS_END();
ASSERT(walBuffer != NULL);
@ -229,7 +231,7 @@ hrnPgWalToBuffer(PgWal pgWal, Buffer *walBuffer)
pgWal.systemId = hrnPgSystemId(pgWal.version) + pgWal.systemId;
// Generate WAL
hrnPgInterfaceVersion(pgWal.version)->wal(pgWal, bufPtr(walBuffer));
hrnPgInterfaceVersion(pgWal.version)->wal(magic, pgWal, bufPtr(walBuffer));
FUNCTION_HARNESS_RETURN_VOID();
}

View File

@ -45,7 +45,22 @@ Put a control file to storage
***********************************************************************************************************************************/
#define HRN_PG_CONTROL_PUT(storageParam, versionParam, ...) \
HRN_STORAGE_PUT( \
storageParam, PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, hrnPgControlToBuffer((PgControl){.version = versionParam, __VA_ARGS__}))
storageParam, PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, \
hrnPgControlToBuffer(0, (PgControl){.version = versionParam, __VA_ARGS__}))
#define HRN_PG_CONTROL_OVERRIDE_PUT(storageParam, versionParam, controlVersionParam, ...) \
HRN_STORAGE_PUT( \
storageParam, PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, \
hrnPgControlToBuffer(controlVersionParam, (PgControl){.version = versionParam, __VA_ARGS__}))
/***********************************************************************************************************************************
Copy WAL info to buffer
***********************************************************************************************************************************/
#define HRN_PG_WAL_TO_BUFFER(walBufferParam, versionParam, ...) \
hrnPgWalToBuffer(walBufferParam, 0, (PgWal){.version = versionParam, __VA_ARGS__})
#define HRN_PG_WAL_OVERRIDE_TO_BUFFER(walBufferParam, versionParam, magicParam, ...) \
hrnPgWalToBuffer(walBufferParam, magicParam, (PgWal){.version = versionParam, __VA_ARGS__})
/***********************************************************************************************************************************
Update control file time
@ -60,7 +75,7 @@ Functions
unsigned int hrnPgCatalogVersion(unsigned int pgVersion);
// Create pg_control
Buffer *hrnPgControlToBuffer(PgControl pgControl);
Buffer *hrnPgControlToBuffer(unsigned int controlVersion, PgControl pgControl);
// Get system id by version
FN_INLINE_ALWAYS uint64_t
@ -70,6 +85,6 @@ hrnPgSystemId(const unsigned int pgVersion)
}
// Create WAL for testing
void hrnPgWalToBuffer(PgWal pgWal, Buffer *walBuffer);
void hrnPgWalToBuffer(Buffer *walBuffer, unsigned int magic, PgWal pgWal);
#endif

View File

@ -35,14 +35,14 @@ Create a pg_control file
#define HRN_PG_INTERFACE_CONTROL_TEST(version) \
void \
hrnPgInterfaceControl##version(PgControl pgControl, unsigned char *buffer) \
hrnPgInterfaceControl##version(const unsigned int controlVersion, const PgControl pgControl, unsigned char *const buffer) \
{ \
ASSERT(buffer != NULL); \
\
*(ControlFileData *)buffer = (ControlFileData) \
{ \
.system_identifier = pgControl.systemId, \
.pg_control_version = PG_CONTROL_VERSION, \
.pg_control_version = controlVersion == 0 ? PG_CONTROL_VERSION : controlVersion, \
.catalog_version_no = pgControl.catalogVersion, \
.checkPoint = pgControl.checkpoint, \
.checkPointCopy = \
@ -66,9 +66,9 @@ Create a WAL file
#define HRN_PG_INTERFACE_WAL_TEST(version) \
void \
hrnPgInterfaceWal##version(PgWal pgWal, unsigned char *buffer) \
hrnPgInterfaceWal##version(const unsigned int magic, const PgWal pgWal, unsigned char *const buffer) \
{ \
((XLogLongPageHeaderData *)buffer)->std.xlp_magic = XLOG_PAGE_MAGIC; \
((XLogLongPageHeaderData *)buffer)->std.xlp_magic = magic == 0 ? XLOG_PAGE_MAGIC : (uint16)magic; \
((XLogLongPageHeaderData *)buffer)->std.xlp_info = XLP_LONG_HEADER; \
((XLogLongPageHeaderData *)buffer)->xlp_sysid = pgWal.systemId; \
((XLogLongPageHeaderData *)buffer)->xlp_seg_size = pgWal.size; \

View File

@ -72,7 +72,7 @@ testRun(void)
Buffer *walBuffer = bufNew((size_t)16 * 1024 * 1024);
bufUsedSet(walBuffer, bufSize(walBuffer));
memset(bufPtr(walBuffer), 0, bufSize(walBuffer));
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_10}, walBuffer);
HRN_PG_WAL_TO_BUFFER(walBuffer, PG_VERSION_10);
HRN_STORAGE_PUT(storagePgWrite(), "pg_wal/000000010000000100000002", walBuffer);
HRN_STORAGE_PUT(storagePgWrite(), "pg_wal/000000010000000100000003", walBuffer);
@ -301,7 +301,7 @@ testRun(void)
Buffer *walBuffer1 = bufNew((size_t)16 * 1024 * 1024);
bufUsedSet(walBuffer1, bufSize(walBuffer1));
memset(bufPtr(walBuffer1), 0, bufSize(walBuffer1));
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_10}, walBuffer1);
HRN_PG_WAL_TO_BUFFER(walBuffer1, PG_VERSION_10);
HRN_STORAGE_PUT(storagePgWrite(), "pg_wal/000000010000000100000001", walBuffer1);
@ -313,7 +313,7 @@ testRun(void)
" match stanza version 11, system-id " HRN_PG_SYSTEMID_11_Z "");
memset(bufPtr(walBuffer1), 0, bufSize(walBuffer1));
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_11, .systemId = 1}, walBuffer1);
HRN_PG_WAL_TO_BUFFER(walBuffer1, PG_VERSION_11, .systemId = 1);
const char *walBuffer1Sha1 = strZ(strNewEncode(encodingHex, cryptoHashOne(hashTypeSha1, walBuffer1)));
HRN_STORAGE_PUT(storagePgWrite(), "pg_wal/000000010000000100000001", walBuffer1);
@ -347,7 +347,7 @@ testRun(void)
HRN_CFG_LOAD(cfgCmdArchivePush, argListTemp);
memset(bufPtr(walBuffer1), 0, bufSize(walBuffer1));
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_11}, walBuffer1);
HRN_PG_WAL_TO_BUFFER(walBuffer1, PG_VERSION_11);
HRN_STORAGE_PUT(storagePgWrite(), "pg_wal/000000010000000100000001", walBuffer1);
@ -374,7 +374,7 @@ testRun(void)
Buffer *walBuffer2 = bufNew((size_t)16 * 1024 * 1024);
bufUsedSet(walBuffer2, bufSize(walBuffer2));
memset(bufPtr(walBuffer2), 0xFF, bufSize(walBuffer2));
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_11}, walBuffer2);
HRN_PG_WAL_TO_BUFFER(walBuffer2, PG_VERSION_11);
const char *walBuffer2Sha1 = strZ(strNewEncode(encodingHex, cryptoHashOne(hashTypeSha1, walBuffer2)));
HRN_STORAGE_PUT(storagePgWrite(), "pg_wal/000000010000000100000001", walBuffer2);
@ -463,7 +463,7 @@ testRun(void)
walBuffer2 = bufNew(1024);
bufUsedSet(walBuffer2, bufSize(walBuffer2));
memset(bufPtr(walBuffer2), 0xFF, bufSize(walBuffer2));
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_11}, walBuffer2);
HRN_PG_WAL_TO_BUFFER(walBuffer2, PG_VERSION_11);
walBuffer2Sha1 = strZ(strNewEncode(encodingHex, cryptoHashOne(hashTypeSha1, walBuffer2)));
HRN_STORAGE_PUT(storageTest, "pg/pg_wal/000000010000000100000002", walBuffer2, .comment = "write WAL");
@ -757,7 +757,7 @@ testRun(void)
Buffer *walBuffer1 = bufNew((size_t)16 * 1024 * 1024);
bufUsedSet(walBuffer1, bufSize(walBuffer1));
memset(bufPtr(walBuffer1), 0xFF, bufSize(walBuffer1));
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_94}, walBuffer1);
HRN_PG_WAL_TO_BUFFER(walBuffer1, PG_VERSION_94);
const char *walBuffer1Sha1 = strZ(strNewEncode(encodingHex, cryptoHashOne(hashTypeSha1, walBuffer1)));
HRN_STORAGE_PUT(storagePgWrite(),"pg_xlog/000000010000000100000001", walBuffer1);
@ -862,7 +862,7 @@ testRun(void)
Buffer *walBuffer2 = bufNew((size_t)16 * 1024 * 1024);
bufUsedSet(walBuffer2, bufSize(walBuffer2));
memset(bufPtr(walBuffer2), 0x0C, bufSize(walBuffer2));
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_94}, walBuffer2);
HRN_PG_WAL_TO_BUFFER(walBuffer2, PG_VERSION_94);
const char *walBuffer2Sha1 = strZ(strNewEncode(encodingHex, cryptoHashOne(hashTypeSha1, walBuffer2)));
HRN_STORAGE_PUT(storagePgWrite(), "pg_xlog/000000010000000100000002", walBuffer2);
@ -911,7 +911,7 @@ testRun(void)
Buffer *walBuffer3 = bufNew((size_t)16 * 1024 * 1024);
bufUsedSet(walBuffer3, bufSize(walBuffer3));
memset(bufPtr(walBuffer3), 0x44, bufSize(walBuffer3));
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_94}, walBuffer3);
HRN_PG_WAL_TO_BUFFER(walBuffer3, PG_VERSION_94);
const char *walBuffer3Sha1 = strZ(strNewEncode(encodingHex, cryptoHashOne(hashTypeSha1, walBuffer3)));
HRN_STORAGE_PUT(storagePgWrite(), "pg_xlog/000000010000000100000003", walBuffer3);

View File

@ -497,7 +497,7 @@ testBackupPqScript(unsigned int pgVersion, time_t backupTimeStart, TestBackupPqS
pgControl.timeline = param.timeline;
HRN_STORAGE_PUT(
storagePgIdxWrite(0), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, hrnPgControlToBuffer(pgControl),
storagePgIdxWrite(0), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, hrnPgControlToBuffer(0, pgControl),
.timeModified = backupTimeStart);
// Update pg_control on primary with the backup time
@ -518,7 +518,7 @@ testBackupPqScript(unsigned int pgVersion, time_t backupTimeStart, TestBackupPqS
Buffer *walBuffer = bufNew((size_t)pgControl.walSegmentSize);
bufUsedSet(walBuffer, bufSize(walBuffer));
memset(bufPtr(walBuffer), 0, bufSize(walBuffer));
hrnPgWalToBuffer((PgWal){.version = pgControl.version, .systemId = pgControl.systemId}, walBuffer);
HRN_PG_WAL_TO_BUFFER(walBuffer, pgControl.version, .systemId = pgControl.systemId);
const String *walChecksum = strNewEncode(encodingHex, cryptoHashOne(hashTypeSha1, walBuffer));
for (unsigned int walSegmentIdx = 0; walSegmentIdx < strLstSize(walSegmentList); walSegmentIdx++)
@ -620,7 +620,7 @@ testBackupPqScript(unsigned int pgVersion, time_t backupTimeStart, TestBackupPqS
ASSERT(!param.noArchiveCheck);
// Save pg_control with updated info
HRN_STORAGE_PUT(storagePgIdxWrite(1), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, hrnPgControlToBuffer(pgControl));
HRN_STORAGE_PUT(storagePgIdxWrite(1), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, hrnPgControlToBuffer(0, pgControl));
if (param.noPriorWal)
{

View File

@ -926,7 +926,7 @@ testRun(void)
Buffer *walBuffer = bufNew((size_t)(1024 * 1024));
bufUsedSet(walBuffer, bufSize(walBuffer));
memset(bufPtr(walBuffer), 0, bufSize(walBuffer));
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_11, .size = 1024 * 1024}, walBuffer);
HRN_PG_WAL_TO_BUFFER(walBuffer, PG_VERSION_11, .size = 1024 * 1024);
const char *walBufferSha1 = strZ(strNewEncode(encodingHex, cryptoHashOne(hashTypeSha1, walBuffer)));
HRN_STORAGE_PUT(
@ -1567,7 +1567,7 @@ testRun(void)
Buffer *walBuffer = bufNew((size_t)(1024 * 1024));
bufUsedSet(walBuffer, bufSize(walBuffer));
memset(bufPtr(walBuffer), 0, bufSize(walBuffer));
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_11, .size = 1024 * 1024}, walBuffer);
HRN_PG_WAL_TO_BUFFER(walBuffer, PG_VERSION_11, .size = 1024 * 1024);
const char *walBufferSha1 = strZ(strNewEncode(encodingHex, cryptoHashOne(hashTypeSha1, walBuffer)));
HRN_STORAGE_PUT(
@ -1781,7 +1781,7 @@ testRun(void)
Buffer *walBuffer = bufNew((size_t)(1024 * 1024));
bufUsedSet(walBuffer, bufSize(walBuffer));
memset(bufPtr(walBuffer), 0, bufSize(walBuffer));
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_11, .size = 1024 * 1024}, walBuffer);
HRN_PG_WAL_TO_BUFFER(walBuffer, PG_VERSION_11, .size = 1024 * 1024);
const char *walBufferSha1 = strZ(strNewEncode(encodingHex, cryptoHashOne(hashTypeSha1, walBuffer)));
HRN_STORAGE_PUT(
@ -1852,7 +1852,7 @@ testRun(void)
Buffer *walBuffer = bufNew((size_t)(1024 * 1024));
bufUsedSet(walBuffer, bufSize(walBuffer));
memset(bufPtr(walBuffer), 0, bufSize(walBuffer));
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_11, .size = 1024 * 1024}, walBuffer);
HRN_PG_WAL_TO_BUFFER(walBuffer, PG_VERSION_11, .size = 1024 * 1024);
const char *walBufferSha1 = strZ(strNewEncode(encodingHex, cryptoHashOne(hashTypeSha1, walBuffer)));
HRN_STORAGE_PUT(
@ -1907,7 +1907,7 @@ testRun(void)
Buffer *walBuffer = bufNew((size_t)(1024 * 1024));
bufUsedSet(walBuffer, bufSize(walBuffer));
memset(bufPtr(walBuffer), 0, bufSize(walBuffer));
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_11, .size = 1024 * 1024}, walBuffer);
HRN_PG_WAL_TO_BUFFER(walBuffer, PG_VERSION_11, .size = 1024 * 1024);
const char *walBufferSha1 = strZ(strNewEncode(encodingHex, cryptoHashOne(hashTypeSha1, walBuffer)));
HRN_STORAGE_PUT(

View File

@ -62,20 +62,14 @@ testRun(void)
TEST_RESULT_UINT(pgInterface[0].version, PG_VERSION_MAX, "check max version");
// -------------------------------------------------------------------------------------------------------------------------
// Create a bogus control file
Buffer *result = bufNew(HRN_PG_CONTROL_SIZE);
memset(bufPtr(result), 0, bufSize(result));
bufUsedSet(result, bufSize(result));
TEST_TITLE("unknown control version");
*(PgControlCommon *)bufPtr(result) = (PgControlCommon)
{
.controlVersion = 501,
.catalogVersion = 19780101,
};
HRN_PG_CONTROL_OVERRIDE_PUT(storageTest, PG_VERSION_15, 1501, .catalogVersion = 202211110);
TEST_ERROR(
pgControlFromBuffer(result), VersionNotSupportedError,
"unexpected control version = 501 and catalog version = 19780101\nHINT: is this version of PostgreSQL supported?");
pgControlFromFile(storageTest), VersionNotSupportedError,
"unexpected control version = 1501 and catalog version = 202211110\n"
"HINT: is this version of PostgreSQL supported?");
// -------------------------------------------------------------------------------------------------------------------------
HRN_PG_CONTROL_PUT(
@ -184,29 +178,29 @@ testRun(void)
{
const String *walFile = STRDEF(TEST_PATH "/0000000F0000000F0000000F");
// Create a bogus control file, initially not in long format)
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("unknown WAL magic");
Buffer *result = bufNew((size_t)16 * 1024 * 1024);
memset(bufPtr(result), 0, bufSize(result));
bufUsedSet(result, bufSize(result));
*(PgWalCommon *)bufPtr(result) = (PgWalCommon){.magic = 777};
TEST_ERROR(pgWalFromBuffer(result), FormatError, "first page header in WAL file is expected to be in long format");
// Add the long flag so that the version will now error
// -------------------------------------------------------------------------------------------------------------------------
((PgWalCommon *)bufPtr(result))->flag = PG_WAL_LONG_HEADER;
HRN_PG_WAL_OVERRIDE_TO_BUFFER(result, PG_VERSION_15, 777);
TEST_ERROR(
pgWalFromBuffer(result), VersionNotSupportedError,
"unexpected WAL magic 777\n"
"HINT: is this version of PostgreSQL supported?");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("invalid wal flag");
((PgWalCommon *)bufPtr(result))->flag = 0;
TEST_ERROR(pgWalFromBuffer(result), FormatError, "first page header in WAL file is expected to be in long format");
// -------------------------------------------------------------------------------------------------------------------------
memset(bufPtr(result), 0, bufSize(result));
hrnPgWalToBuffer(
(PgWal){.version = PG_VERSION_11, .systemId = 0xECAFECAF, .size = PG_WAL_SEGMENT_SIZE_DEFAULT * 2}, result);
HRN_PG_WAL_TO_BUFFER(result, PG_VERSION_11, .systemId = 0xECAFECAF, .size = PG_WAL_SEGMENT_SIZE_DEFAULT * 2);
storagePutP(storageNewWriteP(storageTest, walFile), result);
PgWal info = {0};
@ -217,14 +211,13 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
memset(bufPtr(result), 0, bufSize(result));
hrnPgWalToBuffer(
(PgWal){.version = PG_VERSION_96, .systemId = 0xEAEAEAEA, .size = PG_WAL_SEGMENT_SIZE_DEFAULT * 2}, result);
HRN_PG_WAL_TO_BUFFER(result, PG_VERSION_96, .systemId = 0xEAEAEAEA, .size = PG_WAL_SEGMENT_SIZE_DEFAULT * 2);
TEST_ERROR(pgWalFromBuffer(result), FormatError, "wal segment size is 33554432 but must be 16777216 for PostgreSQL <= 10");
// -------------------------------------------------------------------------------------------------------------------------
memset(bufPtr(result), 0, bufSize(result));
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_93, .systemId = 0xEAEAEAEA, .size = PG_WAL_SEGMENT_SIZE_DEFAULT}, result);
HRN_PG_WAL_TO_BUFFER(result, PG_VERSION_93, .systemId = 0xEAEAEAEA, .size = PG_WAL_SEGMENT_SIZE_DEFAULT);
storagePutP(storageNewWriteP(storageTest, walFile), result);
TEST_ASSIGN(info, pgWalFromFile(walFile, storageTest), "get wal info v9.3");