Skip to content

Commit

Permalink
firmware: tests: devices: Implementing media test #156
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelboing committed Sep 6, 2024
1 parent 7a07b9f commit a43c28b
Showing 1 changed file with 97 additions and 4 deletions.
101 changes: 97 additions & 4 deletions firmware/tests/devices/media_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,116 @@

static void media_init_test(void **state)
{
media_t med = MEDIA_INT_FLASH;
int err = -1;

switch(med)
{
case MEDIA_INT_FLASH:
will_return(__wrap_flash_init, 0);
err = 0;

break;
default:
break;

}
assert_return_code(media_init(med), err);
}

static void media_write_test(void **state)
{
int err = -1;
uint16_t i = 0U;

media_t med = MEDIA_INT_FLASH;
uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
uint8_t adr = 0U;
uint32_t sector = FLASH_SEG_A_ADR;
uint16_t len = 10U;

switch(med)
{
case MEDIA_INT_FLASH:
will_return(__wrap_flash_mutex_take, 0);

/* Address index */
uintptr_t adr_idx = adr + sector;

for(i=0; i<len; ++i)
{
uintptr_t adr_counter = adr_idx + i;

expect_value(__wrap_flash_write_single, data, data[i]);
expect_value(__wrap_flash_write_single, addr, adr_counter);
}
will_return(__wrap_flash_mutex_give, 0);
err = 0;
break;
default:
break;
}

assert_return_code(media_write(med, adr, sector, data, len), err);
}

static void media_read_test(void **state)
{
int err = -1;
uint16_t i = 0U;

media_t med = MEDIA_INT_FLASH;
uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
uint8_t adr = 0U;
uint32_t sector = FLASH_SEG_A_ADR;
uint16_t len = 10U;

switch(med)
{
case MEDIA_INT_FLASH:
will_return(__wrap_flash_mutex_take, 0);

/* Address index */
uintptr_t adr_idx = adr + sector;

for(i=0; i<len; ++i)
{
uintptr_t adr_counter = adr_idx + i;

expect_value(__wrap_flash_read_single, addr, adr_counter);
will_return(__wrap_flash_read_single, data[i]);
}
will_return(__wrap_flash_mutex_give, 0);
err = 0;
break;
default:
break;
}

assert_return_code(media_read(med, adr, sector, data, len), err);
}

static void media_erase_test(void **state)
{
}
int err = -1;

static void media_get_info_test(void **state)
{
media_t med = MEDIA_INT_FLASH;
uint32_t sector = FLASH_SEG_A_ADR;

switch(med)
{
case MEDIA_INT_FLASH:
will_return(__wrap_flash_mutex_take, 0);
expect_value(__wrap_flash_erase, region,(uintptr_t)sector);
will_return(__wrap_flash_mutex_give, 0);
err = 0;
break;

default:
break;
}

assert_return_code(media_erase(med, sector), err);
}

int main(void)
Expand All @@ -71,7 +165,6 @@ int main(void)
cmocka_unit_test(media_write_test),
cmocka_unit_test(media_read_test),
cmocka_unit_test(media_erase_test),
cmocka_unit_test(media_get_info_test),
};

return cmocka_run_group_tests(media_tests, NULL, NULL);
Expand Down

0 comments on commit a43c28b

Please sign in to comment.