Nik Dewally | bc9e194 | 2024-07-02 17:00:15 +0100 | [diff] [blame] | 1 | #################################### |
| 2 | 'tfz-cpp/regression'-directory guide |
| 3 | #################################### |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 4 | |
| 5 | ************ |
| 6 | Introduction |
| 7 | ************ |
| 8 | |
| 9 | This is a regression suite for the TF-Fuzz tool. That is, tests to make sure |
| 10 | that TF-Fuzz is still functioning properly after making changes. Note that |
| 11 | this regression implementation tests the most basic aspects of TF-Fuzz's |
| 12 | implementation, but is not yet complete. Most notably, it does not yet test |
| 13 | ``*active`` and ``*deleted``, nor ``shuffle`` and ``2 to 5 of {...}`` |
| 14 | constructs. |
| 15 | |
Nik Dewally | bc9e194 | 2024-07-02 17:00:15 +0100 | [diff] [blame] | 16 | ************************************************* |
| 17 | ``tf_fuzz/tfz-cpp/regression`` directory contents |
| 18 | ************************************************* |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 19 | .. code-block:: bash |
| 20 | |
| 21 | 000001_set_sst_uid_data_expect_pass |
| 22 | 000002_set_sst_name_data_expect_nothing |
| 23 | 000003_set_sst_name_data |
| 24 | 000004_set_sst_name_rand_data |
| 25 | 000005_set_sst_rand_name_rand_data |
| 26 | 000006_set_sst_multi_name_rand_data |
| 27 | 000007_set_sst_multi_uid_rand_data |
| 28 | 000008_set_sst_name_rand_data_read_check_wrong |
| 29 | 000009_set_sst_name_rand_data_read_check_var_read_print |
| 30 | 000010_read_nonexistent_sst_check_string |
| 31 | 000011_read_nonexistent_sst_check_string_expect_pass |
| 32 | 000012_read_nonexistent_sst_check_string_expect_other |
| 33 | 000013_set_sst_name_rand_data_remove_twice |
| 34 | 000014_set_sst_name_rand_data_remove_other |
| 35 | 000015_set_sst_name_only |
| 36 | 000016_set_sst_single_asset_set_multiple_times |
| 37 | 000017_read_sst_check_single_asset_multiple_times |
| 38 | 000018_000016_and_000017 |
| 39 | 000019_read_asset_to_variable_set_other_asset |
| 40 | add_these_tests |
| 41 | function2OpenFiles |
| 42 | README |
| 43 | regress |
| 44 | regress_lib |
| 45 | |
| 46 | ****************************** |
| 47 | Files for Each Regression Test |
| 48 | ****************************** |
| 49 | |
| 50 | Here's the overall regression scheme: |
| 51 | |
| 52 | - ``bash regress`` from this directory runs regression. It will fail with an |
| 53 | error if a problem is found. If it runs to completion, then regression has |
| 54 | passed. |
| 55 | |
| 56 | - Each test is in its own sub-directory containing these files, by name (always |
| 57 | same name): |
| 58 | |
| 59 | - ``template``: The test-template file to be run though the TF-Fuzz under |
| 60 | test, called "the DUT TF-Fuzz" here. |
| 61 | |
| 62 | - ``exp_stdout_stderr``: The *expected*, combined ``stdout`` and ``stderr`` |
| 63 | from running TF-Fuzz in verbose mode ``-v``. This file contains wildcard |
| 64 | expressions to be checked (more on that below). |
| 65 | |
| 66 | - ``exp_test.c``: The *expected* output C code. This file also contains |
| 67 | wildcard expressions to be resolved against the DUT TF-Fuzz output (again, |
| 68 | more on that below). |
| 69 | |
| 70 | - ``stdout_stderr`` (if present): The *actual* combined ``stdout`` and |
| 71 | ``stderr`` from running the DUT TF-Fuzz in verbose mode ``-v``, during |
| 72 | regression testing. |
| 73 | |
| 74 | - ``test.c`` (if present): The output C code generated from running the DUT |
| 75 | TF-Fuzz in verbose mode ``-v``, during regression testing. |
| 76 | |
| 77 | - ``check.py``: This Python 3 script compares expected to actual |
| 78 | ``stdout``/``stderr`` and C-test code, resolving wildcard references in |
| 79 | ``exp_stdout_stderr`` and ``exp_test.c``. Each test directory has its own |
| 80 | script customized to the needs of that particular test, but they mostly |
| 81 | just runs TF-Fuzz, opens files, then invokes functions in the |
| 82 | ``regress_lib`` directory, which do the majority of the actual work. |
| 83 | |
| 84 | ******************************** |
| 85 | How ``check.py`` Assesses a Test |
| 86 | ******************************** |
| 87 | |
| 88 | To illustrate how ``check.py`` checks a regression test, below is a ``diff`` of |
| 89 | ``test.c`` and ``exp_test.c`` file files, from |
| 90 | ``./000005_set_sst_rand_name_rand_data/``, at the time of writing this: |
| 91 | |
| 92 | .. code-block:: bash |
| 93 | |
| 94 | 47,48c47,48 |
| 95 | < static uint8_t koxjis_data[] = "Gaa wuqnoe xoq uhoz qof er uaycuuf?"; |
| 96 | < static int koxjis_data_size = 35; |
| 97 | --- |
| 98 | > static uint8_t @@@003@@@_data[] = "@@002@10@@[a-z\ ]*[\.\?\!]"; |
| 99 | > static int @@@003@@@_data_size = \d+; |
| 100 | 53,55c53,55 |
| 101 | < /* Creating SST asset "koxjis," with data "Gaa wuqnoe...". */ |
| 102 | < sst_status = psa_ps_set(2110, koxjis_data_size, koxjis_data, |
| 103 | < PSA_STORAGE_FLAG_NONE); |
| 104 | --- |
| 105 | > /* Creating SST asset "@@@003@@@," with data "@@002@10@@...". */ |
| 106 | > sst_status = psa_ps_set(@@@001@@@, @@@003@@@_data_size, @@@003@@@_data, |
| 107 | > PSA_STORAGE_FLAG_[A-Z_]+); |
| 108 | 63c63 |
| 109 | < psa_ps_remove(2110); |
| 110 | --- |
| 111 | > psa_ps_remove(@@@001@@@); |
| 112 | |
| 113 | ``check.py``, short summary, performs a Python ``re.match()`` line-by-line the |
| 114 | generated ``test.c`` against the ``exp_test.c`` file. However, ``exp_test.c``, |
| 115 | in addition to Python regular expressions, also contains "special" wildcards, |
| 116 | described below. |
| 117 | |
| 118 | ********* |
| 119 | Wildcards |
| 120 | ********* |
| 121 | |
| 122 | The wildcards in the ``exp_stdout_stderr`` and ``exp_test.c`` files are of |
| 123 | three basic natures, using the examples shown above (please reference them |
| 124 | above to clearly understand the ideas here): |
| 125 | |
| 126 | .. list-table:: |
| 127 | :widths: 20 80 |
| 128 | |
| 129 | * - ``[a-z\ ]*[\.\?\!]`` or ``[A-Z_]+`` |
| 130 | - | These are Python regex pattern matches for what characters are expected |
| 131 | | at those places. The data consist of quasi-sentences, capitalized at |
| 132 | | the beginning. The capitalized character is covered by the |
| 133 | | ``@@002@10@@`` (see below) before it. The ``[a-z\ ]*[\.\?\!]`` is a |
| 134 | | Python-regex match for all remaining characters of the sentence: A |
| 135 | | sequence of zero or more lower-case letters or blanks followed by |
| 136 | | sentence-ending punctuation. |
| 137 | |
| 138 | * - ``@@@001@@@`` (``@@@``, a pattern number, ``@@@``) |
| 139 | - | This denotes a particular pattern of characters, until the expected and |
| 140 | | actual character streams re-sync again. The important thing, however, |
| 141 | | is that what this wildcard stands for *must be consistent* throughout |
| 142 | | the comparison! In this case above, ``@@@001@@@`` in the ``exp_test.c`` |
| 143 | | must consistently match ``8617`` everywhere throughout the ``test.c`` |
| 144 | | file. Of course, the ``8617`` is different for different random-seed |
| 145 | | values. The number between the two ``@@@`` occurrences in the wildcard |
| 146 | | designates which pattern must consistently match. |
| 147 | |
| 148 | * - ``@@002@10@@`` (``@@``, a pattern number, ``@``, a pattern size, ``@@``) |
| 149 | - | This is a slight variant upon the previous wildcard, in which a specific |
| 150 | | match length is required. In lines 47 and 48 above, random data |
| 151 | | generated consists of 10 characters (thus the ... ``@10@@`` in the |
| 152 | | wildcard) ``Gaa wuqnoe`` followed by other characters we don't care |
| 153 | | about; they can be anything. Thus ``@@002@10@@[a-z\ ]*[\.\?\!]`` in |
| 154 | | line 47: The ``@@002@10@@`` denotes a pattern number 002 for a length |
| 155 | | of 10 characters that must match ``Gaa wuqnoe`` in this case, followed |
| 156 | | by some arbitrary number of characters we don't care about, thus |
| 157 | | ``[a-z\ ]*[\.\?\!]`` -- a sequence of lower-case letters or spaces, |
| 158 | | capped off with normal sentence-ending punctuation. |
| 159 | |
| 160 | After the ``check.py`` capability -- resolving these wildcards -- for this |
| 161 | purpose is fleshed out, we shall have to figure out how to address |
| 162 | ``shuffle {}`` and ``5 to 8 of {}`` randomizations. |
| 163 | |
| 164 | The ``add_these_tests`` directory contains regression tests of the above nature |
| 165 | that the regression framework is not currently able to address. |
| 166 | |
| 167 | -------------- |
| 168 | |
| 169 | *Copyright (c) 2020, Arm Limited. All rights reserved.* |