diff options
Diffstat (limited to 'platforms/test')
-rw-r--r-- | platforms/test/eeprom.c | 4 | ||||
-rw-r--r-- | platforms/test/eeprom_stm32_tests.cpp | 54 | ||||
-rw-r--r-- | platforms/test/flash_stm32_mock.c | 12 | ||||
-rw-r--r-- | platforms/test/timer.c | 36 |
4 files changed, 67 insertions, 39 deletions
diff --git a/platforms/test/eeprom.c b/platforms/test/eeprom.c index e292faa644..d501745e55 100644 --- a/platforms/test/eeprom.c +++ b/platforms/test/eeprom.c @@ -68,7 +68,9 @@ void eeprom_write_block(const void *buf, void *addr, size_t len) { } } -void eeprom_update_byte(uint8_t *addr, uint8_t value) { eeprom_write_byte(addr, value); } +void eeprom_update_byte(uint8_t *addr, uint8_t value) { + eeprom_write_byte(addr, value); +} void eeprom_update_word(uint16_t *addr, uint16_t value) { uint8_t *p = (uint8_t *)addr; diff --git a/platforms/test/eeprom_stm32_tests.cpp b/platforms/test/eeprom_stm32_tests.cpp index 57f31d634f..d2c41fb77d 100644 --- a/platforms/test/eeprom_stm32_tests.cpp +++ b/platforms/test/eeprom_stm32_tests.cpp @@ -60,7 +60,9 @@ class EepromStm32Test : public testing::Test { ~EepromStm32Test() {} protected: - void SetUp() override { EEPROM_Erase(); } + void SetUp() override { + EEPROM_Erase(); + } void TearDown() override { #ifdef EEPROM_DEBUG @@ -83,7 +85,7 @@ TEST_F(EepromStm32Test, TestReadGarbage) { garbage += i; FlashBuf[i] = garbage; } - EEPROM_Init(); // Just verify we don't crash + EEPROM_Init(); // Just verify we don't crash } TEST_F(EepromStm32Test, TestWriteBadAddress) { @@ -206,11 +208,11 @@ TEST_F(EepromStm32Test, TestReadWord) { TEST_F(EepromStm32Test, TestWriteWord) { /* Direct compacted-area: Address < 0x80 */ - EEPROM_WriteDataWord(0, 0xdead); // Aligned - EEPROM_WriteDataWord(3, 0xbeef); // Unaligned + EEPROM_WriteDataWord(0, 0xdead); // Aligned + EEPROM_WriteDataWord(3, 0xbeef); // Unaligned /* Direct compacted-area: Address >= 0x80 */ - EEPROM_WriteDataWord(200, 0xabcd); // Aligned - EEPROM_WriteDataWord(203, 0x9876); // Unaligned + EEPROM_WriteDataWord(200, 0xabcd); // Aligned + EEPROM_WriteDataWord(203, 0x9876); // Unaligned EEPROM_WriteDataWord(EEPROM_SIZE - 4, 0x1234); EEPROM_WriteDataWord(EEPROM_SIZE - 2, 0x5678); /* Write Log word zero-encoded */ @@ -218,10 +220,10 @@ TEST_F(EepromStm32Test, TestWriteWord) { /* Write Log word one-encoded */ EEPROM_WriteDataWord(EEPROM_SIZE - 2, 1); /* Write Log word value aligned */ - EEPROM_WriteDataWord(200, 0x4321); // Aligned + EEPROM_WriteDataWord(200, 0x4321); // Aligned /* Write Log word value unaligned */ - EEPROM_WriteDataByte(202, 0x3c); // Set neighboring byte - EEPROM_WriteDataWord(203, 0xcdef); // Unaligned + EEPROM_WriteDataByte(202, 0x3c); // Set neighboring byte + EEPROM_WriteDataWord(203, 0xcdef); // Unaligned /* Check values */ /* Direct compacted-area */ EXPECT_EQ(*(uint16_t*)&FlashBuf[EEPROM_BASE], (uint16_t)~0xdead); @@ -249,11 +251,11 @@ TEST_F(EepromStm32Test, TestWriteWord) { TEST_F(EepromStm32Test, TestWordRoundTrip) { /* Direct compacted-area: Address < 0x80 */ - EEPROM_WriteDataWord(0, 0xdead); // Aligned - EEPROM_WriteDataWord(3, 0xbeef); // Unaligned + EEPROM_WriteDataWord(0, 0xdead); // Aligned + EEPROM_WriteDataWord(3, 0xbeef); // Unaligned /* Direct compacted-area: Address >= 0x80 */ - EEPROM_WriteDataWord(200, 0xabcd); // Aligned - EEPROM_WriteDataWord(203, 0x9876); // Unaligned + EEPROM_WriteDataWord(200, 0xabcd); // Aligned + EEPROM_WriteDataWord(203, 0x9876); // Unaligned EEPROM_WriteDataWord(EEPROM_SIZE - 4, 0x1234); EEPROM_WriteDataWord(EEPROM_SIZE - 2, 0x5678); /* Check values */ @@ -270,10 +272,10 @@ TEST_F(EepromStm32Test, TestWordRoundTrip) { /* Write Log word one-encoded */ EEPROM_WriteDataWord(EEPROM_SIZE - 2, 1); /* Write Log word value aligned */ - EEPROM_WriteDataWord(200, 0x4321); // Aligned + EEPROM_WriteDataWord(200, 0x4321); // Aligned /* Write Log word value unaligned */ - EEPROM_WriteDataByte(202, 0x3c); // Set neighboring byte - EEPROM_WriteDataWord(203, 0xcdef); // Unaligned + EEPROM_WriteDataByte(202, 0x3c); // Set neighboring byte + EEPROM_WriteDataWord(203, 0xcdef); // Unaligned /* Check values */ EEPROM_Init(); EXPECT_EQ(EEPROM_ReadDataWord(200), 0x4321); @@ -324,34 +326,34 @@ TEST_F(EepromStm32Test, TestByteWordBoundary) { TEST_F(EepromStm32Test, TestDWordRoundTrip) { /* Direct compacted-area: Address < 0x80 */ - eeprom_write_dword((uint32_t*)0, 0xdeadbeef); // Aligned - eeprom_write_dword((uint32_t*)9, 0x12345678); // Unaligned + eeprom_write_dword((uint32_t*)0, 0xdeadbeef); // Aligned + eeprom_write_dword((uint32_t*)9, 0x12345678); // Unaligned /* Direct compacted-area: Address >= 0x80 */ eeprom_write_dword((uint32_t*)200, 0xfacef00d); - eeprom_write_dword((uint32_t*)(EEPROM_SIZE - 4), 0xba5eba11); // Aligned - eeprom_write_dword((uint32_t*)(EEPROM_SIZE - 9), 0xcafed00d); // Unaligned + eeprom_write_dword((uint32_t*)(EEPROM_SIZE - 4), 0xba5eba11); // Aligned + eeprom_write_dword((uint32_t*)(EEPROM_SIZE - 9), 0xcafed00d); // Unaligned /* Check direct values */ EEPROM_Init(); EXPECT_EQ(eeprom_read_dword((uint32_t*)0), 0xdeadbeef); EXPECT_EQ(eeprom_read_dword((uint32_t*)9), 0x12345678); EXPECT_EQ(eeprom_read_dword((uint32_t*)200), 0xfacef00d); - EXPECT_EQ(eeprom_read_dword((uint32_t*)(EEPROM_SIZE - 4)), 0xba5eba11); // Aligned - EXPECT_EQ(eeprom_read_dword((uint32_t*)(EEPROM_SIZE - 9)), 0xcafed00d); // Unaligned + EXPECT_EQ(eeprom_read_dword((uint32_t*)(EEPROM_SIZE - 4)), 0xba5eba11); // Aligned + EXPECT_EQ(eeprom_read_dword((uint32_t*)(EEPROM_SIZE - 9)), 0xcafed00d); // Unaligned /* Write Log byte encoded */ eeprom_write_dword((uint32_t*)0, 0xdecafbad); eeprom_write_dword((uint32_t*)9, 0x87654321); /* Write Log word encoded */ eeprom_write_dword((uint32_t*)200, 1); /* Write Log word value aligned */ - eeprom_write_dword((uint32_t*)(EEPROM_SIZE - 4), 0xdeadc0de); // Aligned - eeprom_write_dword((uint32_t*)(EEPROM_SIZE - 9), 0x6789abcd); // Unaligned + eeprom_write_dword((uint32_t*)(EEPROM_SIZE - 4), 0xdeadc0de); // Aligned + eeprom_write_dword((uint32_t*)(EEPROM_SIZE - 9), 0x6789abcd); // Unaligned /* Check log values */ EEPROM_Init(); EXPECT_EQ(eeprom_read_dword((uint32_t*)0), 0xdecafbad); EXPECT_EQ(eeprom_read_dword((uint32_t*)9), 0x87654321); EXPECT_EQ(eeprom_read_dword((uint32_t*)200), 1); - EXPECT_EQ(eeprom_read_dword((uint32_t*)(EEPROM_SIZE - 4)), 0xdeadc0de); // Aligned - EXPECT_EQ(eeprom_read_dword((uint32_t*)(EEPROM_SIZE - 9)), 0x6789abcd); // Unaligned + EXPECT_EQ(eeprom_read_dword((uint32_t*)(EEPROM_SIZE - 4)), 0xdeadc0de); // Aligned + EXPECT_EQ(eeprom_read_dword((uint32_t*)(EEPROM_SIZE - 9)), 0x6789abcd); // Unaligned } TEST_F(EepromStm32Test, TestBlockRoundTrip) { diff --git a/platforms/test/flash_stm32_mock.c b/platforms/test/flash_stm32_mock.c index 222a004bc7..b6ab170f95 100644 --- a/platforms/test/flash_stm32_mock.c +++ b/platforms/test/flash_stm32_mock.c @@ -44,6 +44,12 @@ FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data) { } } -FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout) { return FLASH_COMPLETE; } -void FLASH_Unlock(void) { flash_locked = false; } -void FLASH_Lock(void) { flash_locked = true; } +FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout) { + return FLASH_COMPLETE; +} +void FLASH_Unlock(void) { + flash_locked = false; +} +void FLASH_Lock(void) { + flash_locked = true; +} diff --git a/platforms/test/timer.c b/platforms/test/timer.c index 61c3a00201..e0acd1b16d 100644 --- a/platforms/test/timer.c +++ b/platforms/test/timer.c @@ -18,16 +18,34 @@ static uint32_t current_time = 0; -void timer_init(void) { current_time = 0; } +void timer_init(void) { + current_time = 0; +} -void timer_clear(void) { current_time = 0; } +void timer_clear(void) { + current_time = 0; +} -uint16_t timer_read(void) { return current_time & 0xFFFF; } -uint32_t timer_read32(void) { return current_time; } -uint16_t timer_elapsed(uint16_t last) { return TIMER_DIFF_16(timer_read(), last); } -uint32_t timer_elapsed32(uint32_t last) { return TIMER_DIFF_32(timer_read32(), last); } +uint16_t timer_read(void) { + return current_time & 0xFFFF; +} +uint32_t timer_read32(void) { + return current_time; +} +uint16_t timer_elapsed(uint16_t last) { + return TIMER_DIFF_16(timer_read(), last); +} +uint32_t timer_elapsed32(uint32_t last) { + return TIMER_DIFF_32(timer_read32(), last); +} -void set_time(uint32_t t) { current_time = t; } -void advance_time(uint32_t ms) { current_time += ms; } +void set_time(uint32_t t) { + current_time = t; +} +void advance_time(uint32_t ms) { + current_time += ms; +} -void wait_ms(uint32_t ms) { advance_time(ms); } +void wait_ms(uint32_t ms) { + advance_time(ms); +} |