exa_qutest.dox 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*! @page exa_qutest Examples for QUTest Unit Testing Harness
  2. <p>The examples in the <span class="img folder">qpc/examples/qutest</span> directory demonstrate how to test embedded code with the [<b>QUTest</b>](https://www.state-machine.com/qtools/qutest.html) unit testing harness. Currently, the following examples are provided:
  3. </p>
  4. - <span class="img folder">blinky</span> &mdash; Simple "Blinky" single-active-object application
  5. - <span class="img folder">dpp</span> &mdash; DPP application from Chapter 9 of PSiCC2
  6. - <span class="img folder">evt-par</span> &mdash; testing events with parameters
  7. - <span class="img folder">qhsmtst</span> &mdash; Test State Machine based on ::QHsm with QM model
  8. - <span class="img folder">qmsmtst</span> &mdash; Test State Machine based on ::QMsm with QM model
  9. - <span class="img folder">unity_basic</span> &mdash; Comparison of a basic testing with Unity and QUTest
  10. - <span class="img folder">unity_mock</span> &mdash; Comparison of a advanced testing (mocking) with Unity and QUTest
  11. @section exa_qutest-dir General Code Organization
  12. The projects within the <span class="img folder">examples/qutest</span> directory have the customary structure used for testing. The production code to be tested is located in the <span class="img folder">src</span> sub-directory. The testing code is located in the <span class="img folder">test_~~~</span> sub-folder(s). The following directory tree illustrates the structure for the `dpp` example:
  13. <ul class="tag">
  14. <li><span class="img folder">examples/</span>
  15. </li>
  16. <ul class="tag">
  17. <li><span class="img folder">qutest/</span> &mdash; Examples for QUTest unit testing harness
  18. </li>
  19. <ul class="tag">
  20. <li><span class="img folder">dpp/</span> &mdash; The simple Blinky example
  21. </li>
  22. <ul class="tag">
  23. <li><span class="img folder">src/</span> &mdash; source code under test &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="tag">A</span>
  24. </li>
  25. <ul class="tag">
  26. <li><span class="img file_h">bsp.h</span> &mdash; BSP header
  27. </li>
  28. <li><span class="img file_h">dpp.h</span> &mdash; DPP header
  29. </li>
  30. <li><span class="img file_qm">dpp.qm</span> &mdash; DPP model
  31. </li>
  32. <li><span class="img file_c">philo.c</span> &mdash; `Philo` active object
  33. </li>
  34. <li><span class="img file_c">table.c</span> &mdash; `Table` active object
  35. </li>
  36. </ul>
  37. </ul>
  38. <ul class="tag">
  39. <li><span class="img folder">test_philo/</span> &mdash; code for unit testing of `Philo` AO &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="tag">B</span>
  40. </li>
  41. <ul class="tag">
  42. <li><span class="img file_mak">Makefile</span> &mdash; cross-platform makefile (host)
  43. </li>
  44. <li><span class="img file_c">test_philo.c</span> &mdash; test fixture for `Philo` AO
  45. </li>
  46. <li><span class="img file_py">test_philo.py</span> &mdash; test script for `Philo` (Python)
  47. </li>
  48. </ul>
  49. </ul>
  50. <ul class="tag">
  51. <li><span class="img folder">test_table/</span> &mdash; code for unit testing of `Table` AO &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="tag">B</span>
  52. </li>
  53. <ul class="tag">
  54. <li><span class="img file_mak">Makefile</span> &mdash; cross-platform makefile (host)
  55. </li>
  56. <li><span class="img file_c">test_philo.c</span> &mdash; test fixture for `Table` AO
  57. </li>
  58. <li><span class="img file_py">test_philo.py</span> &mdash; test script for `Table` (Python)
  59. </li>
  60. </ul>
  61. </ul>
  62. <ul class="tag">
  63. <li><span class="img folder">test_dpp/</span> &mdash; code for unit testing of DPP application &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="tag">C</span>
  64. </li>
  65. <ul class="tag">
  66. <li><span class="img file_mak">Makefile</span> &mdash; cross-platform makefile (host)
  67. </li>
  68. <li><span class="img file_mak">make_efm32</span> &mdash; makefile for the EFM32 **embedded board**
  69. </li>
  70. <li><span class="img file_mak">make_tm4c123</span> &mdash; makefile for the TM4C123 **embedded board**
  71. </li>
  72. <li><span class="img file_c">main.c</span> &mdash; `main()` function for DPP application
  73. </li>
  74. <li><span class="img file_c">test_dpp.c</span> &mdash; test fixture for DPP application
  75. </li>
  76. <li><span class="img file_py">test_init.py</span> &mdash; test script for DPP initialization (Python)
  77. </li>
  78. <li><span class="img file_py">test_tick.py</span> &mdash; test script for DPP tick processing (Python)
  79. </li>
  80. </ul>
  81. </ul>
  82. <li><span class="img folder">~~~/</span> &mdash; Other QUTest examples~~~
  83. </li>
  84. <li><span class="img folder">target_efm32/</span> &mdash; Code for the **embedded target** (EFM32) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="tag">D</span>
  85. </li>
  86. <li><span class="img folder">target_tm4c123/</span> &mdash; Code for the **embedded target** (TM4C123) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="tag">D</span>
  87. </li>
  88. </ul>
  89. </ul>
  90. </ul>
  91. <ul class="tag">
  92. <li><span class="tag">A</span> The <span class="img folder">src</span> sub-directory contains the production code to be tested. This directory contains the <span class="img file_qm">.qm</span> model file as well as the generated code from the model.
  93. </li>
  94. <li><span class="tag">B</span> The <span class="img folder">test_philo</span> sub-directory contains the unit test code for a component, such as `Philo` in this case. Here, you can find the <span class="img file_c">test_*.c</span> **test fixture**, the test scripts <span class="img file_py">test_*.py</span> (Python) as well as the cross-platform <span class="img file_mak">Makefile</span> to build the code and *run* the tests on the host.
  95. </li>
  96. <li><span class="tag">C</span> The <span class="img folder">test_dpp</span> sub-directory contains integration-test code for the application, such as `DPP` in this case. The objective is to test the initialization and interactions *among* components. Here, you can find the <span class="img file_c">main.c</span> `main()` function as well as the <span class="img file_c">test_dpp.c</span> *test fixture*. This directory also contains <span class="img file_mak">make_*</span> *makefiles* to build and run the code on the **embedded targets**.
  97. </li>
  98. <li><span class="tag">D</span> The <span class="img folder">target_efm32</span> sub-directory contains the Code needed to build and run the test code on the **embedded target**, like EFM32 in this case.
  99. </li>
  100. </ul>
  101. @section exa_qutest-test Building and Running the Tests
  102. As usual in Test-Driven Development (TDD), the provided <span class="img file_mak">Makefiles</span> both *build* the code and *run* the tests.
  103. @subsection exa_qutest_host Host Computers
  104. Typically, you start testing on your host computer. Before building/running the code, you need to open a terminal window and launch the [QSPY host application](https://www.state-machine.com/qtools/qspy.html) with the `-t` [command-line option](https://www.state-machine.com/qtools/qspy.html#qspy_command).
  105. Next, you open another terminal window, change directory to the <span class="img folder">test_~~~</span> folder of interest, and type `make`. This will build the application and run the tests (Python), as shown in the screen shot below:
  106. @image html qutest_py.png
  107. @image latex qutest_py.png width=6.5in
  108. @caption{Testing on the host (Python)}
  109. @subsection exa_qutest_target Embedded Targets
  110. The QUTest testing system allows you also to easily test the code directly on the embedded target board. The <span class="img folder">dpp/test_dpp/</span> directory illustrates this option by providing the `makefiles` for embedded boards, such as the TM4C123 (Tiva LaunchPad) <span class="img file_mak">make_tm4c123</span>.
  111. To test the code on an embedded board, you need to connect the board to the host computer and launch the and launch the [QSPY host application](https://www.state-machine.com/qtools/qspy.html) with the `-c COM<n>` [command-line option](https://www.state-machine.com/qtools/qspy.html#qspy_command), where `<n>` is the specific COM port number on your host that the board is using.
  112. Next, you open another terminal window, change directory to the <span class="img folder">test_~~~</span> folder of interest, and type `make -f make_tm4c123`. This will build the application and run the tests (Python), as shown in the screen shot below:
  113. @image html qutest_tm4c123_py.png
  114. @image latex qutest_tm4c123_py.png width=6.5in
  115. @caption{Testing on the TM4C123 embedded target (Python)}
  116. @ifnot LATEX
  117. @nav_next{exa_os}
  118. @endif
  119. */