test_sequence.c.ftl 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. [#ftl]
  2. [#--
  3. ChibiOS/RT - Copyright (C) 2006..2018 Giovanni Di Sirio
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. --]
  14. [#import "/@ftllibs/libutils.ftl" as utils /]
  15. [@pp.dropOutputFile /]
  16. [#list xml.*.application.instances.instance as inst]
  17. [#if inst.@id?string == "org.chibios.spc5.components.portable.chibios_unitary_tests_engine"]
  18. [#assign instance = inst /]
  19. [#break]
  20. [/#if]
  21. [/#list]
  22. [#assign conf = {"instance":instance} /]
  23. [#assign prefix_lower = conf.instance.global_data_and_code.code_prefix.value[0]?trim?lower_case /]
  24. [#assign prefix_upper = conf.instance.global_data_and_code.code_prefix.value[0]?trim?upper_case /]
  25. [#list conf.instance.sequences.sequence as sequence]
  26. [@pp.changeOutputFile name=prefix_lower+"test_sequence_" + (sequence_index + 1)?string("000") + ".c" /]
  27. [@utils.EmitIndentedCCode "" 2 conf.instance.description.copyright.value[0] /]
  28. #include "hal.h"
  29. #include "${prefix_lower}test_root.h"
  30. /**
  31. * @file ${prefix_lower}test_sequence_${(sequence_index + 1)?string("000")}.c
  32. * @brief Test Sequence ${(sequence_index + 1)?string("000")} code.
  33. *
  34. * @page ${prefix_lower}test_sequence_${(sequence_index + 1)?string("000")} [${(sequence_index + 1)?string}] ${utils.WithoutDot(sequence.brief.value[0]?string)}
  35. *
  36. * File: @ref ${prefix_lower}test_sequence_${(sequence_index + 1)?string("000")}.c
  37. *
  38. * <h2>Description</h2>
  39. [@utils.FormatStringAsText " * "
  40. " * "
  41. utils.WithDot(sequence.description.value[0]?string)
  42. 72 /]
  43. *
  44. [#if sequence.condition.value[0]?trim?length > 0]
  45. * <h2>Conditions</h2>
  46. * This sequence is only executed if the following preprocessor condition
  47. * evaluates to true:
  48. * - ${sequence.condition.value[0]}
  49. * .
  50. *
  51. [/#if]
  52. * <h2>Test Cases</h2>
  53. [#if sequence.cases.case?size > 0]
  54. [#list sequence.cases.case as case]
  55. * - @subpage ${prefix_lower}test_${(sequence_index + 1)?string("000")}_${(case_index + 1)?string("000")}
  56. [/#list]
  57. * .
  58. [#else]
  59. * No test cases defined in the test sequence.
  60. [/#if]
  61. */
  62. [#if sequence.condition.value[0]?trim?length > 0]
  63. #if (${sequence.condition.value[0]}) || defined(__DOXYGEN__)
  64. [/#if]
  65. /****************************************************************************
  66. * Shared code.
  67. ****************************************************************************/
  68. [#if sequence.shared_code.value[0]?trim?length > 0]
  69. [@utils.EmitIndentedCCode "" 2 sequence.shared_code.value[0] /]
  70. [/#if]
  71. /****************************************************************************
  72. * Test cases.
  73. ****************************************************************************/
  74. [#list sequence.cases.case as case]
  75. [#-- Building the sequence of the requirements covered by
  76. this test case.--]
  77. [#assign reqseq = [] /]
  78. [#list case.steps.step as step]
  79. [#assign reqseq = reqseq + step.tags.value[0]?string?trim?word_list /]
  80. [/#list]
  81. [#assign reqseq = reqseq?sort /]
  82. [#-- Checking if a condition should be generated.--]
  83. [#if case.condition.value[0]?trim?length > 0]
  84. #if (${case.condition.value[0]?trim}) || defined(__DOXYGEN__)
  85. [/#if]
  86. [#-- Header generation.--]
  87. /**
  88. * @page ${prefix_lower}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])}
  89. *
  90. * <h2>Description</h2>
  91. [@utils.FormatStringAsText " * "
  92. " * "
  93. utils.WithDot(case.description.value[0]?string)
  94. 72 /]
  95. *
  96. [#if case.condition.value[0]?trim?length > 0]
  97. * <h2>Conditions</h2>
  98. * This test is only executed if the following preprocessor condition
  99. * evaluates to true:
  100. * - ${case.condition.value[0]}
  101. * .
  102. *
  103. [/#if]
  104. * <h2>Test Steps</h2>
  105. [#list case.steps.step as step]
  106. [@utils.FormatStringAsText " * - "
  107. " * "
  108. utils.WithDot("[" + (sequence_index + 1)?string + "." + (case_index + 1)?string + "." + (step_index + 1)?string + "] " + step.description.value[0]?string)
  109. 72 /]
  110. [/#list]
  111. [#if case.steps.step?size > 0]
  112. * .
  113. [/#if]
  114. [#if reqseq?size > 0]
  115. * <h2>Covered Requirements</h2>
  116. [#assign reqs = "" /]
  117. [#list reqseq as r]
  118. [#assign reqs = reqs + r /]
  119. [#if r_has_next]
  120. [#assign reqs = reqs + ", " /]
  121. [/#if]
  122. [/#list]
  123. [@utils.FormatStringAsText " * "
  124. " * "
  125. utils.WithDot(reqs)
  126. 72 /]
  127. [/#if]
  128. */
  129. [#if case.various_code.setup_code.value[0]?trim?length > 0]
  130. static void ${prefix_lower}test_${(sequence_index + 1)?string("000")}_${(case_index + 1)?string("000")}_setup(void) {
  131. [@utils.EmitIndentedCCode " " 2 case.various_code.setup_code.value[0] /]
  132. }
  133. [/#if]
  134. [#if case.various_code.teardown_code.value[0]?trim?length > 0]
  135. static void ${prefix_lower}test_${(sequence_index + 1)?string("000")}_${(case_index + 1)?string("000")}_teardown(void) {
  136. [@utils.EmitIndentedCCode " " 2 case.various_code.teardown_code.value[0] /]
  137. }
  138. [/#if]
  139. static void ${prefix_lower}test_${(sequence_index + 1)?string("000")}_${(case_index + 1)?string("000")}_execute(void) {
  140. [#if case.various_code.local_variables.value[0]?trim?length > 0]
  141. [@utils.EmitIndentedCCode " " 2 case.various_code.local_variables.value[0] /]
  142. [/#if]
  143. [#list case.steps.step as step]
  144. [@utils.FormatStringAsText " /* "
  145. " "
  146. utils.WithDot("[" + (sequence_index + 1)?string + "." + (case_index + 1)?string + "." + (step_index + 1)?string + "] " + step.description.value[0]?string) + "*/"
  147. 72 /]
  148. test_set_step(${(step_index + 1)?string});
  149. {
  150. [#if step.tags.value[0]?string?trim != ""]
  151. [#assign reqseq = step.tags.value[0]?string?trim?word_list?sort /]
  152. [#assign reqs = "" /]
  153. [#list reqseq as r]
  154. [#assign reqs = reqs + r /]
  155. [#if r_has_next]
  156. [#assign reqs = reqs + ", " /]
  157. [/#if]
  158. [/#list]
  159. [@utils.FormatStringAsText " /* @covers "
  160. " "
  161. utils.WithDot(reqs) + "*/"
  162. 72 /]
  163. [/#if]
  164. [#if step.code.value[0]?trim?length > 0]
  165. [@utils.EmitIndentedCCode " " 2 step.code.value[0] /]
  166. [/#if]
  167. }
  168. [/#list]
  169. }
  170. static const testcase_t ${prefix_lower}test_${(sequence_index + 1)?string("000")}_${(case_index + 1)?string("000")} = {
  171. "${utils.WithoutDot(case.brief.value[0]?string)}",
  172. [#if case.various_code.setup_code.value[0]?trim?length > 0]
  173. ${prefix_lower}test_${(sequence_index + 1)?string("000")}_${(case_index + 1)?string("000")}_setup,
  174. [#else]
  175. NULL,
  176. [/#if]
  177. [#if case.various_code.teardown_code.value[0]?trim?length > 0]
  178. ${prefix_lower}test_${(sequence_index + 1)?string("000")}_${(case_index + 1)?string("000")}_teardown,
  179. [#else]
  180. NULL,
  181. [/#if]
  182. ${prefix_lower}test_${(sequence_index + 1)?string("000")}_${(case_index + 1)?string("000")}_execute
  183. };
  184. [#if case.condition.value[0]?trim?length > 0]
  185. #endif /* ${case.condition.value[0]?trim} */
  186. [/#if]
  187. [/#list]
  188. /****************************************************************************
  189. * Exported data.
  190. ****************************************************************************/
  191. /**
  192. * @brief Array of test cases.
  193. */
  194. const testcase_t * const ${prefix_lower}test_sequence_${(sequence_index + 1)?string("000")}_array[] = {
  195. [#list sequence.cases.case as case]
  196. [#if case.condition.value[0]?trim?length > 0]
  197. #if (${case.condition.value[0]?trim}) || defined(__DOXYGEN__)
  198. [/#if]
  199. &${prefix_lower}test_${(sequence_index + 1)?string("000")}_${(case_index + 1)?string("000")},
  200. [#if case.condition.value[0]?trim?length > 0]
  201. #endif
  202. [/#if]
  203. [/#list]
  204. NULL
  205. };
  206. /**
  207. * @brief ${utils.WithDot(sequence.brief.value[0]?string)}
  208. */
  209. const testsequence_t ${prefix_lower}test_sequence_${(sequence_index + 1)?string("000")} = {
  210. "${utils.WithoutDot(sequence.brief.value[0]?string)}",
  211. ${prefix_lower}test_sequence_${(sequence_index + 1)?string("000")}_array
  212. };
  213. [#if sequence.condition.value[0]?trim?length > 0]
  214. #endif /* ${sequence.condition.value[0]} */
  215. [/#if]
  216. [/#list]