Skip to content

Commit ebd3e0b

Browse files
committed
Fixing typos, grammar, and general English in mbed OS 5 testing doc
1 parent 78b9c39 commit ebd3e0b

File tree

1 file changed

+39
-34
lines changed

1 file changed

+39
-34
lines changed

docs/testing_mbed_OS_5.md

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Testing in mbed OS 5
22

3-
The way tests are ran and compiled in mbed OS 5 is substantially different than in previous versions of mbed. Previously tests were located in one known location and a python file was kept (`tools/tests.py`) keeping track of their dependencies, capabilities, and configurations. mbed OS 5 has adopted a more distributed approach to testing. Now test code lives alongside the test code, and these are dynamically discovered by the test tools.
3+
The way tests are run and compiled in mbed OS 5 is substantially different from previous versions of mbed. Previously, tests were located in one known location and a python file (`tools/tests.py`) kept track of their dependencies, capabilities, and configurations. mbed OS 5 has adopted a more distributed approach to testing. Test code lives alongside the application code, and which is dynamically discovered by the test tools.
44

55
## Table of Contents
66

@@ -9,76 +9,81 @@ The way tests are ran and compiled in mbed OS 5 is substantially different than
99
- [Test discovery](#test-discovery)
1010
- [Test names](#test-names)
1111
- [Building tests](#building-tests)
12+
- [Building process](#building-process)
1213
- [Running tests](#running-tests)
1314
- [Writing tests](#writing-tests)
1415
- [Debugging tests](#debugging-tests)
16+
- [Exporting tests](#exporting-tests)
17+
- [Running a test while debugging](#running-a-test-while-debugging)
1518
- [Known issues](#known-issues)
1619

17-
## Test code structure
20+
## Using tests
21+
22+
### Test code structure
1823

1924
Tests can exist throughout mbed OS and your project's code. They are located under a special directory called `TESTS` (case is important!).
2025

2126
Placing code under this directory means it will be ignored when building applications and libraries. This code is only ever used when building tests. This is important since all tests require a `main()` function, and building it with your application would cause multiple `main()` functions to be defined.
2227

23-
In addition to being placed under a `TESTS` directory, test sources must exist under two other directories: a "test group" folder and a "test case" folder. The following is an example of this structure:
28+
In addition to being placed under a `TESTS` directory, test sources must exist under two other directories: a test group directory and a test case directory. The following are an examples of this structure:
2429
```
2530
myproject/TESTS/test_group/test_case_1
2631
```
2732

2833
In this example, `myproject` is the project root and all the source files under the `test_case_1` directory will be included in the test. Any other source files from the OS, libraries, and your project that apply to your target's configuration will also be included in the build of your test.
2934

30-
### Test discovery
35+
**Note:** Both the test group and test case directory can be named anything you like. However, the `TESTS` directory **must** be named `TESTS` for the tools to detect the test cases correctly.
36+
37+
#### Test discovery
3138

3239
Since test cases can exist throughout a project, the tools must find them in your project's file structure before building them. This is done by searching for paths that match the pattern detailed above in the [Test code structure](#test-code-structure) section.
3340

34-
Test discovery also obeys the same rules that is used when building your project. This means that tests that are placed under a folder with a prefix like `TARGET_`, `TOOLCHAIN_`, or `FEATURE_` will only be discovered, built, and ran if your current configuration matches this prefix.
41+
Test discovery also obeys the same rules that are used when building your project. This means that tests that are placed under a directory with a prefix like `TARGET_`, `TOOLCHAIN_`, or `FEATURE_` will only be discovered, built, and run if your current configuration matches this prefix.
3542

36-
For example, if a test was placed under the folder `FEATURE_BLE` with the following path:
43+
For example, if you place a test under the directory `FEATURE_BLE` with the following path:
3744

3845
```
3946
myproject/mbed-os/features/FEATURE_BLE/TESTS/ble_tests/unit_test
4047
```
4148

42-
This test case would only be discovered if the target that was being testing supported the BLE feature. Otherwise, the test will be ignored.
49+
This test case will only be discovered if the target being testing supports the BLE feature. Otherwise, the test will be ignored.
4350

44-
Generally, a test should not be placed under a `TARGET_` or `TOOLCHAIN_` folder, since most tests should be designed to work for all target and toolchain configurations.
51+
Generally, a test should not be placed under a `TARGET_` or `TOOLCHAIN_` directory, since most tests should be designed to work for all target and toolchain configurations.
4552

46-
Tests can also be completely ignored by using the `.mbedignore` file descirbed [here]()
53+
Tests can also be completely ignored by using the `.mbedignore` file described [here](../ignoring_files_from_build.md)
4754

48-
### Test names
55+
#### Test names
4956

5057
A test case is named from its position in your project's file structure. For instance, in the above example, a test case with the path `myproject/TESTS/test_group/test_case_1` would be named `tests-test_group-test_case_1`. You will notice that the name is created by joining the directories that make up the path to the test case with a "dash" (`-`) character. This will be a unique name to identify the test case. You will see this name used throughout the build and testing process.
5158

52-
## Building tests
59+
### Building tests
5360

54-
Tests can be built easily through mbed CLI. For information on using mbed CLI, please see its documentation.
61+
Tests can be built easily through mbed CLI. For information on using mbed CLI, please see its [documentation](https://github.com/ARMmbed/mbed-cli).
5562

56-
When tests are built for a target and a given toolchain, the available tests are first discovered, then built in series. You can also create a "test specification" file, which can be used by our testing tools to run automated hardware tests. For more information on the test specification file, please see the docmentation [here](https://github.com/ARMmbed/greentea#test-specification-json-formatted-input).
63+
When tests are built for a target and a given toolchain, the available tests are first discovered, then built in series. You can also create a "test specification" file, which can be used by our testing tools to run automated hardware tests. For more information on the test specification file, please see the documentation [here](https://github.com/ARMmbed/greentea#test-specification-json-formatted-input).
5764

58-
### Building process
65+
#### Building process
5966

60-
The process for building tests is handled by the `test.py` script (not to be confused with `tests.py`) located under the `tools` directory. This handles the discovery and building of all tests cases for a given target and toolchain.
67+
The process for building tests is handled by the `test.py` script (not to be confused with `tests.py`) located under the `tools` directory. This handles the discovery and building of all test cases for a given target and toolchain.
6168

62-
The actual process that occurs is as follows:
69+
The full build process is:
6370

64-
1. Build the "shared" code (all non test code), but do not link it
65-
- The resulting object files are placed in the build directory
66-
1. Find all tests that pertain to the given target and toolchain
67-
1. For each discovered test, build all of its source files and link it with the "shared" code that was built in step 1
68-
1. If specified, create a test specification file and place it in the given directory for use by testing tools
69-
- This is placed in the build directory by default when using mbed CLI
71+
1. Build the non-test code (all code not under a `TESTS` folder), but do not link it. The resulting object files are placed in the build directory.
72+
1. Find all tests that match the given target and toolchain.
73+
1. For each discovered test, build all of its source files and link it with the non-test code that was built in step 1.
74+
1. If specified, create a test specification file and place it in the given directory for use by testing tools. This is placed in the build directory by default when using mbed CLI.
7075

7176
### Running tests
7277

73-
Automated tests can be ran easily through mbed CLI. For information on using mbed CLI, please see its documentation.
78+
Automated tests can be run easily through mbed CLI. For information on using mbed CLI, please see its documentation.
7479

7580
The testing process requires that the tests are built and that a test specification JSON file exists that describes these available tests. The test specification format is detailed [here](https://github.com/ARMmbed/greentea#test-specification-json-formatted-input).
7681

7782
The actual testing process is handled by the Greentea tool. To read more about this tool, please visit its [GitHub repository](https://github.com/ARMmbed/greentea).
7883

7984
### Writing tests
8085

81-
You can write your own tests for your project, or add more tests to mbed OS. Tests are written using the [Greentea client](https://github.com/ARMmbed/mbed-os/tree/master/features/frameworks/greentea-client), [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, located in `/features/frameworks`. Below is an example test that uses all of these frameworks:
86+
You can write tests for your own project, or add more tests to mbed OS. Tests are written using the [Greentea client](https://github.com/ARMmbed/mbed-os/tree/master/features/frameworks/greentea-client), [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, located in `/features/frameworks`. Below is an example test that uses all of these frameworks:
8287

8388
```c++
8489
#include "mbed.h"
@@ -119,15 +124,15 @@ int main() {
119124
}
120125
```
121126
122-
This test will first run a case that succeeds, then it will run a test that fails. This is a good template to use when creating tests. For more complex testing examples, please see the documentation for [utest](https://github.com/ARMmbed/mbed-os/tree/master/features/frameworks/utest).
127+
This test will first run a case that succeeds, then a case that fails. This is a good template to use when creating tests. For more complex testing examples, please see the documentation for [utest](https://github.com/ARMmbed/mbed-os/tree/master/features/frameworks/utest).
123128
124129
## Debugging tests
125130
126131
Debugging tests is a crucial part of the development and porting process. This section will cover exporting the test, then driving the test with the test tools while the target is attached to a debugger.
127132
128133
### Exporting tests
129134
130-
Currently, the easiest way to export a test is to copy the test's source code from its test folder to your project's root. This way it will be treated like a normal application by the tools.
135+
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 it will be treated like a normal application by the tools.
131136
132137
You can find the path to the test you wish to export by running the following command:
133138
@@ -138,18 +143,18 @@ mbed test --compile-list -n <test name>
138143
Once you've copied all of the test's source files to your project root, go ahead and export your project:
139144
140145
```
141-
mbed export -i <ide name>
146+
mbed export -i <IDE name>
142147
```
143148
144-
Your exported project should now be in `projectfiles/<ide>_<target>`. Go ahead and open this project in your IDE.
149+
Your exported project should now be in `projectfiles/<IDE>_<target>`. Go ahead and open this project in your IDE.
145150
146151
### Running a test while debugging
147152
148-
Assuming your test has exported correctly to your IDE, go ahead and build the project and load it onto your target via your debugger.
153+
Assuming your test was exported correctly to your IDE, go ahead and build the project and load it onto your target via your debugger.
149154
150-
Bring the target out of reset and run the program. Your target will now be waiting for a synchronizing character string to be sent from the test tools over the serial port. The `mbed test` command cannot be run as that will attempt to flash the device, which you've already done with your IDE.
155+
Bring the target out of reset and run the program. Your target will now be waiting for a synchronizing character string to be sent from the test tools over the serial port. Do not run the `mbed test` commands, because that will attempt to flash the device, which you've already done with your IDE.
151156
152-
Instead, the underlying test tools can be used to drive the test. [htrun](https://github.com/ARMmbed/htrun) is the tool that needs to be used in this case. This is installed when you install the requirements for mbed OS. However, if you don't have it installed you can do this by running `pip install mbed-host-tests`.
157+
Instead, the underlying test tools can be used to drive the test. [htrun](https://github.com/ARMmbed/htrun) is the tool that needs to be used in this case. This is installed when you install the requirements for mbed OS. However, if you do not have it installed you can do this by running `pip install mbed-host-tests`.
153158
154159
First, find your target's serial port by running the following command:
155160
@@ -161,7 +166,7 @@ $ mbed detect
161166
...
162167
```
163168

164-
From the output, take note of where your target's serial port (in this case, it's `COM270`).
169+
From the output, take note of your target's serial port (in this case, it's `COM270`).
165170

166171
Run the following command when your device is running the test in your debugger:
167172

@@ -177,11 +182,11 @@ So for the example above, the command would be:
177182
mbedhtrun --skip-flashing --skip-reset -p COM270:9600
178183
```
179184

180-
This will detect your attached target and drive the test. At this point the test should proceed and you should be able to debug it. If you need to rerun the test, simply flash and/or reset the device with your debugger, run the program, and run the same command.
185+
This detects your attached target and drives the test. At this point the test will proceed and allow you to debug it. If you need to rerun the test, simply reset the device with your debugger, run the program, and run the same command.
181186

182187
For an explanation of the arguments used in this command, please run `mbedhtrun --help`.
183188

184189
## Known issues
185190

186-
- 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 "shared" build as described in the [Building process](#building-process) section. When the test code is compiled and linked with this "shared" build, a linker error will occur due to their being multiple `main()` functions defined. For this reason, please either rename your main application file if you need to build and run tests or use a different project.
191+
- 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. For this reason, please either rename your main application file if you need to build and run tests or use a different project.
187192
- **NOTE:** This does not affect building projects or applications, just building and running tests.

0 commit comments

Comments
 (0)