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