PageRenderTime 80ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/external/mbed-os/features/frameworks/greentea-client/README.md

https://github.com/adamgreen/gcc4mbed
Markdown | 193 lines | 152 code | 41 blank | 0 comment | 0 complexity | e59240e96af5ebc0af5237c8f53ca988 MD5 | raw file
  1. # Table of Contents
  2. * [greentea-client](#greentea-client)
  3. * [mbed-drivers dependencies](#mbed-drivers-dependencies)
  4. * [Greentea test tools](#greentea-test-tools)
  5. * [Compatibility](#compatibility)
  6. * [Greentea support](#greentea-support)
  7. * [utest support](#utest-support)
  8. * [greentea-client support in your module](#greentea-client-support-in-your-module)
  9. * [Terms](#terms)
  10. * [Test suite](#test-suite)
  11. * [Test case](#test-case)
  12. * [key-value protocol](#key-value-protocol)
  13. * [Where can I use it?](#where-can-i-use-it)
  14. * [Test suite model](#test-suite-model)
  15. * [utest support template](#utest-support-template)
  16. * [No utest support template](#no-utest-support-template)
  17. # greentea-client
  18. **Tip:** If you are unsure about the terms used in this document, please see the [Terms](#Terms) section.
  19. ```greentea-client``` is a C++ client library for [the Greentea test tool](https://github.com/ARMmbed/greentea) when used in an [mbed](www.mbed.com) project.
  20. This package implements the slave side of the simple key-value protocol used for communication between the device under test (DUT) and the host. ```Greentea``` on the host side implements the protocol's master behavior. ```greentea-client``` is released through the [yotta registry](https://yotta.mbed.com/#/module/greentea-client/0.1.8).
  21. ```
  22. DUT <--- serial port connection ---> host
  23. (slave) . (master)
  24. .
  25. [greentea-client] . [conn_process] [htrun]
  26. ===== . ================ =========
  27. | . | |
  28. | . | |
  29. | {{ key ; value }} | |
  30. |------------------------->| (key, value, timestamp) |
  31. | . |------------------------>|
  32. | . | |
  33. | . | |
  34. | . | |
  35. | . | |
  36. | . | |
  37. | . | (key, value, timestamp) |
  38. | {{ key ; value }} |<------------------------|
  39. |<-------------------------| |
  40. | . | |
  41. .
  42. ```
  43. ```greentea-client``` is a [yotta module](http://yottadocs.mbed.com/reference/module.html). You can easily include it in your yotta project as ```dependency```/```testDependency```.
  44. ## mbed-drivers dependencies
  45. This package was introduced as a future replacement for the [mbed-drivers/test_env.h](https://github.com/ARMmbed/mbed-drivers/blob/master/mbed-drivers/test_env.h) test framework. ```mbed-drivers/test_env.h``` is no longer considered the correct way to write tests for mbed modules.
  46. Examples of test cases ported from the old ```mbed-drivers/test_env``` to the ```greentea-client``` model can be found here:
  47. * [core-util](https://github.com/ARMmbed/core-util/pull/95)
  48. * [ualloc](https://github.com/ARMmbed/ualloc/pull/24)
  49. * [minar](https://github.com/ARMmbed/minar/pull/36)
  50. * [mbed-drivers](https://github.com/ARMmbed/mbed-drivers/pull/165)
  51. * [sal](https://github.com/ARMmbed/sal/pull/46)
  52. * [sockets](https://github.com/ARMmbed/sockets/pull/64)
  53. * [utest](https://github.com/ARMmbed/utest/pull/6)
  54. ## Greentea test tools
  55. ```Greentea``` is a test automation tool written in Python and designed to automate test execution for [mbed](www.mbed.com) projects encapsulated as [yotta](http://yottadocs.mbed.com) modules. Its key features include: integration with yotta module, test automation for yotta module's tests and reporting.
  56. ## Compatibility
  57. ```greentea-client``` is compatible with:
  58. * [Greentea](https://github.com/ARMmbed/greentea) v0.2.x onwards
  59. * [htrun](https://github.com/ARMmbed/htrun) v0.2.x onwards
  60. * [utest](https://github.com/ARMmbed/utest) v1.10.0 onwards
  61. * [unity](https://github.com/ARMmbed/utest) v2.0.1 onwards
  62. ### Greentea support
  63. If you wish to use ```greentea-client``` please make sure you are using latest ```Greentea``` tools from [PyPI](https://pypi.python.org/pypi/mbed-greentea) (you will need Python 2.7):
  64. ```
  65. $ pip install mbed-greentea --upgrade
  66. ```
  67. *Note*: If you previously used ```mbed-drivers/test_env.h``` features to write your test cases please downgrade ```Greentea``` to a version lower than ```v0.2.0``` to stay compatible:
  68. ```
  69. $ pip install "mbed-greentea<0.2.0" --upgrade
  70. ```
  71. *Note*: [Greentea v0.1.x](https://github.com/ARMmbed/greentea/tree/master_v0_1_x) is still developed on a ```master_v0_1_x``` branch. We will only apply critical patches to version 0.1.x, no feature development is planned.
  72. ### utest support
  73. ```utest``` is our preferred test harness which allows you to execute a series of (asynchronous) C++ test cases. ```greentea-client``` includes as test dependency ```utest``` yotta module. See the ```greentea-client``` [module.json](https://github.com/ARMmbed/greentea-client/blob/master/module.json) ```testDependency``` section:
  74. ```json
  75. {
  76. "testDependencies": {
  77. "utest": "^1.10.0"
  78. }
  79. }
  80. ```
  81. ### greentea-client support in your module
  82. Currently ```greentea-client``` is in on version ```1.0.x```. Please use a ```^1.0.0``` dependency version in your ```module.json``` file.
  83. Example of ```module.json``` file with ```greentea-client``` as a test dependency:
  84. ```json
  85. {
  86. "testDependencies": {
  87. "greentea-client": "^1.0.0",
  88. "utest" : "^1.10.0",
  89. "unity" : "^2.1.0"
  90. }
  91. }
  92. ```
  93. ## Terms
  94. ### Test suite
  95. A test suite is a binary containing test cases we execute on hardware. The test suite has a beginning and an end (like your ```main()``` function would. The test suite may pass, fail or be in an error state (for example if test suite times out or there was a serial port connection problem).
  96. ### Test case
  97. Preferably you will use ```utest``` to define test cases . test case has the beginning and the end. During test case execution you will use ``ùnity``` assert macros, schedule MINAR callbacks, check for timeouts in your code. Your test cases may pass, fail or be in an error state which means something went wrong and we were unable to determine exactly what that was (you may have to check the logs).
  98. ### key-value protocol
  99. The key-value protocol (also called ```KiVi```) is a simple protocol introduced to the ```Greentea``` test tools. It is used to send simple text messages (events) between the DUT and the host. Each message consists of a _key_ and corresponding _value_ pair.
  100. A ```KiVi``` message is defined as a string encapsulated between double curly braces. The key and value are separated by a semicolon (```;```).
  101. For example: the ```{{timeout;120}}}``` string is a simple key-value message where the key "_timeout_" is associated with the value "_120_". Both ```greentea-client``` and ```Greentea``` understand this format and can detect key-value messages in a data stream. Both _key_ and _value_ are ASCII strings.
  102. This protocol is a master-slave protocol. The host has the role of _master_ and the DUT is the _slave_.
  103. ```greentea-client``` implements the key-value protocol tokenizer and parser.
  104. ## Where can I use it?
  105. It is possible to write test cases that use ```greentea-client``` and at the same time support ```mbed``` features such as [MINAR scheduler](https://github.com/ARMmbed/minar). It is also possible to mix ```greentea-client``` with other test tools we use at ```mbed``` such as [utest](https://github.com/ARMmbed/utest) and [unity](https://github.com/ARMmbed/unity).
  106. You can also find references to ```greentea-client``` in many ```mbed``` packages. For example:
  107. * [mbed-drivers](https://github.com/ARMmbed/mbed-drivers) - check its [module.json](https://github.com/ARMmbed/mbed-drivers/blob/master/module.json)
  108. * [core-util](https://github.com/ARMmbed/core-util) - check its [module.json](https://github.com/ARMmbed/core-util/blob/master/module.json)
  109. # Test suite model
  110. ## utest support template
  111. ```c++
  112. #include "greentea-client/test_env.h"
  113. #include "utest/utest.h"
  114. #include "unity/unity.h"
  115. void test_case_1_func() {
  116. // Test case #1 body
  117. // Here you can run your test cases and assertions
  118. TEST_ASSERT_TRUE(true);
  119. TEST_ASSERT_FALSE(false);
  120. }
  121. void test_case_2_func() {
  122. // Test case #2 body
  123. // Here you can run your test cases and assertions
  124. TEST_ASSERT_TRUE(true);
  125. TEST_ASSERT_FALSE(false);
  126. }
  127. const Case cases[] = {
  128. Case("Test case #1 name", test_case_1_func),
  129. Case("Test case #1 name", test_case_2_func)
  130. };
  131. status_t greentea_setup(const size_t number_of_cases) {
  132. GREENTEA_SETUP(5, "default_auto");
  133. return greentea_test_setup_handler(number_of_cases);
  134. }
  135. void app_start(int, char*[]) {
  136. Harness::run(specification);
  137. }
  138. ```
  139. ## No utest support template
  140. ```c++
  141. #include "greentea-client/test_env.h"
  142. #include "unity/unity.h"
  143. void app_start(int, char*[]) {
  144. bool result = true;
  145. GREENTEA_SETUP(15, "default_auto");
  146. // Test suite body
  147. // Here you can run your test cases and or assertions
  148. TEST_ASSERT_TRUE(true);
  149. TEST_ASSERT_FALSE(false);
  150. GREENTEA_TESTSUITE_RESULT(result);
  151. }
  152. ```