static void test_find_zero_blocks_null(void) { uint64_t offset = 0; uint32_t len = 0; find_zero_blocks(NULL, &offset, &len); TEST_ASSERT_EQUAL_UINT64(0, offset); TEST_ASSERT_EQUAL_UINT32(0, len); }
/* * Trim zero blocks from the beginning and end of buffer * * This function is similar to find_zero_blocks(), but this updates 'buf' so * that the zero block are removed from the beginning of buffer. */ void trim_zero_blocks(void *buf, uint64_t *poffset, uint32_t *plen) { uint8_t *p = buf; uint64_t orig_offset = *poffset; find_zero_blocks(buf, poffset, plen); if (orig_offset < *poffset) memmove(p, p + *poffset - orig_offset, *plen); }
static void test_find_zero_blocks_4097_zero_offset_1(void) { const uint8_t buf[BLOCK_SIZE + 1] = {0}; uint64_t offset = 1; uint32_t len = BLOCK_SIZE; find_zero_blocks(buf, &offset, &len); TEST_ASSERT_EQUAL_UINT64(BLOCK_SIZE, offset); TEST_ASSERT_EQUAL_UINT32(1, len); }
static void test_find_zero_blocks_4095(void) { const uint8_t buf[4095] = {0}; uint64_t offset = 0; uint32_t len = 4095; find_zero_blocks(buf, &offset, &len); TEST_ASSERT_EQUAL_UINT64(0, offset); TEST_ASSERT_EQUAL_UINT32(4095, len); }
static void test_find_zero_blocks_8K_zero_zero(void) { const uint8_t buf[BLOCK_SIZE * 2] = {0}; uint64_t offset = 0; uint32_t len = BLOCK_SIZE * 2; find_zero_blocks(buf, &offset, &len); TEST_ASSERT_EQUAL_UINT64(BLOCK_SIZE * 2, offset); TEST_ASSERT_EQUAL_UINT32(0, len); }
static void test_find_zero_blocks_4K_nonzero_at_middle(void) { uint8_t buf[BLOCK_SIZE] = {0}; buf[BLOCK_SIZE / 2] = 1; uint64_t offset = 0; uint32_t len = BLOCK_SIZE; find_zero_blocks(buf, &offset, &len); TEST_ASSERT_EQUAL_UINT64(0, offset); TEST_ASSERT_EQUAL_UINT32(BLOCK_SIZE, len); }
static void test_find_zero_blocks_20K_zero_zero_middle_zero_zero(void) { uint8_t buf[BLOCK_SIZE * 5] = {0}; buf[BLOCK_SIZE * 5 / 2] = 1; uint64_t offset = 0; uint32_t len = BLOCK_SIZE * 5; find_zero_blocks(buf, &offset, &len); TEST_ASSERT_EQUAL_UINT64(BLOCK_SIZE * 2, offset); TEST_ASSERT_EQUAL_UINT32(BLOCK_SIZE, len); }
static void test_find_zero_blocks_12K_head_zero_zero(void) { uint8_t buf[BLOCK_SIZE * 3] = {0}; buf[0] = 1; uint64_t offset = 0; uint32_t len = BLOCK_SIZE * 3; find_zero_blocks(buf, &offset, &len); TEST_ASSERT_EQUAL_UINT64(0, offset); TEST_ASSERT_EQUAL_UINT32(BLOCK_SIZE, len); }
static void test_find_zero_blocks_8K_zero_tail(void) { uint8_t buf[BLOCK_SIZE * 2] = {0}; buf[BLOCK_SIZE * 2 - 1] = 1; uint64_t offset = 0; uint32_t len = BLOCK_SIZE * 2; find_zero_blocks(buf, &offset, &len); TEST_ASSERT_EQUAL_UINT64(BLOCK_SIZE, offset); TEST_ASSERT_EQUAL_UINT32(BLOCK_SIZE, len); }
static void test_find_zero_blocks_4097_nonzero_at_4096(void) { uint8_t buf[BLOCK_SIZE + 1] = {0}; buf[BLOCK_SIZE] = 1; uint64_t offset = 0; uint32_t len = BLOCK_SIZE + 1; find_zero_blocks(buf, &offset, &len); TEST_ASSERT_EQUAL_UINT64(BLOCK_SIZE, offset); TEST_ASSERT_EQUAL_UINT32(1, len); }