ut/reduce: add ut_build_data_buffer function

This function can be used to create data buffers
with varying levels of compression - we'll use
this in upcoming patches to test how lib/reduce
actually handles compressed buffers.

Modify the unit tests for the compression algorithm
to use this new function as well.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: Ib065898a228c405b201092b718c2f0b920104129

Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/449500
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Jim Harris 2019-03-28 09:30:19 -07:00 committed by Ben Walker
parent b95d25975d
commit c1bab69c61

View File

@ -1111,6 +1111,25 @@ ut_decompress(uint8_t *outbuf, uint32_t *compressed_len, uint8_t *inbuf, uint32_
} }
} }
static void
ut_build_data_buffer(uint8_t *data, uint32_t data_len, uint8_t init_val, uint32_t repeat)
{
uint32_t _repeat = repeat;
SPDK_CU_ASSERT_FATAL(repeat > 0);
while (data_len > 0) {
*data = init_val;
data++;
data_len--;
_repeat--;
if (_repeat == 0) {
init_val++;
_repeat = repeat;
}
}
}
#define BUFSIZE 4096 #define BUFSIZE 4096
static void static void
@ -1119,10 +1138,10 @@ compress_algorithm(void)
uint8_t original_data[BUFSIZE]; uint8_t original_data[BUFSIZE];
uint8_t compressed_data[BUFSIZE]; uint8_t compressed_data[BUFSIZE];
uint8_t decompressed_data[BUFSIZE]; uint8_t decompressed_data[BUFSIZE];
uint32_t compressed_len, decompressed_len, i; uint32_t compressed_len, decompressed_len;
int rc; int rc;
memset(original_data, 0xAA, BUFSIZE); ut_build_data_buffer(original_data, BUFSIZE, 0xAA, BUFSIZE);
compressed_len = sizeof(compressed_data); compressed_len = sizeof(compressed_data);
rc = ut_compress(compressed_data, &compressed_len, original_data, UINT8_MAX); rc = ut_compress(compressed_data, &compressed_len, original_data, UINT8_MAX);
CU_ASSERT(rc == 0); CU_ASSERT(rc == 0);
@ -1151,9 +1170,7 @@ compress_algorithm(void)
CU_ASSERT(decompressed_len == UINT8_MAX + 1); CU_ASSERT(decompressed_len == UINT8_MAX + 1);
CU_ASSERT(memcmp(original_data, decompressed_data, decompressed_len) == 0); CU_ASSERT(memcmp(original_data, decompressed_data, decompressed_len) == 0);
for (i = 0; i < sizeof(original_data); i++) { ut_build_data_buffer(original_data, BUFSIZE, 0x00, 1);
original_data[i] = i & 0xFF;
}
compressed_len = sizeof(compressed_data); compressed_len = sizeof(compressed_data);
rc = ut_compress(compressed_data, &compressed_len, original_data, 2048); rc = ut_compress(compressed_data, &compressed_len, original_data, 2048);
CU_ASSERT(rc == 0); CU_ASSERT(rc == 0);