aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2017-10-27 13:34:22 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2017-10-27 13:34:22 +0000
commitb140ed8c611d2e345fc70afc993495d1f31dc69a (patch)
treebc7c4b0d6376574fd218e2d75d48ecbed9885db1 /test
parent3f72c7787eb9ad2e3bf846b7184fe283ab8a19c2 (diff)
downloadChibiOS-b140ed8c611d2e345fc70afc993495d1f31dc69a.tar.gz
ChibiOS-b140ed8c611d2e345fc70afc993495d1f31dc69a.tar.bz2
ChibiOS-b140ed8c611d2e345fc70afc993495d1f31dc69a.zip
Added test case for dynamic buffers, fixed a problem.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10900 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'test')
-rw-r--r--test/oslib/configuration.xml181
-rw-r--r--test/oslib/source/test/oslib_test_sequence_004.c140
2 files changed, 292 insertions, 29 deletions
diff --git a/test/oslib/configuration.xml b/test/oslib/configuration.xml
index c6b61dcb1..e7ffca0a0 100644
--- a/test/oslib/configuration.xml
+++ b/test/oslib/configuration.xml
@@ -974,14 +974,21 @@ test_assert(p1 == NULL, "allocation not failed");]]></value>
<value>This test case verifies the static objects registry.</value>
</description>
<condition>
- <value />
+ <value>CH_CFG_FACTORY_OBJECTS_REGISTRY == TRUE</value>
</condition>
<various_code>
<setup_code>
<value />
</setup_code>
<teardown_code>
- <value />
+ <value><![CDATA[registered_object_t *rop;
+
+rop = chFactoryFindObject("myobj");
+if (rop != NULL) {
+ while (rop->element.refs > 0U) {
+ chFactoryReleaseObject(rop);
+ }
+}]]></value>
</teardown_code>
<local_variables>
<value><![CDATA[registered_object_t *rop;]]></value>
@@ -996,7 +1003,7 @@ test_assert(p1 == NULL, "allocation not failed");]]></value>
<value />
</tags>
<code>
- <value><![CDATA[rop = chFactoryFindObject("myobj");
+ <value><![CDATA[rop = chFactoryFindObject("myobj");
test_assert(rop == NULL, "found");]]></value>
</code>
</step>
@@ -1008,9 +1015,9 @@ test_assert(rop == NULL, "found");]]></value>
<value />
</tags>
<code>
- <value><![CDATA[static uint32_t myobj = 0x55aa;
-
-rop = chFactoryRegisterObject("myobj", (void *)&myobj);
+ <value><![CDATA[static uint32_t myobj = 0x55aa;
+
+rop = chFactoryRegisterObject("myobj", (void *)&myobj);
test_assert(rop != NULL, "cannot register");]]></value>
</code>
</step>
@@ -1022,10 +1029,10 @@ test_assert(rop != NULL, "cannot register");]]></value>
<value />
</tags>
<code>
- <value><![CDATA[registered_object_t *rop1;
-static uint32_t myobj = 0x55aa;
-
-rop1 = chFactoryRegisterObject("myobj", (void *)&myobj);
+ <value><![CDATA[registered_object_t *rop1;
+static uint32_t myobj = 0x55aa;
+
+rop1 = chFactoryRegisterObject("myobj", (void *)&myobj);
test_assert(rop1 == NULL, "can register");]]></value>
</code>
</step>
@@ -1037,23 +1044,23 @@ test_assert(rop1 == NULL, "can register");]]></value>
<value />
</tags>
<code>
- <value><![CDATA[registered_object_t *rop1, *rop2;
-
-rop1 = chFactoryFindObject("myobj");
-test_assert(rop1 != NULL, "not found");
-test_assert(*(uint32_t *)(rop1->objp) == 0x55aa, "object mismatch");
-test_assert(rop == rop1, "object reference mismatch");
-test_assert(rop1->element.refs == 2, "object reference mismatch");
-
-rop2 = (registered_object_t *)chFactoryDuplicateReference((dyn_element_t *)rop1);
-test_assert(rop1 == rop2, "object reference mismatch");
-test_assert(*(uint32_t *)(rop2->objp) == 0x55aa, "object mismatch");
-test_assert(rop2->element.refs == 3, "object reference mismatch");
-
-chFactoryReleaseObject(rop2);
-test_assert(rop1->element.refs == 2, "references mismatch");
-
-chFactoryReleaseObject(rop1);
+ <value><![CDATA[registered_object_t *rop1, *rop2;
+
+rop1 = chFactoryFindObject("myobj");
+test_assert(rop1 != NULL, "not found");
+test_assert(*(uint32_t *)(rop1->objp) == 0x55aa, "object mismatch");
+test_assert(rop == rop1, "object reference mismatch");
+test_assert(rop1->element.refs == 2, "object reference mismatch");
+
+rop2 = (registered_object_t *)chFactoryDuplicateReference((dyn_element_t *)rop1);
+test_assert(rop1 == rop2, "object reference mismatch");
+test_assert(*(uint32_t *)(rop2->objp) == 0x55aa, "object mismatch");
+test_assert(rop2->element.refs == 3, "object reference mismatch");
+
+chFactoryReleaseObject(rop2);
+test_assert(rop1->element.refs == 2, "references mismatch");
+
+chFactoryReleaseObject(rop1);
test_assert(rop->element.refs == 1, "references mismatch");]]></value>
</code>
</step>
@@ -1076,12 +1083,130 @@ test_assert(rop->element.refs == 1, "references mismatch");]]></value>
<value />
</tags>
<code>
- <value><![CDATA[rop = chFactoryFindObject("myobj");
+ <value><![CDATA[rop = chFactoryFindObject("myobj");
test_assert(rop == NULL, "found");]]></value>
</code>
</step>
</steps>
</case>
+ <case>
+ <brief>
+ <value>Dynamic Buffers Factory.</value>
+ </brief>
+ <description>
+ <value>This test case verifies the dynamic buffers factory.</value>
+ </description>
+ <condition>
+ <value>CH_CFG_FACTORY_GENERIC_BUFFERS == TRUE</value>
+ </condition>
+ <various_code>
+ <setup_code>
+ <value />
+ </setup_code>
+ <teardown_code>
+ <value><![CDATA[dyn_buffer_t *dbp;
+
+dbp = chFactoryFindBuffer("mybuf");
+if (dbp != NULL) {
+ while (dbp->element.refs > 0U) {
+ chFactoryReleaseBuffer(dbp);
+ }
+}]]></value>
+ </teardown_code>
+ <local_variables>
+ <value><![CDATA[dyn_buffer_t *dbp;]]></value>
+ </local_variables>
+ </various_code>
+ <steps>
+ <step>
+ <description>
+ <value>Retrieving a dynamic buffer by name, must not exist.</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[dbp = chFactoryFindBuffer("mybuf");
+test_assert(dbp == NULL, "found");]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
+ <value>Creating a dynamic buffer it must not exists, must succeed.</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[dbp = chFactoryCreateBuffer("mybuf", 128U);
+test_assert(dbp != NULL, "cannot create");]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
+ <value>Creating a dynamic buffer with the same name, must fail.</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[dyn_buffer_t *dbp1;
+
+dbp1 = chFactoryCreateBuffer("mybuf", 128U);
+test_assert(dbp1 == NULL, "can create");]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
+ <value>Retrieving the dynamic buffer by name, must exist, then increasing the reference counter, finally releasing both references.</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[dyn_buffer_t *dbp1, *dbp2;
+
+dbp1 = chFactoryFindBuffer("mybuf");
+test_assert(dbp1 != NULL, "not found");
+test_assert(dbp == dbp1, "object reference mismatch");
+test_assert(dbp1->element.refs == 2, "object reference mismatch");
+
+dbp2 = (dyn_buffer_t *)chFactoryDuplicateReference((dyn_element_t *)dbp1);
+test_assert(dbp1 == dbp2, "object reference mismatch");
+test_assert(dbp2->element.refs == 3, "object reference mismatch");
+
+chFactoryReleaseBuffer(dbp2);
+test_assert(dbp1->element.refs == 2, "references mismatch");
+
+chFactoryReleaseBuffer(dbp1);
+test_assert(dbp->element.refs == 1, "references mismatch");]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
+ <value>Releasing the first reference to the dynamic buffer, must not trigger an assertion.</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[chFactoryReleaseBuffer(dbp);]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
+ <value>Retrieving the dynamic buffer by name again, must not exist.</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[dbp = chFactoryFindBuffer("mybuf");
+test_assert(dbp == NULL, "found");]]></value>
+ </code>
+ </step>
+ </steps>
+ </case>
</cases>
</sequence>
</sequences>
diff --git a/test/oslib/source/test/oslib_test_sequence_004.c b/test/oslib/source/test/oslib_test_sequence_004.c
index 981e92997..3f6533c47 100644
--- a/test/oslib/source/test/oslib_test_sequence_004.c
+++ b/test/oslib/source/test/oslib_test_sequence_004.c
@@ -37,6 +37,7 @@
*
* <h2>Test Cases</h2>
* - @subpage oslib_test_004_001
+ * - @subpage oslib_test_004_002
* .
*/
@@ -51,12 +52,19 @@
* Test cases.
****************************************************************************/
+#if (CH_CFG_FACTORY_OBJECTS_REGISTRY == TRUE) || defined(__DOXYGEN__)
/**
* @page oslib_test_004_001 [4.1] Objects Registry
*
* <h2>Description</h2>
* This test case verifies the static objects registry.
*
+ * <h2>Conditions</h2>
+ * This test is only executed if the following preprocessor condition
+ * evaluates to true:
+ * - CH_CFG_FACTORY_OBJECTS_REGISTRY == TRUE
+ * .
+ *
* <h2>Test Steps</h2>
* - [4.1.1] Retrieving a registered object by name, must not exist.
* - [4.1.2] Registering an object, it must not exists, must succeed.
@@ -71,6 +79,17 @@
* .
*/
+static void oslib_test_004_001_teardown(void) {
+ registered_object_t *rop;
+
+ rop = chFactoryFindObject("myobj");
+ if (rop != NULL) {
+ while (rop->element.refs > 0U) {
+ chFactoryReleaseObject(rop);
+ }
+ }
+}
+
static void oslib_test_004_001_execute(void) {
registered_object_t *rop;
@@ -144,9 +163,123 @@ static void oslib_test_004_001_execute(void) {
static const testcase_t oslib_test_004_001 = {
"Objects Registry",
NULL,
- NULL,
+ oslib_test_004_001_teardown,
oslib_test_004_001_execute
};
+#endif /* CH_CFG_FACTORY_OBJECTS_REGISTRY == TRUE */
+
+#if (CH_CFG_FACTORY_GENERIC_BUFFERS == TRUE) || defined(__DOXYGEN__)
+/**
+ * @page oslib_test_004_002 [4.2] Dynamic Buffers Factory
+ *
+ * <h2>Description</h2>
+ * This test case verifies the dynamic buffers factory.
+ *
+ * <h2>Conditions</h2>
+ * This test is only executed if the following preprocessor condition
+ * evaluates to true:
+ * - CH_CFG_FACTORY_GENERIC_BUFFERS == TRUE
+ * .
+ *
+ * <h2>Test Steps</h2>
+ * - [4.2.1] Retrieving a dynamic buffer by name, must not exist.
+ * - [4.2.2] Creating a dynamic buffer it must not exists, must
+ * succeed.
+ * - [4.2.3] Creating a dynamic buffer with the same name, must fail.
+ * - [4.2.4] Retrieving the dynamic buffer by name, must exist, then
+ * increasing the reference counter, finally releasing both
+ * references.
+ * - [4.2.5] Releasing the first reference to the dynamic buffer, must
+ * not trigger an assertion.
+ * - [4.2.6] Retrieving the dynamic buffer by name again, must not
+ * exist.
+ * .
+ */
+
+static void oslib_test_004_002_teardown(void) {
+ dyn_buffer_t *dbp;
+
+ dbp = chFactoryFindBuffer("mybuf");
+ if (dbp != NULL) {
+ while (dbp->element.refs > 0U) {
+ chFactoryReleaseBuffer(dbp);
+ }
+ }
+}
+
+static void oslib_test_004_002_execute(void) {
+ dyn_buffer_t *dbp;
+
+ /* [4.2.1] Retrieving a dynamic buffer by name, must not exist.*/
+ test_set_step(1);
+ {
+ dbp = chFactoryFindBuffer("mybuf");
+ test_assert(dbp == NULL, "found");
+ }
+
+ /* [4.2.2] Creating a dynamic buffer it must not exists, must
+ succeed.*/
+ test_set_step(2);
+ {
+ dbp = chFactoryCreateBuffer("mybuf", 128U);
+ test_assert(dbp != NULL, "cannot create");
+ }
+
+ /* [4.2.3] Creating a dynamic buffer with the same name, must fail.*/
+ test_set_step(3);
+ {
+ dyn_buffer_t *dbp1;
+
+ dbp1 = chFactoryCreateBuffer("mybuf", 128U);
+ test_assert(dbp1 == NULL, "can create");
+ }
+
+ /* [4.2.4] Retrieving the dynamic buffer by name, must exist, then
+ increasing the reference counter, finally releasing both
+ references.*/
+ test_set_step(4);
+ {
+ dyn_buffer_t *dbp1, *dbp2;
+
+ dbp1 = chFactoryFindBuffer("mybuf");
+ test_assert(dbp1 != NULL, "not found");
+ test_assert(dbp == dbp1, "object reference mismatch");
+ test_assert(dbp1->element.refs == 2, "object reference mismatch");
+
+ dbp2 = (dyn_buffer_t *)chFactoryDuplicateReference((dyn_element_t *)dbp1);
+ test_assert(dbp1 == dbp2, "object reference mismatch");
+ test_assert(dbp2->element.refs == 3, "object reference mismatch");
+
+ chFactoryReleaseBuffer(dbp2);
+ test_assert(dbp1->element.refs == 2, "references mismatch");
+
+ chFactoryReleaseBuffer(dbp1);
+ test_assert(dbp->element.refs == 1, "references mismatch");
+ }
+
+ /* [4.2.5] Releasing the first reference to the dynamic buffer, must
+ not trigger an assertion.*/
+ test_set_step(5);
+ {
+ chFactoryReleaseBuffer(dbp);
+ }
+
+ /* [4.2.6] Retrieving the dynamic buffer by name again, must not
+ exist.*/
+ test_set_step(6);
+ {
+ dbp = chFactoryFindBuffer("mybuf");
+ test_assert(dbp == NULL, "found");
+ }
+}
+
+static const testcase_t oslib_test_004_002 = {
+ "Dynamic Buffers Factory",
+ NULL,
+ oslib_test_004_002_teardown,
+ oslib_test_004_002_execute
+};
+#endif /* CH_CFG_FACTORY_GENERIC_BUFFERS == TRUE */
/****************************************************************************
* Exported data.
@@ -156,7 +289,12 @@ static const testcase_t oslib_test_004_001 = {
* @brief Array of test cases.
*/
const testcase_t * const oslib_test_sequence_004_array[] = {
+#if (CH_CFG_FACTORY_OBJECTS_REGISTRY == TRUE) || defined(__DOXYGEN__)
&oslib_test_004_001,
+#endif
+#if (CH_CFG_FACTORY_GENERIC_BUFFERS == TRUE) || defined(__DOXYGEN__)
+ &oslib_test_004_002,
+#endif
NULL
};