aboutsummaryrefslogtreecommitdiff
path: root/tests/test-xbzrle.c
diff options
context:
space:
mode:
authorJiaxun Yang <jiaxun.yang@flygoat.com>2021-01-18 14:38:05 +0800
committerThomas Huth <thuth@redhat.com>2021-01-20 10:46:54 +0100
commitd2c4f3841d1cba17c99f76812ffcb75a6c402202 (patch)
tree338680b9d8a259330839568b545d8bca0b04d0ec /tests/test-xbzrle.c
parent2d0fc797faaa73fbc1d30f5f9e90407bf3dd93f0 (diff)
tests: Rename PAGE_SIZE definitions
As per POSIX specification of limits.h [1], OS libc may define PAGE_SIZE in limits.h. Self defined PAGE_SIZE is frequently used in tests, to prevent collosion of definition, we give PAGE_SIZE definitons reasonable prefixs. [1]: https://pubs.opengroup.org/onlinepubs/7908799/xsh/limits.h.html Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20210118063808.12471-7-jiaxun.yang@flygoat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
Diffstat (limited to 'tests/test-xbzrle.c')
-rw-r--r--tests/test-xbzrle.c70
1 files changed, 35 insertions, 35 deletions
diff --git a/tests/test-xbzrle.c b/tests/test-xbzrle.c
index f5e08de91e..795d6f1cba 100644
--- a/tests/test-xbzrle.c
+++ b/tests/test-xbzrle.c
@@ -15,7 +15,7 @@
#include "qemu/cutils.h"
#include "../migration/xbzrle.h"
-#define PAGE_SIZE 4096
+#define XBZRLE_PAGE_SIZE 4096
static void test_uleb(void)
{
@@ -41,11 +41,11 @@ static void test_uleb(void)
static void test_encode_decode_zero(void)
{
- uint8_t *buffer = g_malloc0(PAGE_SIZE);
- uint8_t *compressed = g_malloc0(PAGE_SIZE);
+ uint8_t *buffer = g_malloc0(XBZRLE_PAGE_SIZE);
+ uint8_t *compressed = g_malloc0(XBZRLE_PAGE_SIZE);
int i = 0;
int dlen = 0;
- int diff_len = g_test_rand_int_range(0, PAGE_SIZE - 1006);
+ int diff_len = g_test_rand_int_range(0, XBZRLE_PAGE_SIZE - 1006);
for (i = diff_len; i > 0; i--) {
buffer[1000 + i] = i;
@@ -55,8 +55,8 @@ static void test_encode_decode_zero(void)
buffer[1000 + diff_len + 5] = 105;
/* encode zero page */
- dlen = xbzrle_encode_buffer(buffer, buffer, PAGE_SIZE, compressed,
- PAGE_SIZE);
+ dlen = xbzrle_encode_buffer(buffer, buffer, XBZRLE_PAGE_SIZE, compressed,
+ XBZRLE_PAGE_SIZE);
g_assert(dlen == 0);
g_free(buffer);
@@ -65,11 +65,11 @@ static void test_encode_decode_zero(void)
static void test_encode_decode_unchanged(void)
{
- uint8_t *compressed = g_malloc0(PAGE_SIZE);
- uint8_t *test = g_malloc0(PAGE_SIZE);
+ uint8_t *compressed = g_malloc0(XBZRLE_PAGE_SIZE);
+ uint8_t *test = g_malloc0(XBZRLE_PAGE_SIZE);
int i = 0;
int dlen = 0;
- int diff_len = g_test_rand_int_range(0, PAGE_SIZE - 1006);
+ int diff_len = g_test_rand_int_range(0, XBZRLE_PAGE_SIZE - 1006);
for (i = diff_len; i > 0; i--) {
test[1000 + i] = i + 4;
@@ -79,8 +79,8 @@ static void test_encode_decode_unchanged(void)
test[1000 + diff_len + 5] = 109;
/* test unchanged buffer */
- dlen = xbzrle_encode_buffer(test, test, PAGE_SIZE, compressed,
- PAGE_SIZE);
+ dlen = xbzrle_encode_buffer(test, test, XBZRLE_PAGE_SIZE, compressed,
+ XBZRLE_PAGE_SIZE);
g_assert(dlen == 0);
g_free(test);
@@ -89,21 +89,21 @@ static void test_encode_decode_unchanged(void)
static void test_encode_decode_1_byte(void)
{
- uint8_t *buffer = g_malloc0(PAGE_SIZE);
- uint8_t *test = g_malloc0(PAGE_SIZE);
- uint8_t *compressed = g_malloc(PAGE_SIZE);
+ uint8_t *buffer = g_malloc0(XBZRLE_PAGE_SIZE);
+ uint8_t *test = g_malloc0(XBZRLE_PAGE_SIZE);
+ uint8_t *compressed = g_malloc(XBZRLE_PAGE_SIZE);
int dlen = 0, rc = 0;
uint8_t buf[2];
- test[PAGE_SIZE - 1] = 1;
+ test[XBZRLE_PAGE_SIZE - 1] = 1;
- dlen = xbzrle_encode_buffer(buffer, test, PAGE_SIZE, compressed,
- PAGE_SIZE);
+ dlen = xbzrle_encode_buffer(buffer, test, XBZRLE_PAGE_SIZE, compressed,
+ XBZRLE_PAGE_SIZE);
g_assert(dlen == (uleb128_encode_small(&buf[0], 4095) + 2));
- rc = xbzrle_decode_buffer(compressed, dlen, buffer, PAGE_SIZE);
- g_assert(rc == PAGE_SIZE);
- g_assert(memcmp(test, buffer, PAGE_SIZE) == 0);
+ rc = xbzrle_decode_buffer(compressed, dlen, buffer, XBZRLE_PAGE_SIZE);
+ g_assert(rc == XBZRLE_PAGE_SIZE);
+ g_assert(memcmp(test, buffer, XBZRLE_PAGE_SIZE) == 0);
g_free(buffer);
g_free(compressed);
@@ -112,18 +112,18 @@ static void test_encode_decode_1_byte(void)
static void test_encode_decode_overflow(void)
{
- uint8_t *compressed = g_malloc0(PAGE_SIZE);
- uint8_t *test = g_malloc0(PAGE_SIZE);
- uint8_t *buffer = g_malloc0(PAGE_SIZE);
+ uint8_t *compressed = g_malloc0(XBZRLE_PAGE_SIZE);
+ uint8_t *test = g_malloc0(XBZRLE_PAGE_SIZE);
+ uint8_t *buffer = g_malloc0(XBZRLE_PAGE_SIZE);
int i = 0, rc = 0;
- for (i = 0; i < PAGE_SIZE / 2 - 1; i++) {
+ for (i = 0; i < XBZRLE_PAGE_SIZE / 2 - 1; i++) {
test[i * 2] = 1;
}
/* encode overflow */
- rc = xbzrle_encode_buffer(buffer, test, PAGE_SIZE, compressed,
- PAGE_SIZE);
+ rc = xbzrle_encode_buffer(buffer, test, XBZRLE_PAGE_SIZE, compressed,
+ XBZRLE_PAGE_SIZE);
g_assert(rc == -1);
g_free(buffer);
@@ -133,13 +133,13 @@ static void test_encode_decode_overflow(void)
static void encode_decode_range(void)
{
- uint8_t *buffer = g_malloc0(PAGE_SIZE);
- uint8_t *compressed = g_malloc(PAGE_SIZE);
- uint8_t *test = g_malloc0(PAGE_SIZE);
+ uint8_t *buffer = g_malloc0(XBZRLE_PAGE_SIZE);
+ uint8_t *compressed = g_malloc(XBZRLE_PAGE_SIZE);
+ uint8_t *test = g_malloc0(XBZRLE_PAGE_SIZE);
int i = 0, rc = 0;
int dlen = 0;
- int diff_len = g_test_rand_int_range(0, PAGE_SIZE - 1006);
+ int diff_len = g_test_rand_int_range(0, XBZRLE_PAGE_SIZE - 1006);
for (i = diff_len; i > 0; i--) {
buffer[1000 + i] = i;
@@ -153,12 +153,12 @@ static void encode_decode_range(void)
test[1000 + diff_len + 5] = 109;
/* test encode/decode */
- dlen = xbzrle_encode_buffer(test, buffer, PAGE_SIZE, compressed,
- PAGE_SIZE);
+ dlen = xbzrle_encode_buffer(test, buffer, XBZRLE_PAGE_SIZE, compressed,
+ XBZRLE_PAGE_SIZE);
- rc = xbzrle_decode_buffer(compressed, dlen, test, PAGE_SIZE);
- g_assert(rc < PAGE_SIZE);
- g_assert(memcmp(test, buffer, PAGE_SIZE) == 0);
+ rc = xbzrle_decode_buffer(compressed, dlen, test, XBZRLE_PAGE_SIZE);
+ g_assert(rc < XBZRLE_PAGE_SIZE);
+ g_assert(memcmp(test, buffer, XBZRLE_PAGE_SIZE) == 0);
g_free(buffer);
g_free(compressed);