Skip to content

Commit

Permalink
More software EEPROM tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerimoq committed Sep 29, 2018
1 parent 09c1864 commit e04d171
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/oam/nvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ ssize_t nvm_write(uint32_t dst, const void *src_p, size_t size);
/**
* Write given buffers to given NVM addresses.
*
* @param[in] dst_p Address ranges in NVM to write, sorted from lowest
* to highest. Addressing starts at zero(0).
* @param[in] dst_p Address ranges in NVM to write to. Addressing
* starts at zero(0).
* @param[in] src_p Buffers to write in the same order as in
* `dst_p`. The size fields are not used.
* @param[in] length Number of elements in `dst_p` and `src_p`.
Expand Down
100 changes: 83 additions & 17 deletions tst/drivers/software/storage/eeprom_soft/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ static int write_get_blank_chunk_block_0_chunk_1_blank()
return (0);
}

static int mount(struct eeprom_soft_driver_t *eeprom_p)
{
write_mount_block_0_chunk_0_latest();
write_read_header_blank(blocks[0].address,
0,
0xa5c3);
write_calculate_chunk_crc_blank(blocks[0].address,
512);

BTASSERT(eeprom_soft_mount(eeprom_p) == 0);

return (0);
}

static int test_module_init(void)
{
mock_write_flash_module_init(0);
Expand Down Expand Up @@ -451,14 +465,7 @@ static int test_write(void)
membersof(blocks),
512) == 0);

write_mount_block_0_chunk_0_latest();
write_read_header_blank(blocks[0].address,
0,
0xa5c3);
write_calculate_chunk_crc_blank(blocks[0].address,
512);

BTASSERT(eeprom_soft_mount(&eeprom) == 0);
BTASSERT(mount(&eeprom) == 0);

write_get_blank_chunk_block_0_chunk_1_blank();

Expand Down Expand Up @@ -515,15 +522,7 @@ static int test_vwrite(void)
membersof(blocks),
512) == 0);

/* Mount. */
write_mount_block_0_chunk_0_latest();
write_read_header_blank(blocks[0].address,
0,
0xa5c3);
write_calculate_chunk_crc_blank(blocks[0].address,
512);

BTASSERT(eeprom_soft_mount(&eeprom) == 0);
BTASSERT(mount(&eeprom) == 0);

/* Write. */
write_get_blank_chunk_block_0_chunk_1_blank();
Expand Down Expand Up @@ -572,6 +571,72 @@ static int test_vwrite(void)
return (0);
}

static int test_vwrite_out_of_order(void)
{
struct eeprom_soft_driver_t eeprom;
uint8_t buf[504];
char part_1[] = "012";
char part_2[] = "3456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM";
char part_3[] = "NOPQRSTUVWXYZ";
struct iov_uintptr_t dst[3];
struct iov_t src[3];
ssize_t size;

BTASSERT(eeprom_soft_init(&eeprom,
&flash,
&blocks[0],
membersof(blocks),
512) == 0);

BTASSERT(mount(&eeprom) == 0);

/* Write. */
write_get_blank_chunk_block_0_chunk_1_blank();
memset(&buf[0], -1, sizeof(buf));
mock_write_flash_read_seq(&buf[0],
blocks[0].address + 8,
sizeof(buf),
8,
sizeof(buf) / 8);
memcpy(&buf[33],
&part_1[0],
strlen(part_1));
memcpy(&buf[33 + strlen(part_1)],
&part_2[0],
strlen(part_2));
memcpy(&buf[33 + strlen(part_1) + strlen(part_2)],
&part_3[0],
strlen(part_3));
mock_write_flash_write_seq(blocks[0].address + 512 + 8,
&buf[0],
sizeof(buf),
8,
sizeof(buf) / 8);
write_write_header_blank(blocks[0].address + 512,
1,
0xa5c3);

dst[2].address = 33;
dst[2].size = strlen(part_1);
dst[0].address = (33 + strlen(part_1));
dst[0].size = strlen(part_2);
dst[1].address = (33 + strlen(part_1) + strlen(part_2));
dst[1].size = strlen(part_3);

src[2].buf_p = part_1;
src[0].buf_p = part_2;
src[1].buf_p = part_3;

size = iov_uintptr_size(&dst[0], membersof(dst));

BTASSERT(eeprom_soft_vwrite(&eeprom,
&dst[0],
&src[0],
membersof(dst)) == size);

return (0);
}

static int test_read_write_after_failed_mount(void)
{
struct eeprom_soft_driver_t eeprom;
Expand Down Expand Up @@ -647,6 +712,7 @@ int main()
},
{ test_write, "test_write" },
{ test_vwrite, "test_vwrite" },
{ test_vwrite_out_of_order, "test_vwrite_out_of_order" },
{
test_read_write_after_failed_mount,
"test_read_write_after_failed_mount"
Expand Down

0 comments on commit e04d171

Please sign in to comment.