Test Specification for ChibiOS/HAL MFS Complex Driver. 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 "key_storage.h" static const uint8_t pattern1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; static const uint8_t pattern2[] = { 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47 }; static const uint8_t pattern3[] = { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57 }; static const uint8_t pattern512[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63 };]]> Testing ksInit() 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 ksInit() on an uninitialized flash array, KS_NOERROR is expected. Calling ksInit() on a newly initialized flash array, KS_NOERROR is expected. Checking for non existing keys. The keys space is explored with an initialized but empty keys storage, no key should exist. Exploring the keys space, KS_KEY_NOT_FOUND is expected for each key. Creating, updating and erasing a key. A key is created, updated several times with different payloads and finally erased. The key must not already exists, KS_KEY_NOT_FOUND is expected. Creating the key then retrieving it again, KS_KEY_NOT_FOUND is expected, key content and size are compared with the original. Updating the key then retrieving it again, KS_NOERROR is expected, key content and size are compared with the original. Updating the key again with an unaligned key size then retrieving it again, KS_NOERROR is expected, key content and size are compared with the original. Erasing the key the then retrieving it, KS_NOERROR is expected on erase, KS_KEY_NOT_FOUND is expected on retrieve. Erasing the whole storage. The key storage is erased and re-initialized. Creating keys 0, 1 and 2, KS_NOERROR is expected. Erasing storage and verify that the keys have been removed, KS_NOERROR is expected on erase, KS_KEY_NOT_FOUND is expected on retrieve. Testing storage size limit. The storage is entirely filled with different keys and the final error is tested. Filling up the storage by writing keys with increasing IDs, KS_NOERROR is expected. Creating one more key, should fail, KS_OUT_OF_MEM is expected. Adding a smaller key to fill the final gap. A reinitialization is performed and KS_NOERROR is expected. = sizeof(kskeyheader_t), "not enough space"); test_assert((remaining & KS_LLD_PAGE_SIZE) == 0, "unaligned space"); if (remaining > sizeof(kskeyheader_t) * 2) { error = ksWriteKey(KS_CFG_NUM_KEYS - 1, remaining - (sizeof(kskeyheader_t) * 2), pattern512); test_assert(error == KS_NOERROR, "error filling remaining space"); } else { if (remaining == sizeof(kskeyheader_t) * 2) { error = ksEraseKey(1); test_assert(error == KS_NOERROR, "error filling remaining space"); } error = ksEraseKey(0); test_assert(error == KS_NOERROR, "error filling remaining space"); } remaining = KS_LLD_BLOCK0_ADDRESS + KS_LLD_BLOCKS_SIZE - (size_t)ks.free_next; test_assert(remaining == 0, "remaining space not zero"); ksDeinit(); error = ksInit(); test_assert(error == KS_NOERROR, "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 keys with increasing IDs, KS_NOERROR is expected. Erasing one key in the middle, KS_NOERROR is expected. Writing one more key triggers garbage collection, KS_WARNING is expected, KS state is checked for correctness after the operation. fields.instance == 1, "not first instance"); error = ksWriteKey(16, sizeof(pattern512), pattern512); test_assert(error == KS_WARNING, "error creating the key"); test_assert(ks.header->fields.instance == 2, "not second instance"); error = ksGetKey(16, &size, &keyp); test_assert(error == KS_NOERROR, "key not found"); test_assert(size == sizeof(pattern512), "unexpected key length"); test_assert(memcmp(pattern512, keyp, size) == 0, "wrong key content"); test_assert(ks.block == KS_BLOCK1, "unexpected block"); test_assert(ks_lld_is_block_erased(KS_BLOCK0) == true, "block 0 not erased");]]> Checking for all keys in the new bank, KS_NOERROR is expected for each key. Erasing one key in the middle, KS_NOERROR is expected. Writing one more key triggers garbage collection, KS_WARNING is expected, KS state is checked for correctness after the operation. fields.instance == 2, "not second instance"); error = ksWriteKey(16, sizeof(pattern512), pattern512); test_assert(error == KS_WARNING, "error creating the key"); test_assert(ks.header->fields.instance == 3, "not third instance"); error = ksGetKey(16, &size, &keyp); test_assert(error == KS_NOERROR, "key not found"); test_assert(size == sizeof(pattern512), "unexpected key length"); test_assert(memcmp(pattern512, keyp, size) == 0, "wrong key content"); test_assert(ks.block == KS_BLOCK0, "unexpected block"); test_assert(ks_lld_is_block_erased(KS_BLOCK1) == true, "block 0 not erased");]]> Checking for all keys in the new bank, KS_NOERROR is expected for each key. Testing garbage collection by erasing The garbage collection procedure is triggeredby an erase operation and the state of both banks is checked. Filling up the storage by writing keys with increasing IDs, KS_NOERROR is expected. Erase keys until the flash bank is filled entirely. Erasing one more key triggers garbage collection, KS_WARNING is expected, KS state is checked for correctness after the operation. fields.instance == 1, "not first instance"); error = ksEraseKey(16); test_assert(error == KS_WARNING, "error erasing the key"); test_assert(ks.header->fields.instance == 2, "not second instance"); error = ksGetKey(16, &size, &keyp); test_assert(error == KS_KEY_NOT_FOUND, "key not erased"); test_assert(ks.block == KS_BLOCK1, "unexpected block"); test_assert(ks_lld_is_block_erased(KS_BLOCK0) == true, "block 0 not erased");]]>