Commit c1bab69c authored by Jim Harris's avatar Jim Harris Committed by Ben Walker
Browse files

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: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: Ib065898a228c405b201092b718c2f0b920104129

Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/449500


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarPaul Luse <paul.e.luse@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent b95d2597
Loading
Loading
Loading
Loading
+22 −5
Original line number Diff line number Diff line
@@ -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

static void
@@ -1119,10 +1138,10 @@ compress_algorithm(void)
	uint8_t original_data[BUFSIZE];
	uint8_t compressed_data[BUFSIZE];
	uint8_t decompressed_data[BUFSIZE];
	uint32_t compressed_len, decompressed_len, i;
	uint32_t compressed_len, decompressed_len;
	int rc;

	memset(original_data, 0xAA, BUFSIZE);
	ut_build_data_buffer(original_data, BUFSIZE, 0xAA, BUFSIZE);
	compressed_len = sizeof(compressed_data);
	rc = ut_compress(compressed_data, &compressed_len, original_data, UINT8_MAX);
	CU_ASSERT(rc == 0);
@@ -1151,9 +1170,7 @@ compress_algorithm(void)
	CU_ASSERT(decompressed_len == UINT8_MAX + 1);
	CU_ASSERT(memcmp(original_data, decompressed_data, decompressed_len) == 0);

	for (i = 0; i < sizeof(original_data); i++) {
		original_data[i] = i & 0xFF;
	}
	ut_build_data_buffer(original_data, BUFSIZE, 0x00, 1);
	compressed_len = sizeof(compressed_data);
	rc = ut_compress(compressed_data, &compressed_len, original_data, 2048);
	CU_ASSERT(rc == 0);