ChibiOS/HAL MFS Test Suite.
Test suite for ChibiOS/HAL MFS. The purpose of this suite
is to perform unit tests on the MFS module and to converge to
100% code coverage through successive improvements.
mfs_
Internal Tests
Functional tests.
The APIs are tested for functionality, correct cases and
expected error cases are tested.
#include "hal_mfs.h"]]>
Testing mfsStart() behavior.
The initialization function is tested. This function
can fail only in case of Flash Array failures or in case
of unexpected internal errors.
Erasing the flash array using a low level
function.
Calling mfsStart() on an uninitialized flash
array, MFS_NO_ERROR is expected.
Calling mfsStart() on a newly initialized flash
array, MFS_NO_ERROR is expected.
Checking for non existing record.
The records space is explored with an initialized but
empty managed storage, no record should exist.
Exploring the records space, MFS_ERR_NOT_FOUND is
expected for each index.
Creating, updating and erasing a record.
A record is created, updated several times with
different payloads and finally erased.
The record must not already exists,
MFS_ERR_NOT_FOUND is expected.
Creating the record then retrieving it again,
MFS_NO_ERROR is expected, record content and size are
compared with the original.
Updating the record then retrieving it again,
MFS_NO_ERROR is expected, record content and size are
compared with the original.
Erasing the record then trying to retrieve it
again, MFS_NO_ERROR is expected on erase,
MFS_ERR_NOT_FOUND is expected on retrieve.
Erasing the whole storage and re-initialization.
The managed storage is erased, initialized and
re-mounted.
Creating records 1, 2 and 3, MFS_NO_ERROR is
expected.
Records must exist.
Re-mounting, records must still exist.
Erasing storage and verify that the records have
been removed, MFS_NO_ERROR is expected on erase,
MFS_ERR_NOT_FOUND is expected on retrieve.
Testing storage size limit.
The storage is entirely filled with different records
and the final error is tested.
Filling up the storage by writing records with
increasing IDs, MFS_NO_ERROR is expected.
Creating one more record, should fail,
MFS_ERR_OUT_OF_MEM is expected.
Adding a smaller record to fill the final gap. A
reinitialization is performed and MFS_NO_ERROR is
expected.
= sizeof (mfs_data_header_t), "not enough space");
if (remaining > sizeof (mfs_data_header_t) * 2) {
err = mfsWriteRecord(&mfs1, MFS_CFG_MAX_RECORDS,
remaining - (sizeof (mfs_data_header_t) * 2),
mfs_pattern512);
test_assert(err == MFS_NO_ERROR, "error filling remaining space");
err = mfsEraseRecord(&mfs1, MFS_CFG_MAX_RECORDS);
test_assert(err == MFS_NO_ERROR, "error filling remaining space");
}
else {
if (remaining == sizeof (mfs_data_header_t) * 2) {
err = mfsEraseRecord(&mfs1, 2);
test_assert(err == MFS_NO_ERROR, "error filling remaining space");
}
err = mfsEraseRecord(&mfs1, 1);
test_assert(err == MFS_NO_ERROR, "error filling remaining space");
}
remaining = (size_t)flashGetSectorOffset(mfscfg1.flashp, mfscfg1.bank0_start) +
(size_t)mfscfg1.bank_size - (size_t)mfs1.next_offset;
test_assert(remaining == 0U, "remaining space not zero");
mfsStop(&mfs1);
err = mfsStart(&mfs1, &mfscfg1);
test_assert(err == MFS_NO_ERROR, "initialization error");]]>
Testing garbage collection by writing.
The garbage collection procedure is triggeredby a
write operation and the state of both banks is checked.
Filling up the storage by writing records with
increasing IDs, MFS_NO_ERROR is expected.
Erasing one record, MFS_NO_ERROR is expected.
Writing one more record triggers garbage
collection, MFS_WARN_GC is expected, KS state is
checked for correctness after the operation.
Checking for all records in the new bank,
MFS_NOERROR is expected for each record.
Erasing one record, MFS_NO_ERROR is expected.
Writing one more record triggers garbage
collection, MFS_WARN_GC is expected, MFS object state
is checked for correctness after the operation.
Checking for all records in the new bank,
MFS_NO_ERROR is expected for each record.
Testing garbage collection by erasing
The garbage collection procedure is triggered by an
erase operation and the state of both banks is checked.
Filling up the storage by writing records with
increasing IDs, MFS_NO_ERROR is expected.
Erase records until the flash bank is filled
entirely.
Erasing one more record triggers garbage
collection, MFS_WARN_GC is expected, KS state is
checked for correctness after the operation.
Internal Tests
Transaction Mode tests.
This sequence tests the MFS behavior when used in
transaction mode, correct cases and expected error cases are
tested.
#include "hal_mfs.h"]]>
Committing a transaction
A set of new/existing records are written/erased
within a transaction then the transaction is committed,
the state is checked afterward.
Records 1, 2 and 3 are created, MFS_NO_ERROR is
expected.
Presence of records 1, 2 and 3 is verified,
MFS_NO_ERROR is expected.
Starting a transaction with sufficient
pre-allocated space, MFS_NO_ERROR is expected.
Atomically erasing record 1, updating record 2,
reading record 3.
Committing the transaction, MFS_NO_ERROR is
expected.
Testing outcome, records 1 must not be present,
record 2 must contain the new value and record 3 must
be unchanged.
Re-mounting the manage storage, MFS_NO_ERROR is
expected.
Testing outcome again after re-start.
Performing a garbage collection, the result must
not change.
Testing outcome again after garbage collection.
Rolling back a transaction.
A set of new/existing records are written/erased
within a transaction then the transaction is rolled back,
the state is checked afterward.
Records 1, 2 and 3 are created, MFS_NO_ERROR is
expected.
Presence of records 1, 2 and 3 is verified,
MFS_NO_ERROR is expected.
Starting a transaction with sufficient
pre-allocated space, MFS_NO_ERROR is expected..
Atomically erasing record 1, updating record 2,
reading record 3.
Rolling back the transaction, MFS_NO_ERROR is
expected.
State must not have changed, records 1, 2 and 3
must still be there unchanged.
Transaction triggering an early garbage collect.
A transaction is started with sufficient space but
not contiguous, a garbage collection is triggered.
Filling up the storage by writing records with
increasing IDs, MFS_NO_ERROR is expected.
Erasing one record, MFS_NO_ERROR is expected.
Starting a transaction with the whole remaining
space, MFS_ERR_OUT_OF_MEM is expected.
bank_size - mfs1.used_space;
err = mfsStartTransaction(&mfs1, size);
test_assert(err == MFS_ERR_OUT_OF_MEM, "invalid error code");]]>
Starting a transaction with insufficient space
for one more header, MFS_ERR_OUT_OF_MEM is expected.
bank_size - mfs1.used_space) - sizeof (mfs_data_header_t)) + 1;
err = mfsStartTransaction(&mfs1, size);
test_assert(err == MFS_ERR_OUT_OF_MEM, "invalid error code");]]>
Starting a transaction with just enough space for
one more header, MFS_NO_ERROR is expected.
bank_size - mfs1.used_space) - sizeof (mfs_data_header_t);
err = mfsStartTransaction(&mfs1, size);
test_assert(err == MFS_NO_ERROR, "error starting transaction");]]>
Rolling back, MFS_NO_ERROR is expected.
Internal Tests
API Invalid Cases tests.
This test sequence tests the error coded returned by the
various APIs when called when the system is not initialized.
Initialization error from APIs.
The API functions are invoked without prior
initialization.
The function mfsErase() is called,
MFS_ERR_INV_STATE is expected.
The function mfsWriteRecord() is called,
MFS_ERR_INV_STATE is expected.
The function mfsEraseRecord() is called,
MFS_ERR_INV_STATE is expected.
The function mfsReadRecord() is called,
MFS_ERR_INV_STATE is expected.
The function mfsPerformGarbageCollection() is
called, MFS_ERR_INV_STATE is expected.
Erasing non existing record.
An erase operation is attempted on an non-existing
record.
Record one is erased, the error MFS_ERR_NOT_FOUND
is expected.