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