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    ./framework/scripts/recursion.pl library/*.c
15    ./framework/scripts/recursion.pl ${PSA_CORE_PATH}/*.c
16    ./framework/scripts/recursion.pl ${BUILTIN_SRC_PATH}/*.c
17}
18
19component_check_generated_files () {
20    msg "Check make_generated_files.py consistency"
21    make neat
22    $FRAMEWORK/scripts/make_generated_files.py
23    $FRAMEWORK/scripts/make_generated_files.py --check
24    make neat
25
26    msg "Check files generated with make"
27    MBEDTLS_ROOT_DIR="$PWD"
28    make generated_files
29    $FRAMEWORK/scripts/make_generated_files.py --check
30
31    cd $TF_PSA_CRYPTO_ROOT_DIR
32    ./framework/scripts/make_generated_files.py --check
33
34    msg "Check files generated with cmake"
35    cd "$MBEDTLS_ROOT_DIR"
36    mkdir "$OUT_OF_SOURCE_DIR"
37    cd "$OUT_OF_SOURCE_DIR"
38    cmake -D GEN_FILES=ON "$MBEDTLS_ROOT_DIR"
39    make
40    cd "$MBEDTLS_ROOT_DIR"
41
42    # Files for MS Visual Studio are not generated with cmake thus copy the
43    # ones generated with make to pacify make_generated_files.py check.
44    # Files for MS Visual Studio are rather on their way out thus not adding
45    # support for them with cmake.
46    cp -Rf visualc "$OUT_OF_SOURCE_DIR"
47
48    $FRAMEWORK/scripts/make_generated_files.py --root "$OUT_OF_SOURCE_DIR" --check
49
50    cd $TF_PSA_CRYPTO_ROOT_DIR
51    ./framework/scripts/make_generated_files.py --root "$OUT_OF_SOURCE_DIR/tf-psa-crypto" --check
52
53    # This component ends with the generated files present in the source tree.
54    # This is necessary for subsequent components!
55}
56
57component_check_doxy_blocks () {
58    msg "Check: doxygen markup outside doxygen blocks" # < 1s
59    ./framework/scripts/check-doxy-blocks.pl
60}
61
62component_check_files () {
63    msg "Check: file sanity checks (permissions, encodings)" # < 1s
64    framework/scripts/check_files.py
65}
66
67component_check_changelog () {
68    msg "Check: changelog entries" # < 1s
69    rm -f ChangeLog.new
70    ./framework/scripts/assemble_changelog.py -o ChangeLog.new
71    if [ -e ChangeLog.new ]; then
72        # Show the diff for information. It isn't an error if the diff is
73        # non-empty.
74        diff -u ChangeLog ChangeLog.new || true
75        rm ChangeLog.new
76    fi
77}
78
79component_check_names () {
80    msg "Check: declared and exported names (builds the library)" # < 3s
81    framework/scripts/check_names.py -v
82}
83
84component_check_test_cases () {
85    msg "Check: test case descriptions" # < 1s
86    if [ $QUIET -eq 1 ]; then
87        opt='--quiet'
88    else
89        opt=''
90    fi
91    framework/scripts/check_test_cases.py -q $opt
92    unset opt
93}
94
95component_check_doxygen_warnings () {
96    msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
97    ./framework/scripts/doxygen.sh
98}
99
100component_check_code_style () {
101    msg "Check C code style"
102    ./framework/scripts/code_style.py
103}
104
105support_check_code_style () {
106    case $(uncrustify --version) in
107        *0.75.1*) true;;
108        *) false;;
109    esac
110}
111
112component_check_python_files () {
113    msg "Lint: Python scripts"
114    ./framework/scripts/check-python-files.sh
115}
116
117component_check_test_helpers () {
118    msg "unit test: generate_test_code.py"
119    # unittest writes out mundane stuff like number or tests run on stderr.
120    # Our convention is to reserve stderr for actual errors, and write
121    # harmless info on stdout so it can be suppress with --quiet.
122    ./framework/scripts/test_generate_test_code.py 2>&1
123
124    msg "unit test: translate_ciphers.py"
125    python3 -m unittest framework/scripts/translate_ciphers.py 2>&1
126
127    msg "unit test: generate_config_checks.py"
128    tests/scripts/test_config_checks.py 2>&1
129}
130