Minos Galanakis | 6aab5b7 | 2024-07-25 14:24:37 +0100 | [diff] [blame] | 1 | # components-build-system.sh |
| 2 | # |
| 3 | # Copyright The Mbed TLS Contributors |
| 4 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 5 | |
Minos Galanakis | 609f749 | 2024-07-31 16:39:28 +0100 | [diff] [blame] | 6 | # This file contains test components that are executed by all.sh |
Minos Galanakis | 6aab5b7 | 2024-07-25 14:24:37 +0100 | [diff] [blame] | 7 | |
| 8 | ################################################################ |
| 9 | #### Build System Testing |
| 10 | ################################################################ |
| 11 | |
Minos Galanakis | 5357def | 2024-07-26 14:18:23 +0100 | [diff] [blame] | 12 | component_test_make_shared () { |
| 13 | msg "build/test: make shared" # ~ 40s |
Gilles Peskine | 62ee8fd | 2024-06-06 22:12:06 +0200 | [diff] [blame] | 14 | make SHARED=1 TEST_CPP=1 all check |
Minos Galanakis | 5357def | 2024-07-26 14:18:23 +0100 | [diff] [blame] | 15 | ldd programs/util/strerror | grep libmbedcrypto |
| 16 | programs/test/dlopen_demo.sh |
| 17 | } |
Minos Galanakis | 6aab5b7 | 2024-07-25 14:24:37 +0100 | [diff] [blame] | 18 | |
Minos Galanakis | 5357def | 2024-07-26 14:18:23 +0100 | [diff] [blame] | 19 | component_test_cmake_shared () { |
| 20 | msg "build/test: cmake shared" # ~ 2min |
| 21 | cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On . |
| 22 | make |
Ronald Cron | 8126a68 | 2024-10-25 17:34:23 +0200 | [diff] [blame] | 23 | ldd programs/util/strerror | grep libtfpsacrypto |
Minos Galanakis | 5357def | 2024-07-26 14:18:23 +0100 | [diff] [blame] | 24 | make test |
| 25 | programs/test/dlopen_demo.sh |
| 26 | } |
| 27 | |
| 28 | support_test_cmake_out_of_source () { |
| 29 | distrib_id="" |
| 30 | distrib_ver="" |
| 31 | distrib_ver_minor="" |
| 32 | distrib_ver_major="" |
| 33 | |
| 34 | # Attempt to parse lsb-release to find out distribution and version. If not |
| 35 | # found this should fail safe (test is supported). |
| 36 | if [[ -f /etc/lsb-release ]]; then |
| 37 | |
| 38 | while read -r lsb_line; do |
| 39 | case "$lsb_line" in |
| 40 | "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};; |
| 41 | "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};; |
| 42 | esac |
| 43 | done < /etc/lsb-release |
| 44 | |
| 45 | distrib_ver_major="${distrib_ver%%.*}" |
| 46 | distrib_ver="${distrib_ver#*.}" |
| 47 | distrib_ver_minor="${distrib_ver%%.*}" |
| 48 | fi |
| 49 | |
| 50 | # Running the out of source CMake test on Ubuntu 16.04 using more than one |
| 51 | # processor (as the CI does) can create a race condition whereby the build |
| 52 | # fails to see a generated file, despite that file actually having been |
| 53 | # generated. This problem appears to go away with 18.04 or newer, so make |
| 54 | # the out of source tests unsupported on Ubuntu 16.04. |
| 55 | [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ] |
| 56 | } |
| 57 | |
| 58 | component_test_cmake_out_of_source () { |
| 59 | # Remove existing generated files so that we use the ones cmake |
| 60 | # generates |
| 61 | make neat |
| 62 | |
| 63 | msg "build: cmake 'out-of-source' build" |
| 64 | MBEDTLS_ROOT_DIR="$PWD" |
| 65 | mkdir "$OUT_OF_SOURCE_DIR" |
| 66 | cd "$OUT_OF_SOURCE_DIR" |
| 67 | # Note: Explicitly generate files as these are turned off in releases |
Gilles Peskine | 236e05d | 2024-09-11 17:51:11 +0200 | [diff] [blame] | 68 | cmake -D CMAKE_BUILD_TYPE:String=Check -D GEN_FILES=ON -D TEST_CPP=1 "$MBEDTLS_ROOT_DIR" |
Minos Galanakis | 5357def | 2024-07-26 14:18:23 +0100 | [diff] [blame] | 69 | make |
| 70 | |
| 71 | msg "test: cmake 'out-of-source' build" |
| 72 | make test |
| 73 | # Check that ssl-opt.sh can find the test programs. |
| 74 | # Also ensure that there are no error messages such as |
| 75 | # "No such file or directory", which would indicate that some required |
| 76 | # file is missing (ssl-opt.sh tolerates the absence of some files so |
| 77 | # may exit with status 0 but emit errors). |
| 78 | ./tests/ssl-opt.sh -f 'Default' >ssl-opt.out 2>ssl-opt.err |
| 79 | grep PASS ssl-opt.out |
| 80 | cat ssl-opt.err >&2 |
| 81 | # If ssl-opt.err is non-empty, record an error and keep going. |
| 82 | [ ! -s ssl-opt.err ] |
| 83 | rm ssl-opt.out ssl-opt.err |
| 84 | cd "$MBEDTLS_ROOT_DIR" |
| 85 | rm -rf "$OUT_OF_SOURCE_DIR" |
| 86 | } |
| 87 | |
| 88 | component_test_cmake_as_subdirectory () { |
| 89 | # Remove existing generated files so that we use the ones CMake |
| 90 | # generates |
| 91 | make neat |
| 92 | |
| 93 | msg "build: cmake 'as-subdirectory' build" |
| 94 | cd programs/test/cmake_subproject |
| 95 | # Note: Explicitly generate files as these are turned off in releases |
| 96 | cmake -D GEN_FILES=ON . |
| 97 | make |
| 98 | ./cmake_subproject |
| 99 | } |
| 100 | |
| 101 | support_test_cmake_as_subdirectory () { |
| 102 | support_test_cmake_out_of_source |
| 103 | } |
| 104 | |
| 105 | component_test_cmake_as_package () { |
| 106 | # Remove existing generated files so that we use the ones CMake |
| 107 | # generates |
| 108 | make neat |
| 109 | |
| 110 | msg "build: cmake 'as-package' build" |
Bill Roberts | 10ff417 | 2024-03-25 08:52:47 -0500 | [diff] [blame] | 111 | root_dir="$(pwd)" |
Minos Galanakis | 5357def | 2024-07-26 14:18:23 +0100 | [diff] [blame] | 112 | cd programs/test/cmake_package |
Bill Roberts | 10ff417 | 2024-03-25 08:52:47 -0500 | [diff] [blame] | 113 | build_variant_dir="$(pwd)" |
Minos Galanakis | 5357def | 2024-07-26 14:18:23 +0100 | [diff] [blame] | 114 | cmake . |
| 115 | make |
| 116 | ./cmake_package |
Bill Roberts | 10ff417 | 2024-03-25 08:52:47 -0500 | [diff] [blame] | 117 | if [[ "$OSTYPE" == linux* ]]; then |
Ronald Cron | 4870e61 | 2024-10-17 17:49:57 +0200 | [diff] [blame] | 118 | PKG_CONFIG_PATH="${build_variant_dir}/mbedtls/pkgconfig" \ |
| 119 | ${root_dir}/tests/scripts/pkgconfig.sh \ |
| 120 | mbedtls mbedx509 mbedcrypto |
| 121 | # These are the EXPECTED package names. Renaming these could break |
| 122 | # consumers of pkg-config, consider carefully. |
Bill Roberts | 10ff417 | 2024-03-25 08:52:47 -0500 | [diff] [blame] | 123 | fi |
Minos Galanakis | 5357def | 2024-07-26 14:18:23 +0100 | [diff] [blame] | 124 | } |
| 125 | |
Ronald Cron | 4cd797e | 2024-10-17 17:50:32 +0200 | [diff] [blame] | 126 | component_test_tf_psa_crypto_cmake_as_package () { |
| 127 | # Remove existing generated files so that we use the ones CMake |
| 128 | # generates |
| 129 | make neat |
| 130 | |
| 131 | msg "build: cmake 'as-package' build" |
| 132 | root_dir="$(pwd)" |
| 133 | cd tf-psa-crypto/programs/test/cmake_package |
| 134 | build_variant_dir="$(pwd)" |
| 135 | cmake . |
| 136 | make |
| 137 | ./cmake_package |
| 138 | if [[ "$OSTYPE" == linux* ]]; then |
| 139 | PKG_CONFIG_PATH="${build_variant_dir}/tf-psa-crypto/pkgconfig" \ |
| 140 | ${root_dir}/tests/scripts/pkgconfig.sh \ |
| 141 | tfpsacrypto |
| 142 | # This is the EXPECTED package name. Renaming it could break consumers |
| 143 | # of pkg-config, consider carefully. |
| 144 | fi |
| 145 | } |
| 146 | |
Minos Galanakis | 5357def | 2024-07-26 14:18:23 +0100 | [diff] [blame] | 147 | support_test_cmake_as_package () { |
| 148 | support_test_cmake_out_of_source |
| 149 | } |
| 150 | |
| 151 | component_test_cmake_as_package_install () { |
| 152 | # Remove existing generated files so that we use the ones CMake |
| 153 | # generates |
| 154 | make neat |
| 155 | |
| 156 | msg "build: cmake 'as-installed-package' build" |
| 157 | cd programs/test/cmake_package_install |
| 158 | cmake . |
| 159 | make |
| 160 | ./cmake_package_install |
| 161 | } |
| 162 | |
| 163 | support_test_cmake_as_package_install () { |
| 164 | support_test_cmake_out_of_source |
| 165 | } |
| 166 | |
| 167 | component_build_cmake_custom_config_file () { |
| 168 | # Make a copy of config file to use for the in-tree test |
| 169 | cp "$CONFIG_H" include/mbedtls_config_in_tree_copy.h |
| 170 | |
| 171 | MBEDTLS_ROOT_DIR="$PWD" |
| 172 | mkdir "$OUT_OF_SOURCE_DIR" |
| 173 | cd "$OUT_OF_SOURCE_DIR" |
| 174 | |
| 175 | # Build once to get the generated files (which need an intact config file) |
| 176 | cmake "$MBEDTLS_ROOT_DIR" |
| 177 | make |
| 178 | |
| 179 | msg "build: cmake with -DMBEDTLS_CONFIG_FILE" |
| 180 | scripts/config.py -w full_config.h full |
| 181 | echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H" |
| 182 | cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h "$MBEDTLS_ROOT_DIR" |
| 183 | make |
| 184 | |
| 185 | msg "build: cmake with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE" |
| 186 | # In the user config, disable one feature (for simplicity, pick a feature |
| 187 | # that nothing else depends on). |
| 188 | echo '#undef MBEDTLS_NIST_KW_C' >user_config.h |
| 189 | |
| 190 | cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h "$MBEDTLS_ROOT_DIR" |
| 191 | make |
| 192 | not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C |
| 193 | |
| 194 | rm -f user_config.h full_config.h |
| 195 | |
| 196 | cd "$MBEDTLS_ROOT_DIR" |
| 197 | rm -rf "$OUT_OF_SOURCE_DIR" |
| 198 | |
| 199 | # Now repeat the test for an in-tree build: |
| 200 | |
| 201 | # Restore config for the in-tree test |
| 202 | mv include/mbedtls_config_in_tree_copy.h "$CONFIG_H" |
| 203 | |
| 204 | # Build once to get the generated files (which need an intact config) |
| 205 | cmake . |
| 206 | make |
| 207 | |
| 208 | msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE" |
| 209 | scripts/config.py -w full_config.h full |
| 210 | echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H" |
| 211 | cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h . |
| 212 | make |
| 213 | |
| 214 | msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE" |
| 215 | # In the user config, disable one feature (for simplicity, pick a feature |
| 216 | # that nothing else depends on). |
| 217 | echo '#undef MBEDTLS_NIST_KW_C' >user_config.h |
| 218 | |
| 219 | cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h . |
| 220 | make |
| 221 | not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C |
| 222 | |
| 223 | rm -f user_config.h full_config.h |
| 224 | } |
| 225 | |
| 226 | support_build_cmake_custom_config_file () { |
| 227 | support_test_cmake_out_of_source |
| 228 | } |
| 229 | |
| 230 | component_build_cmake_programs_no_testing () { |
| 231 | # Verify that the type of builds performed by oss-fuzz don't get accidentally broken |
| 232 | msg "build: cmake with -DENABLE_PROGRAMS=ON and -DENABLE_TESTING=OFF" |
| 233 | cmake -DENABLE_PROGRAMS=ON -DENABLE_TESTING=OFF . |
| 234 | make |
| 235 | } |
| 236 | support_build_cmake_programs_no_testing () { |
| 237 | support_test_cmake_out_of_source |
| 238 | } |