diff options
author | Giovanni Di Sirio <gdisirio@gmail.com> | 2017-10-24 13:58:24 +0000 |
---|---|---|
committer | Giovanni Di Sirio <gdisirio@gmail.com> | 2017-10-24 13:58:24 +0000 |
commit | de3fbaebe6f00a5109f4a107372d0b059f27de51 (patch) | |
tree | cfd653584bdf76f56c2aa9e439191f781d88f5c5 | |
parent | e0bfea5f016021d639093705b3baff1513cb066b (diff) | |
download | ChibiOS-de3fbaebe6f00a5109f4a107372d0b059f27de51.tar.gz ChibiOS-de3fbaebe6f00a5109f4a107372d0b059f27de51.tar.bz2 ChibiOS-de3fbaebe6f00a5109f4a107372d0b059f27de51.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10896 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r-- | os/common/oslib/include/chfactory.h | 6 | ||||
-rw-r--r-- | os/rt/src/chsys.c | 3 | ||||
-rw-r--r-- | test/oslib/configuration.xml | 122 | ||||
-rw-r--r-- | test/oslib/oslib_test.mk | 3 | ||||
-rw-r--r-- | test/oslib/source/test/oslib_test_sequence_004.c | 104 | ||||
-rwxr-xr-x | tools/ftl/processors/unittest/test/test_root.c.ftl | 25 | ||||
-rwxr-xr-x | tools/ftl/processors/unittest/test/test_root.h.ftl | 15 | ||||
-rwxr-xr-x | tools/ftl/processors/unittest/test/test_sequence.c.ftl | 11 | ||||
-rwxr-xr-x | tools/ftl/processors/unittest/test/test_sequence.h.ftl | 11 |
9 files changed, 264 insertions, 36 deletions
diff --git a/os/common/oslib/include/chfactory.h b/os/common/oslib/include/chfactory.h index c00fe21a1..7ac414719 100644 --- a/os/common/oslib/include/chfactory.h +++ b/os/common/oslib/include/chfactory.h @@ -353,11 +353,9 @@ extern "C" { * @param[in] dep pointer to the element field of the object
* @return The duplicated object reference.
*
- * @iclass
+ * @api
*/
-static inline dyn_element_t *chFactoryDuplicateReferenceI(dyn_element_t *dep) {
-
- chDbgCheckClassI();
+static inline dyn_element_t *chFactoryDuplicateReference(dyn_element_t *dep) {
dep->refs++;
diff --git a/os/rt/src/chsys.c b/os/rt/src/chsys.c index 715c97d74..034c3e85d 100644 --- a/os/rt/src/chsys.c +++ b/os/rt/src/chsys.c @@ -116,6 +116,9 @@ void chSysInit(void) { #if CH_CFG_USE_HEAP == TRUE
_heap_init();
#endif
+#if CH_CFG_USE_FACTORY == TRUE
+ _factory_init();
+#endif
#if CH_DBG_STATISTICS == TRUE
_stats_init();
#endif
diff --git a/test/oslib/configuration.xml b/test/oslib/configuration.xml index 54f56fd90..f663afc3b 100644 --- a/test/oslib/configuration.xml +++ b/test/oslib/configuration.xml @@ -965,7 +965,127 @@ test_assert(p1 == NULL, "allocation not failed");]]></value> <shared_code>
<value />
</shared_code>
- <cases />
+ <cases>
+ <case>
+ <brief>
+ <value>Objects Registry.</value>
+ </brief>
+ <description>
+ <value>This test case verifies the static objects registry.</value>
+ </description>
+ <condition>
+ <value />
+ </condition>
+ <various_code>
+ <setup_code>
+ <value />
+ </setup_code>
+ <teardown_code>
+ <value />
+ </teardown_code>
+ <local_variables>
+ <value><![CDATA[registered_object_t *rop;]]></value>
+ </local_variables>
+ </various_code>
+ <steps>
+ <step>
+ <description>
+ <value>Retrieving a registered object by name, must not exist.</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[registered_object_t *rop;
+
+rop = chFactoryFindObject("myobj");
+test_assert(rop == NULL, "found");]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
+ <value>Registering an object, it must not exists, must succeed.</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[registered_object_t *rop;
+static uint32_t myobj = 0x55aa;
+
+rop = chFactoryRegisterObject("myobj", (void *)&myobj);
+test_assert(rop != NULL, "cannot register");]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
+ <value>Registering an object with the same name, must fail.</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <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>
+ <step>
+ <description>
+ <value>Retrieving the registered object by name, must exist, then increasing the reference counter, finally releasing both references.</value>
+ </description>
+ <tags>
+ <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(rop1->element.refs == 3, "object reference mismatch");
+
+chFactoryReleaseObject(rop1);
+test_assert(rop->element.refs == 2, "references mismatch");
+
+chFactoryReleaseObject(rop2);
+test_assert(rop->element.refs == 1, "references mismatch");]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
+ <value>Releasing the first reference to the object, must not trigger an assertion.</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[chFactoryReleaseObject(rop);]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
+ <value>Retrieving the registered object by name again, must not exist.</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[rop = chFactoryFindObject("myobj");
+test_assert(rop == NULL, "found");]]></value>
+ </code>
+ </step>
+ </steps>
+ </case>
+ </cases>
</sequence>
</sequences>
</instance>
diff --git a/test/oslib/oslib_test.mk b/test/oslib/oslib_test.mk index a7d3020f7..f342719e1 100644 --- a/test/oslib/oslib_test.mk +++ b/test/oslib/oslib_test.mk @@ -2,7 +2,8 @@ TESTSRC += ${CHIBIOS}/test/oslib/source/test/oslib_test_root.c \
${CHIBIOS}/test/oslib/source/test/oslib_test_sequence_001.c \
${CHIBIOS}/test/oslib/source/test/oslib_test_sequence_002.c \
- ${CHIBIOS}/test/oslib/source/test/oslib_test_sequence_003.c
+ ${CHIBIOS}/test/oslib/source/test/oslib_test_sequence_003.c \
+ ${CHIBIOS}/test/oslib/source/test/oslib_test_sequence_004.c
# Required include directories
TESTINC += ${CHIBIOS}/test/oslib/source/test
diff --git a/test/oslib/source/test/oslib_test_sequence_004.c b/test/oslib/source/test/oslib_test_sequence_004.c index d43b9165f..38cb28358 100644 --- a/test/oslib/source/test/oslib_test_sequence_004.c +++ b/test/oslib/source/test/oslib_test_sequence_004.c @@ -36,7 +36,8 @@ * .
*
* <h2>Test Cases</h2>
- * No test cases defined in the test sequence.
+ * - @subpage oslib_test_004_001
+ * .
*/
#if ((CH_CFG_USE_FACTORY == TRUE) && (CH_CFG_USE_MEMPOOLS == TRUE) && (CH_CFG_USE_HEAP == TRUE)) || defined(__DOXYGEN__)
@@ -50,6 +51,106 @@ * Test cases.
****************************************************************************/
+/**
+ * @page oslib_test_004_001 [4.1] Objects Registry
+ *
+ * <h2>Description</h2>
+ * This test case verifies the static objects registry.
+ *
+ * <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.
+ * - [4.1.3] Registering an object with the same name, must fail.
+ * - [4.1.4] Retrieving the registered object by name, must exist, then
+ * increasing the reference counter, finally releasing both
+ * references.
+ * - [4.1.5] Releasing the first reference to the object, must not
+ * trigger an assertion.
+ * - [4.1.6] Retrieving the registered object by name again, must not
+ * exist.
+ * .
+ */
+
+static void oslib_test_004_001_execute(void) {
+ registered_object_t *rop;
+
+ /* [4.1.1] Retrieving a registered object by name, must not exist.*/
+ test_set_step(1);
+ {
+ registered_object_t *rop;
+
+ rop = chFactoryFindObject("myobj");
+ test_assert(rop == NULL, "found");
+ }
+
+ /* [4.1.2] Registering an object, it must not exists, must succeed.*/
+ test_set_step(2);
+ {
+ registered_object_t *rop;
+ static uint32_t myobj = 0x55aa;
+
+ rop = chFactoryRegisterObject("myobj", (void *)&myobj);
+ test_assert(rop != NULL, "cannot register");
+ }
+
+ /* [4.1.3] Registering an object with the same name, must fail.*/
+ test_set_step(3);
+ {
+ registered_object_t *rop1;
+ static uint32_t myobj = 0x55aa;
+
+ rop1 = chFactoryRegisterObject("myobj", (void *)&myobj);
+ test_assert(rop1 == NULL, "can register");
+ }
+
+ /* [4.1.4] Retrieving the registered object by name, must exist, then
+ increasing the reference counter, finally releasing both
+ references.*/
+ test_set_step(4);
+ {
+ 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(rop1->element.refs == 3, "object reference mismatch");
+
+ chFactoryReleaseObject(rop1);
+ test_assert(rop->element.refs == 2, "references mismatch");
+
+ chFactoryReleaseObject(rop2);
+ test_assert(rop->element.refs == 1, "references mismatch");
+ }
+
+ /* [4.1.5] Releasing the first reference to the object, must not
+ trigger an assertion.*/
+ test_set_step(5);
+ {
+ chFactoryReleaseObject(rop);
+ }
+
+ /* [4.1.6] Retrieving the registered object by name again, must not
+ exist.*/
+ test_set_step(6);
+ {
+ rop = chFactoryFindObject("myobj");
+ test_assert(rop == NULL, "found");
+ }
+}
+
+static const testcase_t oslib_test_004_001 = {
+ "Objects Registry",
+ NULL,
+ NULL,
+ oslib_test_004_001_execute
+};
+
/****************************************************************************
* Exported data.
****************************************************************************/
@@ -58,6 +159,7 @@ * @brief Array of test cases.
*/
const testcase_t * const oslib_test_sequence_004_array[] = {
+ &oslib_test_004_001,
NULL
};
diff --git a/tools/ftl/processors/unittest/test/test_root.c.ftl b/tools/ftl/processors/unittest/test/test_root.c.ftl index 90f42cafc..47a84cff0 100755 --- a/tools/ftl/processors/unittest/test/test_root.c.ftl +++ b/tools/ftl/processors/unittest/test/test_root.c.ftl @@ -1,31 +1,32 @@ [#ftl]
[#import "/@ftllibs/libutils.ftl" as utils /]
-[#list conf.*.application.instances.instance as inst]
+[#list xml.*.application.instances.instance as inst]
[#if inst.@id?string == "org.chibios.spc5.components.portable.chibios_unitary_tests_engine"]
[#assign instance = inst /]
[#break]
[/#if]
[/#list]
-[#assign prefix_lower = instance.global_data_and_code.code_prefix.value[0]?trim?lower_case /]
-[#assign prefix_upper = instance.global_data_and_code.code_prefix.value[0]?trim?upper_case /]
+[#assign conf = {"instance":instance} /]
+[#assign prefix_lower = conf.instance.global_data_and_code.code_prefix.value[0]?trim?lower_case /]
+[#assign prefix_upper = conf.instance.global_data_and_code.code_prefix.value[0]?trim?upper_case /]
[@pp.dropOutputFile /]
[@pp.changeOutputFile name=prefix_lower+"test_root.c" /]
-[@utils.EmitIndentedCCode "" 2 instance.description.copyright.value[0] /]
+[@utils.EmitIndentedCCode "" 2 conf.instance.description.copyright.value[0] /]
/**
* @mainpage Test Suite Specification
-[#if instance.description.introduction.value[0]?trim != ""]
+[#if conf.instance.description.introduction.value[0]?trim != ""]
[@utils.FormatStringAsText " * "
" * "
- utils.WithDot(instance.description.introduction.value[0]?trim?cap_first)
+ utils.WithDot(conf.instance.description.introduction.value[0]?trim?cap_first)
72 /]
[#else]
* No introduction.
[/#if]
*
* <h2>Test Sequences</h2>
-[#if instance.sequences.sequence?size > 0]
- [#list instance.sequences.sequence as sequence]
+[#if conf.instance.sequences.sequence?size > 0]
+ [#list conf.instance.sequences.sequence as sequence]
* - @subpage ${prefix_lower}test_sequence_${(sequence_index + 1)?string("000")}
[/#list]
* .
@@ -52,7 +53,7 @@ * @brief Array of test sequences.
*/
const testsequence_t * const ${prefix_lower}test_suite_array[] = {
-[#list instance.sequences.sequence as sequence]
+[#list conf.instance.sequences.sequence as sequence]
[#if sequence.condition.value[0]?trim?length > 0]
#if (${sequence.condition.value[0]}) || defined(__DOXYGEN__)
[/#if]
@@ -68,7 +69,7 @@ const testsequence_t * const ${prefix_lower}test_suite_array[] = { * @brief Test suite root structure.
*/
const testsuite_t ${prefix_lower}test_suite = {
- "${utils.WithDot(conf.*.application.description[0]?trim)}",
+ "${utils.WithoutDot(conf.instance.description.brief.value[0]?trim)}",
${prefix_lower}test_suite_array
};
@@ -76,8 +77,8 @@ const testsuite_t ${prefix_lower}test_suite = { /* Shared code. */
/*===========================================================================*/
-[#if instance.global_data_and_code.global_code.value[0]?trim?length > 0]
-[@utils.EmitIndentedCCode "" 2 instance.global_data_and_code.global_code.value[0] /]
+[#if conf.instance.global_data_and_code.global_code.value[0]?trim?length > 0]
+[@utils.EmitIndentedCCode "" 2 conf.instance.global_data_and_code.global_code.value[0] /]
[/#if]
#endif /* !defined(__DOXYGEN__) */
diff --git a/tools/ftl/processors/unittest/test/test_root.h.ftl b/tools/ftl/processors/unittest/test/test_root.h.ftl index c3c8f3203..9bd01b646 100755 --- a/tools/ftl/processors/unittest/test/test_root.h.ftl +++ b/tools/ftl/processors/unittest/test/test_root.h.ftl @@ -1,16 +1,17 @@ [#ftl]
[#import "/@ftllibs/libutils.ftl" as utils /]
-[#list conf.*.application.instances.instance as inst]
+[#list xml.*.application.instances.instance as inst]
[#if inst.@id?string == "org.chibios.spc5.components.portable.chibios_unitary_tests_engine"]
[#assign instance = inst /]
[#break]
[/#if]
[/#list]
-[#assign prefix_lower = instance.global_data_and_code.code_prefix.value[0]?trim?lower_case /]
-[#assign prefix_upper = instance.global_data_and_code.code_prefix.value[0]?trim?upper_case /]
+[#assign conf = {"instance":instance} /]
+[#assign prefix_lower = conf.instance.global_data_and_code.code_prefix.value[0]?trim?lower_case /]
+[#assign prefix_upper = conf.instance.global_data_and_code.code_prefix.value[0]?trim?upper_case /]
[@pp.dropOutputFile /]
[@pp.changeOutputFile name=prefix_lower+"test_root.h" /]
-[@utils.EmitIndentedCCode "" 2 instance.description.copyright.value[0] /]
+[@utils.EmitIndentedCCode "" 2 conf.instance.description.copyright.value[0] /]
/**
* @file ${prefix_lower}test_root.h
@@ -22,7 +23,7 @@ #include "ch_test.h"
-[#list instance.sequences.sequence as sequence]
+[#list conf.instance.sequences.sequence as sequence]
#include "${prefix_lower}test_sequence_${(sequence_index + 1)?string("000")}.h"
[/#list]
@@ -45,8 +46,8 @@ extern "C" { /* Shared definitions. */
/*===========================================================================*/
-[#if instance.global_data_and_code.global_definitions.value[0]?trim?length > 0]
-[@utils.EmitIndentedCCode "" 2 instance.global_data_and_code.global_definitions.value[0] /]
+[#if conf.instance.global_data_and_code.global_definitions.value[0]?trim?length > 0]
+[@utils.EmitIndentedCCode "" 2 conf.instance.global_data_and_code.global_definitions.value[0] /]
[/#if]
#endif /* !defined(__DOXYGEN__) */
diff --git a/tools/ftl/processors/unittest/test/test_sequence.c.ftl b/tools/ftl/processors/unittest/test/test_sequence.c.ftl index 4173b3e99..474eb1718 100755 --- a/tools/ftl/processors/unittest/test/test_sequence.c.ftl +++ b/tools/ftl/processors/unittest/test/test_sequence.c.ftl @@ -1,17 +1,18 @@ [#ftl]
[#import "/@ftllibs/libutils.ftl" as utils /]
[@pp.dropOutputFile /]
-[#list conf.*.application.instances.instance as inst]
+[#list xml.*.application.instances.instance as inst]
[#if inst.@id?string == "org.chibios.spc5.components.portable.chibios_unitary_tests_engine"]
[#assign instance = inst /]
[#break]
[/#if]
[/#list]
-[#assign prefix_lower = instance.global_data_and_code.code_prefix.value[0]?trim?lower_case /]
-[#assign prefix_upper = instance.global_data_and_code.code_prefix.value[0]?trim?upper_case /]
-[#list instance.sequences.sequence as sequence]
+[#assign conf = {"instance":instance} /]
+[#assign prefix_lower = conf.instance.global_data_and_code.code_prefix.value[0]?trim?lower_case /]
+[#assign prefix_upper = conf.instance.global_data_and_code.code_prefix.value[0]?trim?upper_case /]
+[#list conf.instance.sequences.sequence as sequence]
[@pp.changeOutputFile name=prefix_lower+"test_sequence_" + (sequence_index + 1)?string("000") + ".c" /]
-[@utils.EmitIndentedCCode "" 2 instance.description.copyright.value[0] /]
+[@utils.EmitIndentedCCode "" 2 conf.instance.description.copyright.value[0] /]
#include "hal.h"
#include "${prefix_lower}test_root.h"
diff --git a/tools/ftl/processors/unittest/test/test_sequence.h.ftl b/tools/ftl/processors/unittest/test/test_sequence.h.ftl index 7a5519402..a80dbbe6d 100755 --- a/tools/ftl/processors/unittest/test/test_sequence.h.ftl +++ b/tools/ftl/processors/unittest/test/test_sequence.h.ftl @@ -1,17 +1,18 @@ [#ftl]
[#import "/@ftllibs/libutils.ftl" as utils /]
[@pp.dropOutputFile /]
-[#list conf.*.application.instances.instance as inst]
+[#list xml.*.application.instances.instance as inst]
[#if inst.@id?string == "org.chibios.spc5.components.portable.chibios_unitary_tests_engine"]
[#assign instance = inst /]
[#break]
[/#if]
[/#list]
-[#assign prefix_lower = instance.global_data_and_code.code_prefix.value[0]?trim?lower_case /]
-[#assign prefix_upper = instance.global_data_and_code.code_prefix.value[0]?trim?upper_case /]
-[#list instance.sequences.sequence as sequence]
+[#assign conf = {"instance":instance} /]
+[#assign prefix_lower = conf.instance.global_data_and_code.code_prefix.value[0]?trim?lower_case /]
+[#assign prefix_upper =conf. instance.global_data_and_code.code_prefix.value[0]?trim?upper_case /]
+[#list conf.instance.sequences.sequence as sequence]
[@pp.changeOutputFile name=prefix_lower+"test_sequence_" + (sequence_index + 1)?string("000") + ".h" /]
-[@utils.EmitIndentedCCode "" 2 instance.description.copyright.value[0] /]
+[@utils.EmitIndentedCCode "" 2 conf.instance.description.copyright.value[0] /]
/**
* @file ${prefix_lower}test_sequence_${(sequence_index + 1)?string("000")}.h
|