blob: 7b60b49ca4660a62d4de048a2b6e30be1a61cdd7 [file] [log] [blame]
Minos Galanakis77711192024-07-25 14:24:37 +01001# 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################################################################
Minos Galanakise4317392024-08-01 16:47:29 +010011
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
Gilles Peskine738a5972024-10-03 18:52:58 +020071 framework/scripts/check_test_cases.py -q $opt
Minos Galanakise4317392024-08-01 16:47:29 +010072 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
Valerio Setti5fbb0e82024-09-27 09:35:20 +0200109 # No PSA equivalent - used in test_suite_psa_crypto to get some "known" size
110 # for raw key generation.
111 echo "MBEDTLS_CTR_DRBG_MAX_REQUEST" >> $expected
Minos Galanakise4317392024-08-01 16:47:29 +0100112 # 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
133component_check_doxygen_warnings () {
134 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
135 tests/scripts/doxygen.sh
136}
137
138component_check_code_style () {
139 msg "Check C code style"
140 ./scripts/code_style.py
141}
142
143support_check_code_style () {
144 case $(uncrustify --version) in
145 *0.75.1*) true;;
146 *) false;;
147 esac
148}
149
150component_check_python_files () {
151 msg "Lint: Python scripts"
152 tests/scripts/check-python-files.sh
153}
154
155component_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"
Elena Uziunaitea7395422024-10-08 16:41:15 +0100163 python3 -m unittest framework/scripts/translate_ciphers.py 2>&1
Minos Galanakise4317392024-08-01 16:47:29 +0100164}