From e5049e103d5cf64ca047cb33f5ff3a9f16139dec Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sun, 31 Mar 2019 14:30:25 +0000 Subject: Updates from trunk. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/stable_19.1.x@12719 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- test/lib/ch_test.c | 17 + test/lib/ch_test.h | 7 + test/mfs/configuration.xml | 746 +++++++++++++++++++++++---- test/mfs/mfs_test.mk | 3 +- test/mfs/source/test/mfs_test_root.c | 50 ++ test/mfs/source/test/mfs_test_root.h | 5 + test/mfs/source/test/mfs_test_sequence_001.c | 156 +++--- test/mfs/source/test/mfs_test_sequence_002.c | 506 ++++++++++++++++-- test/mfs/source/test/mfs_test_sequence_003.c | 186 +++++++ test/mfs/source/test/mfs_test_sequence_003.h | 27 + 10 files changed, 1480 insertions(+), 223 deletions(-) create mode 100644 test/mfs/source/test/mfs_test_sequence_003.c create mode 100644 test/mfs/source/test/mfs_test_sequence_003.h (limited to 'test') diff --git a/test/lib/ch_test.c b/test/lib/ch_test.c index 859ecdf9f..7c6253674 100644 --- a/test/lib/ch_test.c +++ b/test/lib/ch_test.c @@ -255,6 +255,23 @@ msg_t test_execute(BaseSequentialStream *stream, const testsuite_t *tsp) { test_print("*** Test Board: "); test_println(BOARD_NAME); #endif +#if defined(TEST_SIZE_REPORT) + { + extern uint8_t __text_base, __text_end, + _data_start, _data_end, + _bss_start, _bss_end; + test_println("***"); + test_print("*** Text size: "); + test_printn((uint32_t)(&__text_end - &__text_base)); + test_println(" bytes"); + test_print("*** Data size: "); + test_printn((uint32_t)(&_data_end - &_data_start)); + test_println(" bytes"); + test_print("*** BSS size: "); + test_printn((uint32_t)(&_bss_end - &_bss_start)); + test_println(" bytes"); + } +#endif #if defined(TEST_REPORT_HOOK_HEADER) TEST_REPORT_HOOK_HEADER #endif diff --git a/test/lib/ch_test.h b/test/lib/ch_test.h index b78591689..3b51085cb 100644 --- a/test/lib/ch_test.h +++ b/test/lib/ch_test.h @@ -104,6 +104,13 @@ typedef struct { */ #define test_set_step(step) test_step = (step) +/** + * @brief End step marker. + * + * @param[in] step the step number + */ +#define test_end_step(step) (void)(step); + /** * @brief Test failure enforcement. * @note This function can only be called from test_case execute context. diff --git a/test/mfs/configuration.xml b/test/mfs/configuration.xml index efc7b5b04..070066b52 100644 --- a/test/mfs/configuration.xml +++ b/test/mfs/configuration.xml @@ -47,6 +47,10 @@ extern const MFSConfig mfscfg1; extern MFSDriver mfs1; extern uint8_t mfs_buffer[512]; +extern const uint8_t mfs_pattern16[16]; +extern const uint8_t mfs_pattern32[32]; +extern const uint8_t mfs_pattern10[10]; +extern const uint8_t mfs_pattern512[512]; flash_error_t bank_erase(mfs_bank_t bank); flash_error_t bank_verify_erased(mfs_bank_t bank); @@ -57,6 +61,54 @@ void test_print_mfs_info(void);]]> MFSDriver mfs1; uint8_t mfs_buffer[512]; + +const uint8_t mfs_pattern16[16] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 +}; + +const uint8_t mfs_pattern32[32] = { + 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 +}; + +const uint8_t mfs_pattern10[10] = { + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57 +}; + +const uint8_t mfs_pattern512[512] = { + 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 +}; void test_print_mfs_info(void) { @@ -128,55 +180,7 @@ flash_error_t bank_verify_erased(mfs_bank_t bank) { -#include "hal_mfs.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 -};]]> +#include "hal_mfs.h"]]> @@ -336,13 +340,13 @@ test_assert(err == MFS_ERR_NOT_FOUND , "record was already present");]]> +test_assert(size == sizeof mfs_pattern16, "unexpected record length"); +test_assert(memcmp(mfs_pattern16, mfs_buffer, size) == 0, "wrong record content");]]> @@ -355,13 +359,13 @@ test_assert(memcmp(pattern1, mfs_buffer, size) == 0, "wrong record content");]]> +test_assert(size == sizeof mfs_pattern32, "unexpected record length"); +test_assert(memcmp(mfs_pattern32, mfs_buffer, size) == 0, "wrong record content");]]> @@ -417,11 +421,11 @@ mfsStart(&mfs1, &mfscfg1);]]> @@ -530,21 +534,21 @@ mfsErase(&mfs1);]]> @@ -559,9 +563,9 @@ for (id = 1; id <= id_max; id++) { @@ -583,7 +587,7 @@ test_assert(remaining >= 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), - pattern512); + 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"); @@ -641,21 +645,21 @@ mfsErase(&mfs1);]]> @@ -690,14 +694,15 @@ test_assert(err == MFS_ERR_NOT_FOUND, "record not erased");]]> size_t size; test_assert(mfs1.current_counter == 1, "not first instance"); -err = mfsWriteRecord(&mfs1, 1, sizeof pattern512, pattern512); +err = mfsWriteRecord(&mfs1, 1, sizeof mfs_pattern512, mfs_pattern512); test_assert(err == MFS_WARN_GC, "error creating the record"); test_assert(mfs1.current_counter == 2, "not second instance"); size = sizeof mfs_buffer; err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer); test_assert(err == MFS_NO_ERROR, "record not found"); -test_assert(size == sizeof pattern512, "unexpected record length"); -test_assert(memcmp(pattern512, mfs_buffer, size) == 0, "wrong record content"); +test_assert(size == sizeof mfs_pattern512, "unexpected record length"); +test_assert(memcmp(mfs_pattern512, mfs_buffer, size) == 0, + "wrong record content"); test_assert(mfs1.current_bank == MFS_BANK_1, "unexpected bank"); test_assert(bank_verify_erased(MFS_BANK_0) == FLASH_NO_ERROR, "bank 0 not erased");]]> @@ -712,7 +717,7 @@ test_assert(bank_verify_erased(MFS_BANK_0) == FLASH_NO_ERROR, "bank 0 not erased size_t size; test_assert(mfs1.current_counter == 2, "not second instance"); -err = mfsWriteRecord(&mfs1, 1, sizeof pattern512, pattern512); +err = mfsWriteRecord(&mfs1, 1, sizeof mfs_pattern512, mfs_pattern512); test_assert(err == MFS_WARN_GC, "error creating the record"); test_assert(mfs1.current_counter == 3, "not third instance"); size = sizeof mfs_buffer; err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer); test_assert(err == MFS_NO_ERROR, "record not found"); -test_assert(size == sizeof pattern512, "unexpected record length"); -test_assert(memcmp(pattern512, mfs_buffer, size) == 0, "wrong record content"); +test_assert(size == sizeof mfs_pattern512, "unexpected record length"); +test_assert(memcmp(mfs_pattern512, mfs_buffer, size) == 0, + "wrong record content"); test_assert(mfs1.current_bank == MFS_BANK_0, "unexpected bank"); test_assert(bank_verify_erased(MFS_BANK_1) == FLASH_NO_ERROR, "bank 1 not erased");]]> @@ -785,7 +792,7 @@ test_assert(bank_verify_erased(MFS_BANK_1) == FLASH_NO_ERROR, "bank 1 not erased @@ -869,9 +878,9 @@ for (id = 1; id <= id_max; id++) { size_t size; mfs_id_t id; mfs_id_t id_max = (mfscfg1.bank_size - sizeof (mfs_bank_header_t)) / - (sizeof (mfs_data_header_t) + (sizeof pattern512 / 2)); + (sizeof (mfs_data_header_t) + (sizeof mfs_pattern512 / 2)); mfs_id_t n = ((mfscfg1.bank_size - sizeof (mfs_bank_header_t)) - - (id_max * (sizeof (mfs_data_header_t) + (sizeof pattern512 / 2)))) / + (id_max * (sizeof (mfs_data_header_t) + (sizeof mfs_pattern512 / 2)))) / sizeof (mfs_data_header_t); for (id = 1; id <= n; id++) { @@ -894,7 +903,7 @@ for (id = 1; id <= n; id++) { + + + 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 diff --git a/test/mfs/mfs_test.mk b/test/mfs/mfs_test.mk index ae6fbf6a2..499ebb47b 100644 --- a/test/mfs/mfs_test.mk +++ b/test/mfs/mfs_test.mk @@ -1,7 +1,8 @@ # List of all the ChibiOS/HAL MFS test files. TESTSRC += ${CHIBIOS}/test/mfs/source/test/mfs_test_root.c \ ${CHIBIOS}/test/mfs/source/test/mfs_test_sequence_001.c \ - ${CHIBIOS}/test/mfs/source/test/mfs_test_sequence_002.c + ${CHIBIOS}/test/mfs/source/test/mfs_test_sequence_002.c \ + ${CHIBIOS}/test/mfs/source/test/mfs_test_sequence_003.c # Required include directories TESTINC += ${CHIBIOS}/test/mfs/source/test diff --git a/test/mfs/source/test/mfs_test_root.c b/test/mfs/source/test/mfs_test_root.c index 447278610..422a41f06 100644 --- a/test/mfs/source/test/mfs_test_root.c +++ b/test/mfs/source/test/mfs_test_root.c @@ -23,6 +23,7 @@ *

Test Sequences

* - @subpage mfs_test_sequence_001 * - @subpage mfs_test_sequence_002 + * - @subpage mfs_test_sequence_003 * . */ @@ -46,6 +47,7 @@ const testsequence_t * const mfs_test_suite_array[] = { &mfs_test_sequence_001, &mfs_test_sequence_002, + &mfs_test_sequence_003, NULL }; @@ -66,6 +68,54 @@ const testsuite_t mfs_test_suite = { MFSDriver mfs1; uint8_t mfs_buffer[512]; +const uint8_t mfs_pattern16[16] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 +}; + +const uint8_t mfs_pattern32[32] = { + 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 +}; + +const uint8_t mfs_pattern10[10] = { + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57 +}; + +const uint8_t mfs_pattern512[512] = { + 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 +}; + void test_print_mfs_info(void) { } diff --git a/test/mfs/source/test/mfs_test_root.h b/test/mfs/source/test/mfs_test_root.h index 672b7da80..22f85634f 100644 --- a/test/mfs/source/test/mfs_test_root.h +++ b/test/mfs/source/test/mfs_test_root.h @@ -26,6 +26,7 @@ #include "mfs_test_sequence_001.h" #include "mfs_test_sequence_002.h" +#include "mfs_test_sequence_003.h" #if !defined(__DOXYGEN__) @@ -55,6 +56,10 @@ extern "C" { extern const MFSConfig mfscfg1; extern MFSDriver mfs1; extern uint8_t mfs_buffer[512]; +extern const uint8_t mfs_pattern16[16]; +extern const uint8_t mfs_pattern32[32]; +extern const uint8_t mfs_pattern10[10]; +extern const uint8_t mfs_pattern512[512]; flash_error_t bank_erase(mfs_bank_t bank); flash_error_t bank_verify_erased(mfs_bank_t bank); diff --git a/test/mfs/source/test/mfs_test_sequence_001.c b/test/mfs/source/test/mfs_test_sequence_001.c index 20b4d8d89..7c6d929ee 100644 --- a/test/mfs/source/test/mfs_test_sequence_001.c +++ b/test/mfs/source/test/mfs_test_sequence_001.c @@ -47,54 +47,6 @@ #include #include "hal_mfs.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 -}; - /**************************************************************************** * Test cases. ****************************************************************************/ @@ -136,6 +88,7 @@ static void mfs_test_001_001_execute(void) { ferr = bank_erase(MFS_BANK_1); test_assert(ferr == FLASH_NO_ERROR, "Bank 1 erase failure"); } + test_end_step(1); /* [1.1.2] Calling mfsStart() on an uninitialized flash array, MFS_NO_ERROR is expected.*/ @@ -146,6 +99,7 @@ static void mfs_test_001_001_execute(void) { err = mfsStart(&mfs1, &mfscfg1); test_assert(err == MFS_NO_ERROR, "initialization error with erased flash"); } + test_end_step(2); /* [1.1.3] Calling mfsStart() on a newly initialized flash array, MFS_NO_ERROR is expected.*/ @@ -156,6 +110,7 @@ static void mfs_test_001_001_execute(void) { err = mfsStart(&mfs1, &mfscfg1); test_assert(err == MFS_NO_ERROR, "initialization error with initialized flash"); } + test_end_step(3); } static const testcase_t mfs_test_001_001 = { @@ -203,6 +158,7 @@ static void mfs_test_001_002_execute(void) { "found a record that should not exists"); } } + test_end_step(1); } static const testcase_t mfs_test_001_002 = { @@ -253,6 +209,7 @@ static void mfs_test_001_003_execute(void) { mfs_error_t err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer); test_assert(err == MFS_ERR_NOT_FOUND , "record was already present"); } + test_end_step(1); /* [1.3.2] Creating the record then retrieving it again, MFS_NO_ERROR is expected, record content and size are compared with the @@ -261,14 +218,15 @@ static void mfs_test_001_003_execute(void) { { mfs_error_t err; - err = mfsWriteRecord(&mfs1, 1, sizeof pattern1, pattern1); + err = mfsWriteRecord(&mfs1, 1, sizeof mfs_pattern16, mfs_pattern16); test_assert(err == MFS_NO_ERROR, "error creating the record"); size = sizeof mfs_buffer; err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer); test_assert(err == MFS_NO_ERROR, "record not found"); - test_assert(size == sizeof pattern1, "unexpected record length"); - test_assert(memcmp(pattern1, mfs_buffer, size) == 0, "wrong record content"); + test_assert(size == sizeof mfs_pattern16, "unexpected record length"); + test_assert(memcmp(mfs_pattern16, mfs_buffer, size) == 0, "wrong record content"); } + test_end_step(2); /* [1.3.3] Updating the record then retrieving it again, MFS_NO_ERROR is expected, record content and size are compared with the @@ -277,14 +235,15 @@ static void mfs_test_001_003_execute(void) { { mfs_error_t err; - err = mfsWriteRecord(&mfs1, 1, sizeof pattern2, pattern2); + err = mfsWriteRecord(&mfs1, 1, sizeof mfs_pattern32, mfs_pattern32); test_assert(err == MFS_NO_ERROR, "error updating the record"); size = sizeof mfs_buffer; err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer); test_assert(err == MFS_NO_ERROR, "record not found"); - test_assert(size == sizeof pattern2, "unexpected record length"); - test_assert(memcmp(pattern2, mfs_buffer, size) == 0, "wrong record content"); + test_assert(size == sizeof mfs_pattern32, "unexpected record length"); + test_assert(memcmp(mfs_pattern32, mfs_buffer, size) == 0, "wrong record content"); } + test_end_step(3); /* [1.3.4] Erasing the record then trying to retrieve it again, MFS_NO_ERROR is expected on erase, MFS_ERR_NOT_FOUND is expected @@ -299,6 +258,7 @@ static void mfs_test_001_003_execute(void) { err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer); test_assert(err == MFS_ERR_NOT_FOUND, "record not erased"); } + test_end_step(4); } static const testcase_t mfs_test_001_003 = { @@ -341,13 +301,14 @@ static void mfs_test_001_004_execute(void) { { mfs_error_t err; - err = mfsWriteRecord(&mfs1, 1, sizeof pattern1, pattern1); + err = mfsWriteRecord(&mfs1, 1, sizeof mfs_pattern16, mfs_pattern16); test_assert(err == MFS_NO_ERROR, "error creating record 1"); - err = mfsWriteRecord(&mfs1, 2, sizeof pattern2, pattern2); + err = mfsWriteRecord(&mfs1, 2, sizeof mfs_pattern32, mfs_pattern32); test_assert(err == MFS_NO_ERROR, "error creating record 2"); - err = mfsWriteRecord(&mfs1, 3, sizeof pattern3, pattern3); + err = mfsWriteRecord(&mfs1, 3, sizeof mfs_pattern10, mfs_pattern10); test_assert(err == MFS_NO_ERROR, "error creating record 3"); } + test_end_step(1); /* [1.4.2] Records must exist.*/ test_set_step(2); @@ -365,6 +326,7 @@ static void mfs_test_001_004_execute(void) { err = mfsReadRecord(&mfs1, 3, &size, mfs_buffer); test_assert(err == MFS_NO_ERROR, "record 2 not present"); } + test_end_step(2); /* [1.4.3] Re-mounting, records must still exist.*/ test_set_step(3); @@ -384,6 +346,7 @@ static void mfs_test_001_004_execute(void) { err = mfsReadRecord(&mfs1, 3, &size, mfs_buffer); test_assert(err == MFS_NO_ERROR, "record 2 not present"); } + test_end_step(3); /* [1.4.4] Erasing storage and verify that the records have been removed, MFS_NO_ERROR is expected on erase, MFS_ERR_NOT_FOUND is @@ -405,6 +368,7 @@ static void mfs_test_001_004_execute(void) { err = mfsReadRecord(&mfs1, 3, &size, mfs_buffer); test_assert(err == MFS_ERR_NOT_FOUND, "record 2 still present"); } + test_end_step(4); } static const testcase_t mfs_test_001_004 = { @@ -448,24 +412,25 @@ static void mfs_test_001_005_execute(void) { { mfs_id_t id; mfs_id_t id_max = (mfscfg1.bank_size - sizeof (mfs_bank_header_t)) / - (sizeof (mfs_data_header_t) + sizeof pattern512); + (sizeof (mfs_data_header_t) + sizeof mfs_pattern512); for (id = 1; id <= id_max; id++) { mfs_error_t err; size_t size; - err = mfsWriteRecord(&mfs1, id, sizeof pattern512, pattern512); + err = mfsWriteRecord(&mfs1, id, sizeof mfs_pattern512, mfs_pattern512); test_assert(err == MFS_NO_ERROR, "error creating the record"); size = sizeof mfs_buffer; err = mfsReadRecord(&mfs1, id, &size, mfs_buffer); test_assert(err == MFS_NO_ERROR, "record not found"); - test_assert(size == sizeof pattern512, + test_assert(size == sizeof mfs_pattern512, "unexpected record length"); - test_assert(memcmp(pattern512, mfs_buffer, size) == 0, + test_assert(memcmp(mfs_pattern512, mfs_buffer, size) == 0, "wrong record content"); } } + test_end_step(1); /* [1.5.2] Creating one more record, should fail, MFS_ERR_OUT_OF_MEM is expected.*/ @@ -473,11 +438,12 @@ static void mfs_test_001_005_execute(void) { { mfs_error_t err; mfs_id_t id_max = (mfscfg1.bank_size - sizeof (mfs_bank_header_t)) / - (sizeof (mfs_data_header_t) + sizeof pattern512); + (sizeof (mfs_data_header_t) + sizeof mfs_pattern512); - err = mfsWriteRecord(&mfs1, id_max, sizeof pattern512 , pattern512); + err = mfsWriteRecord(&mfs1, id_max, sizeof mfs_pattern512 , mfs_pattern512); test_assert(err == MFS_ERR_OUT_OF_MEM, "creation didn't fail"); } + test_end_step(2); /* [1.5.3] Adding a smaller record to fill the final gap. A reinitialization is performed and MFS_NO_ERROR is expected.*/ @@ -493,7 +459,7 @@ static void mfs_test_001_005_execute(void) { if (remaining > sizeof (mfs_data_header_t) * 2) { err = mfsWriteRecord(&mfs1, MFS_CFG_MAX_RECORDS, remaining - (sizeof (mfs_data_header_t) * 2), - pattern512); + 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"); @@ -515,6 +481,7 @@ static void mfs_test_001_005_execute(void) { err = mfsStart(&mfs1, &mfscfg1); test_assert(err == MFS_NO_ERROR, "initialization error"); } + test_end_step(3); } static const testcase_t mfs_test_001_005 = { @@ -566,24 +533,25 @@ static void mfs_test_001_006_execute(void) { { mfs_id_t id; mfs_id_t id_max = (mfscfg1.bank_size - sizeof (mfs_bank_header_t)) / - (sizeof (mfs_data_header_t) + sizeof pattern512); + (sizeof (mfs_data_header_t) + sizeof mfs_pattern512); for (id = 1; id <= id_max; id++) { mfs_error_t err; size_t size; - err = mfsWriteRecord(&mfs1, id, sizeof pattern512, pattern512); + err = mfsWriteRecord(&mfs1, id, sizeof mfs_pattern512, mfs_pattern512); test_assert(err == MFS_NO_ERROR, "error creating the record"); size = sizeof mfs_buffer; err = mfsReadRecord(&mfs1, id, &size, mfs_buffer); test_assert(err == MFS_NO_ERROR, "record not found"); - test_assert(size == sizeof pattern512, + test_assert(size == sizeof mfs_pattern512, "unexpected record length"); - test_assert(memcmp(pattern512, mfs_buffer, size) == 0, + test_assert(memcmp(mfs_pattern512, mfs_buffer, size) == 0, "wrong record content"); } } + test_end_step(1); /* [1.6.2] Erasing one record, MFS_NO_ERROR is expected.*/ test_set_step(2); @@ -597,6 +565,7 @@ static void mfs_test_001_006_execute(void) { err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer); test_assert(err == MFS_ERR_NOT_FOUND, "record not erased"); } + test_end_step(2); /* [1.6.3] Writing one more record triggers garbage collection, MFS_WARN_GC is expected, KS state is checked for correctness after @@ -607,17 +576,19 @@ static void mfs_test_001_006_execute(void) { size_t size; test_assert(mfs1.current_counter == 1, "not first instance"); - err = mfsWriteRecord(&mfs1, 1, sizeof pattern512, pattern512); + err = mfsWriteRecord(&mfs1, 1, sizeof mfs_pattern512, mfs_pattern512); test_assert(err == MFS_WARN_GC, "error creating the record"); test_assert(mfs1.current_counter == 2, "not second instance"); size = sizeof mfs_buffer; err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer); test_assert(err == MFS_NO_ERROR, "record not found"); - test_assert(size == sizeof pattern512, "unexpected record length"); - test_assert(memcmp(pattern512, mfs_buffer, size) == 0, "wrong record content"); + test_assert(size == sizeof mfs_pattern512, "unexpected record length"); + test_assert(memcmp(mfs_pattern512, mfs_buffer, size) == 0, + "wrong record content"); test_assert(mfs1.current_bank == MFS_BANK_1, "unexpected bank"); test_assert(bank_verify_erased(MFS_BANK_0) == FLASH_NO_ERROR, "bank 0 not erased"); } + test_end_step(3); /* [1.6.4] Checking for all records in the new bank, MFS_NOERROR is expected for each record.*/ @@ -625,7 +596,7 @@ static void mfs_test_001_006_execute(void) { { mfs_id_t id; mfs_id_t id_max = (mfscfg1.bank_size - sizeof (mfs_bank_header_t)) / - (sizeof (mfs_data_header_t) + sizeof pattern512); + (sizeof (mfs_data_header_t) + sizeof mfs_pattern512); for (id = 1; id <= MFS_CFG_MAX_RECORDS; id++) { mfs_error_t err; @@ -635,8 +606,9 @@ static void mfs_test_001_006_execute(void) { size = sizeof mfs_buffer; err = mfsReadRecord(&mfs1, id, &size, mfs_buffer); test_assert(err == MFS_NO_ERROR, "record not found"); - test_assert(size == sizeof pattern512, "unexpected record length"); - test_assert(memcmp(pattern512, mfs_buffer, size) == 0, "wrong record content"); + test_assert(size == sizeof mfs_pattern512, "unexpected record length"); + test_assert(memcmp(mfs_pattern512, mfs_buffer, size) == 0, + "wrong record content"); } else { size = sizeof mfs_buffer; @@ -645,6 +617,7 @@ static void mfs_test_001_006_execute(void) { } } } + test_end_step(4); /* [1.6.5] Erasing one record, MFS_NO_ERROR is expected.*/ test_set_step(5); @@ -658,6 +631,7 @@ static void mfs_test_001_006_execute(void) { err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer); test_assert(err == MFS_ERR_NOT_FOUND, "record not erased"); } + test_end_step(5); /* [1.6.6] Writing one more record triggers garbage collection, MFS_WARN_GC is expected, MFS object state is checked for @@ -668,17 +642,19 @@ static void mfs_test_001_006_execute(void) { size_t size; test_assert(mfs1.current_counter == 2, "not second instance"); - err = mfsWriteRecord(&mfs1, 1, sizeof pattern512, pattern512); + err = mfsWriteRecord(&mfs1, 1, sizeof mfs_pattern512, mfs_pattern512); test_assert(err == MFS_WARN_GC, "error creating the record"); test_assert(mfs1.current_counter == 3, "not third instance"); size = sizeof mfs_buffer; err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer); test_assert(err == MFS_NO_ERROR, "record not found"); - test_assert(size == sizeof pattern512, "unexpected record length"); - test_assert(memcmp(pattern512, mfs_buffer, size) == 0, "wrong record content"); + test_assert(size == sizeof mfs_pattern512, "unexpected record length"); + test_assert(memcmp(mfs_pattern512, mfs_buffer, size) == 0, + "wrong record content"); test_assert(mfs1.current_bank == MFS_BANK_0, "unexpected bank"); test_assert(bank_verify_erased(MFS_BANK_1) == FLASH_NO_ERROR, "bank 1 not erased"); } + test_end_step(6); /* [1.6.7] Checking for all records in the new bank, MFS_NO_ERROR is expected for each record.*/ @@ -686,7 +662,7 @@ static void mfs_test_001_006_execute(void) { { mfs_id_t id; mfs_id_t id_max = (mfscfg1.bank_size - sizeof (mfs_bank_header_t)) / - (sizeof (mfs_data_header_t) + sizeof pattern512); + (sizeof (mfs_data_header_t) + sizeof mfs_pattern512); for (id = 1; id <= MFS_CFG_MAX_RECORDS; id++) { mfs_error_t err; @@ -696,8 +672,9 @@ static void mfs_test_001_006_execute(void) { size = sizeof mfs_buffer; err = mfsReadRecord(&mfs1, id, &size, mfs_buffer); test_assert(err == MFS_NO_ERROR, "record not found"); - test_assert(size == sizeof pattern512, "unexpected record length"); - test_assert(memcmp(pattern512, mfs_buffer, size) == 0, "wrong record content"); + test_assert(size == sizeof mfs_pattern512, "unexpected record length"); + test_assert(memcmp(mfs_pattern512, mfs_buffer, size) == 0, + "wrong record content"); } else { size = sizeof mfs_buffer; @@ -706,6 +683,7 @@ static void mfs_test_001_006_execute(void) { } } } + test_end_step(7); } static const testcase_t mfs_test_001_006 = { @@ -749,21 +727,23 @@ static void mfs_test_001_007_execute(void) { { mfs_id_t id; mfs_id_t id_max = (mfscfg1.bank_size - sizeof (mfs_bank_header_t)) / - (sizeof (mfs_data_header_t) + (sizeof pattern512 / 2)); + (sizeof (mfs_data_header_t) + (sizeof mfs_pattern512 / 2)); for (id = 1; id <= id_max; id++) { mfs_error_t err; size_t size; - err = mfsWriteRecord(&mfs1, id, (sizeof pattern512 / 2), pattern512); + err = mfsWriteRecord(&mfs1, id, (sizeof mfs_pattern512 / 2), mfs_pattern512); test_assert(err == MFS_NO_ERROR, "error creating the record"); size = sizeof mfs_buffer; err = mfsReadRecord(&mfs1, id, &size, mfs_buffer); test_assert(err == MFS_NO_ERROR, "record not found"); - test_assert(size == (sizeof pattern512 / 2), "unexpected record length"); - test_assert(memcmp(pattern512, mfs_buffer, size) == 0, "wrong record content"); + test_assert(size == (sizeof mfs_pattern512 / 2), "unexpected record length"); + test_assert(memcmp(mfs_pattern512, mfs_buffer, size) == 0, + "wrong record content"); } } + test_end_step(1); /* [1.7.2] Erase records until the flash bank is filled entirely.*/ test_set_step(2); @@ -772,9 +752,9 @@ static void mfs_test_001_007_execute(void) { size_t size; mfs_id_t id; mfs_id_t id_max = (mfscfg1.bank_size - sizeof (mfs_bank_header_t)) / - (sizeof (mfs_data_header_t) + (sizeof pattern512 / 2)); + (sizeof (mfs_data_header_t) + (sizeof mfs_pattern512 / 2)); mfs_id_t n = ((mfscfg1.bank_size - sizeof (mfs_bank_header_t)) - - (id_max * (sizeof (mfs_data_header_t) + (sizeof pattern512 / 2)))) / + (id_max * (sizeof (mfs_data_header_t) + (sizeof mfs_pattern512 / 2)))) / sizeof (mfs_data_header_t); for (id = 1; id <= n; id++) { @@ -785,6 +765,7 @@ static void mfs_test_001_007_execute(void) { test_assert(err == MFS_ERR_NOT_FOUND, "record not erased"); } } + test_end_step(2); /* [1.7.3] Erasing one more record triggers garbage collection, MFS_WARN_GC is expected, KS state is checked for correctness after @@ -794,7 +775,7 @@ static void mfs_test_001_007_execute(void) { mfs_error_t err; size_t size; mfs_id_t id_max = (mfscfg1.bank_size - sizeof (mfs_bank_header_t)) / - (sizeof (mfs_data_header_t) + (sizeof pattern512 / 2)); + (sizeof (mfs_data_header_t) + (sizeof mfs_pattern512 / 2)); test_assert(mfs1.current_counter == 1, "not first instance"); err = mfsEraseRecord(&mfs1, id_max); @@ -806,6 +787,7 @@ static void mfs_test_001_007_execute(void) { test_assert(mfs1.current_bank == MFS_BANK_1, "unexpected bank"); test_assert(bank_verify_erased(MFS_BANK_0) == FLASH_NO_ERROR, "bank 0 not erased"); } + test_end_step(3); } static const testcase_t mfs_test_001_007 = { diff --git a/test/mfs/source/test/mfs_test_sequence_002.c b/test/mfs/source/test/mfs_test_sequence_002.c index 735b359df..c75858ea2 100644 --- a/test/mfs/source/test/mfs_test_sequence_002.c +++ b/test/mfs/source/test/mfs_test_sequence_002.c @@ -21,17 +21,18 @@ * @file mfs_test_sequence_002.c * @brief Test Sequence 002 code. * - * @page mfs_test_sequence_002 [2] API Invalid Cases tests + * @page mfs_test_sequence_002 [2] Transaction Mode tests * * File: @ref mfs_test_sequence_002.c * *

Description

- * This test sequence tests the error coded returned by the various - * APIs when called when the system is not initialized. + * This sequence tests the MFS behavior when used in transaction mode, + * correct cases and expected error cases are tested. * *

Test Cases

* - @subpage mfs_test_002_001 * - @subpage mfs_test_002_002 + * - @subpage mfs_test_002_003 * . */ @@ -39,6 +40,7 @@ * Shared code. ****************************************************************************/ +#include #include "hal_mfs.h" /**************************************************************************** @@ -46,91 +48,277 @@ ****************************************************************************/ /** - * @page mfs_test_002_001 [2.1] Initialization error from APIs + * @page mfs_test_002_001 [2.1] Committing a transaction * *

Description

- * The API functions are invoked without prior initialization. + * A set of new/existing records are written/erased within a + * transaction then the transaction is committed, the state is checked + * afterward. * *

Test Steps

- * - [2.1.1] The function mfsErase() is called, MFS_ERR_INV_STATE is - * expected. - * - [2.1.2] The function mfsWriteRecord() is called, MFS_ERR_INV_STATE + * - [2.1.1] Records 1, 2 and 3 are created, MFS_NO_ERROR is expected. + * - [2.1.2] Presence of records 1, 2 and 3 is verified, MFS_NO_ERROR * is expected. - * - [2.1.3] The function mfsEraseRecord() is called, MFS_ERR_INV_STATE - * is expected. - * - [2.1.4] The function mfsReadRecord() is called, MFS_ERR_INV_STATE - * is expected. - * - [2.1.5] The function mfsPerformGarbageCollection() is called, - * MFS_ERR_INV_STATE is expected. + * - [2.1.3] Starting a transaction with sufficient pre-allocated + * space, MFS_NO_ERROR is expected. + * - [2.1.4] Atomically erasing record 1, updating record 2, reading + * record 3. + * - [2.1.5] Committing the transaction, MFS_NO_ERROR is expected. + * - [2.1.6] Testing outcome, records 1 must not be present, record 2 + * must contain the new value and record 3 must be unchanged. + * - [2.1.7] Re-mounting the manage storage, MFS_NO_ERROR is expected. + * - [2.1.8] Testing outcome again after re-start. + * - [2.1.9] Performing a garbage collection, the result must not + * change. + * - [2.1.10] Testing outcome again after garbage collection. * . */ +static void mfs_test_002_001_setup(void) { + bank_erase(MFS_BANK_0); + bank_erase(MFS_BANK_1); + mfsStart(&mfs1, &mfscfg1); +} + +static void mfs_test_002_001_teardown(void) { + mfsStop(&mfs1); +} + static void mfs_test_002_001_execute(void) { + uint32_t current_counter; + uint32_t used_space; - /* [2.1.1] The function mfsErase() is called, MFS_ERR_INV_STATE is + /* [2.1.1] Records 1, 2 and 3 are created, MFS_NO_ERROR is expected.*/ test_set_step(1); { - mfs_error_t err = mfsErase(&mfs1); - test_assert(err == MFS_ERR_INV_STATE, "mfsErase() returned wrong status"); + mfs_error_t err; + + err = mfsWriteRecord(&mfs1, 1, sizeof mfs_pattern16, mfs_pattern16); + test_assert(err == MFS_NO_ERROR, "error creating record 1"); + err = mfsWriteRecord(&mfs1, 2, sizeof mfs_pattern16, mfs_pattern16); + test_assert(err == MFS_NO_ERROR, "error creating record 2"); + err = mfsWriteRecord(&mfs1, 3, sizeof mfs_pattern16, mfs_pattern16); + test_assert(err == MFS_NO_ERROR, "error creating record 3"); } + test_end_step(1); - /* [2.1.2] The function mfsWriteRecord() is called, MFS_ERR_INV_STATE + /* [2.1.2] Presence of records 1, 2 and 3 is verified, MFS_NO_ERROR is expected.*/ test_set_step(2); { - mfs_error_t err = mfsWriteRecord(&mfs1, 1, 16, mfs_buffer); - test_assert(err == MFS_ERR_INV_STATE, "mfsWriteRecord() returned wrong status"); + mfs_error_t err; + size_t size; + + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer); + test_assert(err == MFS_NO_ERROR, "record not found"); + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, 2, &size, mfs_buffer); + test_assert(err == MFS_NO_ERROR, "record not found"); + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, 3, &size, mfs_buffer); + test_assert(err == MFS_NO_ERROR, "record not found"); } + test_end_step(2); - /* [2.1.3] The function mfsEraseRecord() is called, MFS_ERR_INV_STATE - is expected.*/ + /* [2.1.3] Starting a transaction with sufficient pre-allocated + space, MFS_NO_ERROR is expected.*/ test_set_step(3); { - mfs_error_t err = mfsEraseRecord(&mfs1, 1); - test_assert(err == MFS_ERR_INV_STATE, "mfsEraseRecord() returned wrong status"); + mfs_error_t err; + + err = mfsStartTransaction(&mfs1, 1024U); + test_assert(err == MFS_NO_ERROR, "error starting transaction"); } + test_end_step(3); - /* [2.1.4] The function mfsReadRecord() is called, MFS_ERR_INV_STATE - is expected.*/ + /* [2.1.4] Atomically erasing record 1, updating record 2, reading + record 3.*/ test_set_step(4); { - size_t size = sizeof mfs_buffer; - mfs_error_t err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer); - test_assert(err == MFS_ERR_INV_STATE, "mfsReadRecord() returned wrong status"); + mfs_error_t err; + size_t size; + + err = mfsEraseRecord(&mfs1, 1); + test_assert(err == MFS_NO_ERROR, "error erasing record 1"); + err = mfsWriteRecord(&mfs1, 2, sizeof mfs_pattern32, mfs_pattern32); + test_assert(err == MFS_NO_ERROR, "error writing record 2"); + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, 3, &size, mfs_buffer); + test_assert(err == MFS_NO_ERROR, "record not found"); + test_assert(size == sizeof mfs_pattern16, "unexpected record length"); + test_assert(memcmp(mfs_pattern16, mfs_buffer, size) == 0, "wrong record content"); } + test_end_step(4); - /* [2.1.5] The function mfsPerformGarbageCollection() is called, - MFS_ERR_INV_STATE is expected.*/ + /* [2.1.5] Committing the transaction, MFS_NO_ERROR is expected.*/ test_set_step(5); { - mfs_error_t err = mfsPerformGarbageCollection(&mfs1); - test_assert(err == MFS_ERR_INV_STATE, "mfsPerformGarbageCollection() returned wrong status"); + mfs_error_t err; + + err = mfsCommitTransaction(&mfs1); + test_assert(err == MFS_NO_ERROR, "error committing transaction"); + + /* Saving some internal state for successive checks.*/ + current_counter = mfs1.current_counter; + used_space = mfs1.used_space; + } + test_end_step(5); + + /* [2.1.6] Testing outcome, records 1 must not be present, record 2 + must contain the new value and record 3 must be unchanged.*/ + test_set_step(6); + { + mfs_error_t err; + size_t size; + + /* Record 1 must not be present.*/ + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer); + test_assert(err == MFS_ERR_NOT_FOUND, "record found"); + + /* Record 2 must contain the new value.*/ + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, 2, &size, mfs_buffer); + test_assert(err == MFS_NO_ERROR, "record not found"); + test_assert(size == sizeof mfs_pattern32, "unexpected record length"); + test_assert(memcmp(mfs_pattern32, mfs_buffer, size) == 0, "wrong record content"); + + /* Record 3 must be unchanged.*/ + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, 3, &size, mfs_buffer); + test_assert(err == MFS_NO_ERROR, "record not found"); + test_assert(size == sizeof mfs_pattern16, "unexpected record length"); + test_assert(memcmp(mfs_pattern16, mfs_buffer, size) == 0, "wrong record content"); + + /* Checking internal data.*/ + test_assert(MFS_BANK_0 == mfs1.current_bank, "internal data mismatch"); + test_assert(current_counter == mfs1.current_counter, "internal data mismatch"); + test_assert(used_space == mfs1.used_space, "internal data mismatch"); + } + test_end_step(6); + + /* [2.1.7] Re-mounting the manage storage, MFS_NO_ERROR is + expected.*/ + test_set_step(7); + { + mfs_error_t err; + + err = mfsStart(&mfs1, &mfscfg1); + test_assert(err == MFS_NO_ERROR, "re-start failed"); + } + test_end_step(7); + + /* [2.1.8] Testing outcome again after re-start.*/ + test_set_step(8); + { + mfs_error_t err; + size_t size; + + /* Record 1 must not be present.*/ + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer); + test_assert(err == MFS_ERR_NOT_FOUND, "record found"); + + /* Record 2 must contain the new value.*/ + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, 2, &size, mfs_buffer); + test_assert(err == MFS_NO_ERROR, "record not found"); + test_assert(size == sizeof mfs_pattern32, "unexpected record length"); + test_assert(memcmp(mfs_pattern32, mfs_buffer, size) == 0, "wrong record content"); + + /* Record 3 must be unchanged.*/ + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, 3, &size, mfs_buffer); + test_assert(err == MFS_NO_ERROR, "record not found"); + test_assert(size == sizeof mfs_pattern16, "unexpected record length"); + test_assert(memcmp(mfs_pattern16, mfs_buffer, size) == 0, "wrong record content"); + + /* Checking internal data.*/ + test_assert(MFS_BANK_0 == mfs1.current_bank, "internal data mismatch"); + test_assert(current_counter == mfs1.current_counter, "internal data mismatch"); + test_assert(used_space == mfs1.used_space, "internal data mismatch"); + } + test_end_step(8); + + /* [2.1.9] Performing a garbage collection, the result must not + change.*/ + test_set_step(9); + { + mfs_error_t err; + + err = mfsPerformGarbageCollection(&mfs1); + test_assert(err == MFS_NO_ERROR, "garbage collection failed"); + } + test_end_step(9); + + /* [2.1.10] Testing outcome again after garbage collection.*/ + test_set_step(10); + { + mfs_error_t err; + size_t size; + + /* Record 1 must not be present.*/ + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer); + test_assert(err == MFS_ERR_NOT_FOUND, "record found"); + + /* Record 2 must contain the new value.*/ + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, 2, &size, mfs_buffer); + test_assert(err == MFS_NO_ERROR, "record not found"); + test_assert(size == sizeof mfs_pattern32, "unexpected record length"); + test_assert(memcmp(mfs_pattern32, mfs_buffer, size) == 0, "wrong record content"); + + /* Record 3 must be unchanged.*/ + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, 3, &size, mfs_buffer); + test_assert(err == MFS_NO_ERROR, "record not found"); + test_assert(size == sizeof mfs_pattern16, "unexpected record length"); + test_assert(memcmp(mfs_pattern16, mfs_buffer, size) == 0, "wrong record content"); + + /* Checking internal data.*/ + test_assert(MFS_BANK_1 == mfs1.current_bank, "internal data mismatch"); + test_assert(current_counter == mfs1.current_counter - 1, "internal data mismatch"); + test_assert(used_space == mfs1.used_space, "internal data mismatch"); } + test_end_step(10); } static const testcase_t mfs_test_002_001 = { - "Initialization error from APIs", - NULL, - NULL, + "Committing a transaction", + mfs_test_002_001_setup, + mfs_test_002_001_teardown, mfs_test_002_001_execute }; /** - * @page mfs_test_002_002 [2.2] Erasing non existing record + * @page mfs_test_002_002 [2.2] Rolling back a transaction * *

Description

- * An erase operation is attempted on an non-existing record. + * A set of new/existing records are written/erased within a + * transaction then the transaction is rolled back, the state is + * checked afterward. * *

Test Steps

- * - [2.2.1] Record one is erased, the error MFS_ERR_NOT_FOUND is - * expected. + * - [2.2.1] Records 1, 2 and 3 are created, MFS_NO_ERROR is expected. + * - [2.2.2] Presence of records 1, 2 and 3 is verified, MFS_NO_ERROR + * is expected. + * - [2.2.3] Starting a transaction with sufficient pre-allocated + * space, MFS_NO_ERROR is expected.. + * - [2.2.4] Atomically erasing record 1, updating record 2, reading + * record 3. + * - [2.2.5] Rolling back the transaction, MFS_NO_ERROR is expected. + * - [2.2.6] State must not have changed, records 1, 2 and 3 must still + * be there unchanged. * . */ static void mfs_test_002_002_setup(void) { + bank_erase(MFS_BANK_0); + bank_erase(MFS_BANK_1); mfsStart(&mfs1, &mfscfg1); - mfsErase(&mfs1); } static void mfs_test_002_002_teardown(void) { @@ -138,26 +326,249 @@ static void mfs_test_002_002_teardown(void) { } static void mfs_test_002_002_execute(void) { + uint32_t current_counter; + uint32_t used_space; - /* [2.2.1] Record one is erased, the error MFS_ERR_NOT_FOUND is + /* [2.2.1] Records 1, 2 and 3 are created, MFS_NO_ERROR is expected.*/ test_set_step(1); { mfs_error_t err; + err = mfsWriteRecord(&mfs1, 1, sizeof mfs_pattern16, mfs_pattern16); + test_assert(err == MFS_NO_ERROR, "error creating record 1"); + err = mfsWriteRecord(&mfs1, 2, sizeof mfs_pattern16, mfs_pattern16); + test_assert(err == MFS_NO_ERROR, "error creating record 2"); + err = mfsWriteRecord(&mfs1, 3, sizeof mfs_pattern16, mfs_pattern16); + test_assert(err == MFS_NO_ERROR, "error creating record 3"); + } + test_end_step(1); + + /* [2.2.2] Presence of records 1, 2 and 3 is verified, MFS_NO_ERROR + is expected.*/ + test_set_step(2); + { + mfs_error_t err; + size_t size; + + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer); + test_assert(err == MFS_NO_ERROR, "record not found"); + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, 2, &size, mfs_buffer); + test_assert(err == MFS_NO_ERROR, "record not found"); + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, 3, &size, mfs_buffer); + test_assert(err == MFS_NO_ERROR, "record not found"); + } + test_end_step(2); + + /* [2.2.3] Starting a transaction with sufficient pre-allocated + space, MFS_NO_ERROR is expected..*/ + test_set_step(3); + { + mfs_error_t err; + + err = mfsStartTransaction(&mfs1, 1024U); + test_assert(err == MFS_NO_ERROR, "error starting transaction"); + } + test_end_step(3); + + /* [2.2.4] Atomically erasing record 1, updating record 2, reading + record 3.*/ + test_set_step(4); + { + mfs_error_t err; + size_t size; + err = mfsEraseRecord(&mfs1, 1); - test_assert(err != MFS_NO_ERROR, "record was present"); - test_assert(err == MFS_ERR_NOT_FOUND, "invalid error code"); + test_assert(err == MFS_NO_ERROR, "error erasing record 1"); + err = mfsWriteRecord(&mfs1, 2, sizeof mfs_pattern32, mfs_pattern32); + test_assert(err == MFS_NO_ERROR, "error writing record 2"); + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, 3, &size, mfs_buffer); + test_assert(err == MFS_NO_ERROR, "record not found"); + test_assert(size == sizeof mfs_pattern16, "unexpected record length"); + test_assert(memcmp(mfs_pattern16, mfs_buffer, size) == 0, "wrong record content"); + + /* Saving some internal state for successive checks.*/ + current_counter = mfs1.current_counter; + used_space = mfs1.used_space; + } + test_end_step(4); + + /* [2.2.5] Rolling back the transaction, MFS_NO_ERROR is expected.*/ + test_set_step(5); + { + mfs_error_t err; + + err = mfsRollbackTransaction(&mfs1); + test_assert(err == MFS_NO_ERROR, "error rolling back transaction"); + } + test_end_step(5); + + /* [2.2.6] State must not have changed, records 1, 2 and 3 must still + be there unchanged.*/ + test_set_step(6); + { + mfs_error_t err; + size_t size; + + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer); + test_assert(err == MFS_NO_ERROR, "record not found"); + test_assert(size == sizeof mfs_pattern16, "size changed"); + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, 2, &size, mfs_buffer); + test_assert(err == MFS_NO_ERROR, "record not found"); + test_assert(size == sizeof mfs_pattern16, "size changed"); + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, 3, &size, mfs_buffer); + test_assert(err == MFS_NO_ERROR, "record not found"); + test_assert(size == sizeof mfs_pattern16, "size changed"); + + /* Checking internal data.*/ + test_assert(MFS_BANK_1 == mfs1.current_bank, "internal data mismatch"); + test_assert(current_counter == mfs1.current_counter - 1, "internal data mismatch"); + test_assert(used_space == mfs1.used_space, "internal data mismatch"); } + test_end_step(6); } static const testcase_t mfs_test_002_002 = { - "Erasing non existing record", + "Rolling back a transaction", mfs_test_002_002_setup, mfs_test_002_002_teardown, mfs_test_002_002_execute }; +/** + * @page mfs_test_002_003 [2.3] Transaction triggering an early garbage collect + * + *

Description

+ * A transaction is started with sufficient space but not contiguous, a + * garbage collection is triggered. + * + *

Test Steps

+ * - [2.3.1] Filling up the storage by writing records with increasing + * IDs, MFS_NO_ERROR is expected. + * - [2.3.2] Erasing one record, MFS_NO_ERROR is expected. + * - [2.3.3] Starting a transaction with the whole remaining space, + * MFS_ERR_OUT_OF_MEM is expected. + * - [2.3.4] Starting a transaction with insufficient space for one + * more header, MFS_ERR_OUT_OF_MEM is expected. + * - [2.3.5] Starting a transaction with just enough space for one more + * header, MFS_NO_ERROR is expected. + * - [2.3.6] Rolling back, MFS_NO_ERROR is expected. + * . + */ + +static void mfs_test_002_003_setup(void) { + bank_erase(MFS_BANK_0); + bank_erase(MFS_BANK_1); + mfsStart(&mfs1, &mfscfg1); +} + +static void mfs_test_002_003_teardown(void) { + mfsStop(&mfs1); +} + +static void mfs_test_002_003_execute(void) { + + /* [2.3.1] Filling up the storage by writing records with increasing + IDs, MFS_NO_ERROR is expected.*/ + test_set_step(1); + { + mfs_id_t id; + mfs_id_t id_max = (mfscfg1.bank_size - sizeof (mfs_bank_header_t)) / + (sizeof (mfs_data_header_t) + sizeof mfs_pattern512); + + for (id = 1; id <= id_max; id++) { + mfs_error_t err; + size_t size; + + err = mfsWriteRecord(&mfs1, id, sizeof mfs_pattern512, mfs_pattern512); + test_assert(err == MFS_NO_ERROR, "error creating the record"); + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, id, &size, mfs_buffer); + test_assert(err == MFS_NO_ERROR, + "record not found"); + test_assert(size == sizeof mfs_pattern512, + "unexpected record length"); + test_assert(memcmp(mfs_pattern512, mfs_buffer, size) == 0, + "wrong record content"); + } + } + test_end_step(1); + + /* [2.3.2] Erasing one record, MFS_NO_ERROR is expected.*/ + test_set_step(2); + { + mfs_error_t err; + size_t size; + + err = mfsEraseRecord(&mfs1, 1); + test_assert(err == MFS_NO_ERROR, "error erasing the record"); + size = sizeof mfs_buffer; + err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer); + test_assert(err == MFS_ERR_NOT_FOUND, "record not erased"); + } + test_end_step(2); + + /* [2.3.3] Starting a transaction with the whole remaining space, + MFS_ERR_OUT_OF_MEM is expected.*/ + test_set_step(3); + { + mfs_error_t err; + size_t size = mfs1.config->bank_size - mfs1.used_space; + + err = mfsStartTransaction(&mfs1, size); + test_assert(err == MFS_ERR_OUT_OF_MEM, "invalid error code"); + } + test_end_step(3); + + /* [2.3.4] Starting a transaction with insufficient space for one + more header, MFS_ERR_OUT_OF_MEM is expected.*/ + test_set_step(4); + { + mfs_error_t err; + size_t size = ((mfs1.config->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"); + } + test_end_step(4); + + /* [2.3.5] Starting a transaction with just enough space for one more + header, MFS_NO_ERROR is expected.*/ + test_set_step(5); + { + mfs_error_t err; + size_t size = (mfs1.config->bank_size - mfs1.used_space) - sizeof (mfs_data_header_t); + + err = mfsStartTransaction(&mfs1, size); + test_assert(err == MFS_NO_ERROR, "error starting transaction"); + } + test_end_step(5); + + /* [2.3.6] Rolling back, MFS_NO_ERROR is expected.*/ + test_set_step(6); + { + mfs_error_t err; + + err = mfsRollbackTransaction(&mfs1); + test_assert(err == MFS_NO_ERROR, "error rolling back transaction"); + } + test_end_step(6); +} + +static const testcase_t mfs_test_002_003 = { + "Transaction triggering an early garbage collect", + mfs_test_002_003_setup, + mfs_test_002_003_teardown, + mfs_test_002_003_execute +}; + /**************************************************************************** * Exported data. ****************************************************************************/ @@ -168,13 +579,14 @@ static const testcase_t mfs_test_002_002 = { const testcase_t * const mfs_test_sequence_002_array[] = { &mfs_test_002_001, &mfs_test_002_002, + &mfs_test_002_003, NULL }; /** - * @brief API Invalid Cases tests. + * @brief Transaction Mode tests. */ const testsequence_t mfs_test_sequence_002 = { - "API Invalid Cases tests", + "Transaction Mode tests", mfs_test_sequence_002_array }; diff --git a/test/mfs/source/test/mfs_test_sequence_003.c b/test/mfs/source/test/mfs_test_sequence_003.c new file mode 100644 index 000000000..e31f53bab --- /dev/null +++ b/test/mfs/source/test/mfs_test_sequence_003.c @@ -0,0 +1,186 @@ +/* + ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#include "hal.h" +#include "mfs_test_root.h" + +/** + * @file mfs_test_sequence_003.c + * @brief Test Sequence 003 code. + * + * @page mfs_test_sequence_003 [3] API Invalid Cases tests + * + * File: @ref mfs_test_sequence_003.c + * + *

Description

+ * This test sequence tests the error coded returned by the various + * APIs when called when the system is not initialized. + * + *

Test Cases

+ * - @subpage mfs_test_003_001 + * - @subpage mfs_test_003_002 + * . + */ + +/**************************************************************************** + * Shared code. + ****************************************************************************/ + +#include "hal_mfs.h" + +/**************************************************************************** + * Test cases. + ****************************************************************************/ + +/** + * @page mfs_test_003_001 [3.1] Initialization error from APIs + * + *

Description

+ * The API functions are invoked without prior initialization. + * + *

Test Steps

+ * - [3.1.1] The function mfsErase() is called, MFS_ERR_INV_STATE is + * expected. + * - [3.1.2] The function mfsWriteRecord() is called, MFS_ERR_INV_STATE + * is expected. + * - [3.1.3] The function mfsEraseRecord() is called, MFS_ERR_INV_STATE + * is expected. + * - [3.1.4] The function mfsReadRecord() is called, MFS_ERR_INV_STATE + * is expected. + * - [3.1.5] The function mfsPerformGarbageCollection() is called, + * MFS_ERR_INV_STATE is expected. + * . + */ + +static void mfs_test_003_001_execute(void) { + + /* [3.1.1] The function mfsErase() is called, MFS_ERR_INV_STATE is + expected.*/ + test_set_step(1); + { + mfs_error_t err = mfsErase(&mfs1); + test_assert(err == MFS_ERR_INV_STATE, "mfsErase() returned wrong status"); + } + test_end_step(1); + + /* [3.1.2] The function mfsWriteRecord() is called, MFS_ERR_INV_STATE + is expected.*/ + test_set_step(2); + { + mfs_error_t err = mfsWriteRecord(&mfs1, 1, 16, mfs_buffer); + test_assert(err == MFS_ERR_INV_STATE, "mfsWriteRecord() returned wrong status"); + } + test_end_step(2); + + /* [3.1.3] The function mfsEraseRecord() is called, MFS_ERR_INV_STATE + is expected.*/ + test_set_step(3); + { + mfs_error_t err = mfsEraseRecord(&mfs1, 1); + test_assert(err == MFS_ERR_INV_STATE, "mfsEraseRecord() returned wrong status"); + } + test_end_step(3); + + /* [3.1.4] The function mfsReadRecord() is called, MFS_ERR_INV_STATE + is expected.*/ + test_set_step(4); + { + size_t size = sizeof mfs_buffer; + mfs_error_t err = mfsReadRecord(&mfs1, 1, &size, mfs_buffer); + test_assert(err == MFS_ERR_INV_STATE, "mfsReadRecord() returned wrong status"); + } + test_end_step(4); + + /* [3.1.5] The function mfsPerformGarbageCollection() is called, + MFS_ERR_INV_STATE is expected.*/ + test_set_step(5); + { + mfs_error_t err = mfsPerformGarbageCollection(&mfs1); + test_assert(err == MFS_ERR_INV_STATE, "mfsPerformGarbageCollection() returned wrong status"); + } + test_end_step(5); +} + +static const testcase_t mfs_test_003_001 = { + "Initialization error from APIs", + NULL, + NULL, + mfs_test_003_001_execute +}; + +/** + * @page mfs_test_003_002 [3.2] Erasing non existing record + * + *

Description

+ * An erase operation is attempted on an non-existing record. + * + *

Test Steps

+ * - [3.2.1] Record one is erased, the error MFS_ERR_NOT_FOUND is + * expected. + * . + */ + +static void mfs_test_003_002_setup(void) { + mfsStart(&mfs1, &mfscfg1); + mfsErase(&mfs1); +} + +static void mfs_test_003_002_teardown(void) { + mfsStop(&mfs1); +} + +static void mfs_test_003_002_execute(void) { + + /* [3.2.1] Record one is erased, the error MFS_ERR_NOT_FOUND is + expected.*/ + test_set_step(1); + { + mfs_error_t err; + + err = mfsEraseRecord(&mfs1, 1); + test_assert(err != MFS_NO_ERROR, "record was present"); + test_assert(err == MFS_ERR_NOT_FOUND, "invalid error code"); + } + test_end_step(1); +} + +static const testcase_t mfs_test_003_002 = { + "Erasing non existing record", + mfs_test_003_002_setup, + mfs_test_003_002_teardown, + mfs_test_003_002_execute +}; + +/**************************************************************************** + * Exported data. + ****************************************************************************/ + +/** + * @brief Array of test cases. + */ +const testcase_t * const mfs_test_sequence_003_array[] = { + &mfs_test_003_001, + &mfs_test_003_002, + NULL +}; + +/** + * @brief API Invalid Cases tests. + */ +const testsequence_t mfs_test_sequence_003 = { + "API Invalid Cases tests", + mfs_test_sequence_003_array +}; diff --git a/test/mfs/source/test/mfs_test_sequence_003.h b/test/mfs/source/test/mfs_test_sequence_003.h new file mode 100644 index 000000000..336f8bff6 --- /dev/null +++ b/test/mfs/source/test/mfs_test_sequence_003.h @@ -0,0 +1,27 @@ +/* + ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/** + * @file mfs_test_sequence_003.h + * @brief Test Sequence 003 header. + */ + +#ifndef MFS_TEST_SEQUENCE_003_H +#define MFS_TEST_SEQUENCE_003_H + +extern const testsequence_t mfs_test_sequence_003; + +#endif /* MFS_TEST_SEQUENCE_003_H */ -- cgit v1.2.3