Minos Galanakis | 6aab5b7 | 2024-07-25 14:24:37 +0100 | [diff] [blame] | 1 | # components-basic-checks.sh |
| 2 | # |
| 3 | # Copyright The Mbed TLS Contributors |
| 4 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 5 | |
Minos Galanakis | 609f749 | 2024-07-31 16:39:28 +0100 | [diff] [blame] | 6 | # This file contains test components that are executed by all.sh |
Minos Galanakis | 6aab5b7 | 2024-07-25 14:24:37 +0100 | [diff] [blame] | 7 | |
| 8 | ################################################################ |
| 9 | #### Basic checks |
| 10 | ################################################################ |
| 11 | |
Minos Galanakis | 85c78f5 | 2024-07-26 14:11:08 +0100 | [diff] [blame] | 12 | component_check_recursion () { |
| 13 | msg "Check: recursion.pl" # < 1s |
| 14 | tests/scripts/recursion.pl library/*.c |
| 15 | tests/scripts/recursion.pl ${PSA_CORE_PATH}/*.c |
| 16 | tests/scripts/recursion.pl ${BUILTIN_SRC_PATH}/*.c |
| 17 | } |
| 18 | |
| 19 | component_check_generated_files () { |
| 20 | msg "Check: check-generated-files, files generated with make" # 2s |
| 21 | make generated_files |
| 22 | tests/scripts/check-generated-files.sh |
| 23 | |
| 24 | msg "Check: check-generated-files -u, files present" # 2s |
| 25 | tests/scripts/check-generated-files.sh -u |
| 26 | # Check that the generated files are considered up to date. |
| 27 | tests/scripts/check-generated-files.sh |
| 28 | |
| 29 | msg "Check: check-generated-files -u, files absent" # 2s |
| 30 | command make neat |
| 31 | tests/scripts/check-generated-files.sh -u |
| 32 | # Check that the generated files are considered up to date. |
| 33 | tests/scripts/check-generated-files.sh |
| 34 | |
| 35 | # This component ends with the generated files present in the source tree. |
| 36 | # This is necessary for subsequent components! |
| 37 | } |
| 38 | |
| 39 | component_check_doxy_blocks () { |
| 40 | msg "Check: doxygen markup outside doxygen blocks" # < 1s |
| 41 | tests/scripts/check-doxy-blocks.pl |
| 42 | } |
| 43 | |
| 44 | component_check_files () { |
| 45 | msg "Check: file sanity checks (permissions, encodings)" # < 1s |
| 46 | tests/scripts/check_files.py |
| 47 | } |
| 48 | |
| 49 | component_check_changelog () { |
| 50 | msg "Check: changelog entries" # < 1s |
| 51 | rm -f ChangeLog.new |
| 52 | scripts/assemble_changelog.py -o ChangeLog.new |
| 53 | if [ -e ChangeLog.new ]; then |
| 54 | # Show the diff for information. It isn't an error if the diff is |
| 55 | # non-empty. |
| 56 | diff -u ChangeLog ChangeLog.new || true |
| 57 | rm ChangeLog.new |
| 58 | fi |
| 59 | } |
| 60 | |
| 61 | component_check_names () { |
| 62 | msg "Check: declared and exported names (builds the library)" # < 3s |
| 63 | tests/scripts/check_names.py -v |
| 64 | } |
| 65 | |
| 66 | component_check_test_cases () { |
| 67 | msg "Check: test case descriptions" # < 1s |
| 68 | if [ $QUIET -eq 1 ]; then |
| 69 | opt='--quiet' |
| 70 | else |
| 71 | opt='' |
| 72 | fi |
Gilles Peskine | 3146772 | 2024-10-03 18:52:58 +0200 | [diff] [blame] | 73 | framework/scripts/check_test_cases.py -q $opt |
Minos Galanakis | 85c78f5 | 2024-07-26 14:11:08 +0100 | [diff] [blame] | 74 | unset opt |
| 75 | } |
| 76 | |
| 77 | component_check_test_dependencies () { |
| 78 | msg "Check: test case dependencies: legacy vs PSA" # < 1s |
| 79 | # The purpose of this component is to catch unjustified dependencies on |
| 80 | # legacy feature macros (MBEDTLS_xxx) in PSA tests. Generally speaking, |
| 81 | # PSA test should use PSA feature macros (PSA_WANT_xxx, more rarely |
| 82 | # MBEDTLS_PSA_xxx). |
| 83 | # |
| 84 | # Most of the time, use of legacy MBEDTLS_xxx macros are mistakes, which |
| 85 | # this component is meant to catch. However a few of them are justified, |
| 86 | # mostly by the absence of a PSA equivalent, so this component includes a |
| 87 | # list of expected exceptions. |
| 88 | |
| 89 | found="check-test-deps-found-$$" |
| 90 | expected="check-test-deps-expected-$$" |
| 91 | |
| 92 | # Find legacy dependencies in PSA tests |
| 93 | grep 'depends_on' \ |
| 94 | tf-psa-crypto/tests/suites/test_suite_psa*.data \ |
| 95 | tf-psa-crypto/tests/suites/test_suite_psa*.function | |
| 96 | grep -Eo '!?MBEDTLS_[^: ]*' | |
| 97 | grep -v -e MBEDTLS_PSA_ -e MBEDTLS_TEST_ | |
| 98 | sort -u > $found |
| 99 | |
| 100 | # Expected ones with justification - keep in sorted order by ASCII table! |
| 101 | rm -f $expected |
| 102 | # No PSA equivalent - WANT_KEY_TYPE_AES means all sizes |
| 103 | echo "!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH" >> $expected |
| 104 | # No PSA equivalent - used to skip decryption tests in PSA-ECB, CBC/XTS/NIST_KW/DES |
| 105 | echo "!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT" >> $expected |
| 106 | # MBEDTLS_ASN1_WRITE_C is used by import_rsa_made_up() in test_suite_psa_crypto |
| 107 | # in order to build a fake RSA key of the wanted size based on |
| 108 | # PSA_VENDOR_RSA_MAX_KEY_BITS. The legacy module is only used by |
| 109 | # the test code and that's probably the most convenient way of achieving |
| 110 | # the test's goal. |
| 111 | echo "MBEDTLS_ASN1_WRITE_C" >> $expected |
| 112 | # No PSA equivalent - we should probably have one in the future. |
| 113 | echo "MBEDTLS_ECP_RESTARTABLE" >> $expected |
| 114 | # No PSA equivalent - needed by some init tests |
| 115 | echo "MBEDTLS_ENTROPY_NV_SEED" >> $expected |
| 116 | # No PSA equivalent - required to run threaded tests. |
| 117 | echo "MBEDTLS_THREADING_PTHREAD" >> $expected |
| 118 | |
| 119 | # Compare reality with expectation. |
| 120 | # We want an exact match, to ensure the above list remains up-to-date. |
| 121 | # |
| 122 | # The output should be empty. When it's not: |
| 123 | # - Each '+' line is a macro that was found but not expected. You want to |
| 124 | # find where that macro occurs, and either replace it with PSA macros, or |
| 125 | # add it to the exceptions list above with a justification. |
| 126 | # - Each '-' line is a macro that was expected but not found; it means the |
| 127 | # exceptions list above should be updated by removing that macro. |
| 128 | diff -U0 $expected $found |
| 129 | |
| 130 | rm $found $expected |
| 131 | } |
| 132 | |
| 133 | component_check_doxygen_warnings () { |
| 134 | msg "Check: doxygen warnings (builds the documentation)" # ~ 3s |
| 135 | tests/scripts/doxygen.sh |
| 136 | } |
| 137 | |
| 138 | component_check_code_style () { |
| 139 | msg "Check C code style" |
| 140 | ./scripts/code_style.py |
| 141 | } |
| 142 | |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 143 | support_check_code_style () { |
Minos Galanakis | 85c78f5 | 2024-07-26 14:11:08 +0100 | [diff] [blame] | 144 | case $(uncrustify --version) in |
| 145 | *0.75.1*) true;; |
| 146 | *) false;; |
| 147 | esac |
| 148 | } |
| 149 | |
| 150 | component_check_python_files () { |
| 151 | msg "Lint: Python scripts" |
| 152 | tests/scripts/check-python-files.sh |
| 153 | } |
| 154 | |
| 155 | component_check_test_helpers () { |
| 156 | msg "unit test: generate_test_code.py" |
| 157 | # unittest writes out mundane stuff like number or tests run on stderr. |
| 158 | # Our convention is to reserve stderr for actual errors, and write |
| 159 | # harmless info on stdout so it can be suppress with --quiet. |
| 160 | ./framework/scripts/test_generate_test_code.py 2>&1 |
| 161 | |
| 162 | msg "unit test: translate_ciphers.py" |
| 163 | python3 -m unittest tests/scripts/translate_ciphers.py 2>&1 |
| 164 | } |
Minos Galanakis | 6aab5b7 | 2024-07-25 14:24:37 +0100 | [diff] [blame] | 165 | |