Bug fixes and unit tests (#14)

Added unit tests for I2C_eeprom_cyclic_store and fixed a bug in the format() method and a possible bug with the "empty" marker literal being expressed as ~0UL (which isn't necessarily the same size as a uint32_t).
This commit is contained in:
Tomas Hübner
2021-01-07 18:05:51 +01:00
committed by GitHub
parent cd9ea6fb4c
commit 5bfc57b1d2
2 changed files with 729 additions and 5 deletions
+12 -5
View File
@@ -75,18 +75,25 @@ public:
*
* Formatting is done by writing the max version number to each slot,
* thus it performs a write cycle to the first write page of each slot.
*
* @return True if successful or false if unable to write to eeprom.
*/
void format()
bool format()
{
// Reset the EEPROM by writing a ~0 into all pages
for (uint16_t slot = 0; slot < _totalPages; slot++)
auto totalSlots = _totalPages / _bufferPages;
auto slotSize = _pageSize * _bufferPages;
for (uint16_t slot = 0; slot < totalSlots; slot++)
{
_eeprom->writeBlock(slot * _pageSize, (uint8_t *)"\xff\xff\xff\xff", 4);
if(_eeprom->writeBlock(slot * slotSize, (uint8_t *)"\xff\xff\xff\xff", 4) != 0)
return false;
}
_isEmpty = true;
_currentSlot = 0;
_isInitialized = true;
return true;
}
/**
@@ -219,7 +226,7 @@ private:
return false;
}
if (current == ~0UL)
if (current == 0xffffffff)
{
// Memory is blank
_isEmpty = true;
@@ -236,7 +243,7 @@ private:
return false;
}
if (probe == ~0UL || probe <= current)
if (probe == 0xffffffff || probe <= current)
{
// 1. Nothing has been written to the memory at Probe
// 2. The slots have the same timestamp, this shouldn't happen, treat as if Probe slot hasn't been written