1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-05 00:28:52 +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

View File

@ -432,6 +432,7 @@ unit:
# ----------------------------------------------------------------------------------------------------------------------------
- name: interface
total: 9
harness: postgres
coverage:
- postgres/interface

View File

@ -348,9 +348,32 @@ sub run
my @stryHarnessFile = ('common/harnessTest');
foreach my $strFile (@{$hTest->{&TESTDEF_HARNESS}})
foreach my $strHarness (@{$hTest->{&TESTDEF_HARNESS}})
{
push(@stryHarnessFile, "common/harness" . ucfirst($strFile));
my $bFound = false;
my $strFile = "common/harness" . ucfirst($strHarness);
# Include harness file if present
if ($self->{oStorageTest}->exists("${strRepoCopyTestSrcPath}/${strFile}.c"))
{
push(@stryHarnessFile, $strFile);
$bFound = true;
}
# Include files in the harness directory if present
for my $strFileSub (
$self->{oStorageTest}->list("${strRepoCopyTestSrcPath}/${strFile}",
{bIgnoreMissing => true, strExpression => '\.c$'}))
{
push(@stryHarnessFile, "${strFile}/" . substr($strFileSub, 0, length($strFileSub) - 2));
$bFound = true;
}
# Error when no harness files were found
if (!$bFound)
{
confess &log(ERROR, "no files found for harness '${strHarness}'");
}
}
# Generate list of core files (files to be tested/included in this unit will be excluded)

View File

@ -0,0 +1,258 @@
/***********************************************************************************************************************************
Harness for PostgreSQL Interface
***********************************************************************************************************************************/
#include "build.auto.h"
#include "common/assert.h"
#include "common/harnessDebug.h"
#include "common/harnessPostgres.h"
/***********************************************************************************************************************************
Interface definition
***********************************************************************************************************************************/
uint32_t hrnPgInterfaceCatalogVersion083(void);
void hrnPgInterfaceControl083(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal083(PgWal pgWal, unsigned char *buffer);
uint32_t hrnPgInterfaceCatalogVersion084(void);
void hrnPgInterfaceControl084(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal084(PgWal pgWal, unsigned char *buffer);
uint32_t hrnPgInterfaceCatalogVersion090(void);
void hrnPgInterfaceControl090(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal090(PgWal pgWal, unsigned char *buffer);
uint32_t hrnPgInterfaceCatalogVersion091(void);
void hrnPgInterfaceControl091(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal091(PgWal pgWal, unsigned char *buffer);
uint32_t hrnPgInterfaceCatalogVersion092(void);
void hrnPgInterfaceControl092(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal092(PgWal pgWal, unsigned char *buffer);
uint32_t hrnPgInterfaceCatalogVersion093(void);
void hrnPgInterfaceControl093(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal093(PgWal pgWal, unsigned char *buffer);
uint32_t hrnPgInterfaceCatalogVersion094(void);
void hrnPgInterfaceControl094(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal094(PgWal pgWal, unsigned char *buffer);
uint32_t hrnPgInterfaceCatalogVersion095(void);
void hrnPgInterfaceControl095(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal095(PgWal pgWal, unsigned char *buffer);
uint32_t hrnPgInterfaceCatalogVersion096(void);
void hrnPgInterfaceControl096(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal096(PgWal pgWal, unsigned char *buffer);
uint32_t hrnPgInterfaceCatalogVersion100(void);
void hrnPgInterfaceControl100(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal100(PgWal pgWal, unsigned char *buffer);
uint32_t hrnPgInterfaceCatalogVersion110(void);
void hrnPgInterfaceControl110(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal110(PgWal pgWal, unsigned char *buffer);
uint32_t hrnPgInterfaceCatalogVersion120(void);
void hrnPgInterfaceControl120(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal120(PgWal pgWal, unsigned char *buffer);
uint32_t hrnPgInterfaceCatalogVersion130(void);
void hrnPgInterfaceControl130(PgControl pgControl, unsigned char *buffer);
void hrnPgInterfaceWal130(PgWal pgWal, unsigned char *buffer);
typedef struct HrnPgInterface
{
// Version of PostgreSQL supported by this interface
unsigned int version;
// Catalog version
unsigned int (*catalogVersion)(void);
// Create pg_control
void (*control)(PgControl, unsigned char *);
// Create WAL header
void (*wal)(PgWal, unsigned char *);
} HrnPgInterface;
static const HrnPgInterface hrnPgInterface[] =
{
{
.version = PG_VERSION_13,
.catalogVersion = hrnPgInterfaceCatalogVersion130,
.control = hrnPgInterfaceControl130,
.wal = hrnPgInterfaceWal130,
},
{
.version = PG_VERSION_12,
.catalogVersion = hrnPgInterfaceCatalogVersion120,
.control = hrnPgInterfaceControl120,
.wal = hrnPgInterfaceWal120,
},
{
.version = PG_VERSION_11,
.catalogVersion = hrnPgInterfaceCatalogVersion110,
.control = hrnPgInterfaceControl110,
.wal = hrnPgInterfaceWal110,
},
{
.version = PG_VERSION_10,
.catalogVersion = hrnPgInterfaceCatalogVersion100,
.control = hrnPgInterfaceControl100,
.wal = hrnPgInterfaceWal100,
},
{
.version = PG_VERSION_96,
.catalogVersion = hrnPgInterfaceCatalogVersion096,
.control = hrnPgInterfaceControl096,
.wal = hrnPgInterfaceWal096,
},
{
.version = PG_VERSION_95,
.catalogVersion = hrnPgInterfaceCatalogVersion095,
.control = hrnPgInterfaceControl095,
.wal = hrnPgInterfaceWal095,
},
{
.version = PG_VERSION_94,
.catalogVersion = hrnPgInterfaceCatalogVersion094,
.control = hrnPgInterfaceControl094,
.wal = hrnPgInterfaceWal094,
},
{
.version = PG_VERSION_93,
.catalogVersion = hrnPgInterfaceCatalogVersion093,
.control = hrnPgInterfaceControl093,
.wal = hrnPgInterfaceWal093,
},
{
.version = PG_VERSION_92,
.catalogVersion = hrnPgInterfaceCatalogVersion092,
.control = hrnPgInterfaceControl092,
.wal = hrnPgInterfaceWal092,
},
{
.version = PG_VERSION_91,
.catalogVersion = hrnPgInterfaceCatalogVersion091,
.control = hrnPgInterfaceControl091,
.wal = hrnPgInterfaceWal091,
},
{
.version = PG_VERSION_90,
.catalogVersion = hrnPgInterfaceCatalogVersion090,
.control = hrnPgInterfaceControl090,
.wal = hrnPgInterfaceWal090,
},
{
.version = PG_VERSION_84,
.catalogVersion = hrnPgInterfaceCatalogVersion084,
.control = hrnPgInterfaceControl084,
.wal = hrnPgInterfaceWal084,
},
{
.version = PG_VERSION_83,
.catalogVersion = hrnPgInterfaceCatalogVersion083,
.control = hrnPgInterfaceControl083,
.wal = hrnPgInterfaceWal083,
},
};
/***********************************************************************************************************************************
Get the interface for a PostgreSQL version
***********************************************************************************************************************************/
static const HrnPgInterface *
hrnPgInterfaceVersion(unsigned int pgVersion)
{
FUNCTION_HARNESS_BEGIN();
FUNCTION_HARNESS_PARAM(UINT, pgVersion);
FUNCTION_HARNESS_END();
const HrnPgInterface *result = NULL;
for (unsigned int interfaceIdx = 0; interfaceIdx < sizeof(hrnPgInterface) / sizeof(HrnPgInterface); interfaceIdx++)
{
if (hrnPgInterface[interfaceIdx].version == pgVersion)
{
result = &hrnPgInterface[interfaceIdx];
break;
}
}
// If the version was not found then error
if (result == NULL)
THROW_FMT(AssertError, "invalid " PG_NAME " version %u", pgVersion);
FUNCTION_HARNESS_RETURN(STRUCT, result);
}
/**********************************************************************************************************************************/
unsigned int
hrnPgCatalogVersion(unsigned int pgVersion)
{
FUNCTION_HARNESS_BEGIN();
FUNCTION_HARNESS_PARAM(UINT, pgVersion);
FUNCTION_HARNESS_END();
FUNCTION_HARNESS_RETURN(UINT, hrnPgInterfaceVersion(pgVersion)->catalogVersion());
}
/**********************************************************************************************************************************/
Buffer *
hrnPgControlToBuffer(PgControl pgControl)
{
FUNCTION_HARNESS_BEGIN();
FUNCTION_HARNESS_PARAM(PG_CONTROL, pgControl);
FUNCTION_HARNESS_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 ?
hrnPgInterfaceVersion(pgControl.version)->catalogVersion() : pgControl.catalogVersion;
// Create the buffer and clear it
Buffer *result = bufNew(HRN_PG_CONTROL_SIZE);
memset(bufPtr(result), 0, bufSize(result));
bufUsedSet(result, bufSize(result));
// Generate pg_control
hrnPgInterfaceVersion(pgControl.version)->control(pgControl, bufPtr(result));
FUNCTION_HARNESS_RETURN(BUFFER, result);
}
/**********************************************************************************************************************************/
void
hrnPgWalToBuffer(PgWal pgWal, Buffer *walBuffer)
{
FUNCTION_HARNESS_BEGIN();
FUNCTION_HARNESS_PARAM(PG_WAL, pgWal);
FUNCTION_HARNESS_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
hrnPgInterfaceVersion(pgWal.version)->wal(pgWal, bufPtr(walBuffer));
FUNCTION_HARNESS_RETURN_VOID();
}

View File

@ -0,0 +1,27 @@
/***********************************************************************************************************************************
Harness for PostgreSQL Interface
***********************************************************************************************************************************/
#ifndef TEST_COMMON_HARNESS_POSTGRES_H
#define TEST_COMMON_HARNESS_POSTGRES_H
#include "postgres/interface.h"
#include "postgres/version.h"
/***********************************************************************************************************************************
Control file size used to create pg_control
***********************************************************************************************************************************/
#define HRN_PG_CONTROL_SIZE 8192
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
// Get the catalog version for a PostgreSQL version
unsigned int hrnPgCatalogVersion(unsigned int pgVersion);
// Create pg_control
Buffer *hrnPgControlToBuffer(PgControl pgControl);
// Create WAL for testing
void hrnPgWalToBuffer(PgWal pgWal, Buffer *walBuffer);
#endif

View File

@ -0,0 +1,10 @@
/***********************************************************************************************************************************
Harness for PostgreSQL Interface (see PG_VERSION for version)
***********************************************************************************************************************************/
#include "build.auto.h"
#define PG_VERSION PG_VERSION_83
#include "common/harnessPostgres/harnessVersion.intern.h"
HRN_PG_INTERFACE(083);

View File

@ -0,0 +1,10 @@
/***********************************************************************************************************************************
Harness for PostgreSQL Interface (see PG_VERSION for version)
***********************************************************************************************************************************/
#include "build.auto.h"
#define PG_VERSION PG_VERSION_84
#include "common/harnessPostgres/harnessVersion.intern.h"
HRN_PG_INTERFACE(084);

View File

@ -0,0 +1,10 @@
/***********************************************************************************************************************************
Harness for PostgreSQL Interface (see PG_VERSION for version)
***********************************************************************************************************************************/
#include "build.auto.h"
#define PG_VERSION PG_VERSION_90
#include "common/harnessPostgres/harnessVersion.intern.h"
HRN_PG_INTERFACE(090);

View File

@ -0,0 +1,10 @@
/***********************************************************************************************************************************
Harness for PostgreSQL Interface (see PG_VERSION for version)
***********************************************************************************************************************************/
#include "build.auto.h"
#define PG_VERSION PG_VERSION_91
#include "common/harnessPostgres/harnessVersion.intern.h"
HRN_PG_INTERFACE(091);

View File

@ -0,0 +1,10 @@
/***********************************************************************************************************************************
Harness for PostgreSQL Interface (see PG_VERSION for version)
***********************************************************************************************************************************/
#include "build.auto.h"
#define PG_VERSION PG_VERSION_92
#include "common/harnessPostgres/harnessVersion.intern.h"
HRN_PG_INTERFACE(092);

View File

@ -0,0 +1,10 @@
/***********************************************************************************************************************************
Harness for PostgreSQL Interface (see PG_VERSION for version)
***********************************************************************************************************************************/
#include "build.auto.h"
#define PG_VERSION PG_VERSION_93
#include "common/harnessPostgres/harnessVersion.intern.h"
HRN_PG_INTERFACE(093);

View File

@ -0,0 +1,10 @@
/***********************************************************************************************************************************
Harness for PostgreSQL Interface (see PG_VERSION for version)
***********************************************************************************************************************************/
#include "build.auto.h"
#define PG_VERSION PG_VERSION_94
#include "common/harnessPostgres/harnessVersion.intern.h"
HRN_PG_INTERFACE(094);

View File

@ -0,0 +1,10 @@
/***********************************************************************************************************************************
Harness for PostgreSQL Interface (see PG_VERSION for version)
***********************************************************************************************************************************/
#include "build.auto.h"
#define PG_VERSION PG_VERSION_95
#include "common/harnessPostgres/harnessVersion.intern.h"
HRN_PG_INTERFACE(095);

View File

@ -0,0 +1,10 @@
/***********************************************************************************************************************************
Harness for PostgreSQL Interface (see PG_VERSION for version)
***********************************************************************************************************************************/
#include "build.auto.h"
#define PG_VERSION PG_VERSION_96
#include "common/harnessPostgres/harnessVersion.intern.h"
HRN_PG_INTERFACE(096);

View File

@ -0,0 +1,10 @@
/***********************************************************************************************************************************
Harness for PostgreSQL Interface (see PG_VERSION for version)
***********************************************************************************************************************************/
#include "build.auto.h"
#define PG_VERSION PG_VERSION_10
#include "common/harnessPostgres/harnessVersion.intern.h"
HRN_PG_INTERFACE(100);

View File

@ -0,0 +1,10 @@
/***********************************************************************************************************************************
Harness for PostgreSQL Interface (see PG_VERSION for version)
***********************************************************************************************************************************/
#include "build.auto.h"
#define PG_VERSION PG_VERSION_11
#include "common/harnessPostgres/harnessVersion.intern.h"
HRN_PG_INTERFACE(110);

View File

@ -0,0 +1,10 @@
/***********************************************************************************************************************************
Harness for PostgreSQL Interface (see PG_VERSION for version)
***********************************************************************************************************************************/
#include "build.auto.h"
#define PG_VERSION PG_VERSION_12
#include "common/harnessPostgres/harnessVersion.intern.h"
HRN_PG_INTERFACE(120);

View File

@ -0,0 +1,10 @@
/***********************************************************************************************************************************
Harness for PostgreSQL Interface (see PG_VERSION for version)
***********************************************************************************************************************************/
#include "build.auto.h"
#define PG_VERSION PG_VERSION_13
#include "common/harnessPostgres/harnessVersion.intern.h"
HRN_PG_INTERFACE(130);

View File

@ -0,0 +1,102 @@
/***********************************************************************************************************************************
Harness for PostgreSQL Interface
Macros to create harness functions per PostgreSQL version.
***********************************************************************************************************************************/
#ifndef TEST_COMMON_HARNESS_POSTGRES_VERSIONINTERN_H
#define TEST_COMMON_HARNESS_POSTGRES_VERSIONINTERN_H
#include "postgres/version.h"
#include "postgres/interface/version.vendor.h"
#include "common/harnessPostgres.h"
/***********************************************************************************************************************************
Get the catalog version
***********************************************************************************************************************************/
#if PG_VERSION > PG_VERSION_MAX
#elif PG_VERSION >= PG_VERSION_83
#define HRN_PG_INTERFACE_CATALOG_VERSION(version) \
uint32_t \
hrnPgInterfaceCatalogVersion##version(void) \
{ \
return CATALOG_VERSION_NO; \
}
#endif
/***********************************************************************************************************************************
Create a pg_control file
***********************************************************************************************************************************/
#if PG_VERSION > PG_VERSION_MAX
#elif PG_VERSION >= PG_VERSION_93
#define HRN_PG_INTERFACE_CONTROL_TEST(version) \
void \
hrnPgInterfaceControl##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 HRN_PG_INTERFACE_CONTROL_TEST(version) \
void \
hrnPgInterfaceControl##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
/***********************************************************************************************************************************
Create a WAL file
***********************************************************************************************************************************/
#if PG_VERSION > PG_VERSION_MAX
#elif PG_VERSION >= PG_VERSION_83
#define HRN_PG_INTERFACE_WAL_TEST(version) \
void \
hrnPgInterfaceWal##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 HRN_PG_INTERFACE(version) \
HRN_PG_INTERFACE_CATALOG_VERSION(version) \
HRN_PG_INTERFACE_CONTROL_TEST(version) \
HRN_PG_INTERFACE_WAL_TEST(version)
#endif

View File

@ -13,6 +13,7 @@ Test Archive Get Command
#include "storage/posix/storage.h"
#include "common/harnessInfo.h"
#include "common/harnessPostgres.h"
#include "common/harnessStorage.h"
/***********************************************************************************************************************************
@ -146,7 +147,7 @@ testRun(void)
HRN_STORAGE_PUT(
storagePgWrite(), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL,
pgControlTestToBuffer((PgControl){.version = PG_VERSION_10, .systemId = 0xFACEFACEFACEFACE}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_10, .systemId = 0xFACEFACEFACEFACE}));
HRN_INFO_PUT(
storageRepoWrite(), INFO_ARCHIVE_PATH_FILE,
@ -601,7 +602,7 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
HRN_STORAGE_PUT(
storagePgWrite(), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL,
pgControlTestToBuffer((PgControl){.version = PG_VERSION_10, .systemId = 0xFACEFACEFACEFACE}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_10, .systemId = 0xFACEFACEFACEFACE}));
storagePathCreateP(storageTest, strNewFmt("%s/pg/pg_wal", testPath()));
@ -760,7 +761,7 @@ testRun(void)
HRN_STORAGE_PUT(
storagePgWrite(), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL,
pgControlTestToBuffer((PgControl){.version = PG_VERSION_11, .systemId = 0xFACEFACEFACEFACE}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_11, .systemId = 0xFACEFACEFACEFACE}));
HRN_INFO_PUT(
storageRepoWrite(), INFO_ARCHIVE_PATH_FILE,
@ -791,7 +792,7 @@ testRun(void)
HRN_STORAGE_PUT(
storagePgWrite(), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL,
pgControlTestToBuffer((PgControl){.version = PG_VERSION_10, .systemId = 0x8888888888888888}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_10, .systemId = 0x8888888888888888}));
TEST_ERROR(cmdArchiveGet(), RepoInvalidError, "unable to find a valid repository");
@ -804,7 +805,7 @@ testRun(void)
HRN_STORAGE_PUT(
storagePgWrite(), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL,
pgControlTestToBuffer((PgControl){.version = PG_VERSION_10, .systemId = 0xFACEFACEFACEFACE}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_10, .systemId = 0xFACEFACEFACEFACE}));
TEST_RESULT_INT(cmdArchiveGet(), 1, "get");

View File

@ -12,6 +12,7 @@ Test Archive Push Command
#include "common/harnessConfig.h"
#include "common/harnessFork.h"
#include "common/harnessInfo.h"
#include "common/harnessPostgres.h"
/***********************************************************************************************************************************
Test Run
@ -85,7 +86,7 @@ testRun(void)
Buffer *walBuffer = bufNew((size_t)16 * 1024 * 1024);
bufUsedSet(walBuffer, bufSize(walBuffer));
memset(bufPtr(walBuffer), 0, bufSize(walBuffer));
pgWalTestToBuffer((PgWal){.version = PG_VERSION_10, .systemId = 0xFACEFACEFACEFACE}, walBuffer);
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_10, .systemId = 0xFACEFACEFACEFACE}, walBuffer);
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_wal/000000010000000100000002")), walBuffer);
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_wal/000000010000000100000003")), walBuffer);
@ -120,7 +121,7 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
storagePutP(
storageNewWriteP(storageTest, strNew("pg/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL)),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_96, .systemId = 0xFACEFACEFACEFACE}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_96, .systemId = 0xFACEFACEFACEFACE}));
// Create incorrect archive info
storagePutP(
@ -298,7 +299,7 @@ testRun(void)
storagePutP(
storageNewWriteP(storageTest, strNew("pg/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL)),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_11, .systemId = 0xFACEFACEFACEFACE}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_11, .systemId = 0xFACEFACEFACEFACE}));
storagePutP(
storageNewWriteP(storageTest, strNew("repo/archive/test/archive.info")),
@ -314,7 +315,7 @@ testRun(void)
Buffer *walBuffer1 = bufNew((size_t)16 * 1024 * 1024);
bufUsedSet(walBuffer1, bufSize(walBuffer1));
memset(bufPtr(walBuffer1), 0, bufSize(walBuffer1));
pgWalTestToBuffer((PgWal){.version = PG_VERSION_10, .systemId = 0xFACEFACEFACEFACE}, walBuffer1);
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_10, .systemId = 0xFACEFACEFACEFACE}, walBuffer1);
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_wal/000000010000000100000001")), walBuffer1);
@ -326,7 +327,7 @@ testRun(void)
" stanza version 11, system-id 18072658121562454734");
memset(bufPtr(walBuffer1), 0, bufSize(walBuffer1));
pgWalTestToBuffer((PgWal){.version = PG_VERSION_11, .systemId = 0xECAFECAFECAFECAF}, walBuffer1);
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_11, .systemId = 0xECAFECAFECAFECAF}, walBuffer1);
const char *walBuffer1Sha1 = strZ(bufHex(cryptoHashOne(HASH_TYPE_SHA1_STR, walBuffer1)));
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_wal/000000010000000100000001")), walBuffer1);
@ -362,7 +363,7 @@ testRun(void)
harnessCfgLoad(cfgCmdArchivePush, argListTemp);
memset(bufPtr(walBuffer1), 0, bufSize(walBuffer1));
pgWalTestToBuffer((PgWal){.version = PG_VERSION_11, .systemId = 0xFACEFACEFACEFACE}, walBuffer1);
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_11, .systemId = 0xFACEFACEFACEFACE}, walBuffer1);
// Check sha1 checksum against fixed values once to make sure they are not getting munged. After this we'll calculate them
// directly from the buffers to reduce the cost of maintaining checksums.
@ -390,7 +391,7 @@ testRun(void)
Buffer *walBuffer2 = bufNew((size_t)16 * 1024 * 1024);
bufUsedSet(walBuffer2, bufSize(walBuffer2));
memset(bufPtr(walBuffer2), 0xFF, bufSize(walBuffer2));
pgWalTestToBuffer((PgWal){.version = PG_VERSION_11, .systemId = 0xFACEFACEFACEFACE}, walBuffer2);
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_11, .systemId = 0xFACEFACEFACEFACE}, walBuffer2);
const char *walBuffer2Sha1 = strZ(bufHex(cryptoHashOne(HASH_TYPE_SHA1_STR, walBuffer2)));
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_wal/000000010000000100000001")), walBuffer2);
@ -724,7 +725,7 @@ testRun(void)
storagePutP(
storageNewWriteP(storageTest, strNew("pg/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL)),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_94, .systemId = 0xAAAABBBBCCCCDDDD}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_94, .systemId = 0xAAAABBBBCCCCDDDD}));
storagePutP(
storageNewWriteP(storageTest, strNew("repo/archive/test/archive.info")),
@ -814,7 +815,7 @@ testRun(void)
Buffer *walBuffer1 = bufNew((size_t)16 * 1024 * 1024);
bufUsedSet(walBuffer1, bufSize(walBuffer1));
memset(bufPtr(walBuffer1), 0xFF, bufSize(walBuffer1));
pgWalTestToBuffer((PgWal){.version = PG_VERSION_94, .systemId = 0xAAAABBBBCCCCDDDD}, walBuffer1);
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_94, .systemId = 0xAAAABBBBCCCCDDDD}, walBuffer1);
const char *walBuffer1Sha1 = strZ(bufHex(cryptoHashOne(HASH_TYPE_SHA1_STR, walBuffer1)));
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_xlog/000000010000000100000001")), walBuffer1);
@ -923,7 +924,7 @@ testRun(void)
Buffer *walBuffer2 = bufNew((size_t)16 * 1024 * 1024);
bufUsedSet(walBuffer2, bufSize(walBuffer2));
memset(bufPtr(walBuffer2), 0x0C, bufSize(walBuffer2));
pgWalTestToBuffer((PgWal){.version = PG_VERSION_94, .systemId = 0xAAAABBBBCCCCDDDD}, walBuffer2);
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_94, .systemId = 0xAAAABBBBCCCCDDDD}, walBuffer2);
const char *walBuffer2Sha1 = strZ(bufHex(cryptoHashOne(HASH_TYPE_SHA1_STR, walBuffer2)));
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_xlog/000000010000000100000002")), walBuffer2);
@ -972,7 +973,7 @@ testRun(void)
Buffer *walBuffer3 = bufNew((size_t)16 * 1024 * 1024);
bufUsedSet(walBuffer3, bufSize(walBuffer3));
memset(bufPtr(walBuffer3), 0x44, bufSize(walBuffer3));
pgWalTestToBuffer((PgWal){.version = PG_VERSION_94, .systemId = 0xAAAABBBBCCCCDDDD}, walBuffer3);
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_94, .systemId = 0xAAAABBBBCCCCDDDD}, walBuffer3);
const char *walBuffer3Sha1 = strZ(bufHex(cryptoHashOne(HASH_TYPE_SHA1_STR, walBuffer3)));
storagePutP(storageNewWriteP(storagePgWrite(), strNew("pg_xlog/000000010000000100000003")), walBuffer3);

View File

@ -12,6 +12,7 @@ Test Backup Command
#include "storage/posix/storage.h"
#include "common/harnessConfig.h"
#include "common/harnessPostgres.h"
#include "common/harnessPq.h"
#include "common/harnessStorage.h"
@ -281,7 +282,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));
pgWalTestToBuffer((PgWal){.version = pgControl.version, .systemId = pgControl.systemId}, walBuffer);
hrnPgWalToBuffer((PgWal){.version = pgControl.version, .systemId = pgControl.systemId}, walBuffer);
const String *walChecksum = bufHex(cryptoHashOne(HASH_TYPE_SHA1_STR, walBuffer));
for (unsigned int walSegmentIdx = 0; walSegmentIdx < strLstSize(walSegmentList); walSegmentIdx++)
@ -998,7 +999,7 @@ testRun(void)
harnessCfgLoad(cfgCmdBackup, argList);
TEST_ERROR(
backupInit(infoBackupNew(PG_VERSION_91, 1000000000000000910, pgCatalogTestVersion(PG_VERSION_91), NULL)), ConfigError,
backupInit(infoBackupNew(PG_VERSION_91, 1000000000000000910, hrnPgCatalogVersion(PG_VERSION_91), NULL)), ConfigError,
"option 'backup-standby' not valid for PostgreSQL < 9.2");
// -------------------------------------------------------------------------------------------------------------------------
@ -1007,7 +1008,7 @@ testRun(void)
// Create pg_control
storagePutP(
storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg1Path))),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_92, .systemId = 1000000000000000920}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_92, .systemId = 1000000000000000920}));
argList = strLstNew();
strLstAddZ(argList, "--" CFGOPT_STANZA "=test1");
@ -1019,7 +1020,7 @@ testRun(void)
harnessCfgLoad(cfgCmdBackup, argList);
TEST_RESULT_VOID(
backupInit(infoBackupNew(PG_VERSION_92, 1000000000000000920, pgCatalogTestVersion(PG_VERSION_92), NULL)),
backupInit(infoBackupNew(PG_VERSION_92, 1000000000000000920, hrnPgCatalogVersion(PG_VERSION_92), NULL)),
"backup init");
TEST_RESULT_BOOL(cfgOptionBool(cfgOptBackupStandby), false, " check backup-standby");
@ -1032,7 +1033,7 @@ testRun(void)
// Create pg_control
storagePutP(
storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg1Path))),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_10, .systemId = 1000000000000001000}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_10, .systemId = 1000000000000001000}));
argList = strLstNew();
strLstAddZ(argList, "--" CFGOPT_STANZA "=test1");
@ -1043,12 +1044,12 @@ testRun(void)
harnessCfgLoad(cfgCmdBackup, argList);
TEST_ERROR(
backupInit(infoBackupNew(PG_VERSION_11, 1000000000000001100, pgCatalogTestVersion(PG_VERSION_11), NULL)),
backupInit(infoBackupNew(PG_VERSION_11, 1000000000000001100, hrnPgCatalogVersion(PG_VERSION_11), NULL)),
BackupMismatchError,
"PostgreSQL version 10, system-id 1000000000000001000 do not match stanza version 11, system-id 1000000000000001100\n"
"HINT: is this the correct stanza?");
TEST_ERROR(
backupInit(infoBackupNew(PG_VERSION_10, 1000000000000001100, pgCatalogTestVersion(PG_VERSION_10), NULL)),
backupInit(infoBackupNew(PG_VERSION_10, 1000000000000001100, hrnPgCatalogVersion(PG_VERSION_10), NULL)),
BackupMismatchError,
"PostgreSQL version 10, system-id 1000000000000001000 do not match stanza version 10, system-id 1000000000000001100\n"
"HINT: is this the correct stanza?");
@ -1059,7 +1060,7 @@ testRun(void)
// Create pg_control
storagePutP(
storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg1Path))),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_83, .systemId = 1000000000000000830}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_83, .systemId = 1000000000000000830}));
argList = strLstNew();
strLstAddZ(argList, "--" CFGOPT_STANZA "=test1");
@ -1071,7 +1072,7 @@ testRun(void)
harnessCfgLoad(cfgCmdBackup, argList);
TEST_RESULT_VOID(
backupInit(infoBackupNew(PG_VERSION_83, 1000000000000000830, pgCatalogTestVersion(PG_VERSION_83), NULL)),
backupInit(infoBackupNew(PG_VERSION_83, 1000000000000000830, hrnPgCatalogVersion(PG_VERSION_83), NULL)),
"backup init");
TEST_RESULT_BOOL(cfgOptionBool(cfgOptStartFast), false, " check start-fast");
@ -1083,7 +1084,7 @@ testRun(void)
// Create pg_control
storagePutP(
storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg1Path))),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_84, .systemId = 1000000000000000840}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_84, .systemId = 1000000000000000840}));
argList = strLstNew();
strLstAddZ(argList, "--" CFGOPT_STANZA "=test1");
@ -1095,7 +1096,7 @@ testRun(void)
harnessCfgLoad(cfgCmdBackup, argList);
TEST_RESULT_VOID(
backupInit(infoBackupNew(PG_VERSION_84, 1000000000000000840, pgCatalogTestVersion(PG_VERSION_84), NULL)),
backupInit(infoBackupNew(PG_VERSION_84, 1000000000000000840, hrnPgCatalogVersion(PG_VERSION_84), NULL)),
"backup init");
TEST_RESULT_BOOL(cfgOptionBool(cfgOptStopAuto), false, " check stop-auto");
@ -1107,7 +1108,7 @@ testRun(void)
// Create pg_control
storagePutP(
storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg1Path))),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_93, .systemId = PG_VERSION_93}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_93, .systemId = PG_VERSION_93}));
argList = strLstNew();
strLstAddZ(argList, "--" CFGOPT_STANZA "=test1");
@ -1126,7 +1127,7 @@ testRun(void)
});
TEST_RESULT_VOID(
dbFree(backupInit(infoBackupNew(PG_VERSION_93, PG_VERSION_93, pgCatalogTestVersion(PG_VERSION_93), NULL))->dbPrimary),
dbFree(backupInit(infoBackupNew(PG_VERSION_93, PG_VERSION_93, hrnPgCatalogVersion(PG_VERSION_93), NULL))->dbPrimary),
"backup init");
TEST_RESULT_BOOL(cfgOptionBool(cfgOptChecksumPage), false, " check checksum-page");
@ -1139,7 +1140,7 @@ testRun(void)
// Create pg_control with page checksums
storagePutP(
storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg1Path))),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_93, .systemId = PG_VERSION_93, .pageChecksum = true}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_93, .systemId = PG_VERSION_93, .pageChecksum = true}));
argList = strLstNew();
strLstAddZ(argList, "--" CFGOPT_STANZA "=test1");
@ -1158,14 +1159,14 @@ testRun(void)
});
TEST_RESULT_VOID(
dbFree(backupInit(infoBackupNew(PG_VERSION_93, PG_VERSION_93, pgCatalogTestVersion(PG_VERSION_93), NULL))->dbPrimary),
dbFree(backupInit(infoBackupNew(PG_VERSION_93, PG_VERSION_93, hrnPgCatalogVersion(PG_VERSION_93), NULL))->dbPrimary),
"backup init");
TEST_RESULT_BOOL(cfgOptionBool(cfgOptChecksumPage), false, " check checksum-page");
// Create pg_control without page checksums
storagePutP(
storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg1Path))),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_93, .systemId = PG_VERSION_93}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_93, .systemId = PG_VERSION_93}));
harnessPqScriptSet((HarnessPq [])
{
@ -1176,7 +1177,7 @@ testRun(void)
});
TEST_RESULT_VOID(
dbFree(backupInit(infoBackupNew(PG_VERSION_93, PG_VERSION_93, pgCatalogTestVersion(PG_VERSION_93), NULL))->dbPrimary),
dbFree(backupInit(infoBackupNew(PG_VERSION_93, PG_VERSION_93, hrnPgCatalogVersion(PG_VERSION_93), NULL))->dbPrimary),
"backup init");
TEST_RESULT_BOOL(cfgOptionBool(cfgOptChecksumPage), false, " check checksum-page");
}
@ -1200,7 +1201,7 @@ testRun(void)
// Create pg_control
storagePutP(
storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg1Path))),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_93, .systemId = PG_VERSION_93}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_93, .systemId = PG_VERSION_93}));
harnessPqScriptSet((HarnessPq [])
{
@ -1222,7 +1223,7 @@ testRun(void)
});
BackupData *backupData = backupInit(
infoBackupNew(PG_VERSION_93, PG_VERSION_93, pgCatalogTestVersion(PG_VERSION_93), NULL));
infoBackupNew(PG_VERSION_93, PG_VERSION_93, hrnPgCatalogVersion(PG_VERSION_93), NULL));
TEST_RESULT_INT(backupTime(backupData, true), 1575392588, "multiple tries for sleep");
TEST_ERROR(backupTime(backupData, true), KernelError, "PostgreSQL clock has not advanced to the next second after 3 tries");
@ -1436,7 +1437,7 @@ testRun(void)
// Create pg_control
storagePutP(
storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg1Path))),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_84, .systemId = 1000000000000000840}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_84, .systemId = 1000000000000000840}));
// Create stanza
StringList *argList = strLstNew();
@ -1687,7 +1688,7 @@ testRun(void)
storageNewWriteP(
storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg1Path)),
.timeModified = backupTimeStart),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_95, .systemId = 1000000000000000950}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_95, .systemId = 1000000000000000950}));
// Create stanza
StringList *argList = strLstNew();
@ -1723,7 +1724,7 @@ testRun(void)
// Create a backup manifest that looks like a halted backup manifest
Manifest *manifestResume = manifestNewBuild(
storagePg(), PG_VERSION_95, pgCatalogTestVersion(PG_VERSION_95), true, false, NULL, NULL);
storagePg(), PG_VERSION_95, hrnPgCatalogVersion(PG_VERSION_95), true, false, NULL, NULL);
ManifestData *manifestResumeData = (ManifestData *)manifestData(manifestResume);
manifestResumeData->backupType = backupTypeFull;
@ -1811,7 +1812,7 @@ testRun(void)
// Create a backup manifest that looks like a halted backup manifest
Manifest *manifestResume = manifestNewBuild(
storagePg(), PG_VERSION_95, pgCatalogTestVersion(PG_VERSION_95), true, false, NULL, NULL);
storagePg(), PG_VERSION_95, hrnPgCatalogVersion(PG_VERSION_95), true, false, NULL, NULL);
ManifestData *manifestResumeData = (ManifestData *)manifestData(manifestResume);
manifestResumeData->backupType = backupTypeFull;
@ -2007,7 +2008,7 @@ testRun(void)
// Create a backup manifest that looks like a halted backup manifest
Manifest *manifestResume = manifestNewBuild(
storagePg(), PG_VERSION_95, pgCatalogTestVersion(PG_VERSION_95), true, false, NULL, NULL);
storagePg(), PG_VERSION_95, hrnPgCatalogVersion(PG_VERSION_95), true, false, NULL, NULL);
ManifestData *manifestResumeData = (ManifestData *)manifestData(manifestResume);
manifestResumeData->backupType = backupTypeDiff;
@ -2149,7 +2150,7 @@ testRun(void)
storageNewWriteP(
storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg1Path)),
.timeModified = backupTimeStart),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_96, .systemId = 1000000000000000960}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_96, .systemId = 1000000000000000960}));
// Update version
storagePutP(
@ -2291,7 +2292,7 @@ testRun(void)
storageNewWriteP(
storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg1Path)),
.timeModified = backupTimeStart),
pgControlTestToBuffer(
hrnPgControlToBuffer(
(PgControl){
.version = PG_VERSION_11, .systemId = 1000000000000001100, .pageChecksum = true,
.walSegmentSize = 1024 * 1024}));
@ -2383,7 +2384,7 @@ testRun(void)
storagePutP(
storageNewWriteP(
storageTest,
strNewFmt("pg1-tblspc/32768/%s/1/5", strZ(pgTablespaceId(PG_VERSION_11, pgCatalogTestVersion(PG_VERSION_11)))),
strNewFmt("pg1-tblspc/32768/%s/1/5", strZ(pgTablespaceId(PG_VERSION_11, hrnPgCatalogVersion(PG_VERSION_11)))),
.timeModified = backupTimeStart),
NULL);

View File

@ -1,17 +1,18 @@
/***********************************************************************************************************************************
Test Check Command
***********************************************************************************************************************************/
#include "command/stanza/create.h"
#include "info/infoArchive.h"
#include "info/infoBackup.h"
#include "postgres/version.h"
#include "storage/helper.h"
#include "storage/posix/storage.h"
#include "storage/storage.intern.h"
#include "command/stanza/create.h"
#include "common/harnessConfig.h"
#include "common/harnessInfo.h"
#include "common/harnessPostgres.h"
#include "common/harnessPq.h"
#include "info/infoArchive.h"
#include "info/infoBackup.h"
/***********************************************************************************************************************************
Test Run
@ -147,7 +148,7 @@ testRun(void)
// Create pg_control for standby
storagePutP(
storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg1))),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_92, .systemId = 6569239123849665679}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_92, .systemId = 6569239123849665679}));
argList = strLstNew();
strLstAdd(argList, stanzaOpt);
@ -181,7 +182,7 @@ testRun(void)
// Create pg_control for primary
storagePutP(
storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg8))),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_92, .systemId = 6569239123849665679}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_92, .systemId = 6569239123849665679}));
// Create info files
const Buffer *archiveInfoContent = harnessInfoChecksum(
@ -481,14 +482,14 @@ testRun(void)
InfoArchive *archiveInfo = infoArchiveNew(PG_VERSION_96, 6569239123849665679, NULL);
InfoPgData archivePg = infoPgData(infoArchivePg(archiveInfo), infoPgDataCurrentId(infoArchivePg(archiveInfo)));
InfoBackup *backupInfo = infoBackupNew(PG_VERSION_96, 6569239123849665679, pgCatalogTestVersion(PG_VERSION_96), NULL);
InfoBackup *backupInfo = infoBackupNew(PG_VERSION_96, 6569239123849665679, hrnPgCatalogVersion(PG_VERSION_96), NULL);
InfoPgData backupPg = infoPgData(infoBackupPg(backupInfo), infoPgDataCurrentId(infoBackupPg(backupInfo)));
TEST_RESULT_VOID(checkStanzaInfo(&archivePg, &backupPg), "stanza info files match");
// Create a corrupted backup file - system id
// -------------------------------------------------------------------------------------------------------------------------
backupInfo = infoBackupNew(PG_VERSION_96, 6569239123849665999, pgCatalogTestVersion(PG_VERSION_96), NULL);
backupInfo = infoBackupNew(PG_VERSION_96, 6569239123849665999, hrnPgCatalogVersion(PG_VERSION_96), NULL);
backupPg = infoPgData(infoBackupPg(backupInfo), infoPgDataCurrentId(infoBackupPg(backupInfo)));
TEST_ERROR_FMT(
@ -499,7 +500,7 @@ testRun(void)
// Create a corrupted backup file - system id and version
// -------------------------------------------------------------------------------------------------------------------------
backupInfo = infoBackupNew(PG_VERSION_95, 6569239123849665999, pgCatalogTestVersion(PG_VERSION_95), NULL);
backupInfo = infoBackupNew(PG_VERSION_95, 6569239123849665999, hrnPgCatalogVersion(PG_VERSION_95), NULL);
backupPg = infoPgData(infoBackupPg(backupInfo), infoPgDataCurrentId(infoBackupPg(backupInfo)));
TEST_ERROR_FMT(
@ -510,7 +511,7 @@ testRun(void)
// Create a corrupted backup file - version
// -------------------------------------------------------------------------------------------------------------------------
backupInfo = infoBackupNew(PG_VERSION_95, 6569239123849665679, pgCatalogTestVersion(PG_VERSION_95), NULL);
backupInfo = infoBackupNew(PG_VERSION_95, 6569239123849665679, hrnPgCatalogVersion(PG_VERSION_95), NULL);
backupPg = infoPgData(infoBackupPg(backupInfo), infoPgDataCurrentId(infoBackupPg(backupInfo)));
TEST_ERROR_FMT(
@ -521,7 +522,7 @@ testRun(void)
// Create a corrupted backup file - db id
// -------------------------------------------------------------------------------------------------------------------------
infoBackupPgSet(backupInfo, PG_VERSION_96, 6569239123849665679, pgCatalogTestVersion(PG_VERSION_96));
infoBackupPgSet(backupInfo, PG_VERSION_96, 6569239123849665679, hrnPgCatalogVersion(PG_VERSION_96));
backupPg = infoPgData(infoBackupPg(backupInfo), infoPgDataCurrentId(infoBackupPg(backupInfo)));
TEST_ERROR_FMT(
@ -544,7 +545,7 @@ testRun(void)
// Create pg_control
storagePutP(
storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(stanza))),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_96, .systemId = 6569239123849665679}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_96, .systemId = 6569239123849665679}));
// Create info files
TEST_RESULT_VOID(cmdStanzaCreate(), "stanza create - encryption");

View File

@ -12,6 +12,7 @@ Test Restore Command
#include "common/harnessConfig.h"
#include "common/harnessInfo.h"
#include "common/harnessPostgres.h"
#include "common/harnessStorage.h"
/***********************************************************************************************************************************
@ -1431,7 +1432,7 @@ testRun(void)
TEST_TITLE("one database selected with tablespace id");
manifest->pub.data.pgVersion = PG_VERSION_94;
manifest->pub.data.pgCatalogVersion = pgCatalogTestVersion(PG_VERSION_94);
manifest->pub.data.pgCatalogVersion = hrnPgCatalogVersion(PG_VERSION_94);
MEM_CONTEXT_BEGIN(manifest->pub.memContext)
{
@ -2308,7 +2309,7 @@ testRun(void)
manifest->pub.info = infoNew(NULL);
manifest->pub.data.backupLabel = strNew(TEST_LABEL);
manifest->pub.data.pgVersion = PG_VERSION_10;
manifest->pub.data.pgCatalogVersion = pgCatalogTestVersion(PG_VERSION_10);
manifest->pub.data.pgCatalogVersion = hrnPgCatalogVersion(PG_VERSION_10);
manifest->pub.data.backupType = backupTypeFull;
manifest->pub.data.backupTimestampCopyStart = 1482182861; // So file timestamps should be less than this

View File

@ -1,13 +1,14 @@
/***********************************************************************************************************************************
Test Stanza Commands
***********************************************************************************************************************************/
#include "postgres/interface.h"
#include "postgres/version.h"
#include "storage/posix/storage.h"
#include "common/harnessConfig.h"
#include "common/harnessInfo.h"
#include "common/harnessPostgres.h"
#include "common/harnessPq.h"
#include "postgres/interface.h"
#include "postgres/version.h"
/***********************************************************************************************************************************
Test Run
@ -62,7 +63,7 @@ testRun(void)
// Create pg_control
storagePutP(
storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(stanza))),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_96, .systemId = 6569239123849665679}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_96, .systemId = 6569239123849665679}));
TEST_RESULT_VOID(cmdStanzaCreate(), "stanza create - one repo, no files exist");
harnessLogResult("P00 INFO: stanza-create for stanza 'db' on repo1");
@ -559,7 +560,7 @@ testRun(void)
// Create pg_control
storagePutP(
storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg1))),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_92, .systemId = 6569239123849665699}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_92, .systemId = 6569239123849665699}));
harnessPqScriptSet((HarnessPq [])
{
@ -589,7 +590,7 @@ testRun(void)
// Create pg_control with different version
storagePutP(
storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg1))),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_91, .systemId = 6569239123849665699}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_91, .systemId = 6569239123849665699}));
harnessPqScriptSet((HarnessPq [])
{
@ -608,7 +609,7 @@ testRun(void)
// Create pg_control
storagePutP(
storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg1))),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_92, .systemId = 6569239123849665699}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_92, .systemId = 6569239123849665699}));
harnessPqScriptSet((HarnessPq [])
{
@ -637,12 +638,12 @@ testRun(void)
// Create pg_control for primary
storagePutP(
storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg1))),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_92, .systemId = 6569239123849665699}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_92, .systemId = 6569239123849665699}));
// Create pg_control for standby
storagePutP(
storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, testPath())),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_94, .systemId = 6569239123849665700}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_94, .systemId = 6569239123849665700}));
harnessPqScriptSet((HarnessPq [])
{
@ -665,7 +666,7 @@ testRun(void)
TEST_RESULT_VOID(
storagePutP(
storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(stanza))),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_96, .systemId = 6569239123849665679})),
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_96, .systemId = 6569239123849665679})),
"create pg_control");
// Load Parameters
@ -999,7 +1000,7 @@ testRun(void)
// Create pg_control for stanza-create
storagePutP(
storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(stanzaOther))),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_96, .systemId = 6569239123849665679}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_96, .systemId = 6569239123849665679}));
TEST_RESULT_VOID(cmdStanzaCreate(), "create a stanza that will not be deleted");
harnessLogResult("P00 INFO: stanza-create for stanza 'otherstanza' on repo1");

View File

@ -1,15 +1,16 @@
/***********************************************************************************************************************************
Test Stanza Commands
***********************************************************************************************************************************/
#include "storage/posix/storage.h"
#include "common/harnessConfig.h"
#include "common/harnessInfo.h"
#include "common/harnessPq.h"
#include "common/io/bufferRead.h"
#include "common/io/bufferWrite.h"
#include "postgres/interface.h"
#include "postgres/version.h"
#include "storage/posix/storage.h"
#include "common/harnessConfig.h"
#include "common/harnessInfo.h"
#include "common/harnessPostgres.h"
#include "common/harnessPq.h"
/***********************************************************************************************************************************
Test Run
@ -968,7 +969,7 @@ testRun(void)
Buffer *walBuffer = bufNew((size_t)(1024 * 1024));
bufUsedSet(walBuffer, bufSize(walBuffer));
memset(bufPtr(walBuffer), 0, bufSize(walBuffer));
pgWalTestToBuffer(
hrnPgWalToBuffer(
(PgWal){.version = PG_VERSION_11, .systemId = 6626363367545678089, .size = 1024 * 1024}, walBuffer);
const char *walBufferSha1 = strZ(bufHex(cryptoHashOne(HASH_TYPE_SHA1_STR, walBuffer)));
@ -1532,7 +1533,7 @@ testRun(void)
Buffer *walBuffer = bufNew((size_t)(1024 * 1024));
bufUsedSet(walBuffer, bufSize(walBuffer));
memset(bufPtr(walBuffer), 0, bufSize(walBuffer));
pgWalTestToBuffer(
hrnPgWalToBuffer(
(PgWal){.version = PG_VERSION_11, .systemId = 6626363367545678089, .size = 1024 * 1024}, walBuffer);
const char *walBufferSha1 = strZ(bufHex(cryptoHashOne(HASH_TYPE_SHA1_STR, walBuffer)));
TEST_RESULT_VOID(

View File

@ -8,6 +8,7 @@ Test Backup Info Handler
#include "common/harnessConfig.h"
#include "common/harnessInfo.h"
#include "common/harnessPostgres.h"
/***********************************************************************************************************************************
Test Run
@ -59,7 +60,7 @@ testRun(void)
Buffer *contentCompare = bufNew(0);
TEST_ASSIGN(
infoBackup, infoBackupNew(PG_VERSION_94, 6569239123849665679, pgCatalogTestVersion(PG_VERSION_94), NULL),
infoBackup, infoBackupNew(PG_VERSION_94, 6569239123849665679, hrnPgCatalogVersion(PG_VERSION_94), NULL),
"infoBackupNew() - no cipher sub");
TEST_RESULT_VOID(infoBackupSave(infoBackup, ioBufferWriteNew(contentCompare)), " save backup info from new");
TEST_RESULT_STR(strNewBuf(contentCompare), strNewBuf(contentSave), " check save");
@ -74,7 +75,7 @@ testRun(void)
TEST_ASSIGN(
infoBackup,
infoBackupNew(
PG_VERSION_10, 6569239123849665999, pgCatalogTestVersion(PG_VERSION_10),
PG_VERSION_10, 6569239123849665999, hrnPgCatalogVersion(PG_VERSION_10),
strNew("zWa/6Xtp-IVZC5444yXB+cgFDFl7MxGlgkZSaoPvTGirhPygu4jOKOXf9LO4vjfO")),
"infoBackupNew() - cipher sub");
@ -93,7 +94,7 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
InfoPgData infoPgData = {0};
TEST_RESULT_VOID(
infoBackupPgSet(infoBackup, PG_VERSION_94, 6569239123849665679, pgCatalogTestVersion(PG_VERSION_94)),
infoBackupPgSet(infoBackup, PG_VERSION_94, 6569239123849665679, hrnPgCatalogVersion(PG_VERSION_94)),
"add another infoPg");
TEST_RESULT_INT(infoPgDataTotal(infoBackupPg(infoBackup)), 2, " history incremented");
TEST_ASSIGN(infoPgData, infoPgDataCurrent(infoBackupPg(infoBackup)), " get current infoPgData");
@ -699,7 +700,7 @@ testRun(void)
// With the infoBackup from above, upgrade the DB so there a 2 histories then save to disk
TEST_ASSIGN(
infoBackup, infoBackupPgSet(infoBackup, PG_VERSION_11, 6739907367085689196, pgCatalogTestVersion(PG_VERSION_11)),
infoBackup, infoBackupPgSet(infoBackup, PG_VERSION_11, 6739907367085689196, hrnPgCatalogVersion(PG_VERSION_11)),
"upgrade db");
TEST_RESULT_VOID(
infoBackupSaveFile(infoBackup, storageRepoWrite(), INFO_BACKUP_PATH_FILE_STR, cipherTypeNone, NULL),
@ -828,7 +829,7 @@ testRun(void)
"HINT: has a stanza-create been performed?",
testPath(), testPath(), testPath(), testPath());
InfoBackup *infoBackup = infoBackupNew(PG_VERSION_10, 6569239123849665999, pgCatalogTestVersion(PG_VERSION_10), NULL);
InfoBackup *infoBackup = infoBackupNew(PG_VERSION_10, 6569239123849665999, hrnPgCatalogVersion(PG_VERSION_10), NULL);
TEST_RESULT_VOID(
infoBackupSaveFile(infoBackup, storageTest, STRDEF(INFO_BACKUP_FILE), cipherTypeNone, NULL), "save backup info");

View File

@ -5,6 +5,7 @@ Test PostgreSQL Info Handler
#include "common/io/bufferWrite.h"
#include "common/harnessInfo.h"
#include "common/harnessPostgres.h"
/***********************************************************************************************************************************
Test save callback
@ -50,7 +51,7 @@ testRun(void)
infoPg,
infoPgSet(
infoPgNew(infoPgArchive, NULL), infoPgArchive, PG_VERSION_94, 6569239123849665679,
pgCatalogTestVersion(PG_VERSION_94)),
hrnPgCatalogVersion(PG_VERSION_94)),
"infoPgSet - infoPgArchive");
TEST_RESULT_INT(infoPgDataTotal(infoPg), 1, " 1 history");
TEST_RESULT_INT(infoPgDataCurrentId(infoPg), 0, " 0 historyCurrent");
@ -61,7 +62,7 @@ testRun(void)
TEST_RESULT_UINT(pgData.catalogVersion, 0, " catalog version not set for archive");
TEST_ASSIGN(
infoPg, infoPgSet(infoPg, infoPgArchive, PG_VERSION_95, 6569239123849665999, pgCatalogTestVersion(PG_VERSION_95)),
infoPg, infoPgSet(infoPg, infoPgArchive, PG_VERSION_95, 6569239123849665999, hrnPgCatalogVersion(PG_VERSION_95)),
"infoPgSet - infoPgArchive second db");
TEST_RESULT_INT(infoPgDataTotal(infoPg), 2, " 2 history");
TEST_RESULT_INT(infoPgDataCurrentId(infoPg), 0, " 0 historyCurrent");
@ -77,7 +78,7 @@ testRun(void)
infoPg,
infoPgSet(
infoPgNew(infoPgBackup, strNew("123xyz")), infoPgBackup, PG_VERSION_94, 6569239123849665679,
pgCatalogTestVersion(PG_VERSION_94)),
hrnPgCatalogVersion(PG_VERSION_94)),
"infoPgSet - infoPgBackup");
TEST_RESULT_INT(infoPgDataTotal(infoPg), 1, " 1 history");
TEST_RESULT_INT(infoPgDataCurrentId(infoPg), 0, " 0 historyCurrent");

View File

@ -9,6 +9,7 @@ Test Backup Manifest Handler
#include "storage/posix/storage.h"
#include "common/harnessInfo.h"
#include "common/harnessPostgres.h"
/***********************************************************************************************************************************
Special string constants
@ -280,7 +281,7 @@ testRun(void)
Manifest *manifest = NULL;
TEST_ASSIGN(
manifest,
manifestNewBuild(storagePg, PG_VERSION_83, pgCatalogTestVersion(PG_VERSION_83), false, false, exclusionList, NULL),
manifestNewBuild(storagePg, PG_VERSION_83, hrnPgCatalogVersion(PG_VERSION_83), false, false, exclusionList, NULL),
"build manifest");
Buffer *contentSave = bufNew(0);
@ -404,7 +405,7 @@ testRun(void)
// Test manifest - mode stored for shared cluster tablespace dir, pg_xlog contents ignored because online
TEST_ASSIGN(
manifest, manifestNewBuild(storagePg, PG_VERSION_84, pgCatalogTestVersion(PG_VERSION_84), true, false, NULL, NULL),
manifest, manifestNewBuild(storagePg, PG_VERSION_84, hrnPgCatalogVersion(PG_VERSION_84), true, false, NULL, NULL),
"build manifest");
contentSave = bufNew(0);
@ -519,7 +520,7 @@ testRun(void)
// Test tablespace error
TEST_ERROR(
manifestNewBuild(storagePg, PG_VERSION_90, pgCatalogTestVersion(PG_VERSION_90), false, false, NULL, tablespaceList),
manifestNewBuild(storagePg, PG_VERSION_90, hrnPgCatalogVersion(PG_VERSION_90), false, false, NULL, tablespaceList),
AssertError,
"tablespace with oid 1 not found in tablespace map\n"
"HINT: was a tablespace created or dropped during the backup?");
@ -533,7 +534,7 @@ testRun(void)
// Test manifest - temp tables and pg_notify files ignored
TEST_ASSIGN(
manifest,
manifestNewBuild(storagePg, PG_VERSION_90, pgCatalogTestVersion(PG_VERSION_90), false, false, NULL, tablespaceList),
manifestNewBuild(storagePg, PG_VERSION_90, hrnPgCatalogVersion(PG_VERSION_90), false, false, NULL, tablespaceList),
"build manifest");
contentSave = bufNew(0);
@ -626,7 +627,7 @@ testRun(void)
// Test manifest - temp tables, unlogged tables, pg_serial and pg_xlog files ignored
TEST_ASSIGN(
manifest, manifestNewBuild(storagePg, PG_VERSION_91, pgCatalogTestVersion(PG_VERSION_91), true, false, NULL, NULL),
manifest, manifestNewBuild(storagePg, PG_VERSION_91, hrnPgCatalogVersion(PG_VERSION_91), true, false, NULL, NULL),
"build manifest");
contentSave = bufNew(0);
@ -711,7 +712,7 @@ testRun(void)
// Test manifest - pg_snapshots files ignored
TEST_ASSIGN(
manifest, manifestNewBuild(storagePg, PG_VERSION_92, pgCatalogTestVersion(PG_VERSION_92), false, false, NULL, NULL),
manifest, manifestNewBuild(storagePg, PG_VERSION_92, hrnPgCatalogVersion(PG_VERSION_92), false, false, NULL, NULL),
"build manifest");
contentSave = bufNew(0);
@ -853,7 +854,7 @@ testRun(void)
// Test manifest - pg_dynshmem, pg_replslot and postgresql.auto.conf.tmp files ignored
TEST_ASSIGN(
manifest, manifestNewBuild(storagePg, PG_VERSION_94, pgCatalogTestVersion(PG_VERSION_94), false, true, NULL, NULL),
manifest, manifestNewBuild(storagePg, PG_VERSION_94, hrnPgCatalogVersion(PG_VERSION_94), false, true, NULL, NULL),
"build manifest");
contentSave = bufNew(0);
@ -948,7 +949,7 @@ testRun(void)
// Tablespace link errors when correct verion not found
TEST_ERROR_FMT(
manifestNewBuild(storagePg, PG_VERSION_12, pgCatalogTestVersion(PG_VERSION_12), false, false, NULL, NULL),
manifestNewBuild(storagePg, PG_VERSION_12, hrnPgCatalogVersion(PG_VERSION_12), false, false, NULL, NULL),
FileOpenError,
"unable to get info for missing path/file '%s/pg/pg_tblspc/1/PG_12_201909212': [2] No such file or directory",
testPath());
@ -977,7 +978,7 @@ testRun(void)
// and backup_label ignored. Old recovery files and pg_xlog are now just another file/directory and will not be ignored.
// pg_wal contents will be ignored online. pg_clog pgVersion > 10 master:true, pg_xact pgVersion > 10 master:false
TEST_ASSIGN(
manifest, manifestNewBuild(storagePg, PG_VERSION_12, pgCatalogTestVersion(PG_VERSION_12), true, false, NULL, NULL),
manifest, manifestNewBuild(storagePg, PG_VERSION_12, hrnPgCatalogVersion(PG_VERSION_12), true, false, NULL, NULL),
"build manifest");
contentSave = bufNew(0);
@ -1049,7 +1050,7 @@ testRun(void)
// pg_wal not ignored
TEST_ASSIGN(
manifest, manifestNewBuild(storagePg, PG_VERSION_13, pgCatalogTestVersion(PG_VERSION_13), false, false, NULL, NULL),
manifest, manifestNewBuild(storagePg, PG_VERSION_13, hrnPgCatalogVersion(PG_VERSION_13), false, false, NULL, NULL),
"build manifest");
contentSave = bufNew(0);
@ -1121,7 +1122,7 @@ testRun(void)
FileOpenError, "unable to create symlink");
TEST_ERROR(
manifestNewBuild(storagePg, PG_VERSION_94, pgCatalogTestVersion(PG_VERSION_94), false, false, NULL, NULL),
manifestNewBuild(storagePg, PG_VERSION_94, hrnPgCatalogVersion(PG_VERSION_94), false, false, NULL, NULL),
LinkDestinationError, "link 'link' destination '{[path]}/pg/base' is in PGDATA");
THROW_ON_SYS_ERROR(
@ -1133,7 +1134,7 @@ testRun(void)
storagePathCreateP(storagePgWrite, strNew(MANIFEST_TARGET_PGTBLSPC "/somedir"), .mode = 0700, .noParentCreate = true);
TEST_ERROR(
manifestNewBuild(storagePg, PG_VERSION_94, pgCatalogTestVersion(PG_VERSION_94), false, false, NULL, NULL),
manifestNewBuild(storagePg, PG_VERSION_94, hrnPgCatalogVersion(PG_VERSION_94), false, false, NULL, NULL),
LinkExpectedError, "'pg_data/pg_tblspc/somedir' is not a symlink - pg_tblspc should contain only symlinks");
storagePathRemoveP(storagePgWrite, strNew(MANIFEST_TARGET_PGTBLSPC "/somedir"));
@ -1144,7 +1145,7 @@ testRun(void)
storagePutP(storageNewWriteP(storagePgWrite, strNew(MANIFEST_TARGET_PGTBLSPC "/somefile")), NULL);
TEST_ERROR(
manifestNewBuild(storagePg, PG_VERSION_94, pgCatalogTestVersion(PG_VERSION_94), false, false, NULL, NULL),
manifestNewBuild(storagePg, PG_VERSION_94, hrnPgCatalogVersion(PG_VERSION_94), false, false, NULL, NULL),
LinkExpectedError, "'pg_data/pg_tblspc/somefile' is not a symlink - pg_tblspc should contain only symlinks");
storageRemoveP(storagePgWrite, strNew(MANIFEST_TARGET_PGTBLSPC "/somefile"));
@ -1157,7 +1158,7 @@ testRun(void)
"unable to create symlink");
TEST_ERROR(
manifestNewBuild(storagePg, PG_VERSION_94, pgCatalogTestVersion(PG_VERSION_94), false, true, NULL, NULL), FileOpenError,
manifestNewBuild(storagePg, PG_VERSION_94, hrnPgCatalogVersion(PG_VERSION_94), false, true, NULL, NULL), FileOpenError,
"unable to get info for missing path/file '{[path]}/pg/link-to-link': [2] No such file or directory");
THROW_ON_SYS_ERROR(
@ -1175,7 +1176,7 @@ testRun(void)
FileOpenError, "unable to create symlink");
TEST_ERROR_FMT(
manifestNewBuild(storagePg, PG_VERSION_94, pgCatalogTestVersion(PG_VERSION_94), false, false, NULL, NULL),
manifestNewBuild(storagePg, PG_VERSION_94, hrnPgCatalogVersion(PG_VERSION_94), false, false, NULL, NULL),
LinkDestinationError, "link '%s/pg/linktolink' cannot reference another link '%s/linktest'", testPath(), testPath());
#undef TEST_MANIFEST_HEADER
@ -1286,7 +1287,7 @@ testRun(void)
Manifest *manifest = manifestNewInternal();
manifest->pub.info = infoNew(NULL);
manifest->pub.data.pgVersion = PG_VERSION_96;
manifest->pub.data.pgCatalogVersion = pgCatalogTestVersion(PG_VERSION_96);
manifest->pub.data.pgCatalogVersion = hrnPgCatalogVersion(PG_VERSION_96);
manifest->pub.data.backupOptionDelta = BOOL_FALSE_VAR;
manifestTargetAdd(manifest, &(ManifestTarget){.name = MANIFEST_TARGET_PGDATA_STR, .path = STRDEF("/pg")});

View File

@ -3,6 +3,8 @@ Test PostgreSQL Interface
***********************************************************************************************************************************/
#include "storage/posix/storage.h"
#include "common/harnessPostgres.h"
/***********************************************************************************************************************************
Test Run
***********************************************************************************************************************************/
@ -48,7 +50,7 @@ testRun(void)
String *controlFile = strNew(PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL);
// Create a bogus control file
Buffer *result = bufNew(PG_CONTROL_SIZE);
Buffer *result = bufNew(HRN_PG_CONTROL_SIZE);
memset(bufPtr(result), 0, bufSize(result));
bufUsedSet(result, bufSize(result));
@ -62,13 +64,10 @@ testRun(void)
pgControlFromBuffer(result), VersionNotSupportedError,
"unexpected control version = 501 and catalog version = 19780101\nHINT: is this version of PostgreSQL supported?");
//--------------------------------------------------------------------------------------------------------------------------
TEST_ERROR(pgControlTestToBuffer((PgControl){.version = 0}), AssertError, "invalid PostgreSQL version 0");
//--------------------------------------------------------------------------------------------------------------------------
storagePutP(
storageNewWriteP(storageTest, controlFile),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_11, .systemId = 0xFACEFACE, .walSegmentSize = 1024 * 1024}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_11, .systemId = 0xFACEFACE, .walSegmentSize = 1024 * 1024}));
PgControl info = {0};
TEST_ASSIGN(info, pgControlFromFile(storageTest), "get control info v11");
@ -79,7 +78,7 @@ testRun(void)
//--------------------------------------------------------------------------------------------------------------------------
storagePutP(
storageNewWriteP(storageTest, controlFile),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_93, .walSegmentSize = 1024 * 1024}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_93, .walSegmentSize = 1024 * 1024}));
TEST_ERROR(
pgControlFromFile(storageTest), FormatError, "wal segment size is 1048576 but must be 16777216 for PostgreSQL <= 10");
@ -87,16 +86,16 @@ testRun(void)
//--------------------------------------------------------------------------------------------------------------------------
storagePutP(
storageNewWriteP(storageTest, controlFile),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_95, .pageSize = 32 * 1024}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_95, .pageSize = 32 * 1024}));
TEST_ERROR(pgControlFromFile(storageTest), FormatError, "page size is 32768 but must be 8192");
//--------------------------------------------------------------------------------------------------------------------------
storagePutP(
storageNewWriteP(storageTest, controlFile),
pgControlTestToBuffer(
hrnPgControlToBuffer(
(PgControl){
.version = PG_VERSION_83, .systemId = 0xEFEFEFEFEF, .catalogVersion = pgCatalogTestVersion(PG_VERSION_83)}));
.version = PG_VERSION_83, .systemId = 0xEFEFEFEFEF, .catalogVersion = hrnPgCatalogVersion(PG_VERSION_83)}));
TEST_ASSIGN(info, pgControlFromFile(storageTest), "get control info v83");
TEST_RESULT_UINT(info.systemId, 0xEFEFEFEFEF, " check system id");
@ -209,11 +208,7 @@ testRun(void)
//--------------------------------------------------------------------------------------------------------------------------
memset(bufPtr(result), 0, bufSize(result));
TEST_ERROR(pgWalTestToBuffer((PgWal){.version = 0}, result), AssertError, "invalid PostgreSQL version 0");
//--------------------------------------------------------------------------------------------------------------------------
memset(bufPtr(result), 0, bufSize(result));
pgWalTestToBuffer(
hrnPgWalToBuffer(
(PgWal){.version = PG_VERSION_11, .systemId = 0xECAFECAF, .size = PG_WAL_SEGMENT_SIZE_DEFAULT * 2}, result);
storagePutP(storageNewWriteP(storageTest, walFile), result);
@ -225,14 +220,14 @@ testRun(void)
//--------------------------------------------------------------------------------------------------------------------------
memset(bufPtr(result), 0, bufSize(result));
pgWalTestToBuffer(
hrnPgWalToBuffer(
(PgWal){.version = PG_VERSION_83, .systemId = 0xEAEAEAEA, .size = PG_WAL_SEGMENT_SIZE_DEFAULT * 2}, result);
TEST_ERROR(pgWalFromBuffer(result), FormatError, "wal segment size is 33554432 but must be 16777216 for PostgreSQL <= 10");
//--------------------------------------------------------------------------------------------------------------------------
memset(bufPtr(result), 0, bufSize(result));
pgWalTestToBuffer((PgWal){.version = PG_VERSION_83, .systemId = 0xEAEAEAEA, .size = PG_WAL_SEGMENT_SIZE_DEFAULT}, result);
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_83, .systemId = 0xEAEAEAEA, .size = PG_WAL_SEGMENT_SIZE_DEFAULT}, result);
storagePutP(storageNewWriteP(storageTest, walFile), result);
TEST_ASSIGN(info, pgWalFromFile(walFile, storageTest), "get wal info v8.3");