summaryrefslogtreecommitdiff
path: root/platforms/test
diff options
context:
space:
mode:
Diffstat (limited to 'platforms/test')
-rw-r--r--platforms/test/bootloaders/none.c (renamed from platforms/test/bootloader.c)0
-rw-r--r--platforms/test/eeprom.c8
-rw-r--r--platforms/test/eeprom_stm32_tests.cpp57
-rw-r--r--platforms/test/eeprom_stm32_tests.h8
-rw-r--r--platforms/test/flash_stm32_mock.c12
-rw-r--r--platforms/test/rules.mk2
-rw-r--r--platforms/test/timer.c36
7 files changed, 77 insertions, 46 deletions
diff --git a/platforms/test/bootloader.c b/platforms/test/bootloaders/none.c
index 5155d9ff04..5155d9ff04 100644
--- a/platforms/test/bootloader.c
+++ b/platforms/test/bootloaders/none.c
diff --git a/platforms/test/eeprom.c b/platforms/test/eeprom.c
index 5c8e69dae3..d501745e55 100644
--- a/platforms/test/eeprom.c
+++ b/platforms/test/eeprom.c
@@ -16,9 +16,7 @@
#include "eeprom.h"
-#define EEPROM_SIZE 32
-
-static uint8_t buffer[EEPROM_SIZE];
+static uint8_t buffer[TOTAL_EEPROM_BYTE_COUNT];
uint8_t eeprom_read_byte(const uint8_t *addr) {
uintptr_t offset = (uintptr_t)addr;
@@ -70,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 5bc8d87900..d2c41fb77d 100644
--- a/platforms/test/eeprom_stm32_tests.cpp
+++ b/platforms/test/eeprom_stm32_tests.cpp
@@ -17,8 +17,6 @@
#include "gtest/gtest.h"
extern "C" {
-#include "flash_stm32.h"
-#include "eeprom_stm32.h"
#include "eeprom.h"
}
@@ -46,7 +44,6 @@ extern "C" {
*
*/
-#define EEPROM_SIZE (FEE_PAGE_SIZE * FEE_PAGE_COUNT / 2)
#define LOG_SIZE EEPROM_SIZE
#define LOG_BASE (MOCK_FLASH_SIZE - LOG_SIZE)
#define EEPROM_BASE (LOG_BASE - EEPROM_SIZE)
@@ -63,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
@@ -86,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) {
@@ -209,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 */
@@ -221,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);
@@ -252,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 */
@@ -273,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);
@@ -327,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/eeprom_stm32_tests.h b/platforms/test/eeprom_stm32_tests.h
new file mode 100644
index 0000000000..35ed885e52
--- /dev/null
+++ b/platforms/test/eeprom_stm32_tests.h
@@ -0,0 +1,8 @@
+// Copyright 2018-2022 Nick Brassel (@tzarc)
+// SPDX-License-Identifier: GPL-2.0-or-later
+#pragma once
+
+#include "flash_stm32.h"
+#include "eeprom_stm32.h"
+
+#define EEPROM_SIZE (FEE_PAGE_SIZE * FEE_PAGE_COUNT / 2)
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/rules.mk b/platforms/test/rules.mk
index 66b853d8ee..55512c7392 100644
--- a/platforms/test/rules.mk
+++ b/platforms/test/rules.mk
@@ -1,4 +1,4 @@
-eeprom_stm32_DEFS := -DFLASH_STM32_MOCKED -DNO_PRINT -DFEE_FLASH_BASE=FlashBuf
+eeprom_stm32_DEFS := -DEEPROM_TEST_HARNESS -DFLASH_STM32_MOCKED -DNO_PRINT -DFEE_FLASH_BASE=FlashBuf
eeprom_stm32_tiny_DEFS := $(eeprom_stm32_DEFS) \
-DFEE_MCU_FLASH_SIZE=1 \
-DMOCK_FLASH_SIZE=1024 \
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);
+}