1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-03 00:26:59 +02:00

Move PostgreSQL version interface test functions to a test harness.

Some version interface test functions were integrated into the core code because they relied on the PostgreSQL versioned interface. Even though they were compiled out for production builds they cluttered the core code and made it harder to determine what was required by core.

Create a PostgreSQL version interface in a test harness to contain these functions. This does require some duplication but the cleaner core code seems a good tradeoff. It is possible for some of this code to be auto-generated but since it is only updated once per year the matter is not pressing.
This commit is contained in:
David Steele
2021-05-17 07:20:28 -04:00
parent 18cc02238b
commit ae7f0af202
33 changed files with 664 additions and 426 deletions

View File

@ -43,10 +43,9 @@ STRING_STATIC(PG_NAME_LSN_STR, "lsn");
STRING_STATIC(PG_NAME_LOCATION_STR, "location");
/***********************************************************************************************************************************
Control file size. The control file is actually 8192 bytes but only the first 512 bytes are used to prevent torn pages even on
really old storage with 512-byte sectors. This is true across all versions of PostgreSQL.
The control file is 8192 bytes but only the first 512 bytes are used to prevent torn pages even on really old storage with 512-byte
sectors. This is true across all versions of PostgreSQL.
***********************************************************************************************************************************/
#define PG_CONTROL_SIZE ((unsigned int)(8 * 1024))
#define PG_CONTROL_DATA_SIZE 512
/***********************************************************************************************************************************
@ -75,17 +74,6 @@ typedef struct PgInterface
// Convert WAL header to a common data structure
PgWal (*wal)(const unsigned char *);
#ifdef DEBUG
// Catalog version for testing
unsigned int catalogVersion;
// Create pg_control for testing
void (*controlTest)(PgControl, unsigned char *);
// Create WAL header for testing
void (*walTest)(PgWal, unsigned char *);
#endif
} PgInterface;
static const PgInterface pgInterface[] =
@ -99,13 +87,6 @@ static const PgInterface pgInterface[] =
.walIs = pgInterfaceWalIs130,
.wal = pgInterfaceWal130,
#ifdef DEBUG
.catalogVersion = 202007201,
.controlTest = pgInterfaceControlTest130,
.walTest = pgInterfaceWalTest130,
#endif
},
{
.version = PG_VERSION_12,
@ -116,13 +97,6 @@ static const PgInterface pgInterface[] =
.walIs = pgInterfaceWalIs120,
.wal = pgInterfaceWal120,
#ifdef DEBUG
.catalogVersion = 201909212,
.controlTest = pgInterfaceControlTest120,
.walTest = pgInterfaceWalTest120,
#endif
},
{
.version = PG_VERSION_11,
@ -133,13 +107,6 @@ static const PgInterface pgInterface[] =
.walIs = pgInterfaceWalIs110,
.wal = pgInterfaceWal110,
#ifdef DEBUG
.catalogVersion = 201809051,
.controlTest = pgInterfaceControlTest110,
.walTest = pgInterfaceWalTest110,
#endif
},
{
.version = PG_VERSION_10,
@ -150,13 +117,6 @@ static const PgInterface pgInterface[] =
.walIs = pgInterfaceWalIs100,
.wal = pgInterfaceWal100,
#ifdef DEBUG
.catalogVersion = 201707211,
.controlTest = pgInterfaceControlTest100,
.walTest = pgInterfaceWalTest100,
#endif
},
{
.version = PG_VERSION_96,
@ -167,13 +127,6 @@ static const PgInterface pgInterface[] =
.walIs = pgInterfaceWalIs096,
.wal = pgInterfaceWal096,
#ifdef DEBUG
.catalogVersion = 201608131,
.controlTest = pgInterfaceControlTest096,
.walTest = pgInterfaceWalTest096,
#endif
},
{
.version = PG_VERSION_95,
@ -184,13 +137,6 @@ static const PgInterface pgInterface[] =
.walIs = pgInterfaceWalIs095,
.wal = pgInterfaceWal095,
#ifdef DEBUG
.catalogVersion = 201510051,
.controlTest = pgInterfaceControlTest095,
.walTest = pgInterfaceWalTest095,
#endif
},
{
.version = PG_VERSION_94,
@ -201,13 +147,6 @@ static const PgInterface pgInterface[] =
.walIs = pgInterfaceWalIs094,
.wal = pgInterfaceWal094,
#ifdef DEBUG
.catalogVersion = 201409291,
.controlTest = pgInterfaceControlTest094,
.walTest = pgInterfaceWalTest094,
#endif
},
{
.version = PG_VERSION_93,
@ -218,13 +157,6 @@ static const PgInterface pgInterface[] =
.walIs = pgInterfaceWalIs093,
.wal = pgInterfaceWal093,
#ifdef DEBUG
.catalogVersion = 201306121,
.controlTest = pgInterfaceControlTest093,
.walTest = pgInterfaceWalTest093,
#endif
},
{
.version = PG_VERSION_92,
@ -235,13 +167,6 @@ static const PgInterface pgInterface[] =
.walIs = pgInterfaceWalIs092,
.wal = pgInterfaceWal092,
#ifdef DEBUG
.catalogVersion = 201204301,
.controlTest = pgInterfaceControlTest092,
.walTest = pgInterfaceWalTest092,
#endif
},
{
.version = PG_VERSION_91,
@ -252,13 +177,6 @@ static const PgInterface pgInterface[] =
.walIs = pgInterfaceWalIs091,
.wal = pgInterfaceWal091,
#ifdef DEBUG
.catalogVersion = 201105231,
.controlTest = pgInterfaceControlTest091,
.walTest = pgInterfaceWalTest091,
#endif
},
{
.version = PG_VERSION_90,
@ -269,13 +187,6 @@ static const PgInterface pgInterface[] =
.walIs = pgInterfaceWalIs090,
.wal = pgInterfaceWal090,
#ifdef DEBUG
.catalogVersion = 201008051,
.controlTest = pgInterfaceControlTest090,
.walTest = pgInterfaceWalTest090,
#endif
},
{
.version = PG_VERSION_84,
@ -286,13 +197,6 @@ static const PgInterface pgInterface[] =
.walIs = pgInterfaceWalIs084,
.wal = pgInterfaceWal084,
#ifdef DEBUG
.catalogVersion = 200904091,
.controlTest = pgInterfaceControlTest084,
.walTest = pgInterfaceWalTest084,
#endif
},
{
.version = PG_VERSION_83,
@ -303,13 +207,6 @@ static const PgInterface pgInterface[] =
.walIs = pgInterfaceWalIs083,
.wal = pgInterfaceWal083,
#ifdef DEBUG
.catalogVersion = 200711281,
.controlTest = pgInterfaceControlTest083,
.walTest = pgInterfaceWalTest083,
#endif
},
};
@ -739,75 +636,6 @@ pgXactPath(unsigned int pgVersion)
FUNCTION_TEST_RETURN(pgVersion >= PG_VERSION_WAL_RENAME ? PG_PATH_PGXACT_STR : PG_PATH_PGCLOG_STR);
}
/**********************************************************************************************************************************/
#ifdef DEBUG
unsigned int
pgCatalogTestVersion(unsigned int pgVersion)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(UINT, pgVersion);
FUNCTION_TEST_END();
FUNCTION_TEST_RETURN(pgInterfaceVersion(pgVersion)->catalogVersion);
}
#endif
/**********************************************************************************************************************************/
#ifdef DEBUG
Buffer *
pgControlTestToBuffer(PgControl pgControl)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(PG_CONTROL, pgControl);
FUNCTION_TEST_END();
// Set defaults if values are not passed
pgControl.pageSize = pgControl.pageSize == 0 ? PG_PAGE_SIZE_DEFAULT : pgControl.pageSize;
pgControl.walSegmentSize = pgControl.walSegmentSize == 0 ? PG_WAL_SEGMENT_SIZE_DEFAULT : pgControl.walSegmentSize;
pgControl.catalogVersion = pgControl.catalogVersion == 0 ?
pgInterfaceVersion(pgControl.version)->catalogVersion : pgControl.catalogVersion;
// Create the buffer and clear it
Buffer *result = bufNew(PG_CONTROL_SIZE);
memset(bufPtr(result), 0, bufSize(result));
bufUsedSet(result, bufSize(result));
// Generate pg_control
pgInterfaceVersion(pgControl.version)->controlTest(pgControl, bufPtr(result));
FUNCTION_TEST_RETURN(result);
}
#endif
/**********************************************************************************************************************************/
#ifdef DEBUG
void
pgWalTestToBuffer(PgWal pgWal, Buffer *walBuffer)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(PG_WAL, pgWal);
FUNCTION_TEST_PARAM(BUFFER, walBuffer);
FUNCTION_TEST_END();
ASSERT(walBuffer != NULL);
// Set default WAL segment size if not specified
if (pgWal.size == 0)
pgWal.size = PG_WAL_SEGMENT_SIZE_DEFAULT;
// Generate WAL
pgInterfaceVersion(pgWal.version)->walTest(pgWal, bufPtr(walBuffer));
FUNCTION_TEST_RETURN_VOID();
}
#endif
/**********************************************************************************************************************************/
unsigned int
pgVersionFromStr(const String *version)

View File

@ -168,20 +168,6 @@ const String *pgWalPath(unsigned int pgVersion);
// Get transaction commit log path (this was changed in PostgreSQL 10 to avoid including "log" in the name)
const String *pgXactPath(unsigned int pgVersion);
/***********************************************************************************************************************************
Test Functions
***********************************************************************************************************************************/
#ifdef DEBUG
// Get the catalog version for a PostgreSQL version for testing
unsigned int pgCatalogTestVersion(unsigned int pgVersion);
// Create pg_control for testing
Buffer *pgControlTestToBuffer(PgControl pgControl);
// Create WAL for testing
void pgWalTestToBuffer(PgWal pgWal, Buffer *walBuffer);
#endif
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/

View File

@ -87,48 +87,4 @@ uint32_t pgInterfaceControlVersion130(void);
bool pgInterfaceWalIs130(const unsigned char *walFile);
PgWal pgInterfaceWal130(const unsigned char *controlFile);
/***********************************************************************************************************************************
Test Functions
***********************************************************************************************************************************/
#ifdef DEBUG
void pgInterfaceControlTest083(PgControl pgControl, unsigned char *buffer);
void pgInterfaceWalTest083(PgWal pgWal, unsigned char *buffer);
void pgInterfaceControlTest084(PgControl pgControl, unsigned char *buffer);
void pgInterfaceWalTest084(PgWal pgWal, unsigned char *buffer);
void pgInterfaceControlTest090(PgControl pgControl, unsigned char *buffer);
void pgInterfaceWalTest090(PgWal pgWal, unsigned char *buffer);
void pgInterfaceControlTest091(PgControl pgControl, unsigned char *buffer);
void pgInterfaceWalTest091(PgWal pgWal, unsigned char *buffer);
void pgInterfaceControlTest092(PgControl pgControl, unsigned char *buffer);
void pgInterfaceWalTest092(PgWal pgWal, unsigned char *buffer);
void pgInterfaceControlTest093(PgControl pgControl, unsigned char *buffer);
void pgInterfaceWalTest093(PgWal pgWal, unsigned char *buffer);
void pgInterfaceControlTest094(PgControl pgControl, unsigned char *buffer);
void pgInterfaceWalTest094(PgWal pgWal, unsigned char *buffer);
void pgInterfaceControlTest095(PgControl pgControl, unsigned char *buffer);
void pgInterfaceWalTest095(PgWal pgWal, unsigned char *buffer);
void pgInterfaceControlTest096(PgControl pgControl, unsigned char *buffer);
void pgInterfaceWalTest096(PgWal pgWal, unsigned char *buffer);
void pgInterfaceControlTest100(PgControl pgControl, unsigned char *buffer);
void pgInterfaceWalTest100(PgWal pgWal, unsigned char *buffer);
void pgInterfaceControlTest110(PgControl pgControl, unsigned char *buffer);
void pgInterfaceWalTest110(PgWal pgWal, unsigned char *buffer);
void pgInterfaceControlTest120(PgControl pgControl, unsigned char *buffer);
void pgInterfaceWalTest120(PgWal pgWal, unsigned char *buffer);
void pgInterfaceControlTest130(PgControl pgControl, unsigned char *buffer);
void pgInterfaceWalTest130(PgWal pgWal, unsigned char *buffer);
#endif
#endif

View File

@ -97,51 +97,6 @@ Get the control version
#endif
/***********************************************************************************************************************************
Create a pg_control file for testing
***********************************************************************************************************************************/
#if PG_VERSION > PG_VERSION_MAX
#elif PG_VERSION >= PG_VERSION_93
#define PG_INTERFACE_CONTROL_TEST(version) \
void \
pgInterfaceControlTest##version(PgControl pgControl, unsigned char *buffer) \
{ \
ASSERT(buffer != NULL); \
\
*(ControlFileData *)buffer = (ControlFileData) \
{ \
.system_identifier = pgControl.systemId, \
.pg_control_version = PG_CONTROL_VERSION, \
.catalog_version_no = pgControl.catalogVersion, \
.blcksz = pgControl.pageSize, \
.xlog_seg_size = pgControl.walSegmentSize, \
.data_checksum_version = pgControl.pageChecksum, \
}; \
}
#elif PG_VERSION >= PG_VERSION_83
#define PG_INTERFACE_CONTROL_TEST(version) \
void \
pgInterfaceControlTest##version(PgControl pgControl, unsigned char *buffer) \
{ \
ASSERT(buffer != NULL); \
ASSERT(!pgControl.pageChecksum); \
\
*(ControlFileData *)buffer = (ControlFileData) \
{ \
.system_identifier = pgControl.systemId, \
.pg_control_version = PG_CONTROL_VERSION, \
.catalog_version_no = pgControl.catalogVersion, \
.blcksz = pgControl.pageSize, \
.xlog_seg_size = pgControl.walSegmentSize, \
}; \
}
#endif
/***********************************************************************************************************************************
Determine if the supplied WAL is for this version of PostgreSQL
***********************************************************************************************************************************/
@ -183,47 +138,14 @@ Read the version specific WAL header into a general data structure
#endif
/***********************************************************************************************************************************
Create a WAL file file for testing
***********************************************************************************************************************************/
#if PG_VERSION > PG_VERSION_MAX
#elif PG_VERSION >= PG_VERSION_83
#define PG_INTERFACE_WAL_TEST(version) \
void \
pgInterfaceWalTest##version(PgWal pgWal, unsigned char *buffer) \
{ \
((XLogLongPageHeaderData *)buffer)->std.xlp_magic = XLOG_PAGE_MAGIC; \
((XLogLongPageHeaderData *)buffer)->std.xlp_info = XLP_LONG_HEADER; \
((XLogLongPageHeaderData *)buffer)->xlp_sysid = pgWal.systemId; \
((XLogLongPageHeaderData *)buffer)->xlp_seg_size = pgWal.size; \
}
#endif
/***********************************************************************************************************************************
Call all macros with a single macro to make the vXXX.c files as simple as possible
***********************************************************************************************************************************/
#define PG_INTERFACE_BASE(version) \
#define PG_INTERFACE(version) \
PG_INTERFACE_CONTROL_IS(version) \
PG_INTERFACE_CONTROL(version) \
PG_INTERFACE_CONTROL_VERSION(version) \
PG_INTERFACE_WAL_IS(version) \
PG_INTERFACE_WAL(version)
#ifdef DEBUG
#define PG_INTERFACE(version) \
PG_INTERFACE_BASE(version) \
PG_INTERFACE_CONTROL_TEST(version) \
PG_INTERFACE_WAL_TEST(version)
#else
#define PG_INTERFACE(version) \
PG_INTERFACE_BASE(version)
#endif
#endif