diff options
author | Giovanni Di Sirio <gdisirio@gmail.com> | 2017-09-17 13:28:22 +0000 |
---|---|---|
committer | Giovanni Di Sirio <gdisirio@gmail.com> | 2017-09-17 13:28:22 +0000 |
commit | fb355909fa1e96f24087c1380daef19cc0eb0532 (patch) | |
tree | 5977799efb0b08fa87384c56de96982dce98e277 /tools/ftl/processors/unittest | |
parent | 7209ce9df2badcbc29e4af9e9f231382cdc5c095 (diff) | |
download | ChibiOS-fb355909fa1e96f24087c1380daef19cc0eb0532.tar.gz ChibiOS-fb355909fa1e96f24087c1380daef19cc0eb0532.tar.bz2 ChibiOS-fb355909fa1e96f24087c1380daef19cc0eb0532.zip |
Added an FTL unit-test generator tool independent from SPC5Studio, it uses the same configuration.xml file so SPC5Studio can still be used but it is not in the critical path.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10612 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'tools/ftl/processors/unittest')
-rwxr-xr-x | tools/ftl/processors/unittest/test/test_root.c.ftl | 74 | ||||
-rwxr-xr-x | tools/ftl/processors/unittest/test/test_root.h.ftl | 50 | ||||
-rwxr-xr-x | tools/ftl/processors/unittest/test/test_sequence.c.ftl | 210 | ||||
-rwxr-xr-x | tools/ftl/processors/unittest/test/test_sequence.h.ftl | 25 |
4 files changed, 359 insertions, 0 deletions
diff --git a/tools/ftl/processors/unittest/test/test_root.c.ftl b/tools/ftl/processors/unittest/test/test_root.c.ftl new file mode 100755 index 000000000..6751ef56d --- /dev/null +++ b/tools/ftl/processors/unittest/test/test_root.c.ftl @@ -0,0 +1,74 @@ +[#ftl]
+[#import "/@ftllibs/libutils.ftl" as utils /]
+[@pp.dropOutputFile /]
+[@pp.changeOutputFile name="test_root.c" /]
+[#list conf.*.application.instances.instance as inst]
+ [#if inst.@id?string == "org.chibios.spc5.components.portable.chibios_unitary_tests_engine"]
+ [#assign instance = inst /]
+ [#break]
+ [/#if]
+[/#list]
+[@utils.EmitIndentedCCode "" 2 instance.description.copyright.value[0] /]
+
+/**
+ * @mainpage Test Suite Specification
+[#if instance.description.introduction.value[0]?trim != ""]
+[@utils.FormatStringAsText " * "
+ " * "
+ utils.WithDot(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]
+ * - @subpage test_sequence_${(sequence_index + 1)?string("000")}
+ [/#list]
+ * .
+[#else]
+ * No test sequences defined in the test suite.
+[/#if]
+ */
+
+/**
+ * @file test_root.c
+ * @brief Test Suite root structures code.
+ */
+
+#include "hal.h"
+#include "ch_test.h"
+#include "test_root.h"
+
+#if !defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Module exported variables. */
+/*===========================================================================*/
+
+/**
+ * @brief Array of all the test sequences.
+ */
+const testcase_t * const *test_suite[] = {
+[#list instance.sequences.sequence as sequence]
+ [#if sequence.condition.value[0]?trim?length > 0]
+#if (${sequence.condition.value[0]}) || defined(__DOXYGEN__)
+ [/#if]
+ test_sequence_${(sequence_index + 1)?string("000")},
+ [#if sequence.condition.value[0]?trim?length > 0]
+#endif
+ [/#if]
+[/#list]
+ NULL
+};
+
+/*===========================================================================*/
+/* 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]
+#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 new file mode 100755 index 000000000..930a676cc --- /dev/null +++ b/tools/ftl/processors/unittest/test/test_root.h.ftl @@ -0,0 +1,50 @@ +[#ftl]
+[#import "/@ftllibs/libutils.ftl" as utils /]
+[@pp.dropOutputFile /]
+[@pp.changeOutputFile name="test_root.h" /]
+[#list conf.*.application.instances.instance as inst]
+ [#if inst.@id?string == "org.chibios.spc5.components.portable.chibios_unitary_tests_engine"]
+ [#assign instance = inst /]
+ [#break]
+ [/#if]
+[/#list]
+[@utils.EmitIndentedCCode "" 2 instance.description.copyright.value[0] /]
+
+/**
+ * @file test_root.h
+ * @brief Test Suite root structures header.
+ */
+
+#ifndef TEST_ROOT_H
+#define TEST_ROOT_H
+
+[#list instance.sequences.sequence as sequence]
+#include "test_sequence_${(sequence_index + 1)?string("000")}.h"
+[/#list]
+
+#if !defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+extern const testcase_t * const *test_suite[];
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+/*===========================================================================*/
+/* 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]
+#endif /* !defined(__DOXYGEN__) */
+
+#endif /* TEST_ROOT_H */
diff --git a/tools/ftl/processors/unittest/test/test_sequence.c.ftl b/tools/ftl/processors/unittest/test/test_sequence.c.ftl new file mode 100755 index 000000000..7be0c58f2 --- /dev/null +++ b/tools/ftl/processors/unittest/test/test_sequence.c.ftl @@ -0,0 +1,210 @@ +[#ftl]
+[#import "/@ftllibs/libutils.ftl" as utils /]
+[@pp.dropOutputFile /]
+[#list conf.*.application.instances.instance as inst]
+ [#if inst.@id?string == "org.chibios.spc5.components.portable.chibios_unitary_tests_engine"]
+ [#assign instance = inst /]
+ [#break]
+ [/#if]
+[/#list]
+[#list instance.sequences.sequence as sequence]
+ [@pp.changeOutputFile name="test_sequence_" + (sequence_index + 1)?string("000") + ".c" /]
+[@utils.EmitIndentedCCode "" 2 instance.description.copyright.value[0] /]
+
+#include "hal.h"
+#include "ch_test.h"
+#include "test_root.h"
+
+/**
+ * @file test_sequence_${(sequence_index + 1)?string("000")}.c
+ * @brief Test Sequence ${(sequence_index + 1)?string("000")} code.
+ *
+ * @page test_sequence_${(sequence_index + 1)?string("000")} [${(sequence_index + 1)?string}] ${utils.WithoutDot(sequence.brief.value[0]?string)}
+ *
+ * File: @ref test_sequence_${(sequence_index + 1)?string("000")}.c
+ *
+ * <h2>Description</h2>
+[@utils.FormatStringAsText " * "
+ " * "
+ utils.WithDot(sequence.description.value[0]?string)
+ 72 /]
+ *
+ [#if sequence.condition.value[0]?trim?length > 0]
+ * <h2>Conditions</h2>
+ * This sequence is only executed if the following preprocessor condition
+ * evaluates to true:
+ * - ${sequence.condition.value[0]}
+ * .
+ *
+ [/#if]
+ * <h2>Test Cases</h2>
+ [#if sequence.cases.case?size > 0]
+ [#list sequence.cases.case as case]
+ * - @subpage test_${(sequence_index + 1)?string("000")}_${(case_index + 1)?string("000")}
+ [/#list]
+ * .
+ [#else]
+ * No test cases defined in the test sequence.
+ [/#if]
+ */
+
+ [#if sequence.condition.value[0]?trim?length > 0]
+#if (${sequence.condition.value[0]}) || defined(__DOXYGEN__)
+
+ [/#if]
+/****************************************************************************
+ * Shared code.
+ ****************************************************************************/
+
+ [#if sequence.shared_code.value[0]?trim?length > 0]
+[@utils.EmitIndentedCCode "" 2 sequence.shared_code.value[0] /]
+ [/#if]
+
+/****************************************************************************
+ * Test cases.
+ ****************************************************************************/
+
+ [#list sequence.cases.case as case]
+ [#-- Building the sequence of the requirements covered by
+ this test case.--]
+ [#assign reqseq = [] /]
+ [#list case.steps.step as step]
+ [#assign reqseq = reqseq + step.tags.value[0]?string?trim?word_list /]
+ [/#list]
+ [#assign reqseq = reqseq?sort /]
+ [#-- Checking if a condition should be generated.--]
+ [#if case.condition.value[0]?trim?length > 0]
+#if (${case.condition.value[0]?trim}) || defined(__DOXYGEN__)
+ [/#if]
+ [#-- Header generation.--]
+/**
+ * @page test_${(sequence_index + 1)?string("000")}_${(case_index + 1)?string("000")} [${(sequence_index + 1)?string}.${(case_index + 1)?string}] ${utils.WithoutDot(case.brief.value[0])}
+ *
+ * <h2>Description</h2>
+[@utils.FormatStringAsText " * "
+ " * "
+ utils.WithDot(case.description.value[0]?string)
+ 72 /]
+ *
+ [#if case.condition.value[0]?trim?length > 0]
+ * <h2>Conditions</h2>
+ * This test is only executed if the following preprocessor condition
+ * evaluates to true:
+ * - ${case.condition.value[0]}
+ * .
+ *
+ [/#if]
+ * <h2>Test Steps</h2>
+ [#list case.steps.step as step]
+[@utils.FormatStringAsText " * - "
+ " * "
+ utils.WithDot("[" + (sequence_index + 1)?string + "." + (case_index + 1)?string + "." + (step_index + 1)?string + "] " + step.description.value[0]?string)
+ 72 /]
+ [/#list]
+ [#if case.steps.step?size > 0]
+ * .
+ [/#if]
+ [#if reqseq?size > 0]
+ * <h2>Covered Requirements</h2>
+ [#assign reqs = "" /]
+ [#list reqseq as r]
+ [#assign reqs = reqs + r /]
+ [#if r_has_next]
+ [#assign reqs = reqs + ", " /]
+ [/#if]
+ [/#list]
+[@utils.FormatStringAsText " * "
+ " * "
+ utils.WithDot(reqs)
+ 72 /]
+ [/#if]
+ */
+
+ [#if case.various_code.setup_code.value[0]?trim?length > 0]
+static void test_${(sequence_index + 1)?string("000")}_${(case_index + 1)?string("000")}_setup(void) {
+[@utils.EmitIndentedCCode " " 2 case.various_code.setup_code.value[0] /]
+}
+
+ [/#if]
+ [#if case.various_code.teardown_code.value[0]?trim?length > 0]
+static void test_${(sequence_index + 1)?string("000")}_${(case_index + 1)?string("000")}_teardown(void) {
+[@utils.EmitIndentedCCode " " 2 case.various_code.teardown_code.value[0] /]
+}
+
+ [/#if]
+static void test_${(sequence_index + 1)?string("000")}_${(case_index + 1)?string("000")}_execute(void) {
+ [#if case.various_code.local_variables.value[0]?trim?length > 0]
+[@utils.EmitIndentedCCode " " 2 case.various_code.local_variables.value[0] /]
+ [/#if]
+ [#list case.steps.step as step]
+
+[@utils.FormatStringAsText " /* "
+ " "
+ utils.WithDot("[" + (sequence_index + 1)?string + "." + (case_index + 1)?string + "." + (step_index + 1)?string + "] " + step.description.value[0]?string) + "*/"
+ 72 /]
+ test_set_step(${(step_index + 1)?string});
+ {
+ [#if step.tags.value[0]?string?trim != ""]
+ [#assign reqseq = step.tags.value[0]?string?trim?word_list?sort /]
+ [#assign reqs = "" /]
+ [#list reqseq as r]
+ [#assign reqs = reqs + r /]
+ [#if r_has_next]
+ [#assign reqs = reqs + ", " /]
+ [/#if]
+ [/#list]
+[@utils.FormatStringAsText " /* @covers "
+ " "
+ utils.WithDot(reqs) + "*/"
+ 72 /]
+ [/#if]
+ [#if step.code.value[0]?trim?length > 0]
+[@utils.EmitIndentedCCode " " 2 step.code.value[0] /]
+ [/#if]
+ }
+ [/#list]
+}
+
+static const testcase_t test_${(sequence_index + 1)?string("000")}_${(case_index + 1)?string("000")} = {
+ "${utils.WithoutDot(case.brief.value[0]?string)}",
+ [#if case.various_code.setup_code.value[0]?trim?length > 0]
+ test_${(sequence_index + 1)?string("000")}_${(case_index + 1)?string("000")}_setup,
+ [#else]
+ NULL,
+ [/#if]
+ [#if case.various_code.teardown_code.value[0]?trim?length > 0]
+ test_${(sequence_index + 1)?string("000")}_${(case_index + 1)?string("000")}_teardown,
+ [#else]
+ NULL,
+ [/#if]
+ test_${(sequence_index + 1)?string("000")}_${(case_index + 1)?string("000")}_execute
+};
+ [#if case.condition.value[0]?trim?length > 0]
+#endif /* ${case.condition.value[0]?trim} */
+ [/#if]
+
+ [/#list]
+/****************************************************************************
+ * Exported data.
+ ****************************************************************************/
+
+/**
+ * @brief ${utils.WithDot(sequence.brief.value[0]?string)}
+ */
+const testcase_t * const test_sequence_${(sequence_index + 1)?string("000")}[] = {
+ [#list sequence.cases.case as case]
+ [#if case.condition.value[0]?trim?length > 0]
+#if (${case.condition.value[0]?trim}) || defined(__DOXYGEN__)
+ [/#if]
+ &test_${(sequence_index + 1)?string("000")}_${(case_index + 1)?string("000")},
+ [#if case.condition.value[0]?trim?length > 0]
+#endif
+ [/#if]
+ [/#list]
+ NULL
+};
+ [#if sequence.condition.value[0]?trim?length > 0]
+
+#endif /* ${sequence.condition.value[0]} */
+ [/#if]
+[/#list]
diff --git a/tools/ftl/processors/unittest/test/test_sequence.h.ftl b/tools/ftl/processors/unittest/test/test_sequence.h.ftl new file mode 100755 index 000000000..eb3911888 --- /dev/null +++ b/tools/ftl/processors/unittest/test/test_sequence.h.ftl @@ -0,0 +1,25 @@ +[#ftl]
+[#import "/@ftllibs/libutils.ftl" as utils /]
+[@pp.dropOutputFile /]
+[#list conf.*.application.instances.instance as inst]
+ [#if inst.@id?string == "org.chibios.spc5.components.portable.chibios_unitary_tests_engine"]
+ [#assign instance = inst /]
+ [#break]
+ [/#if]
+[/#list]
+[#list instance.sequences.sequence as sequence]
+ [@pp.changeOutputFile name="test_sequence_" + (sequence_index + 1)?string("000") + ".h" /]
+[@utils.EmitIndentedCCode "" 2 instance.description.copyright.value[0] /]
+
+/**
+ * @file test_sequence_${(sequence_index + 1)?string("000")}.h
+ * @brief Test Sequence ${(sequence_index + 1)?string("000")} header.
+ */
+
+#ifndef TEST_SEQUENCE_${(sequence_index + 1)?string("000")}_H
+#define TEST_SEQUENCE_${(sequence_index + 1)?string("000")}_H
+
+extern const testcase_t * const test_sequence_${(sequence_index + 1)?string("000")}[];
+
+#endif /* TEST_SEQUENCE_${(sequence_index + 1)?string("000")}_H */
+[/#list]
|