blob: fa9e99bd96b2356217ca1e8e77d8963d4b8e68cb [file] [log] [blame]
Minos Galanakis6aab5b72024-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
Minos Galanakis609f7492024-07-31 16:39:28 +01006# This file contains test components that are executed by all.sh
Minos Galanakis6aab5b72024-07-25 14:24:37 +01007
8################################################################
9#### Basic checks
10################################################################
11
Minos Galanakis85c78f52024-07-26 14:11:08 +010012component_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
19component_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
39component_check_doxy_blocks () {
40 msg "Check: doxygen markup outside doxygen blocks" # < 1s
41 tests/scripts/check-doxy-blocks.pl
42}
43
44component_check_files () {
45 msg "Check: file sanity checks (permissions, encodings)" # < 1s
46 tests/scripts/check_files.py
47}
48
49component_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
61component_check_names () {
62 msg "Check: declared and exported names (builds the library)" # < 3s
63 tests/scripts/check_names.py -v
64}
65
66component_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 Peskine31467722024-10-03 18:52:58 +020073 framework/scripts/check_test_cases.py -q $opt
Minos Galanakis85c78f52024-07-26 14:11:08 +010074 unset opt
75}
76
77component_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
Valerio Setti7213fbc2024-09-27 09:35:20 +0200112 # No PSA equivalent - used in test_suite_psa_crypto to get some "known" size
113 # for raw key generation.
114 echo "MBEDTLS_CTR_DRBG_MAX_REQUEST" >> $expected
Minos Galanakis85c78f52024-07-26 14:11:08 +0100115 # No PSA equivalent - we should probably have one in the future.
116 echo "MBEDTLS_ECP_RESTARTABLE" >> $expected
117 # No PSA equivalent - needed by some init tests
118 echo "MBEDTLS_ENTROPY_NV_SEED" >> $expected
119 # No PSA equivalent - required to run threaded tests.
120 echo "MBEDTLS_THREADING_PTHREAD" >> $expected
121
122 # Compare reality with expectation.
123 # We want an exact match, to ensure the above list remains up-to-date.
124 #
125 # The output should be empty. When it's not:
126 # - Each '+' line is a macro that was found but not expected. You want to
127 # find where that macro occurs, and either replace it with PSA macros, or
128 # add it to the exceptions list above with a justification.
129 # - Each '-' line is a macro that was expected but not found; it means the
130 # exceptions list above should be updated by removing that macro.
131 diff -U0 $expected $found
132
133 rm $found $expected
134}
135
136component_check_doxygen_warnings () {
137 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
138 tests/scripts/doxygen.sh
139}
140
141component_check_code_style () {
142 msg "Check C code style"
Elena Uziunaitee0d3ffe2024-12-10 15:22:34 +0000143 ./framework/scripts/code_style.py
Minos Galanakis85c78f52024-07-26 14:11:08 +0100144}
145
Minos Galanakisf78447f2024-07-26 20:49:51 +0100146support_check_code_style () {
Minos Galanakis85c78f52024-07-26 14:11:08 +0100147 case $(uncrustify --version) in
148 *0.75.1*) true;;
149 *) false;;
150 esac
151}
152
153component_check_python_files () {
154 msg "Lint: Python scripts"
155 tests/scripts/check-python-files.sh
156}
157
158component_check_test_helpers () {
159 msg "unit test: generate_test_code.py"
160 # unittest writes out mundane stuff like number or tests run on stderr.
161 # Our convention is to reserve stderr for actual errors, and write
162 # harmless info on stdout so it can be suppress with --quiet.
163 ./framework/scripts/test_generate_test_code.py 2>&1
164
165 msg "unit test: translate_ciphers.py"
Elena Uziunaite9669eea2024-10-08 16:41:15 +0100166 python3 -m unittest framework/scripts/translate_ciphers.py 2>&1
Minos Galanakis85c78f52024-07-26 14:11:08 +0100167}