From 27631eb5714067c802b1318081c1d85babea5036 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 28 Mar 2019 13:54:35 -0700 Subject: [PATCH] ut/reduce: move ut_compress/decompress functions This just moves code to prepare for these functions to be used earlier in the file without adding extra function declarations. Move ut_build_data_buffer as well for similar reasons. Signed-off-by: Jim Harris Change-Id: Ifd4fb4abbd43aaa01fca3b73bbfd847ffdd4d6f7 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/449512 Tested-by: SPDK CI Jenkins Reviewed-by: Paul Luse Reviewed-by: Shuhei Matsumoto Reviewed-by: Ben Walker --- test/unit/lib/reduce/reduce.c/reduce_ut.c | 156 +++++++++++----------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/test/unit/lib/reduce/reduce.c/reduce_ut.c b/test/unit/lib/reduce/reduce.c/reduce_ut.c index 14937826b..441cbbdd1 100644 --- a/test/unit/lib/reduce/reduce.c/reduce_ut.c +++ b/test/unit/lib/reduce/reduce.c/reduce_ut.c @@ -389,6 +389,84 @@ backing_dev_io_execute(uint32_t count) } } +static int +ut_compress(char *outbuf, uint32_t *compressed_len, char *inbuf, uint32_t inbuflen) +{ + uint32_t len = 0; + uint8_t count; + char last; + + while (true) { + if (inbuflen == 0) { + *compressed_len = len; + return 0; + } + + if (*compressed_len < (len + 2)) { + return -ENOSPC; + } + + last = *inbuf; + count = 1; + inbuflen--; + inbuf++; + + while (inbuflen > 0 && *inbuf == last && count < UINT8_MAX) { + count++; + inbuflen--; + inbuf++; + } + + outbuf[len] = count; + outbuf[len + 1] = last; + len += 2; + } +} + +static int +ut_decompress(uint8_t *outbuf, uint32_t *compressed_len, uint8_t *inbuf, uint32_t inbuflen) +{ + uint32_t len = 0; + + SPDK_CU_ASSERT_FATAL(inbuflen % 2 == 0); + + while (true) { + if (inbuflen == 0) { + *compressed_len = len; + return 0; + } + + if ((len + inbuf[0]) > *compressed_len) { + return -ENOSPC; + } + + memset(outbuf, inbuf[1], inbuf[0]); + outbuf += inbuf[0]; + len += inbuf[0]; + inbuflen -= 2; + inbuf += 2; + } +} + +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; + } + } +} + static void backing_dev_compress(struct spdk_reduce_backing_dev *backing_dev, struct iovec *src_iov, int src_iovcnt, @@ -1052,84 +1130,6 @@ overlapped(void) backing_dev_destroy(&backing_dev); } -static int -ut_compress(char *outbuf, uint32_t *compressed_len, char *inbuf, uint32_t inbuflen) -{ - uint32_t len = 0; - uint8_t count; - char last; - - while (true) { - if (inbuflen == 0) { - *compressed_len = len; - return 0; - } - - if (*compressed_len < (len + 2)) { - return -ENOSPC; - } - - last = *inbuf; - count = 1; - inbuflen--; - inbuf++; - - while (inbuflen > 0 && *inbuf == last && count < UINT8_MAX) { - count++; - inbuflen--; - inbuf++; - } - - outbuf[len] = count; - outbuf[len + 1] = last; - len += 2; - } -} - -static int -ut_decompress(uint8_t *outbuf, uint32_t *compressed_len, uint8_t *inbuf, uint32_t inbuflen) -{ - uint32_t len = 0; - - SPDK_CU_ASSERT_FATAL(inbuflen % 2 == 0); - - while (true) { - if (inbuflen == 0) { - *compressed_len = len; - return 0; - } - - if ((len + inbuf[0]) > *compressed_len) { - return -ENOSPC; - } - - memset(outbuf, inbuf[1], inbuf[0]); - outbuf += inbuf[0]; - len += inbuf[0]; - inbuflen -= 2; - inbuf += 2; - } -} - -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