2019-04-15 08:29:25 -04:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Test Common Functions and Definitions for Backup and Expire Commands
|
|
|
|
***********************************************************************************************************************************/
|
2019-06-17 07:52:03 -04:00
|
|
|
#include "common/io/bufferWrite.h"
|
|
|
|
#include "common/regExp.h"
|
|
|
|
#include "common/type/json.h"
|
|
|
|
#include "postgres/interface.h"
|
2020-05-18 19:11:26 -04:00
|
|
|
#include "postgres/interface/static.vendor.h"
|
2019-05-03 15:46:15 -04:00
|
|
|
#include "storage/posix/storage.h"
|
2019-04-15 08:29:25 -04:00
|
|
|
|
2021-09-24 17:40:31 -04:00
|
|
|
#include "common/harnessPack.h"
|
|
|
|
|
2019-04-15 08:29:25 -04:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Test Run
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
void
|
|
|
|
testRun(void)
|
|
|
|
{
|
|
|
|
FUNCTION_HARNESS_VOID();
|
|
|
|
|
|
|
|
// *****************************************************************************************************************************
|
|
|
|
if (testBegin("backupRegExp()"))
|
|
|
|
{
|
2021-05-21 17:36:43 -04:00
|
|
|
const String *full = STRDEF("20181119-152138F");
|
|
|
|
const String *incr = STRDEF("20181119-152138F_20181119-152152I");
|
|
|
|
const String *diff = STRDEF("20181119-152138F_20181119-152152D");
|
2019-04-15 08:29:25 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-15 17:00:20 -04:00
|
|
|
TEST_TITLE("regular expression - error");
|
|
|
|
|
2019-04-15 08:29:25 -04:00
|
|
|
TEST_ERROR(
|
|
|
|
backupRegExpP(0),
|
|
|
|
AssertError, "assertion 'param.full || param.differential || param.incremental' failed");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-15 17:00:20 -04:00
|
|
|
TEST_TITLE("regular expression - match full");
|
|
|
|
|
2019-12-19 16:25:46 -05:00
|
|
|
String *filter = backupRegExpP(.full = true);
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(filter, "^[0-9]{8}\\-[0-9]{6}F$", "full backup regex with anchors");
|
2021-07-15 17:00:20 -04:00
|
|
|
TEST_RESULT_BOOL(regExpMatchOne(filter, incr), false, "does not exactly match incr");
|
|
|
|
TEST_RESULT_BOOL(regExpMatchOne(filter, diff), false, "does not exactly match diff");
|
|
|
|
TEST_RESULT_BOOL(regExpMatchOne(filter, full), true, "exactly matches full");
|
2019-04-15 08:29:25 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-15 17:00:20 -04:00
|
|
|
TEST_TITLE("regular expression - match full, incremental");
|
|
|
|
|
2019-04-15 08:29:25 -04:00
|
|
|
filter = backupRegExpP(.full = true, .incremental = true);
|
2019-05-16 09:56:48 -04:00
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(
|
|
|
|
filter, "^[0-9]{8}\\-[0-9]{6}F(\\_[0-9]{8}\\-[0-9]{6}I){0,1}$", "full and optional incr backup regex with anchors");
|
2021-07-15 17:00:20 -04:00
|
|
|
TEST_RESULT_BOOL(regExpMatchOne(filter, incr), true, "match incr");
|
|
|
|
TEST_RESULT_BOOL(regExpMatchOne(filter, diff), false, "does not match diff");
|
|
|
|
TEST_RESULT_BOOL(regExpMatchOne(filter, full), true, "match full");
|
2019-04-15 08:29:25 -04:00
|
|
|
TEST_RESULT_BOOL(
|
|
|
|
regExpMatchOne(
|
2021-07-15 17:00:20 -04:00
|
|
|
filter, STRDEF("12341234-123123F_12341234-123123IG")), false, "does not match with trailing character");
|
2019-04-15 08:29:25 -04:00
|
|
|
TEST_RESULT_BOOL(
|
|
|
|
regExpMatchOne(
|
2021-07-15 17:00:20 -04:00
|
|
|
filter, STRDEF("A12341234-123123F_12341234-123123I")), false, "does not match with leading character");
|
2019-04-15 08:29:25 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-15 17:00:20 -04:00
|
|
|
TEST_TITLE("regular expression - match full, differential");
|
|
|
|
|
2019-04-15 08:29:25 -04:00
|
|
|
filter = backupRegExpP(.full = true, .differential = true);
|
2019-05-16 09:56:48 -04:00
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(
|
|
|
|
filter, "^[0-9]{8}\\-[0-9]{6}F(\\_[0-9]{8}\\-[0-9]{6}D){0,1}$", "full and optional diff backup regex with anchors");
|
2021-07-15 17:00:20 -04:00
|
|
|
TEST_RESULT_BOOL(regExpMatchOne(filter, incr), false, "does not match incr");
|
|
|
|
TEST_RESULT_BOOL(regExpMatchOne(filter, diff), true, "match diff");
|
|
|
|
TEST_RESULT_BOOL(regExpMatchOne(filter, full), true, "match full");
|
2019-04-15 08:29:25 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-15 17:00:20 -04:00
|
|
|
TEST_TITLE("regular expression - match full, incremental, differential");
|
|
|
|
|
2019-04-15 08:29:25 -04:00
|
|
|
filter = backupRegExpP(.full = true, .incremental = true, .differential = true);
|
2019-05-16 09:56:48 -04:00
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(
|
|
|
|
filter, "^[0-9]{8}\\-[0-9]{6}F(\\_[0-9]{8}\\-[0-9]{6}(D|I)){0,1}$",
|
|
|
|
"full, optional diff and incr backup regex with anchors");
|
2021-07-15 17:00:20 -04:00
|
|
|
TEST_RESULT_BOOL(regExpMatchOne(filter, incr), true, "match incr");
|
|
|
|
TEST_RESULT_BOOL(regExpMatchOne(filter, diff), true, "match diff");
|
|
|
|
TEST_RESULT_BOOL(regExpMatchOne(filter, full), true, "match full");
|
2019-04-15 08:29:25 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-15 17:00:20 -04:00
|
|
|
TEST_TITLE("regular expression - match incremental, differential without end anchor");
|
|
|
|
|
2019-12-12 18:52:16 -05:00
|
|
|
filter = backupRegExpP(.incremental = true, .differential = true, .noAnchorEnd = true);
|
2019-05-16 09:56:48 -04:00
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(filter, "^[0-9]{8}\\-[0-9]{6}F\\_[0-9]{8}\\-[0-9]{6}(D|I)", "diff and incr backup regex with anchors");
|
2021-07-15 17:00:20 -04:00
|
|
|
TEST_RESULT_BOOL(regExpMatchOne(filter, incr), true, "match incr");
|
|
|
|
TEST_RESULT_BOOL(regExpMatchOne(filter, diff), true, "match diff");
|
|
|
|
TEST_RESULT_BOOL(regExpMatchOne(filter, full), false, "does not match full");
|
2019-04-15 08:29:25 -04:00
|
|
|
TEST_RESULT_BOOL(
|
|
|
|
regExpMatchOne(
|
2021-07-15 17:00:20 -04:00
|
|
|
filter, STRDEF("A12341234-123123F_12341234-123123I")), false, "does not match with leading character");
|
2019-04-15 08:29:25 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-15 17:00:20 -04:00
|
|
|
TEST_TITLE("regular expression - match incremental");
|
|
|
|
|
2019-04-15 08:29:25 -04:00
|
|
|
filter = backupRegExpP(.incremental = true);
|
2019-05-16 09:56:48 -04:00
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(filter, "^[0-9]{8}\\-[0-9]{6}F\\_[0-9]{8}\\-[0-9]{6}I$", "incr backup regex with anchors");
|
2021-07-15 17:00:20 -04:00
|
|
|
TEST_RESULT_BOOL(regExpMatchOne(filter, incr), true, "match incr");
|
|
|
|
TEST_RESULT_BOOL(regExpMatchOne(filter, diff), false, "does not match diff");
|
|
|
|
TEST_RESULT_BOOL(regExpMatchOne(filter, full), false, "does not match full");
|
2019-04-15 08:29:25 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-15 17:00:20 -04:00
|
|
|
TEST_TITLE("regular expression - match differential");
|
|
|
|
|
2019-04-15 08:29:25 -04:00
|
|
|
filter = backupRegExpP(.differential = true);
|
2019-05-16 09:56:48 -04:00
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(filter, "^[0-9]{8}\\-[0-9]{6}F\\_[0-9]{8}\\-[0-9]{6}D$", "diff backup regex with anchors");
|
2021-07-15 17:00:20 -04:00
|
|
|
TEST_RESULT_BOOL(regExpMatchOne(filter, incr), false, "does not match incr");
|
|
|
|
TEST_RESULT_BOOL(regExpMatchOne(filter, diff), true, "match diff");
|
|
|
|
TEST_RESULT_BOOL(regExpMatchOne(filter, full), false, "does not match full");
|
2019-04-15 08:29:25 -04:00
|
|
|
}
|
|
|
|
|
2019-06-17 07:52:03 -04:00
|
|
|
// *****************************************************************************************************************************
|
|
|
|
if (testBegin("PageChecksum"))
|
|
|
|
{
|
2021-07-15 17:00:20 -04:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_TITLE("segment page default");
|
|
|
|
|
2019-06-17 07:52:03 -04:00
|
|
|
TEST_RESULT_UINT(PG_SEGMENT_PAGE_DEFAULT, 131072, "check pages per segment");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-15 17:00:20 -04:00
|
|
|
TEST_TITLE("pages with all zeroes");
|
|
|
|
|
|
|
|
// Test pages with all zeros (these are considered valid)
|
2019-06-17 07:52:03 -04:00
|
|
|
Buffer *buffer = bufNew(PG_PAGE_SIZE_DEFAULT * 3);
|
|
|
|
Buffer *bufferOut = bufNew(0);
|
|
|
|
bufUsedSet(buffer, bufSize(buffer));
|
|
|
|
memset(bufPtr(buffer), 0, bufSize(buffer));
|
2020-01-23 14:15:58 -07:00
|
|
|
*(PageHeaderData *)(bufPtr(buffer) + (PG_PAGE_SIZE_DEFAULT * 0x00)) = (PageHeaderData){.pd_upper = 0};
|
|
|
|
*(PageHeaderData *)(bufPtr(buffer) + (PG_PAGE_SIZE_DEFAULT * 0x01)) = (PageHeaderData){.pd_upper = 0};
|
|
|
|
*(PageHeaderData *)(bufPtr(buffer) + (PG_PAGE_SIZE_DEFAULT * 0x02)) = (PageHeaderData){.pd_upper = 0};
|
2019-06-17 07:52:03 -04:00
|
|
|
|
2019-06-24 10:20:47 -04:00
|
|
|
IoWrite *write = ioBufferWriteNew(bufferOut);
|
2020-03-05 09:14:27 -05:00
|
|
|
ioFilterGroupAdd(ioWriteFilterGroup(write), pageChecksumNew(0, PG_SEGMENT_PAGE_DEFAULT, 0));
|
2019-06-17 07:52:03 -04:00
|
|
|
ioWriteOpen(write);
|
|
|
|
ioWrite(write, buffer);
|
|
|
|
ioWriteClose(write);
|
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(
|
2021-09-24 17:40:31 -04:00
|
|
|
hrnPackToStr(ioFilterGroupResultPackP(ioWriteFilterGroup(write), PAGE_CHECKSUM_FILTER_TYPE)),
|
|
|
|
"2:bool:true, 3:bool:true", "all zero pages");
|
2019-06-17 07:52:03 -04:00
|
|
|
|
2020-03-05 16:12:54 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-15 17:00:20 -04:00
|
|
|
TEST_TITLE("single valid page");
|
|
|
|
|
2020-03-05 16:12:54 -05:00
|
|
|
buffer = bufNew(PG_PAGE_SIZE_DEFAULT * 1);
|
|
|
|
bufUsedSet(buffer, bufSize(buffer));
|
|
|
|
memset(bufPtr(buffer), 0, bufSize(buffer));
|
|
|
|
|
|
|
|
// Page 0 has good checksum
|
|
|
|
*(PageHeaderData *)(bufPtr(buffer) + (PG_PAGE_SIZE_DEFAULT * 0x00)) = (PageHeaderData)
|
|
|
|
{
|
|
|
|
.pd_upper = 0x01,
|
|
|
|
.pd_lsn = (PageXLogRecPtr)
|
|
|
|
{
|
|
|
|
.xlogid = 0xF0F0F0F0,
|
|
|
|
.xrecoff = 0xF0F0F0F0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
((PageHeaderData *)(bufPtr(buffer) + (PG_PAGE_SIZE_DEFAULT * 0x00)))->pd_checksum = pgPageChecksum(
|
|
|
|
bufPtr(buffer) + (PG_PAGE_SIZE_DEFAULT * 0x00), 0);
|
|
|
|
|
|
|
|
write = ioBufferWriteNew(bufferOut);
|
|
|
|
|
|
|
|
ioFilterGroupAdd(
|
|
|
|
ioWriteFilterGroup(write),
|
2021-09-22 10:48:21 -04:00
|
|
|
pageChecksumNewPack(ioFilterParamList(pageChecksumNew(0, PG_SEGMENT_PAGE_DEFAULT, 0xFACEFACE00000000))));
|
2020-03-05 16:12:54 -05:00
|
|
|
ioWriteOpen(write);
|
|
|
|
ioWrite(write, buffer);
|
|
|
|
ioWriteClose(write);
|
|
|
|
|
|
|
|
TEST_RESULT_STR_Z(
|
2021-09-24 17:40:31 -04:00
|
|
|
hrnPackToStr(ioFilterGroupResultPackP(ioWriteFilterGroup(write), PAGE_CHECKSUM_FILTER_TYPE)),
|
|
|
|
"2:bool:true, 3:bool:true", "single valid page");
|
2020-03-05 16:12:54 -05:00
|
|
|
|
2019-06-17 07:52:03 -04:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-15 17:00:20 -04:00
|
|
|
TEST_TITLE("single checksum error");
|
|
|
|
|
2019-06-17 07:52:03 -04:00
|
|
|
buffer = bufNew(PG_PAGE_SIZE_DEFAULT * 1);
|
|
|
|
bufUsedSet(buffer, bufSize(buffer));
|
|
|
|
memset(bufPtr(buffer), 0, bufSize(buffer));
|
|
|
|
|
|
|
|
// Page 0 has bogus checksum
|
2020-01-23 14:15:58 -07:00
|
|
|
*(PageHeaderData *)(bufPtr(buffer) + (PG_PAGE_SIZE_DEFAULT * 0x00)) = (PageHeaderData)
|
|
|
|
{
|
|
|
|
.pd_upper = 0x01,
|
2020-03-04 13:31:27 -05:00
|
|
|
.pd_lsn = (PageXLogRecPtr)
|
2020-01-23 14:15:58 -07:00
|
|
|
{
|
2020-03-04 13:31:27 -05:00
|
|
|
.xlogid = 0xF0F0F0F0,
|
2020-01-23 14:15:58 -07:00
|
|
|
.xrecoff = 0xF0F0F0F0,
|
|
|
|
},
|
|
|
|
};
|
2019-06-17 07:52:03 -04:00
|
|
|
|
2019-06-24 10:20:47 -04:00
|
|
|
write = ioBufferWriteNew(bufferOut);
|
2019-07-15 16:49:46 -04:00
|
|
|
|
2019-06-24 10:20:47 -04:00
|
|
|
ioFilterGroupAdd(
|
2019-07-15 16:49:46 -04:00
|
|
|
ioWriteFilterGroup(write),
|
2021-09-22 10:48:21 -04:00
|
|
|
pageChecksumNewPack(ioFilterParamList(pageChecksumNew(0, PG_SEGMENT_PAGE_DEFAULT, 0xFACEFACE00000000))));
|
2019-06-17 07:52:03 -04:00
|
|
|
ioWriteOpen(write);
|
|
|
|
ioWrite(write, buffer);
|
|
|
|
ioWriteClose(write);
|
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(
|
2021-09-24 17:40:31 -04:00
|
|
|
hrnPackToStr(ioFilterGroupResultPackP(ioWriteFilterGroup(write), PAGE_CHECKSUM_FILTER_TYPE)),
|
|
|
|
"1:array:[1:obj:{1:u64:17361641481138401520}], 2:bool:false, 3:bool:true", "single checksum error");
|
2019-06-17 07:52:03 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-15 17:00:20 -04:00
|
|
|
TEST_TITLE("various checksum errors some of which will be skipped because of the LSN");
|
|
|
|
|
2019-06-17 07:52:03 -04:00
|
|
|
buffer = bufNew(PG_PAGE_SIZE_DEFAULT * 8 - (PG_PAGE_SIZE_DEFAULT - 512));
|
|
|
|
bufUsedSet(buffer, bufSize(buffer));
|
|
|
|
memset(bufPtr(buffer), 0, bufSize(buffer));
|
|
|
|
|
|
|
|
// Page 0 has bogus checksum
|
2020-01-23 14:15:58 -07:00
|
|
|
*(PageHeaderData *)(bufPtr(buffer) + (PG_PAGE_SIZE_DEFAULT * 0x00)) = (PageHeaderData)
|
|
|
|
{
|
|
|
|
.pd_upper = 0x01,
|
2020-03-04 13:31:27 -05:00
|
|
|
.pd_lsn = (PageXLogRecPtr)
|
2020-01-23 14:15:58 -07:00
|
|
|
{
|
2020-03-04 13:31:27 -05:00
|
|
|
.xlogid = 0xF0F0F0F0,
|
2020-01-23 14:15:58 -07:00
|
|
|
.xrecoff = 0xF0F0F0F0,
|
|
|
|
},
|
|
|
|
};
|
2019-06-17 07:52:03 -04:00
|
|
|
|
|
|
|
// Page 1 has bogus checksum but lsn above the limit
|
2020-01-23 14:15:58 -07:00
|
|
|
*(PageHeaderData *)(bufPtr(buffer) + (PG_PAGE_SIZE_DEFAULT * 0x01)) = (PageHeaderData)
|
|
|
|
{
|
|
|
|
.pd_upper = 0x01,
|
2020-03-04 13:31:27 -05:00
|
|
|
.pd_lsn = (PageXLogRecPtr)
|
2020-01-23 14:15:58 -07:00
|
|
|
{
|
2020-03-04 13:31:27 -05:00
|
|
|
.xlogid = 0xFACEFACE,
|
2020-01-23 14:15:58 -07:00
|
|
|
.xrecoff = 0x00000000,
|
|
|
|
},
|
|
|
|
};
|
2019-06-17 07:52:03 -04:00
|
|
|
|
|
|
|
// Page 2 has bogus checksum
|
2020-01-23 14:15:58 -07:00
|
|
|
*(PageHeaderData *)(bufPtr(buffer) + (PG_PAGE_SIZE_DEFAULT * 0x02)) = (PageHeaderData)
|
|
|
|
{
|
|
|
|
.pd_upper = 0x01,
|
2020-03-04 13:31:27 -05:00
|
|
|
.pd_lsn = (PageXLogRecPtr)
|
2020-01-23 14:15:58 -07:00
|
|
|
{
|
|
|
|
.xrecoff = 0x2,
|
|
|
|
},
|
|
|
|
};
|
2019-06-17 07:52:03 -04:00
|
|
|
|
|
|
|
// Page 3 has bogus checksum
|
2020-01-23 14:15:58 -07:00
|
|
|
*(PageHeaderData *)(bufPtr(buffer) + (PG_PAGE_SIZE_DEFAULT * 0x03)) = (PageHeaderData)
|
|
|
|
{
|
|
|
|
.pd_upper = 0x01,
|
2020-03-04 13:31:27 -05:00
|
|
|
.pd_lsn = (PageXLogRecPtr)
|
2020-01-23 14:15:58 -07:00
|
|
|
{
|
|
|
|
.xrecoff = 0x3,
|
|
|
|
},
|
|
|
|
};
|
2019-06-17 07:52:03 -04:00
|
|
|
|
|
|
|
// Page 4 has bogus checksum
|
2020-01-23 14:15:58 -07:00
|
|
|
*(PageHeaderData *)(bufPtr(buffer) + (PG_PAGE_SIZE_DEFAULT * 0x04)) = (PageHeaderData)
|
|
|
|
{
|
|
|
|
.pd_upper = 0x01,
|
2020-03-04 13:31:27 -05:00
|
|
|
.pd_lsn = (PageXLogRecPtr)
|
2020-01-23 14:15:58 -07:00
|
|
|
{
|
|
|
|
.xrecoff = 0x4,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Page 5 is zero
|
|
|
|
*(PageHeaderData *)(bufPtr(buffer) + (PG_PAGE_SIZE_DEFAULT * 0x05)) = (PageHeaderData){.pd_upper = 0x00};
|
2019-06-17 07:52:03 -04:00
|
|
|
|
|
|
|
// Page 6 has bogus checksum
|
2020-01-23 14:15:58 -07:00
|
|
|
*(PageHeaderData *)(bufPtr(buffer) + (PG_PAGE_SIZE_DEFAULT * 0x06)) = (PageHeaderData)
|
|
|
|
{
|
|
|
|
.pd_upper = 0x01,
|
2020-03-04 13:31:27 -05:00
|
|
|
.pd_lsn = (PageXLogRecPtr)
|
2020-01-23 14:15:58 -07:00
|
|
|
{
|
|
|
|
.xrecoff = 0x6,
|
|
|
|
},
|
|
|
|
};
|
2019-06-17 07:52:03 -04:00
|
|
|
|
|
|
|
// Page 7 has bogus checksum (and is misaligned but large enough to test)
|
2020-01-23 14:15:58 -07:00
|
|
|
*(PageHeaderData *)(bufPtr(buffer) + (PG_PAGE_SIZE_DEFAULT * 0x07)) = (PageHeaderData)
|
|
|
|
{
|
|
|
|
.pd_upper = 0x01,
|
2020-03-04 13:31:27 -05:00
|
|
|
.pd_lsn = (PageXLogRecPtr)
|
2020-01-23 14:15:58 -07:00
|
|
|
{
|
|
|
|
.xrecoff = 0x7,
|
|
|
|
},
|
|
|
|
};
|
2019-06-17 07:52:03 -04:00
|
|
|
|
2019-06-24 10:20:47 -04:00
|
|
|
write = ioBufferWriteNew(bufferOut);
|
2020-03-05 09:14:27 -05:00
|
|
|
ioFilterGroupAdd(ioWriteFilterGroup(write), pageChecksumNew(0, PG_SEGMENT_PAGE_DEFAULT, 0xFACEFACE00000000));
|
2019-06-17 07:52:03 -04:00
|
|
|
ioWriteOpen(write);
|
|
|
|
ioWrite(write, buffer);
|
|
|
|
ioWriteClose(write);
|
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(
|
2021-09-24 17:40:31 -04:00
|
|
|
hrnPackToStr(ioFilterGroupResultPackP(ioWriteFilterGroup(write), PAGE_CHECKSUM_FILTER_TYPE)),
|
|
|
|
"1:array:[1:obj:{1:u64:17361641481138401520}, 3:obj:{1:u64:2}, 4:obj:{1:u64:3}, 5:obj:{1:u64:4}, 7:obj:{1:u64:6},"
|
|
|
|
" 8:obj:{1:u64:7}], 2:bool:false, 3:bool:false",
|
|
|
|
"various checksum errors");
|
2019-06-17 07:52:03 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-15 17:00:20 -04:00
|
|
|
TEST_TITLE("impossibly misaligned page");
|
|
|
|
|
2019-06-17 07:52:03 -04:00
|
|
|
buffer = bufNew(256);
|
|
|
|
bufUsedSet(buffer, bufSize(buffer));
|
|
|
|
memset(bufPtr(buffer), 0, bufSize(buffer));
|
|
|
|
|
2020-01-23 14:15:58 -07:00
|
|
|
*(PageHeaderData *)(bufPtr(buffer) + (PG_PAGE_SIZE_DEFAULT * 0x00)) = (PageHeaderData){.pd_upper = 0};
|
|
|
|
|
2019-06-24 10:20:47 -04:00
|
|
|
write = ioBufferWriteNew(bufferOut);
|
2020-03-05 09:14:27 -05:00
|
|
|
ioFilterGroupAdd(ioWriteFilterGroup(write), pageChecksumNew(0, PG_SEGMENT_PAGE_DEFAULT, 0xFACEFACE00000000));
|
2019-06-17 07:52:03 -04:00
|
|
|
ioWriteOpen(write);
|
|
|
|
ioWrite(write, buffer);
|
|
|
|
ioWriteClose(write);
|
|
|
|
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_STR_Z(
|
2021-09-24 17:40:31 -04:00
|
|
|
hrnPackToStr(ioFilterGroupResultPackP(ioWriteFilterGroup(write), PAGE_CHECKSUM_FILTER_TYPE)),
|
|
|
|
"2:bool:false, 3:bool:false", "misalignment");
|
2019-06-17 07:52:03 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2021-07-15 17:00:20 -04:00
|
|
|
TEST_TITLE("two misaligned buffers in a row");
|
|
|
|
|
2019-06-17 07:52:03 -04:00
|
|
|
buffer = bufNew(513);
|
|
|
|
bufUsedSet(buffer, bufSize(buffer));
|
|
|
|
memset(bufPtr(buffer), 0, bufSize(buffer));
|
|
|
|
|
2020-01-23 14:15:58 -07:00
|
|
|
*(PageHeaderData *)(bufPtr(buffer) + (PG_PAGE_SIZE_DEFAULT * 0x00)) = (PageHeaderData){.pd_upper = 0};
|
|
|
|
|
2019-06-24 10:20:47 -04:00
|
|
|
write = ioBufferWriteNew(bufferOut);
|
2020-03-05 09:14:27 -05:00
|
|
|
ioFilterGroupAdd(ioWriteFilterGroup(write), pageChecksumNew(0, PG_SEGMENT_PAGE_DEFAULT, 0xFACEFACE00000000));
|
2019-06-17 07:52:03 -04:00
|
|
|
ioWriteOpen(write);
|
|
|
|
ioWrite(write, buffer);
|
|
|
|
TEST_ERROR(ioWrite(write, buffer), AssertError, "should not be possible to see two misaligned pages in a row");
|
|
|
|
}
|
|
|
|
|
2021-03-10 18:42:22 -05:00
|
|
|
FUNCTION_HARNESS_RETURN_VOID();
|
2019-04-15 08:29:25 -04:00
|
|
|
}
|