Gabor Mezei | 95ecaaf | 2023-01-16 16:53:29 +0100 | [diff] [blame^] | 1 | #!/usr/bin/env python3 |
| 2 | """Generate test data for ecp functions. |
| 3 | |
| 4 | With no arguments, generate all test data. With non-option arguments, |
| 5 | generate only the specified files. |
| 6 | |
| 7 | Class structure: |
| 8 | |
| 9 | Child classes of test_data_generation.BaseTarget (file targets) represent an output |
| 10 | file. These indicate where test cases will be written to, for all subclasses of |
| 11 | this target. Multiple file targets should not reuse a `target_basename`. |
| 12 | |
| 13 | Each subclass derived from a file target can either be: |
| 14 | - A concrete class, representing a test function, which generates test cases. |
| 15 | - An abstract class containing shared methods and attributes, not associated |
| 16 | with a test function. |
| 17 | |
| 18 | Both concrete and abstract subclasses can be derived from, to implement |
| 19 | additional test cases (see BignumCmp and BignumCmpAbs for examples of deriving |
| 20 | from abstract and concrete classes). |
| 21 | |
| 22 | |
| 23 | Adding test case generation for a function: |
| 24 | |
| 25 | A subclass representing the test function should be added, deriving from a |
| 26 | file target such as BignumTarget. This test class must set/implement the |
| 27 | following: |
| 28 | - test_function: the function name from the associated .function file. |
| 29 | - test_name: a descriptive name or brief summary to refer to the test |
| 30 | function. |
| 31 | - arguments(): a method to generate the list of arguments required for the |
| 32 | test_function. |
| 33 | - generate_function_tests(): a method to generate TestCases for the function. |
| 34 | This should create instances of the class with required input data, and |
| 35 | call `.create_test_case()` to yield the TestCase. |
| 36 | |
| 37 | Additional details and other attributes/methods are given in the documentation |
| 38 | of BaseTarget in test_data_generation.py. |
| 39 | """ |
| 40 | |
| 41 | # Copyright The Mbed TLS Contributors |
| 42 | # SPDX-License-Identifier: Apache-2.0 |
| 43 | # |
| 44 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 45 | # not use this file except in compliance with the License. |
| 46 | # You may obtain a copy of the License at |
| 47 | # |
| 48 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 49 | # |
| 50 | # Unless required by applicable law or agreed to in writing, software |
| 51 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 52 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 53 | # See the License for the specific language governing permissions and |
| 54 | # limitations under the License. |
| 55 | |
| 56 | import sys |
| 57 | |
| 58 | import scripts_path # pylint: disable=unused-import |
| 59 | from mbedtls_dev import test_data_generation |
| 60 | # Import modules containing additional test classes |
| 61 | # Test function classes in these modules will be registered by |
| 62 | # the framework |
| 63 | from mbedtls_dev import ecp # pylint: disable=unused-import |
| 64 | |
| 65 | if __name__ == '__main__': |
| 66 | # Use the section of the docstring relevant to the CLI as description |
| 67 | test_data_generation.main(sys.argv[1:], "\n".join(__doc__.splitlines()[:4])) |