Gilles Peskine | 508caf5 | 2019-09-16 16:29:15 +0200 | [diff] [blame] | 1 | # Mbed TLS test framework |
| 2 | |
| 3 | This document is an overview of the Mbed TLS test framework and test tools. |
| 4 | |
| 5 | This document is incomplete. You can help by expanding it. |
| 6 | |
Gilles Peskine | e94bc87 | 2019-09-27 20:22:41 +0200 | [diff] [blame] | 7 | ## Unit tests |
| 8 | |
Gilles Peskine | 7334462 | 2019-10-01 10:36:10 +0200 | [diff] [blame] | 9 | See <https://tls.mbed.org/kb/development/test_suites> |
Gilles Peskine | e94bc87 | 2019-09-27 20:22:41 +0200 | [diff] [blame] | 10 | |
| 11 | ### Unit test descriptions |
| 12 | |
| 13 | Each test case has a description which succinctly describes for a human audience what the test does. The first non-comment line of each paragraph in a `.data` file is the test description. The following rules and guidelines apply: |
| 14 | |
| 15 | * Test descriptions may not contain semicolons, line breaks and other control characters, or non-ASCII characters. <br> |
| 16 | Rationale: keep the tools that process test descriptions (`generate_test_code.py`, [outcome file](#outcome-file) tools) simple. |
| 17 | * Test descriptions must be unique within a `.data` file. If you can't think of a better description, the convention is to append `#1`, `#2`, etc. <br> |
| 18 | Rationale: make it easy to relate a failure log to the test data. Avoid confusion between cases in the [outcome file](#outcome-file). |
| 19 | * Test descriptions should be a maximum of **66 characters**. <br> |
| 20 | Rationale: 66 characters is what our various tools assume (leaving room for 14 more characters on an 80-column line). Longer descriptions may be truncated or may break a visual alignment. <br> |
| 21 | We have a lot of test cases with longer descriptions, but they should be avoided. At least please make sure that the first 66 characters describe the test uniquely. |
| 22 | * Make the description descriptive. “foo: x=2, y=4” is more descriptive than “foo #2”. “foo: 0<x<y, both even” is even better if these inequalities and parities are why this particular test data was chosen. |
| 23 | * Avoid changing the description of an existing test case without a good reason. This breaks the tracking of failures across CI runs, since this tracking is based on the descriptions. |
| 24 | |
Gilles Peskine | fb4f933 | 2020-06-25 14:18:34 +0200 | [diff] [blame] | 25 | `tests/scripts/check_test_cases.py` enforces some rules and warns if some guidelines are violated. |
Gilles Peskine | e94bc87 | 2019-09-27 20:22:41 +0200 | [diff] [blame] | 26 | |
| 27 | ## TLS tests |
| 28 | |
| 29 | ### SSL extension tests |
| 30 | |
| 31 | #### SSL test case descriptions |
| 32 | |
| 33 | Each test case in `ssl-opt.sh` has a description which succinctly describes for a human audience what the test does. The test description is the first parameter to `run_tests`. |
| 34 | |
Gilles Peskine | fb4f933 | 2020-06-25 14:18:34 +0200 | [diff] [blame] | 35 | The same rules and guidelines apply as for [unit test descriptions](#unit-test-descriptions). In addition, the description must be written on the same line as `run_test`, in double quotes, for the sake of `check_test_cases.py`. |
Gilles Peskine | e94bc87 | 2019-09-27 20:22:41 +0200 | [diff] [blame] | 36 | |
Gilles Peskine | 508caf5 | 2019-09-16 16:29:15 +0200 | [diff] [blame] | 37 | ## Running tests |
| 38 | |
| 39 | ### Outcome file |
| 40 | |
| 41 | #### Generating an outcome file |
| 42 | |
| 43 | Unit tests and `ssl-opt.sh` record the outcome of each test case in a **test outcome file**. This feature is enabled if the environment variable `MBEDTLS_TEST_OUTCOME_FILE` is set. Set it to the path of the desired file. |
| 44 | |
| 45 | If you run `all.sh --outcome-file test-outcome.csv`, this collects the outcome of all the test cases in `test-outcome.csv`. |
| 46 | |
| 47 | #### Outcome file format |
| 48 | |
| 49 | The outcome file is in a CSV format using `;` (semicolon) as the delimiter and no quoting. This means that fields may not contain newlines or semicolons. There is no title line. |
| 50 | |
| 51 | The outcome file has 6 fields: |
| 52 | |
| 53 | * **Platform**: a description of the platform, e.g. `Linux-x86_64` or `Linux-x86_64-gcc7-msan`. |
| 54 | * **Configuration**: a unique description of the configuration (`config.h`). |
| 55 | * **Test suite**: `test_suite_xxx` or `ssl-opt`. |
| 56 | * **Test case**: the description of the test case. |
| 57 | * **Result**: one of `PASS`, `SKIP` or `FAIL`. |
| 58 | * **Cause**: more information explaining the result. |