From ed7adbc766d817a6915c1279fc9dbe2f7c0f4567 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Fri, 17 Nov 2017 13:02:26 +0000 Subject: More MFS tests. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11029 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- test/mfs/configuration.xml | 146 +++++++++++++++++++++- test/mfs/mfs_test.mk | 3 +- test/mfs/source/test/mfs_test_root.c | 2 + test/mfs/source/test/mfs_test_root.h | 1 + test/mfs/source/test/mfs_test_sequence_001.c | 4 +- test/mfs/source/test/mfs_test_sequence_002.c | 180 +++++++++++++++++++++++++++ test/mfs/source/test/mfs_test_sequence_002.h | 27 ++++ 7 files changed, 359 insertions(+), 4 deletions(-) create mode 100644 test/mfs/source/test/mfs_test_sequence_002.c create mode 100644 test/mfs/source/test/mfs_test_sequence_002.h (limited to 'test/mfs') diff --git a/test/mfs/configuration.xml b/test/mfs/configuration.xml index c715b6b93..bb2533c80 100644 --- a/test/mfs/configuration.xml +++ b/test/mfs/configuration.xml @@ -731,7 +731,7 @@ test_assert(bank_verify_erased(MFS_BANK_1) == FLASH_NO_ERROR, "bank 1 not erased - Checking for all records in the new bank, MFS_NO_ERROR is expected for each key. + Checking for all records in the new bank, MFS_NO_ERROR is expected for each record. @@ -865,6 +865,150 @@ test_assert(bank_verify_erased(MFS_BANK_0) == FLASH_NO_ERROR, "bank 0 not erased + + + 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. + + + + + + + + + + + + diff --git a/test/mfs/mfs_test.mk b/test/mfs/mfs_test.mk index fda8965c3..ae6fbf6a2 100644 --- a/test/mfs/mfs_test.mk +++ b/test/mfs/mfs_test.mk @@ -1,6 +1,7 @@ # 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_001.c \ + ${CHIBIOS}/test/mfs/source/test/mfs_test_sequence_002.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 3f38c99dd..27d5efb59 100644 --- a/test/mfs/source/test/mfs_test_root.c +++ b/test/mfs/source/test/mfs_test_root.c @@ -22,6 +22,7 @@ * *

Test Sequences

* - @subpage mfs_test_sequence_001 + * - @subpage mfs_test_sequence_002 * . */ @@ -44,6 +45,7 @@ */ const testsequence_t * const mfs_test_suite_array[] = { &mfs_test_sequence_001, + &mfs_test_sequence_002, NULL }; diff --git a/test/mfs/source/test/mfs_test_root.h b/test/mfs/source/test/mfs_test_root.h index 18c12ee8f..51577e6a7 100644 --- a/test/mfs/source/test/mfs_test_root.h +++ b/test/mfs/source/test/mfs_test_root.h @@ -25,6 +25,7 @@ #include "ch_test.h" #include "mfs_test_sequence_001.h" +#include "mfs_test_sequence_002.h" #if !defined(__DOXYGEN__) diff --git a/test/mfs/source/test/mfs_test_sequence_001.c b/test/mfs/source/test/mfs_test_sequence_001.c index c0cc35730..d6ee2fe42 100644 --- a/test/mfs/source/test/mfs_test_sequence_001.c +++ b/test/mfs/source/test/mfs_test_sequence_001.c @@ -507,7 +507,7 @@ static const testcase_t mfs_test_001_005 = { * MFS_WARN_GC is expected, MFS object state is checked for * correctness after the operation. * - [1.6.7] Checking for all records in the new bank, MFS_NO_ERROR is - * expected for each key. + * expected for each record. * . */ @@ -643,7 +643,7 @@ static void mfs_test_001_006_execute(void) { } /* [1.6.7] Checking for all records in the new bank, MFS_NO_ERROR is - expected for each key.*/ + expected for each record.*/ test_set_step(7); { mfs_id_t id; diff --git a/test/mfs/source/test/mfs_test_sequence_002.c b/test/mfs/source/test/mfs_test_sequence_002.c new file mode 100644 index 000000000..973760518 --- /dev/null +++ b/test/mfs/source/test/mfs_test_sequence_002.c @@ -0,0 +1,180 @@ +/* + ChibiOS - Copyright (C) 2006..2017 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_002.c + * @brief Test Sequence 002 code. + * + * @page mfs_test_sequence_002 [2] API Invalid Cases 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. + * + *

Test Cases

+ * - @subpage mfs_test_002_001 + * - @subpage mfs_test_002_002 + * . + */ + +/**************************************************************************** + * Shared code. + ****************************************************************************/ + +#include "mfs.h" + +/**************************************************************************** + * Test cases. + ****************************************************************************/ + +/** + * @page mfs_test_002_001 [2.1] Initialization error from APIs + * + *

Description

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

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 + * 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. + * . + */ + +static void mfs_test_002_001_execute(void) { + + /* [2.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"); + } + + /* [2.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"); + } + + /* [2.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"); + } + + /* [2.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"); + } + + /* [2.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"); + } +} + +static const testcase_t mfs_test_002_001 = { + "Initialization error from APIs", + NULL, + NULL, + mfs_test_002_001_execute +}; + +/** + * @page mfs_test_002_002 [2.2] Erasing non existing record + * + *

Description

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

Test Steps

+ * - [2.2.1] Record one is erased, the error MFS_ERR_NOT_FOUND is + * expected. + * . + */ + +static void mfs_test_002_002_setup(void) { + mfsStart(&mfs1, &mfscfg1); + mfsErase(&mfs1); +} + +static void mfs_test_002_002_teardown(void) { + mfsStop(&mfs1); +} + +static void mfs_test_002_002_execute(void) { + + /* [2.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"); + } +} + +static const testcase_t mfs_test_002_002 = { + "Erasing non existing record", + mfs_test_002_002_setup, + mfs_test_002_002_teardown, + mfs_test_002_002_execute +}; + +/**************************************************************************** + * Exported data. + ****************************************************************************/ + +/** + * @brief Array of test cases. + */ +const testcase_t * const mfs_test_sequence_002_array[] = { + &mfs_test_002_001, + &mfs_test_002_002, + NULL +}; + +/** + * @brief API Invalid Cases tests. + */ +const testsequence_t mfs_test_sequence_002 = { + "API Invalid Cases tests", + mfs_test_sequence_002_array +}; diff --git a/test/mfs/source/test/mfs_test_sequence_002.h b/test/mfs/source/test/mfs_test_sequence_002.h new file mode 100644 index 000000000..d451e5d5a --- /dev/null +++ b/test/mfs/source/test/mfs_test_sequence_002.h @@ -0,0 +1,27 @@ +/* + ChibiOS - Copyright (C) 2006..2017 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_002.h + * @brief Test Sequence 002 header. + */ + +#ifndef MFS_TEST_SEQUENCE_002_H +#define MFS_TEST_SEQUENCE_002_H + +extern const testsequence_t mfs_test_sequence_002; + +#endif /* MFS_TEST_SEQUENCE_002_H */ -- cgit v1.2.3