1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-18 04:58:51 +02:00

Move block testBlockDelta() to harness module.

This makes the function available to other test modules.

Also rename to hrnBlockDeltaRender().
This commit is contained in:
David Steele 2023-12-26 21:07:56 -03:00
parent 9049fec2c0
commit 4324b568a9
4 changed files with 83 additions and 51 deletions

View File

@ -885,6 +885,10 @@ unit:
command/backup/backup:
function:
- backupProcess
harness:
name: blockIncr
shim:
command/restore/blockDelta: ~
coverage:
- command/backup/backup

View File

@ -0,0 +1,57 @@
/***********************************************************************************************************************************
Harness for Testing Block Deltas
***********************************************************************************************************************************/
#include "build.auto.h"
#include "command/restore/blockDelta.h"
#include "common/harnessBlockIncr.h"
#include "common/harnessDebug.h"
/***********************************************************************************************************************************
Include shimmed C modules
***********************************************************************************************************************************/
{[SHIM_MODULE]}
/**********************************************************************************************************************************/
String *
hrnBlockDeltaRender(const BlockMap *const blockMap, const size_t blockSize, const size_t checksumSize)
{
FUNCTION_HARNESS_BEGIN();
FUNCTION_HARNESS_PARAM(BLOCK_MAP, blockMap);
FUNCTION_HARNESS_PARAM(SIZE, blockSize);
FUNCTION_HARNESS_PARAM(SIZE, checksumSize);
FUNCTION_HARNESS_END();
ASSERT(blockMap != NULL);
ASSERT(blockSize > 0);
String *const result = strNew();
BlockDelta *const blockDelta = blockDeltaNew(blockMap, blockSize, checksumSize, NULL, cipherTypeNone, NULL, compressTypeNone);
for (unsigned int readIdx = 0; readIdx < blockDeltaReadSize(blockDelta); readIdx++)
{
const BlockDeltaRead *const read = blockDeltaReadGet(blockDelta, readIdx);
strCatFmt(
result, "read {reference: %u, bundleId: %" PRIu64 ", offset: %" PRIu64 ", size: %" PRIu64 "}\n", read->reference,
read->bundleId, read->offset, read->size);
for (unsigned int superBlockIdx = 0; superBlockIdx < lstSize(read->superBlockList); superBlockIdx++)
{
const BlockDeltaSuperBlock *const superBlock = lstGet(read->superBlockList, superBlockIdx);
strCatFmt(
result, " super block {max: %" PRIu64 ", size: %" PRIu64 "}\n", superBlock->superBlockSize, superBlock->size);
for (unsigned int blockIdx = 0; blockIdx < lstSize(superBlock->blockList); blockIdx++)
{
const BlockDeltaBlock *const block = lstGet(superBlock->blockList, blockIdx);
strCatFmt(result, " block {no: %" PRIu64 ", offset: %" PRIu64 "}\n", block->no, block->offset);
}
}
}
FUNCTION_HARNESS_RETURN(STRING, result);
}

View File

@ -0,0 +1,15 @@
/***********************************************************************************************************************************
Harness for Testing Block Deltas
***********************************************************************************************************************************/
#ifndef TEST_COMMON_HARNESS_BLOCK_DELTA_H
#define TEST_COMMON_HARNESS_BLOCK_DELTA_H
#include "command/backup/blockMap.h"
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
// Render the block delta as text for testing
String *hrnBlockDeltaRender(const BlockMap *blockMap, size_t blockSize, size_t checksumSize);
#endif

View File

@ -11,6 +11,7 @@ Test Backup Command
#include "storage/posix/storage.h"
#include "common/harnessBackup.h"
#include "common/harnessBlockIncr.h"
#include "common/harnessConfig.h"
#include "common/harnessManifest.h"
#include "common/harnessPack.h"
@ -19,51 +20,6 @@ Test Backup Command
#include "common/harnessProtocol.h"
#include "common/harnessStorage.h"
/***********************************************************************************************************************************
Test block delta
***********************************************************************************************************************************/
static String *
testBlockDelta(const BlockMap *const blockMap, const size_t blockSize, const size_t checksumSize)
{
FUNCTION_HARNESS_BEGIN();
FUNCTION_HARNESS_PARAM(BLOCK_MAP, blockMap);
FUNCTION_HARNESS_PARAM(SIZE, blockSize);
FUNCTION_HARNESS_PARAM(SIZE, checksumSize);
FUNCTION_HARNESS_END();
ASSERT(blockMap != NULL);
ASSERT(blockSize > 0);
String *const result = strNew();
BlockDelta *const blockDelta = blockDeltaNew(blockMap, blockSize, checksumSize, NULL, cipherTypeNone, NULL, compressTypeNone);
for (unsigned int readIdx = 0; readIdx < blockDeltaReadSize(blockDelta); readIdx++)
{
const BlockDeltaRead *const read = blockDeltaReadGet(blockDelta, readIdx);
strCatFmt(
result, "read {reference: %u, bundleId: %" PRIu64 ", offset: %" PRIu64 ", size: %" PRIu64 "}\n", read->reference,
read->bundleId, read->offset, read->size);
for (unsigned int superBlockIdx = 0; superBlockIdx < lstSize(read->superBlockList); superBlockIdx++)
{
const BlockDeltaSuperBlock *const superBlock = lstGet(read->superBlockList, superBlockIdx);
strCatFmt(
result, " super block {max: %" PRIu64 ", size: %" PRIu64 "}\n", superBlock->superBlockSize, superBlock->size);
for (unsigned int blockIdx = 0; blockIdx < lstSize(superBlock->blockList); blockIdx++)
{
const BlockDeltaBlock *const block = lstGet(superBlock->blockList, blockIdx);
strCatFmt(result, " block {no: %" PRIu64 ", offset: %" PRIu64 "}\n", block->no, block->offset);
}
}
}
FUNCTION_HARNESS_RETURN(STRING, result);
}
/***********************************************************************************************************************************
Get a list of all files in the backup and a redacted version of the manifest that can be tested against a static string
***********************************************************************************************************************************/
@ -877,7 +833,7 @@ testRun(void)
TEST_TITLE("equal block delta");
TEST_RESULT_STR_Z(
testBlockDelta(blockMapNewRead(ioBufferReadNewOpen(buffer), 1, 5), 1, 5),
hrnBlockDeltaRender(blockMapNewRead(ioBufferReadNewOpen(buffer), 1, 5), 1, 5),
"read {reference: 128, bundleId: 0, offset: 0, size: 107}\n"
" super block {max: 1, size: 3}\n"
" block {no: 0, offset: 0}\n"
@ -1075,7 +1031,7 @@ testRun(void)
TEST_TITLE("unequal block delta");
TEST_RESULT_STR_Z(
testBlockDelta(blockMapNewRead(ioBufferReadNewOpen(buffer), 3, 8), 3, 8),
hrnBlockDeltaRender(blockMapNewRead(ioBufferReadNewOpen(buffer), 3, 8), 3, 8),
"read {reference: 2, bundleId: 0, offset: 0, size: 1}\n"
" super block {max: 2, size: 1}\n"
" block {no: 0, offset: 15}\n"
@ -1158,7 +1114,7 @@ testRun(void)
const Buffer *map = BUF(bufPtr(destination) + (bufUsed(destination) - (size_t)mapSize), (size_t)mapSize);
TEST_RESULT_STR_Z(
testBlockDelta(blockMapNewRead(ioBufferReadNewOpen(map), 3, 8), 3, 8),
hrnBlockDeltaRender(blockMapNewRead(ioBufferReadNewOpen(map), 3, 8), 3, 8),
"read {reference: 0, bundleId: 0, offset: 0, size: 2}\n"
" super block {max: 2, size: 2}\n"
" block {no: 0, offset: 0}\n",
@ -1195,7 +1151,7 @@ testRun(void)
map = BUF(bufPtr(destination) + (bufUsed(destination) - (size_t)mapSize), (size_t)mapSize);
TEST_RESULT_STR_Z(
testBlockDelta(blockMapNewRead(ioBufferReadNewOpen(map), 3, 8), 3, 8),
hrnBlockDeltaRender(blockMapNewRead(ioBufferReadNewOpen(map), 3, 8), 3, 8),
"read {reference: 2, bundleId: 4, offset: 5, size: 9}\n"
" super block {max: 3, size: 3}\n"
" block {no: 0, offset: 0}\n"
@ -1236,7 +1192,7 @@ testRun(void)
map = BUF(bufPtr(destination) + (bufUsed(destination) - (size_t)mapSize), (size_t)mapSize);
TEST_RESULT_STR_Z(
testBlockDelta(blockMapNewRead(ioBufferReadNewOpen(map), 3, 8), 3, 8),
hrnBlockDeltaRender(blockMapNewRead(ioBufferReadNewOpen(map), 3, 8), 3, 8),
"read {reference: 3, bundleId: 0, offset: 0, size: 4}\n"
" super block {max: 3, size: 3}\n"
" block {no: 0, offset: 0}\n"
@ -1281,7 +1237,7 @@ testRun(void)
map = BUF(bufPtr(destination) + (bufUsed(destination) - (size_t)mapSize), (size_t)mapSize);
TEST_RESULT_STR_Z(
testBlockDelta(blockMapNewRead(ioBufferReadNewOpen(map), 3, 8), 3, 8),
hrnBlockDeltaRender(blockMapNewRead(ioBufferReadNewOpen(map), 3, 8), 3, 8),
"read {reference: 2, bundleId: 4, offset: 5, size: 9}\n"
" super block {max: 6, size: 6}\n"
" block {no: 0, offset: 0}\n"