test: flash: implement wrappers for flash_write() and flash_erase()

tags/0.1.0
S.J.R. van Schaik 7 years ago
parent a63e7656fe
commit 108178d1be
  1. 2
      Makefile
  2. 5
      source/tests/Makefile
  3. 10
      source/tests/ftl/read_page_desc.c
  4. 51
      source/tests/main.c

@ -63,7 +63,7 @@ $(BUILD)/tbm: $(tbm-obj) $(LDSCRIPT)
$(BUILD)/test: $(test-obj)
@echo "LD $@"
@mkdir -p $(dir $@)
@$(LD) -o $@ $(CFLAGS) $(LDFLAGS) $(test-obj) -Wl,--wrap=flash_read $(LIBS) $(TEST_LIBS)
@$(LD) -o $@ $(CFLAGS) $(LDFLAGS) $(TEST_LDFLAGS) $(test-obj) $(LIBS) $(TEST_LIBS)
test: $(BUILD)/test
@$(BUILD)/test

@ -2,3 +2,8 @@ test-obj-y += source/tests/main.o
test-obj-y += source/tests/ftl/find_block_div.o
test-obj-y += source/tests/ftl/next_upage.o
test-obj-y += source/tests/ftl/read_page_desc.o
test-obj-y += source/tests/ftl/write_page_desc.o
TEST_LDFLAGS += -Wl,--wrap=flash_read
TEST_LDFLAGS += -Wl,--wrap=flash_write
TEST_LDFLAGS += -Wl,--wrap=flash_is_erased

@ -29,8 +29,8 @@ static void test_read_page_desc1(void **state)
expect_value(__wrap_flash_read, addr, (16 - 1) * 4 * KIB +
sizeof(struct ftl_page_group));
expect_value(__wrap_flash_read, len, sizeof page_desc);
will_return(__wrap_flash_read, &page_desc);
will_return(__wrap_flash_read, sizeof page_desc);
will_return(__wrap_flash_read, &page_desc);
map.log2_pages_per_group = ilog2(16);
map.log2_page_size = ilog2(4 * KIB);
@ -53,8 +53,8 @@ static void test_read_page_desc2(void **state)
expect_value(__wrap_flash_read, addr, (16 - 1) * 4 * KIB +
sizeof(struct ftl_page_group) + 14 * sizeof(struct ftl_page_desc));
expect_value(__wrap_flash_read, len, sizeof page_desc);
will_return(__wrap_flash_read, &page_desc);
will_return(__wrap_flash_read, sizeof page_desc);
will_return(__wrap_flash_read, &page_desc);
map.log2_pages_per_group = ilog2(16);
map.log2_page_size = ilog2(4 * KIB);
@ -93,8 +93,8 @@ static void test_read_page_desc4(void **state)
expect_value(__wrap_flash_read, addr, (32 - 1) * 4 * KIB +
sizeof(struct ftl_page_group));
expect_value(__wrap_flash_read, len, sizeof page_desc);
will_return(__wrap_flash_read, &page_desc);
will_return(__wrap_flash_read, sizeof page_desc);
will_return(__wrap_flash_read, &page_desc);
map.log2_pages_per_group = ilog2(16);
map.log2_page_size = ilog2(4 * KIB);
@ -117,8 +117,8 @@ static void test_read_page_desc5(void **state)
expect_value(__wrap_flash_read, addr, (32 - 1) * 4 * KIB +
sizeof(struct ftl_page_group) + 14 * sizeof(struct ftl_page_desc));
expect_value(__wrap_flash_read, len, sizeof page_desc);
will_return(__wrap_flash_read, &page_desc);
will_return(__wrap_flash_read, sizeof page_desc);
will_return(__wrap_flash_read, &page_desc);
map.log2_pages_per_group = ilog2(16);
map.log2_page_size = ilog2(4 * KIB);
@ -157,8 +157,8 @@ static void test_read_page_desc7(void **state)
expect_value(__wrap_flash_read, addr, (48 - 1) * 4 * KIB +
sizeof(struct ftl_page_group));
expect_value(__wrap_flash_read, len, sizeof page_desc);
will_return(__wrap_flash_read, &page_desc);
will_return(__wrap_flash_read, sizeof page_desc);
will_return(__wrap_flash_read, &page_desc);
map.log2_pages_per_group = ilog2(16);
map.log2_page_size = ilog2(4 * KIB);

@ -13,23 +13,69 @@
size_t __wrap_flash_read(struct flash_dev *dev, uint32_t addr,
void *data, size_t len) __attribute__((used));
size_t __wrap_flash_write(struct flash_dev *dev, uint32_t addr,
const void *data, size_t len) __attribute__((used));
int __wrap_flash_is_erased(struct flash_dev *dev, uint32_t addr,
size_t len) __attribute__((used));
size_t __wrap_flash_read(struct flash_dev *dev, uint32_t addr,
void *data, size_t len)
{
const void *ret_data;
size_t ret_len;
(void)dev;
check_expected(addr);
check_expected(len);
memcpy(data, mock_ptr_type(void *), len);
ret_len = mock_type(size_t);
ret_data = mock_type(const void *);
if (len > ret_len)
len = ret_len;
memcpy(data, ret_data, len);
return len;
}
size_t __wrap_flash_write(struct flash_dev *dev, uint32_t addr,
const void *data, size_t len)
{
void *ret_data;
size_t ret_len;
(void)dev;
check_expected(addr);
check_expected(len);
ret_len = mock_type(size_t);
ret_data = mock_type(void *);
if (len > ret_len)
len = ret_len;
memcpy(ret_data, data, len);
return len;
}
int __wrap_flash_is_erased(struct flash_dev *dev, uint32_t addr, size_t len)
{
(void)dev;
check_expected(addr);
check_expected(len);
return mock_type(size_t);
return mock_type(int);
}
int test_find_block_div(void);
int test_next_upage(void);
int test_read_page_desc(void);
int test_write_page_desc(void);
int main(void)
{
@ -38,6 +84,7 @@ int main(void)
count += test_find_block_div();
count += test_next_upage();
count += test_read_page_desc();
count += test_write_page_desc();
return count;
}

Loading…
Cancel
Save