feat: Power-Cycle-Zähler für den Werksreset
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
#include "unity.h"
|
||||
#include "fake_flash.h"
|
||||
#include "config/nl_flash_layout.h"
|
||||
#include "config/nl_reset_counter.h"
|
||||
|
||||
static uint8_t boot(void)
|
||||
{
|
||||
nl_resetcnt_init(NL_FL_RESETCNT);
|
||||
return nl_resetcnt_boot();
|
||||
}
|
||||
|
||||
void setUp(void) { fake_flash_reset(); }
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_UINT(0, fake_flash_dirty_writes);
|
||||
}
|
||||
|
||||
static void test_first_boot_is_one(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_UINT8(1, boot());
|
||||
}
|
||||
|
||||
static void test_fast_boots_count_up(void)
|
||||
{
|
||||
for (uint8_t i = 1; i <= 5; i++)
|
||||
TEST_ASSERT_EQUAL_UINT8(i, boot());
|
||||
}
|
||||
|
||||
static void test_clear_resets(void)
|
||||
{
|
||||
boot();
|
||||
boot();
|
||||
TEST_ASSERT_EQUAL_INT(0, nl_resetcnt_clear());
|
||||
TEST_ASSERT_EQUAL_UINT8(1, boot());
|
||||
}
|
||||
|
||||
static void test_clear_twice_writes_once(void)
|
||||
{
|
||||
boot();
|
||||
nl_resetcnt_clear();
|
||||
nl_resetcnt_clear();
|
||||
/* slot 0: count 1, slot 1: count 0, slot 2 still free */
|
||||
TEST_ASSERT_EQUAL_HEX8(0xFF, fake_flash_mem[NL_FL_RESETCNT + 8]);
|
||||
}
|
||||
|
||||
static void test_wraps_after_full_sector(void)
|
||||
{
|
||||
for (int i = 0; i < 700; i++) {
|
||||
boot();
|
||||
nl_resetcnt_clear();
|
||||
}
|
||||
TEST_ASSERT_EQUAL_UINT(1, fake_flash_erases[NL_FL_RESETCNT / NL_FLASH_SECTOR_SIZE]);
|
||||
TEST_ASSERT_EQUAL_UINT8(1, boot());
|
||||
TEST_ASSERT_EQUAL_UINT8(2, boot());
|
||||
}
|
||||
|
||||
static void test_garbage_counts_as_zero(void)
|
||||
{
|
||||
fake_flash_mem[NL_FL_RESETCNT + 0] = 0x12;
|
||||
fake_flash_mem[NL_FL_RESETCNT + 3] = 0x00;
|
||||
TEST_ASSERT_EQUAL_UINT8(1, boot());
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(test_first_boot_is_one);
|
||||
RUN_TEST(test_fast_boots_count_up);
|
||||
RUN_TEST(test_clear_resets);
|
||||
RUN_TEST(test_clear_twice_writes_once);
|
||||
RUN_TEST(test_wraps_after_full_sector);
|
||||
RUN_TEST(test_garbage_counts_as_zero);
|
||||
return UNITY_END();
|
||||
}
|
||||
Reference in New Issue
Block a user