1a8e1175bSopenharmony_ci# Mbed TLS test framework 2a8e1175bSopenharmony_ci 3a8e1175bSopenharmony_ciThis document is an overview of the Mbed TLS test framework and test tools. 4a8e1175bSopenharmony_ci 5a8e1175bSopenharmony_ciThis document is incomplete. You can help by expanding it. 6a8e1175bSopenharmony_ci 7a8e1175bSopenharmony_ci## Unit tests 8a8e1175bSopenharmony_ci 9a8e1175bSopenharmony_ciSee <https://mbed-tls.readthedocs.io/en/latest/kb/development/test_suites> 10a8e1175bSopenharmony_ci 11a8e1175bSopenharmony_ci### Unit test descriptions 12a8e1175bSopenharmony_ci 13a8e1175bSopenharmony_ciEach 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: 14a8e1175bSopenharmony_ci 15a8e1175bSopenharmony_ci* Test descriptions may not contain semicolons, line breaks and other control characters, or non-ASCII characters. <br> 16a8e1175bSopenharmony_ci Rationale: keep the tools that process test descriptions (`generate_test_code.py`, [outcome file](#outcome-file) tools) simple. 17a8e1175bSopenharmony_ci* 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> 18a8e1175bSopenharmony_ci Rationale: make it easy to relate a failure log to the test data. Avoid confusion between cases in the [outcome file](#outcome-file). 19a8e1175bSopenharmony_ci* Test descriptions should be a maximum of **66 characters**. <br> 20a8e1175bSopenharmony_ci 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> 21a8e1175bSopenharmony_ci 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. 22a8e1175bSopenharmony_ci* 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. 23a8e1175bSopenharmony_ci* 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. 24a8e1175bSopenharmony_ci 25a8e1175bSopenharmony_ci`tests/scripts/check_test_cases.py` enforces some rules and warns if some guidelines are violated. 26a8e1175bSopenharmony_ci 27a8e1175bSopenharmony_ci## TLS tests 28a8e1175bSopenharmony_ci 29a8e1175bSopenharmony_ci### SSL extension tests 30a8e1175bSopenharmony_ci 31a8e1175bSopenharmony_ci#### SSL test case descriptions 32a8e1175bSopenharmony_ci 33a8e1175bSopenharmony_ciEach 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_test`. 34a8e1175bSopenharmony_ci 35a8e1175bSopenharmony_ciThe 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`. 36a8e1175bSopenharmony_ci 37a8e1175bSopenharmony_ci### SSL cipher suite tests 38a8e1175bSopenharmony_ci 39a8e1175bSopenharmony_ciEach test case in `compat.sh` has a description which succinctly describes for a human audience what the test does. The test description is `$TITLE` defined in `run_client`. 40a8e1175bSopenharmony_ci 41a8e1175bSopenharmony_ciThe same rules and guidelines apply as for [unit test descriptions](#unit-test-descriptions). In addition, failure cause in `compat.sh` is not classified as `ssl-opt.sh`, so the information of failed log files are followed as prompt. 42a8e1175bSopenharmony_ci 43a8e1175bSopenharmony_ci## Running tests 44a8e1175bSopenharmony_ci 45a8e1175bSopenharmony_ci### Outcome file 46a8e1175bSopenharmony_ci 47a8e1175bSopenharmony_ci#### Generating an outcome file 48a8e1175bSopenharmony_ci 49a8e1175bSopenharmony_ciUnit tests, `ssl-opt.sh` and `compat.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. 50a8e1175bSopenharmony_ci 51a8e1175bSopenharmony_ciIf you run `all.sh --outcome-file test-outcome.csv`, this collects the outcome of all the test cases in `test-outcome.csv`. 52a8e1175bSopenharmony_ci 53a8e1175bSopenharmony_ci#### Outcome file format 54a8e1175bSopenharmony_ci 55a8e1175bSopenharmony_ciThe 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. 56a8e1175bSopenharmony_ci 57a8e1175bSopenharmony_ciThe outcome file has 6 fields: 58a8e1175bSopenharmony_ci 59a8e1175bSopenharmony_ci* **Platform**: a description of the platform, e.g. `Linux-x86_64` or `Linux-x86_64-gcc7-msan`. 60a8e1175bSopenharmony_ci* **Configuration**: a unique description of the configuration (`mbedtls_config.h`). 61a8e1175bSopenharmony_ci* **Test suite**: `test_suite_xxx`, `ssl-opt` or `compat`. 62a8e1175bSopenharmony_ci* **Test case**: the description of the test case. 63a8e1175bSopenharmony_ci* **Result**: one of `PASS`, `SKIP` or `FAIL`. 64a8e1175bSopenharmony_ci* **Cause**: more information explaining the result. 65