Skip to content

Commit

Permalink
fix(dfu_tests): fix dfu tests
Browse files Browse the repository at this point in the history
more accurately measure time to compute CRC over flash
add more delay between dfu messages (erasure takes time)

Signed-off-by: Cyril Fougeray <[email protected]>
  • Loading branch information
fouge committed Dec 23, 2024
1 parent 0dc3ea5 commit aa669c2
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions main_board/src/system/dfu/dfu_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ZTEST(hil, test_dfu_upload_tests)
dfu_block.message.j_message.payload.dfu_block.block_number + 1,
DFU_BLOCK_SIZE_MAX);

k_msleep(100);
k_msleep(200);
}

LOG_INF("Reading back flash");
Expand Down Expand Up @@ -117,25 +117,31 @@ ZTEST(hil, test_dfu_upload_tests)
// Test CRC speed over entire slot
ZTEST(hil, test_crc_over_flash)
{
uint32_t tick = k_cycle_get_32();

const struct flash_area *flash_area_p = NULL;
int ret = flash_area_open(DT_FIXED_PARTITION_ID(DT_ALIAS(secondary_slot)),
&flash_area_p);
zassert_equal(ret, 0, "Unable to open secondary slot");

uint8_t buf[DFU_FLASH_PAGE_SIZE];
uint32_t computed_crc = 0;
uint32_t crc_computation_ticks = 0;

// read entire flash area content to calculate CRC32
for (size_t off = 0; off < flash_area_p->fa_size;
off += DFU_FLASH_PAGE_SIZE) {
size_t len = (flash_area_p->fa_size - off < DFU_FLASH_PAGE_SIZE)
? flash_area_p->fa_size - off
: DFU_FLASH_PAGE_SIZE;

ret = flash_area_read(flash_area_p, (off_t)off, buf, len);
zassert_equal(ret, 0, "Unable to read @0x%x in secondary slot", off);
computed_crc = crc32_ieee_update(computed_crc, buf, len);
uint32_t tick = k_cycle_get_32();
{
size_t len = (flash_area_p->fa_size - off < DFU_FLASH_PAGE_SIZE)
? flash_area_p->fa_size - off
: DFU_FLASH_PAGE_SIZE;

ret = flash_area_read(flash_area_p, (off_t)off, buf, len);
zassert_equal(ret, 0, "Unable to read @0x%x in secondary slot",
off);
computed_crc = crc32_ieee_update(computed_crc, buf, len);
}
crc_computation_ticks += (k_cycle_get_32() - tick);

#ifdef CONFIG_BOARD_DIAMOND_MAIN
// hogging thread on diamond main mcu (bigger & external flash)
Expand All @@ -147,12 +153,12 @@ ZTEST(hil, test_crc_over_flash)
flash_area_close(flash_area_p);
UNUSED(computed_crc);

uint32_t tock = k_cycle_get_32();
int32_t crc_computation_us = (int32_t)(crc_computation_ticks) /
(sys_clock_hw_cycles_per_sec() / 1000 / 1000);

int32_t crc_computation_us =
(int32_t)(tock - tick) / (sys_clock_hw_cycles_per_sec() / 1000 / 1000);
LOG_INF("CRC over entire slot took %uus, %u cycles (%u cycle/sec)",
crc_computation_us, tock - tick, sys_clock_hw_cycles_per_sec());
crc_computation_us, crc_computation_ticks,
sys_clock_hw_cycles_per_sec());

#ifdef CONFIG_BOARD_DIAMOND_MAIN
// check within 1400ms (1.4s)
Expand Down

0 comments on commit aa669c2

Please sign in to comment.