More MFS tests.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11029 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
Giovanni Di Sirio 2017-11-17 13:02:26 +00:00
parent dc52593ffb
commit ed7adbc766
7 changed files with 359 additions and 4 deletions

View File

@ -731,7 +731,7 @@ test_assert(bank_verify_erased(MFS_BANK_1) == FLASH_NO_ERROR, "bank 1 not erased
</step>
<step>
<description>
<value>Checking for all records in the new bank, MFS_NO_ERROR is expected for each key.</value>
<value>Checking for all records in the new bank, MFS_NO_ERROR is expected for each record.</value>
</description>
<tags>
<value />
@ -865,6 +865,150 @@ test_assert(bank_verify_erased(MFS_BANK_0) == FLASH_NO_ERROR, "bank 0 not erased
</case>
</cases>
</sequence>
<sequence>
<type index="0">
<value>Internal Tests</value>
</type>
<brief>
<value>API Invalid Cases tests.</value>
</brief>
<description>
<value>This test sequence tests the error coded returned by the various APIs when called when the system is not initialized.</value>
</description>
<condition>
<value />
</condition>
<shared_code>
<value><![CDATA[#include "mfs.h"]]></value>
</shared_code>
<cases>
<case>
<brief>
<value>Initialization error from APIs.</value>
</brief>
<description>
<value>The API functions are invoked without prior initialization.</value>
</description>
<condition>
<value />
</condition>
<various_code>
<setup_code>
<value />
</setup_code>
<teardown_code>
<value />
</teardown_code>
<local_variables>
<value />
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>The function mfsErase() is called, MFS_ERR_INV_STATE is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[mfs_error_t err = mfsErase(&mfs1);
test_assert(err == MFS_ERR_INV_STATE, "mfsErase() returned wrong status");]]></value>
</code>
</step>
<step>
<description>
<value>The function mfsWriteRecord() is called, MFS_ERR_INV_STATE is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[mfs_error_t err = mfsWriteRecord(&mfs1, 1, 16, mfs_buffer);
test_assert(err == MFS_ERR_INV_STATE, "mfsWriteRecord() returned wrong status");]]></value>
</code>
</step>
<step>
<description>
<value>The function mfsEraseRecord() is called, MFS_ERR_INV_STATE is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[mfs_error_t err = mfsEraseRecord(&mfs1, 1);
test_assert(err == MFS_ERR_INV_STATE, "mfsEraseRecord() returned wrong status");]]></value>
</code>
</step>
<step>
<description>
<value>The function mfsReadRecord() is called, MFS_ERR_INV_STATE is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[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");]]></value>
</code>
</step>
<step>
<description>
<value>The function mfsPerformGarbageCollection() is called, MFS_ERR_INV_STATE is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[mfs_error_t err = mfsPerformGarbageCollection(&mfs1);
test_assert(err == MFS_ERR_INV_STATE, "mfsPerformGarbageCollection() returned wrong status");]]></value>
</code>
</step>
</steps>
</case>
<case>
<brief>
<value>Erasing non existing record.</value>
</brief>
<description>
<value>An erase operation is attempted on an non-existing record.</value>
</description>
<condition>
<value />
</condition>
<various_code>
<setup_code>
<value><![CDATA[mfsStart(&mfs1, &mfscfg1);
mfsErase(&mfs1);]]></value>
</setup_code>
<teardown_code>
<value><![CDATA[mfsStop(&mfs1);]]></value>
</teardown_code>
<local_variables>
<value />
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>Record one is erased, the error MFS_ERR_NOT_FOUND is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[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");]]></value>
</code>
</step>
</steps>
</case>
</cases>
</sequence>
</sequences>
</instance>
</instances>

View File

@ -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

View File

@ -22,6 +22,7 @@
*
* <h2>Test Sequences</h2>
* - @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
};

View File

@ -25,6 +25,7 @@
#include "ch_test.h"
#include "mfs_test_sequence_001.h"
#include "mfs_test_sequence_002.h"
#if !defined(__DOXYGEN__)

View File

@ -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;

View File

@ -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
*
* <h2>Description</h2>
* This test sequence tests the error coded returned by the various
* APIs when called when the system is not initialized.
*
* <h2>Test Cases</h2>
* - @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
*
* <h2>Description</h2>
* The API functions are invoked without prior initialization.
*
* <h2>Test Steps</h2>
* - [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
*
* <h2>Description</h2>
* An erase operation is attempted on an non-existing record.
*
* <h2>Test Steps</h2>
* - [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
};

View File

@ -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 */