@@ -44,19 +44,23 @@ void test_reset(void) {
4444}
4545
4646void test_getFreeSpace (void ) {
47+ nonVolatileStorage::mockEepromNmbr64KPages = 2 ;
48+ nonVolatileStorage::detectNmbr64KBanks ();
49+
4750 // No measurements stored -> free space should equal the size of the measurements area
4851 measurementGroupCollection::oldestMeasurementOffset = 0 ;
4952 measurementGroupCollection::newMeasurementsOffset = 0 ;
50- TEST_ASSERT_EQUAL_UINT32 (nonVolatileStorage::measurementsSize , measurementGroupCollection::getFreeSpace ());
53+ TEST_ASSERT_EQUAL_UINT32 (nonVolatileStorage::getMeasurementsAreaSize () , measurementGroupCollection::getFreeSpace ());
5154
52- // Simulate some measurements stored
53- measurementGroupCollection::newMeasurementsOffset = nonVolatileStorage::measurementsSize / 2 ;
54- TEST_ASSERT_EQUAL_UINT32 (nonVolatileStorage::measurementsSize / 2 , measurementGroupCollection::getFreeSpace ());
55+ // Simulate some measurements stored, at the first half of the memory
56+ measurementGroupCollection::oldestMeasurementOffset = 0 ;
57+ measurementGroupCollection::newMeasurementsOffset = nonVolatileStorage::getMeasurementsAreaSize () / 2 ;
58+ TEST_ASSERT_EQUAL_UINT32 (nonVolatileStorage::getMeasurementsAreaSize () / 2 , measurementGroupCollection::getFreeSpace ());
5559
56- // Now assume the free area is wrapping around the end of the memory
57- measurementGroupCollection::oldestMeasurementOffset = nonVolatileStorage::measurementsSize / 4 ;
58- measurementGroupCollection::newMeasurementsOffset = (nonVolatileStorage::measurementsSize * 3 ) / 4 ;
59- TEST_ASSERT_EQUAL_UINT32 (nonVolatileStorage::measurementsSize / 2 , measurementGroupCollection::getFreeSpace ());
60+ // Now assume the free area is wrapping around the end of the memory, measurements stored at the last quarter and the first quarter of the memory
61+ measurementGroupCollection::oldestMeasurementOffset = nonVolatileStorage::getMeasurementsAreaSize () * 3 / 4 ;
62+ measurementGroupCollection::newMeasurementsOffset = (nonVolatileStorage::getMeasurementsAreaSize () ) / 4 ;
63+ TEST_ASSERT_EQUAL_UINT32 (nonVolatileStorage::getMeasurementsAreaSize () / 2 , measurementGroupCollection::getFreeSpace ());
6064}
6165
6266void test_getAddressFromOffset () {
@@ -88,7 +92,7 @@ void test_add(void) {
8892void test_add_wrap (void ) { // addresses in NVS need to wrap around end of measurements area, not overwriting settings in settings area.
8993 static constexpr uint32_t expectLengthInBytes{16 };
9094 measurementGroupCollection::reset ();
91- measurementGroupCollection::newMeasurementsOffset = nonVolatileStorage::measurementsSize - (expectLengthInBytes / 2 ); // 8 from the end, writing 16 bytes, should wrap
95+ measurementGroupCollection::newMeasurementsOffset = nonVolatileStorage::getMeasurementsAreaSize () - (expectLengthInBytes / 2 ); // 8 from the end, writing 16 bytes, should wrap
9296
9397 measurementGroup testMeasurementGroup;
9498 testMeasurementGroup.addMeasurement (0 , 0 , 0 .0f );
@@ -104,7 +108,7 @@ void test_add_wrap(void) { // addresses in NVS need to wrap around end of
104108 testMeasurementGroup.toBytes (expectedBytes, expectLengthInBytes);
105109
106110 uint8_t actualBytes[expectLengthInBytes];
107- TEST_ASSERT_EQUAL_UINT8_ARRAY (expectedBytes, nonVolatileStorage::mockEepromMemory + nonVolatileStorage::measurementsStartAddress + nonVolatileStorage::measurementsSize - (expectLengthInBytes / 2 ), expectLengthInBytes / 2 );
111+ TEST_ASSERT_EQUAL_UINT8_ARRAY (expectedBytes, nonVolatileStorage::mockEepromMemory + nonVolatileStorage::measurementsStartAddress + nonVolatileStorage::getMeasurementsAreaSize () - (expectLengthInBytes / 2 ), expectLengthInBytes / 2 );
108112 TEST_ASSERT_EQUAL_UINT8_ARRAY (expectedBytes + (expectLengthInBytes / 2 ), nonVolatileStorage::mockEepromMemory + nonVolatileStorage::measurementsStartAddress, expectLengthInBytes / 2 );
109113}
110114
0 commit comments