diff --git a/os/common/oslib/src/chfactory.c b/os/common/oslib/src/chfactory.c
index 687eec393..74e80e528 100644
--- a/os/common/oslib/src/chfactory.c
+++ b/os/common/oslib/src/chfactory.c
@@ -138,7 +138,7 @@ static dyn_element_t *dyn_create_object_heap(const char *name,
/* Allocating space for the new buffer object.*/
dep = (dyn_element_t *)chHeapAlloc(NULL, size);
- if (dep) {
+ if (dep == NULL) {
return NULL;
}
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");]]>
This test case verifies the static objects registry.
-
+ CH_CFG_FACTORY_OBJECTS_REGISTRY == TRUE
-
+ element.refs > 0U) {
+ chFactoryReleaseObject(rop);
+ }
+}]]>
@@ -996,7 +1003,7 @@ test_assert(p1 == NULL, "allocation not failed");]]>
-
@@ -1008,9 +1015,9 @@ test_assert(rop == NULL, "found");]]>
-
@@ -1022,10 +1029,10 @@ test_assert(rop != NULL, "cannot register");]]>
-
@@ -1037,23 +1044,23 @@ test_assert(rop1 == NULL, "can register");]]>
- 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);
+ 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");]]>
@@ -1076,12 +1083,130 @@ test_assert(rop->element.refs == 1, "references mismatch");]]>
-
+
+
+ Dynamic Buffers Factory.
+
+
+ This test case verifies the dynamic buffers factory.
+
+
+ CH_CFG_FACTORY_GENERIC_BUFFERS == TRUE
+
+
+
+
+
+
+ element.refs > 0U) {
+ chFactoryReleaseBuffer(dbp);
+ }
+}]]>
+
+
+
+
+
+
+
+
+ Retrieving a dynamic buffer by name, must not exist.
+
+
+
+
+
+
+
+
+
+
+ Creating a dynamic buffer it must not exists, must succeed.
+
+
+
+
+
+
+
+
+
+
+ Creating a dynamic buffer with the same name, must fail.
+
+
+
+
+
+
+
+
+
+
+ Retrieving the dynamic buffer by name, must exist, then increasing the reference counter, finally releasing both references.
+
+
+
+
+
+ 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");]]>
+
+
+
+
+ Releasing the first reference to the dynamic buffer, must not trigger an assertion.
+
+
+
+
+
+
+
+
+
+
+ Retrieving the dynamic buffer by name again, must not exist.
+
+
+
+
+
+
+
+
+
+
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 @@
*
* Test Cases
* - @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
*
* Description
* This test case verifies the static objects registry.
*
+ * Conditions
+ * This test is only executed if the following preprocessor condition
+ * evaluates to true:
+ * - CH_CFG_FACTORY_OBJECTS_REGISTRY == TRUE
+ * .
+ *
* Test Steps
* - [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
+ *
+ * Description
+ * This test case verifies the dynamic buffers factory.
+ *
+ * Conditions
+ * This test is only executed if the following preprocessor condition
+ * evaluates to true:
+ * - CH_CFG_FACTORY_GENERIC_BUFFERS == TRUE
+ * .
+ *
+ * Test Steps
+ * - [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
};