You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tools/testing/testing_greentea.md
+34-32Lines changed: 34 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
## Greentea testing applications
2
2
3
-
Greentea is the automated testing tool for Arm Mbed OS development. It's a test runner that automates the process of flashing development boards, starting tests, and accumulating test results into test reports. Developers use it for local development as well as for automation in a continuous integration environment.
3
+
Greentea is the automated testing tool for Arm Mbed OS development. It's a test runner that automates the process of flashing development boards, starting tests and accumulating test results into test reports. You can use it for local development, as well as for automation in a continuous integration environment.
4
4
5
-
Greentea tests run on embedded devices, but Greentea also supports 'host tests'. These are Python scripts that run on a computer and can communicate back to the embedded device. You can for example verify that a value was actually written to the cloud when the device said it did so.
5
+
Greentea tests run on embedded devices, but Greentea also supports `host tests`. These are Python scripts that run on a computer and can communicate back to the embedded device. You can, for example, verify that a value wrote to the cloud when the device said it did.
6
6
7
-
This document should help you start using Greentea. Please see the [`htrun` documentation](https://github.com/ARMmbed/mbed-os-tools/tree/master/packages/mbed-host-tests), the tool Greentea uses to drive tests, for the technical details of the interactions between the platform and the host machine.
7
+
This document will help you start using Greentea. Please see the [`htrun` documentation](https://github.com/ARMmbed/mbed-os-tools/tree/master/packages/mbed-host-tests), the tool Greentea uses to drive tests, for the technical details of the interactions between the platform and the host machine.
8
8
9
9
### Using tests
10
10
@@ -73,15 +73,15 @@ If you need to test with multiple configurations, then you can use the `--app-co
73
73
74
74
### Writing your first test
75
75
76
-
You can write tests for your own project or add more tests to Mbed OS. You can write tests by using the [Greentea client](https://github.com/ARMmbed/mbed-os/tree/master/features/frameworks/greentea-client), and the [UNITY](https://github.com/ARMmbed/mbed-os/tree/master/features/frameworks/unity) and [utest](https://github.com/ARMmbed/mbed-os/tree/master/features/frameworks/utest) frameworks, which are located in `/features/frameworks`.
76
+
You can write tests for your own project or add more tests to Mbed OS. You can write tests by using the [Greentea client](https://github.com/ARMmbed/mbed-os/tree/master/features/frameworks/greentea-client) and the [UNITY](https://github.com/ARMmbed/mbed-os/tree/master/features/frameworks/unity) and [utest](https://github.com/ARMmbed/mbed-os/tree/master/features/frameworks/utest) frameworks, which are located in `/features/frameworks`.
77
77
78
-
Let's write your first test. Use Mbed CLI to create a new project:
78
+
To write your first test, use Mbed CLI to create a new project:
79
79
80
80
```
81
81
$ mbed new first-greentea-test
82
82
```
83
83
84
-
As specified above, there is a convention where all tests live in the `TESTS/` directory. In the `first-greentea-test` folder create a folder `TESTS/test-group/simple-test/`.
84
+
By convention, all tests live in the `TESTS/` directory. In the `first-greentea-test` folder, create a folder `TESTS/test-group/simple-test/`.
85
85
86
86
```
87
87
first-greentea-test/
@@ -93,7 +93,7 @@ first-greentea-test/
93
93
94
94
*Test structure for Greentea tests*
95
95
96
-
In this folder, create a file `main.cpp`. In here you can use UNITY, utest and the Greentea Client to write your test:
96
+
In this folder, create a file `main.cpp`. You can use UNITY, utest and the Greentea client to write your test:
97
97
98
98
```cpp
99
99
#include"mbed.h"
@@ -103,7 +103,7 @@ In this folder, create a file `main.cpp`. In here you can use UNITY, utest and t
Let's run this test (tip: to see all tests, run `mbed test --compile-list`):
135
+
<span class="tips">**Tip:** To see all tests, run `mbed test --compile-list`.</span>
136
+
137
+
Run the test:
136
138
137
139
```
138
140
# run the test with the GCC_ARM toolchain, automatically detect the target, and run in verbose mode (-v)
139
141
$ mbed test -t GCC_ARM -m auto -v -n tests-test-group-simple-test
140
142
```
141
143
142
-
This will yield (on a NUCLEO F411RE):
144
+
This yields (on a NUCLEO F411RE):
143
145
144
146
```
145
147
mbedgt: test suite report:
@@ -159,17 +161,17 @@ mbedgt: test case results: 1 OK
159
161
mbedgt: completed in 18.64 sec
160
162
```
161
163
162
-
Victory! Now change the test in a way that it should fail (for example, expect 6 instead of 4), re-run the test, and observe the difference.
164
+
Change the test in a way that it fails (for example, expect 6 instead of 4), rerun the test and observe the difference.
163
165
164
166
### Writing integration tests using host tests
165
167
166
-
The previous test was simple because it was all self-contained. Everything that ran only impacted the microcontroller. But typical test cases involve things in the real world. Things like: did my device actually get an internet connection, or did my device actually register with my cloud service? (We have [a lot of these](https://github.com/ARMmbed/simple-mbed-cloud-client/tree/master/TESTS) for Pelion Device Management.) To test these scenarios you can use a 'host test' that runs on your computer. After the device says it did something you can verify that it actually happened, and then pass or fail the test accordingly.
168
+
The previous test was self-contained. Everything that ran only affected the microcontroller. However, typical test cases involve peripherals in the real world. This raises questions such as: Did my device actually get an internet connection, or did my device actually register with my cloud service? (We have [a lot of these](https://github.com/ARMmbed/simple-mbed-cloud-client/tree/master/TESTS) for Pelion Device Management.) To test these scenarios, you can use a host test that runs on your computer. After the device says it did something, you can verify that it happened and then pass or fail the test accordingly.
167
169
168
-
To interact with the host test from the device you have two functions: `greentea_send_kv` and `greentea_parse_kv`. The latter blocks until it gets a message back from the host. Let's write an integration test that sends 'hello' to the host, and waits until it gets 'world' back.
170
+
To interact with the host test from the device, you can use two functions: `greentea_send_kv` and `greentea_parse_kv`. The latter blocks until it gets a message back from the host.
169
171
170
172
#### Creating the host test
171
173
172
-
Create a file called `hello_world_tests.py` in the `TESTS/host_tests` folder, and fill it with:
174
+
This example writes an integration test that sends `hello` to the host and waits until it receives `world`. Create a file called `hello_world_tests.py` in the `TESTS/host_tests` folder, and fill it with:
173
175
174
176
```py
175
177
from mbed_host_tests import BaseHostTest
@@ -205,11 +207,11 @@ class HelloWorldHostTests(BaseHostTest):
205
207
self.logger = HtrunLogger('TEST')
206
208
```
207
209
208
-
This registers one function you can call from the device: `init`. The function will check whether the value was `hello`, and if so, return`world` back to the device, via the `send_kv` function.
210
+
This registers one function you can call from the device: `init`. The function checks whether the value was `hello`, and if so, returns`world` back to the device using the `send_kv` function.
209
211
210
212
#### Creating the Greentea test
211
213
212
-
Now let's write the embedded part of this test. Create a new file `main.cpp` in `TESTS/tests/integration-test`, and fill it with:
214
+
This example writes the embedded part of this test. Create a new file `main.cpp` in `TESTS/tests/integration-test`, and fill it with:
You see the calls to/from the host through the `greentea_send_kv` and `greentea_parse_kv` functions. Also take a note of the `GREENTEA_SETUP` call. Here we specify which host test we want to use, and the test is then automatically loaded when running (based on the Python name).
261
+
You see the calls to and from the host through the `greentea_send_kv` and `greentea_parse_kv` functions. Note the `GREENTEA_SETUP` call. This specifies which host test to use, and the test is then automatically loaded when running (based on the Python name).
260
262
261
-
Let's run the test, and see if everything works:
263
+
Run the test:
262
264
263
265
```
264
266
$ mbed test -v -n tests-test-group-integration-test
265
267
```
266
268
267
269
### Debugging tests
268
270
269
-
Debugging tests is a crucial part of the development and porting process. This section covers exporting the test, then driving the test with the test tools while the target is attached to a debugger.
271
+
Debugging tests is a crucial part of the development and porting process. This section covers exporting the test and driving the test with the test tools while the target is attached to a debugger.
270
272
271
273
#### Exporting tests
272
274
273
-
Currently, the easiest way to export a test is to copy the test's source code from its test directory to your project's root. This way, the tools treat it like a normal application.
275
+
The easiest way to export a test is to copy the test's source code from its test directory to your project's root. This way, the tools treat it like a normal application.
274
276
275
277
You can find the path to the test that you want to export by running the following command:
276
278
@@ -322,7 +324,7 @@ This detects your attached target and drives the test. If you need to rerun the
322
324
323
325
For an explanation of the arguments used in this command, please run `mbedhtrun --help`.
324
326
325
-
### Command-line usage
327
+
### Command-line use
326
328
327
329
This section highlights a few of the capabilities of the Greentea command-line interface. For a full list of the available options, please run `mbed test --help`.
328
330
@@ -343,11 +345,11 @@ Test Case:
343
345
...
344
346
```
345
347
346
-
After compilation you can use the `--run-list` argument to list all tests that are ready to be ran.
348
+
After compilation, you can use the `--run-list` argument to list all tests that are ready to be ran.
347
349
348
350
#### Executing all tests
349
351
350
-
The default action of Greentea using `mbed test` is to execute all tests that are found. You can also add `-v` to make the output more verbose.
352
+
The default action of Greentea using `mbed test` is to execute all tests found. You can also add `-v` to make the output more verbose.
351
353
352
354
#### Limiting tests
353
355
@@ -432,20 +434,20 @@ mbed test --report-text text_report.text --run
432
434
433
435
### Test specification JSON format
434
436
435
-
The Greentea test specification format decouples the tool from your build system. It provides important data, such as test names, paths to test binaries and the platform on which the binaries should run. This file is automatically generated when running tests through Mbed CLI, but you can also provide it yourself. This way you have fine-grained control over exactly which tests are run, and through which compilers.
437
+
The Greentea test specification format decouples the tool from your build system. It provides important data, such as test names, paths to test binaries and the platform on which the binaries should run. This file is automatically generated when running tests through Mbed CLI, but you can also provide it yourself. This way you can control exactly which tests are run and through which compilers.
436
438
437
439
Greentea automatically looks for files called `test_spec.json` in your working directory. You can also use the `--test-spec` argument to direct Greentea to a specific test specification file.
438
440
439
-
When you use the `-t` / `--target` argument with the `--test-spec` argument, you can select which "build" should be used. In the example below, you could provide the arguments `--test-spec test_spec.json -t K64F-ARM` to only run that build's tests.
441
+
When you use the `-t` / `--target` argument with the `--test-spec` argument, you can select which "build" to use. In the example below, you could provide the arguments `--test-spec test_spec.json -t K64F-ARM` to only run that build's tests.
440
442
441
443
#### Example of test specification file
442
444
443
-
In the below example, there are two defined builds:
445
+
The below example uses two defined builds:
444
446
445
447
- Build `K64F-ARM` for NXP `K64F` platform compiled with `ARMCC` compiler.
446
448
- Build `K64F-GCC` for NXP `K64F` platform compiled with `GCC ARM` compiler.
447
449
448
-
Place this file in your root folder and name it `test_spec.json`.
450
+
Place this file in your root folder, and name it `test_spec.json`.
449
451
450
452
```json
451
453
{
@@ -494,7 +496,7 @@ Place this file in your root folder and name it `test_spec.json`.
494
496
}
495
497
```
496
498
497
-
If you now run `mbed test --run-list` this will now list only these tests:
499
+
If you run `mbed test --run-list`, this will now list only these tests:
498
500
499
501
```
500
502
mbedgt: greentea test automation tool ver. 1.2.5
@@ -511,4 +513,4 @@ mbedgt: available tests for built 'K64F-ARM', location 'BUILD/tests/K64F/ARM'
511
513
512
514
### Known issues
513
515
514
-
There cannot be a `main()` function outside of a `TESTS` directory when building and running tests. This is because this function will be included in the non-test code build, as described in the [Building process](#building-process) section. When the test code is compiled and linked with the non-test code build, a linker error will occur, due to their being multiple `main()` functions defined. This is why you should either rename your main application file, if you need to build and run tests, or use a different project. Note that this does not affect building projects or applications, only building and running tests.
516
+
There cannot be a `main()` function outside of a `TESTS` directory when building and running tests. This is because this function will be included in the nontest code build, as described in the [building process](#building-process) section. When the test code is compiled and linked with the nontest code build, a linker error will occur, due to there being multiple `main()` functions defined. This is why you should either rename your main application file if you need to build and run tests, or use a different project. Note that this does not affect building projects or applications, only building and running tests.
0 commit comments