quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

components-platform.sh (26536B)


      1 # components-platform.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 #### Platform Testing
     10 ################################################################
     11 
     12 support_test_aesni () {
     13     # Check that gcc targets x86_64 (we can build AESNI), and check for
     14     # AESNI support on the host (we can run AESNI).
     15     #
     16     # The name of this function is possibly slightly misleading, but needs to align
     17     # with the name of the corresponding test, component_test_aesni.
     18     #
     19     # In principle 32-bit x86 can support AESNI, but our implementation does not
     20     # support 32-bit x86, so we check for x86-64.
     21     # We can only grep /proc/cpuinfo on Linux, so this also checks for Linux
     22     (gcc -v 2>&1 | grep Target | grep -q x86_64) &&
     23         [[ "$HOSTTYPE" == "x86_64" && "$OSTYPE" == "linux-gnu" ]] &&
     24         (lscpu | grep -qw aes)
     25 }
     26 
     27 component_test_aesni () { # ~ 60s
     28     # This tests the two AESNI implementations (intrinsics and assembly), and also the plain C
     29     # fallback. It also tests the logic that is used to select which implementation(s) to build.
     30     #
     31     # This test does not require the host to have support for AESNI (if it doesn't, the run-time
     32     # AESNI detection will fallback to the plain C implementation, so the tests will instead
     33     # exercise the plain C impl).
     34 
     35     msg "build: default config with different AES implementations"
     36     scripts/config.py set MBEDTLS_AESNI_C
     37     scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
     38     scripts/config.py set MBEDTLS_HAVE_ASM
     39 
     40     # test the intrinsics implementation
     41     msg "AES tests, test intrinsics"
     42     make clean
     43     make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
     44     # check that we built intrinsics - this should be used by default when supported by the compiler
     45     ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
     46 
     47     # test the asm implementation
     48     msg "AES tests, test assembly"
     49     make clean
     50     make CC=gcc CFLAGS='-Werror -Wall -Wextra -mno-pclmul -mno-sse2 -mno-aes'
     51     # check that we built assembly - this should be built if the compiler does not support intrinsics
     52     ./programs/test/selftest aes | grep "AESNI code" | grep -q "assembly"
     53 
     54     # test the plain C implementation
     55     scripts/config.py unset MBEDTLS_AESNI_C
     56     scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
     57     msg "AES tests, plain C"
     58     make clean
     59     make CC=gcc CFLAGS='-O2 -Werror'
     60     # check that there is no AESNI code present
     61     ./programs/test/selftest aes | not grep -q "AESNI code"
     62     not grep -q "AES note: using AESNI" ./programs/test/selftest
     63     grep -q "AES note: built-in implementation." ./programs/test/selftest
     64 
     65     # test the intrinsics implementation
     66     scripts/config.py set MBEDTLS_AESNI_C
     67     scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
     68     msg "AES tests, test AESNI only"
     69     make clean
     70     make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
     71     ./programs/test/selftest aes | grep -q "AES note: using AESNI"
     72     ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
     73     grep -q "AES note: using AESNI" ./programs/test/selftest
     74     not grep -q "AES note: built-in implementation." ./programs/test/selftest
     75 }
     76 
     77 support_test_aesni_m32 () {
     78     support_test_m32_no_asm && (lscpu | grep -qw aes)
     79 }
     80 
     81 component_test_aesni_m32 () { # ~ 60s
     82     # This tests are duplicated from component_test_aesni for i386 target
     83     #
     84     # AESNI intrinsic code supports i386 and assembly code does not support it.
     85 
     86     msg "build: default config with different AES implementations"
     87     scripts/config.py set MBEDTLS_AESNI_C
     88     scripts/config.py set MBEDTLS_PADLOCK_C
     89     scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
     90     scripts/config.py set MBEDTLS_HAVE_ASM
     91 
     92     # test the intrinsics implementation with gcc
     93     msg "AES tests, test intrinsics (gcc)"
     94     make clean
     95     make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra' LDFLAGS='-m32'
     96     # check that we built intrinsics - this should be used by default when supported by the compiler
     97     ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
     98     grep -q "AES note: using AESNI" ./programs/test/selftest
     99     grep -q "AES note: built-in implementation." ./programs/test/selftest
    100     grep -q "AES note: using VIA Padlock" ./programs/test/selftest
    101     grep -q mbedtls_aesni_has_support ./programs/test/selftest
    102 
    103     scripts/config.py set MBEDTLS_AESNI_C
    104     scripts/config.py unset MBEDTLS_PADLOCK_C
    105     scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
    106     msg "AES tests, test AESNI only"
    107     make clean
    108     make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra -mpclmul -msse2 -maes' LDFLAGS='-m32'
    109     ./programs/test/selftest aes | grep -q "AES note: using AESNI"
    110     ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
    111     grep -q "AES note: using AESNI" ./programs/test/selftest
    112     not grep -q "AES note: built-in implementation." ./programs/test/selftest
    113     not grep -q "AES note: using VIA Padlock" ./programs/test/selftest
    114     not grep -q mbedtls_aesni_has_support ./programs/test/selftest
    115 }
    116 
    117 support_test_aesni_m32_clang () {
    118     # clang >= 4 is required to build with target attributes
    119     support_test_aesni_m32 && [[ $(clang_version) -ge 4 ]]
    120 }
    121 
    122 component_test_aesni_m32_clang () {
    123 
    124     scripts/config.py set MBEDTLS_AESNI_C
    125     scripts/config.py set MBEDTLS_PADLOCK_C
    126     scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
    127     scripts/config.py set MBEDTLS_HAVE_ASM
    128 
    129     # test the intrinsics implementation with clang
    130     msg "AES tests, test intrinsics (clang)"
    131     make clean
    132     make CC=clang CFLAGS='-m32 -Werror -Wall -Wextra' LDFLAGS='-m32'
    133     # check that we built intrinsics - this should be used by default when supported by the compiler
    134     ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
    135     grep -q "AES note: using AESNI" ./programs/test/selftest
    136     grep -q "AES note: built-in implementation." ./programs/test/selftest
    137     grep -q "AES note: using VIA Padlock" ./programs/test/selftest
    138     grep -q mbedtls_aesni_has_support ./programs/test/selftest
    139 }
    140 
    141 support_build_aes_armce () {
    142     # clang >= 11 is required to build with AES extensions
    143     [[ $(clang_version) -ge 11 ]]
    144 }
    145 
    146 component_build_aes_armce () {
    147     # Test variations of AES with Armv8 crypto extensions
    148     scripts/config.py set MBEDTLS_AESCE_C
    149     scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
    150 
    151     msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, aarch64"
    152     make -B library/aesce.o library/aesce.s CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
    153     msg "clang, test aarch64 crypto instructions built"
    154     grep -E 'aes[a-z]+\s*[qv]' library/aesce.s
    155 
    156     msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, arm"
    157     make -B library/aesce.o library/aesce.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
    158     msg "clang, test A32 crypto instructions built"
    159     grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.s
    160 
    161     msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, thumb"
    162     make -B library/aesce.o library/aesce.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
    163     msg "clang, test T32 crypto instructions built"
    164     grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.s
    165 
    166     scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
    167 
    168     msg "MBEDTLS_AES_USE_both, clang, aarch64"
    169     make -B library/aesce.o library/aesce.s CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
    170     msg "clang, test aarch64 crypto instructions built"
    171     grep -E 'aes[a-z]+\s*[qv]' library/aesce.s
    172 
    173     msg "MBEDTLS_AES_USE_both, clang, arm"
    174     make -B library/aesce.o library/aesce.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
    175     msg "clang, test A32 crypto instructions built"
    176     grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.s
    177 
    178     msg "MBEDTLS_AES_USE_both, clang, thumb"
    179     make -B library/aesce.o library/aesce.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
    180     msg "clang, test T32 crypto instructions built"
    181     grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.s
    182 
    183     scripts/config.py unset MBEDTLS_AESCE_C
    184 
    185     msg "no MBEDTLS_AESCE_C, clang, aarch64"
    186     make -B library/aesce.o library/aesce.s CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a"
    187     msg "clang, test aarch64 crypto instructions not built"
    188     not grep -E 'aes[a-z]+\s*[qv]' library/aesce.s
    189 
    190     msg "no MBEDTLS_AESCE_C, clang, arm"
    191     make -B library/aesce.o library/aesce.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72 -marm"
    192     msg "clang, test A32 crypto instructions not built"
    193     not grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.s
    194 
    195     msg "no MBEDTLS_AESCE_C, clang, thumb"
    196     make -B library/aesce.o library/aesce.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32 -mthumb"
    197     msg "clang, test T32 crypto instructions not built"
    198     not grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.s
    199 }
    200 
    201 support_build_sha_armce () {
    202     # clang >= 4 is required to build with SHA extensions
    203     [[ $(clang_version) -ge 4 ]]
    204 }
    205 
    206 component_build_sha_armce () {
    207     scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
    208 
    209     # Test variations of SHA256 Armv8 crypto extensions
    210     scripts/config.py set MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
    211         msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, aarch64"
    212         make -B library/sha256.o library/sha256.s CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
    213         msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, test aarch64 crypto instructions built"
    214         grep -E 'sha256[a-z0-9]+\s+[qv]' library/sha256.s
    215 
    216         msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, arm"
    217         make -B library/sha256.o library/sha256.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
    218         msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, test A32 crypto instructions built"
    219         grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.s
    220     scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
    221 
    222 
    223     # test the deprecated form of the config option
    224     scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
    225         msg "MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY clang, thumb"
    226         make -B library/sha256.o library/sha256.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
    227         msg "MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY clang, test T32 crypto instructions built"
    228         grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.s
    229     scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
    230 
    231     scripts/config.py set MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
    232         msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT clang, aarch64"
    233         make -B library/sha256.o library/sha256.s CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
    234         msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT clang, test aarch64 crypto instructions built"
    235         grep -E 'sha256[a-z0-9]+\s+[qv]' library/sha256.s
    236     scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
    237 
    238 
    239     # test the deprecated form of the config option
    240     scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
    241         msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, arm"
    242         make -B library/sha256.o library/sha256.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -std=c99"
    243 
    244         msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, thumb"
    245         make -B library/sha256.o library/sha256.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
    246         msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, test T32 crypto instructions built"
    247         grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.s
    248     scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
    249 
    250     # examine the disassembly for absence of SHA instructions
    251     msg "clang, test A32 crypto instructions not built"
    252     make -B library/sha256.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72 -marm"
    253     not grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.s
    254 
    255     msg "clang, test T32 crypto instructions not built"
    256     make -B library/sha256.s CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32 -mthumb"
    257     not grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.s
    258 
    259     msg "clang, test aarch64 crypto instructions not built"
    260     make -B library/sha256.s CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a"
    261     not grep -E 'sha256[a-z0-9]+\s+[qv]' library/sha256.s
    262 }
    263 
    264 component_test_m32_no_asm () {
    265     # Build without assembly, so as to use portable C code (in a 32-bit
    266     # build) and not the i386-specific inline assembly.
    267     #
    268     # Note that we require gcc, because clang Asan builds fail to link for
    269     # this target (cannot find libclang_rt.lsan-i386.a - this is a known clang issue).
    270     msg "build: i386, make, gcc, no asm (ASan build)" # ~ 30s
    271     scripts/config.py full
    272     scripts/config.py unset MBEDTLS_HAVE_ASM
    273     scripts/config.py unset MBEDTLS_PADLOCK_C
    274     scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
    275     make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
    276 
    277     msg "test: i386, make, gcc, no asm (ASan build)"
    278     make test
    279 }
    280 
    281 support_test_m32_no_asm () {
    282     case $(uname -m) in
    283         amd64|x86_64) true;;
    284         *) false;;
    285     esac
    286 }
    287 
    288 component_test_m32_o2 () {
    289     # Build with optimization, to use the i386 specific inline assembly
    290     # and go faster for tests.
    291     msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
    292     scripts/config.py full
    293     scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
    294     make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
    295 
    296     msg "test: i386, make, gcc -O2 (ASan build)"
    297     make test
    298 
    299     msg "test ssl-opt.sh, i386, make, gcc-O2"
    300     tests/ssl-opt.sh
    301 }
    302 
    303 support_test_m32_o2 () {
    304     support_test_m32_no_asm "$@"
    305 }
    306 
    307 component_test_m32_everest () {
    308     msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
    309     scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
    310     scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
    311     make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
    312 
    313     msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
    314     make test
    315 
    316     msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
    317     tests/ssl-opt.sh -f ECDH
    318 
    319     msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
    320     # Exclude some symmetric ciphers that are redundant here to gain time.
    321     tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
    322 }
    323 
    324 support_test_m32_everest () {
    325     support_test_m32_no_asm "$@"
    326 }
    327 
    328 component_test_mx32 () {
    329     msg "build: 64-bit ILP32, make, gcc" # ~ 30s
    330     scripts/config.py full
    331     make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
    332 
    333     msg "test: 64-bit ILP32, make, gcc"
    334     make test
    335 }
    336 
    337 support_test_mx32 () {
    338     case $(uname -m) in
    339         amd64|x86_64) true;;
    340         *) false;;
    341     esac
    342 }
    343 
    344 component_test_arm_linux_gnueabi_gcc_arm5vte () {
    345     # Mimic Debian armel port
    346     msg "test: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, default config" # ~4m
    347     make CC="${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc" AR="${ARM_LINUX_GNUEABI_GCC_PREFIX}ar" CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1'
    348 
    349     msg "test: main suites make, default config (out-of-box)" # ~7m 40s
    350     make test
    351 
    352     msg "selftest: make, default config (out-of-box)" # ~0s
    353     programs/test/selftest
    354 
    355     msg "program demos: make, default config (out-of-box)" # ~0s
    356     tests/scripts/run_demos.py
    357 }
    358 
    359 support_test_arm_linux_gnueabi_gcc_arm5vte () {
    360     can_run_arm_linux_gnueabi
    361 }
    362 
    363 # The hard float ABI is not implemented for Thumb 1, so use gnueabi
    364 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
    365 component_test_arm_linux_gnueabi_gcc_thumb_1_opt_0 () {
    366     msg "test: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -O0, thumb 1, default config" # ~2m 10s
    367     make CC="${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc" CFLAGS='-std=c99 -Werror -Wextra -O0 -mcpu=arm1136j-s -mthumb'
    368 
    369     msg "test: main suites make, default config (out-of-box)" # ~36m
    370     make test
    371 
    372     msg "selftest: make, default config (out-of-box)" # ~10s
    373     programs/test/selftest
    374 
    375     msg "program demos: make, default config (out-of-box)" # ~0s
    376     tests/scripts/run_demos.py
    377 }
    378 
    379 support_test_arm_linux_gnueabi_gcc_thumb_1_opt_0 () {
    380     can_run_arm_linux_gnueabi
    381 }
    382 
    383 component_test_arm_linux_gnueabi_gcc_thumb_1_opt_s () {
    384     msg "test: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -Os, thumb 1, default config" # ~3m 10s
    385     make CC="${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc" CFLAGS='-std=c99 -Werror -Wextra -Os -mcpu=arm1136j-s -mthumb'
    386 
    387     msg "test: main suites make, default config (out-of-box)" # ~21m 10s
    388     make test
    389 
    390     msg "selftest: make, default config (out-of-box)" # ~2s
    391     programs/test/selftest
    392 
    393     msg "program demos: make, default config (out-of-box)" # ~0s
    394     tests/scripts/run_demos.py
    395 }
    396 
    397 support_test_arm_linux_gnueabi_gcc_thumb_1_opt_s () {
    398     can_run_arm_linux_gnueabi
    399 }
    400 
    401 component_test_arm_linux_gnueabihf_gcc_armv7 () {
    402     msg "test: ${ARM_LINUX_GNUEABIHF_GCC_PREFIX}gcc -O2, A32, default config" # ~4m 30s
    403     make CC="${ARM_LINUX_GNUEABIHF_GCC_PREFIX}gcc" CFLAGS='-std=c99 -Werror -Wextra -O2 -march=armv7-a -marm'
    404 
    405     msg "test: main suites make, default config (out-of-box)" # ~3m 30s
    406     make test
    407 
    408     msg "selftest: make, default config (out-of-box)" # ~0s
    409     programs/test/selftest
    410 
    411     msg "program demos: make, default config (out-of-box)" # ~0s
    412     tests/scripts/run_demos.py
    413 }
    414 
    415 support_test_arm_linux_gnueabihf_gcc_armv7 () {
    416     can_run_arm_linux_gnueabihf
    417 }
    418 
    419 component_test_arm_linux_gnueabihf_gcc_thumb_2 () {
    420     msg "test: ${ARM_LINUX_GNUEABIHF_GCC_PREFIX}gcc -Os, thumb 2, default config" # ~4m
    421     make CC="${ARM_LINUX_GNUEABIHF_GCC_PREFIX}gcc" CFLAGS='-std=c99 -Werror -Wextra -Os -march=armv7-a -mthumb'
    422 
    423     msg "test: main suites make, default config (out-of-box)" # ~3m 40s
    424     make test
    425 
    426     msg "selftest: make, default config (out-of-box)" # ~0s
    427     programs/test/selftest
    428 
    429     msg "program demos: make, default config (out-of-box)" # ~0s
    430     tests/scripts/run_demos.py
    431 }
    432 
    433 support_test_arm_linux_gnueabihf_gcc_thumb_2 () {
    434     can_run_arm_linux_gnueabihf
    435 }
    436 
    437 component_test_aarch64_linux_gnu_gcc () {
    438     msg "test: ${AARCH64_LINUX_GNU_GCC_PREFIX}gcc -O2, default config" # ~3m 50s
    439     make CC="${AARCH64_LINUX_GNU_GCC_PREFIX}gcc" CFLAGS='-std=c99 -Werror -Wextra -O2'
    440 
    441     msg "test: main suites make, default config (out-of-box)" # ~1m 50s
    442     make test
    443 
    444     msg "selftest: make, default config (out-of-box)" # ~0s
    445     programs/test/selftest
    446 
    447     msg "program demos: make, default config (out-of-box)" # ~0s
    448     tests/scripts/run_demos.py
    449 }
    450 
    451 support_test_aarch64_linux_gnu_gcc () {
    452     # Minimum version of GCC for MBEDTLS_AESCE_C is 6.0
    453     [ "$(gcc_version "${AARCH64_LINUX_GNU_GCC_PREFIX}gcc")" -ge 6 ] && can_run_aarch64_linux_gnu
    454 }
    455 
    456 component_build_arm_none_eabi_gcc () {
    457     msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
    458     scripts/config.py baremetal
    459     make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -Wall -Wextra -O1' lib
    460 
    461     msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
    462     ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
    463 }
    464 
    465 component_build_arm_linux_gnueabi_gcc_arm5vte () {
    466     msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
    467     scripts/config.py baremetal
    468     # Build for a target platform that's close to what Debian uses
    469     # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
    470     # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
    471     # Build everything including programs, see for example
    472     # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
    473     make CC="${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc" AR="${ARM_LINUX_GNUEABI_GCC_PREFIX}ar" CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te'
    474 
    475     msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
    476     ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t library/*.o
    477 }
    478 
    479 support_build_arm_linux_gnueabi_gcc_arm5vte () {
    480     type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
    481 }
    482 
    483 component_build_arm_none_eabi_gcc_arm5vte () {
    484     msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
    485     scripts/config.py baremetal
    486     # This is an imperfect substitute for
    487     # component_build_arm_linux_gnueabi_gcc_arm5vte
    488     # in case the gcc-arm-linux-gnueabi toolchain is not available
    489     make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" CFLAGS='-std=c99 -Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
    490 
    491     msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
    492     ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
    493 }
    494 
    495 component_build_arm_none_eabi_gcc_m0plus () {
    496     msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
    497     scripts/config.py baremetal_size
    498     make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -Wall -Wextra -mthumb -mcpu=cortex-m0plus -Os' lib
    499 
    500     msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
    501     ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
    502     for lib in library/*.a; do
    503         echo "$lib:"
    504         ${ARM_NONE_EABI_GCC_PREFIX}size -t $lib | grep TOTALS
    505     done
    506 }
    507 
    508 component_build_arm_none_eabi_gcc_no_udbl_division () {
    509     msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
    510     scripts/config.py baremetal
    511     scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
    512     make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -Wall -Wextra' lib
    513     echo "Checking that software 64-bit division is not required"
    514     not grep __aeabi_uldiv library/*.o
    515 }
    516 
    517 component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
    518     msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
    519     scripts/config.py baremetal
    520     scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
    521     make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -O1 -march=armv6-m -mthumb' lib
    522     echo "Checking that software 64-bit multiplication is not required"
    523     not grep __aeabi_lmul library/*.o
    524 }
    525 
    526 component_build_arm_clang_thumb () {
    527     # ~ 30s
    528 
    529     scripts/config.py baremetal
    530 
    531     msg "build: clang thumb 2, make"
    532     make clean
    533     make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
    534 
    535     # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
    536     msg "build: clang thumb 1 -O0, make"
    537     make clean
    538     make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
    539 
    540     msg "build: clang thumb 1 -Os, make"
    541     make clean
    542     make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
    543 }
    544 
    545 component_build_armcc () {
    546     # Common configuration for all the builds below
    547     scripts/config.py baremetal
    548 
    549     # armc[56] don't support SHA-512 intrinsics
    550     scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
    551 
    552     # older versions of armcc/armclang don't support AESCE_C on 32-bit Arm
    553     scripts/config.py unset MBEDTLS_AESCE_C
    554 
    555     # Stop armclang warning about feature detection for A64_CRYPTO.
    556     # With this enabled, the library does build correctly under armclang,
    557     # but in baremetal builds (as tested here), feature detection is
    558     # unavailable, and the user is notified via a #warning. So enabling
    559     # this feature would prevent us from building with -Werror on
    560     # armclang. Tracked in #7198.
    561     scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
    562 
    563     scripts/config.py set MBEDTLS_HAVE_ASM
    564 
    565     # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
    566 
    567     # ARM Compiler 6 - Target ARMv7-A
    568     helper_armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-a"
    569 
    570     # ARM Compiler 6 - Target ARMv7-M
    571     helper_armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m"
    572 
    573     # ARM Compiler 6 - Target ARMv7-M+DSP
    574     helper_armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m+dsp"
    575 
    576     # ARM Compiler 6 - Target ARMv8-A - AArch32
    577     helper_armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8.2-a"
    578 
    579     # ARM Compiler 6 - Target ARMv8-M
    580     helper_armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8-m.main"
    581 
    582     # ARM Compiler 6 - Target Cortex-M0 - no optimisation
    583     helper_armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
    584 
    585     # ARM Compiler 6 - Target Cortex-M0
    586     helper_armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
    587 
    588     # ARM Compiler 6 - Target ARMv8.2-A - AArch64
    589     #
    590     # Re-enable MBEDTLS_AESCE_C as this should be supported by the version of armclang
    591     # that we have in our CI
    592     scripts/config.py set MBEDTLS_AESCE_C
    593     helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto"
    594 }
    595 
    596 support_build_armcc () {
    597     armc6_cc="$ARMC6_BIN_DIR/armclang"
    598     (check_tools "$armc6_cc" > /dev/null 2>&1)
    599 }
    600 
    601 # For timebeing, no VIA Padlock platform available.
    602 component_build_aes_via_padlock () {
    603 
    604     msg "AES:VIA PadLock, build with default configuration."
    605     scripts/config.py unset MBEDTLS_AESNI_C
    606     scripts/config.py set MBEDTLS_PADLOCK_C
    607     scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
    608     make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
    609     grep -q mbedtls_padlock_has_support ./programs/test/selftest
    610 
    611 }
    612 
    613 support_build_aes_via_padlock_only () {
    614     ( [ "$MBEDTLS_TEST_PLATFORM" == "Linux-x86_64" ] || \
    615         [ "$MBEDTLS_TEST_PLATFORM" == "Linux-amd64" ] ) && \
    616     [ "`dpkg --print-foreign-architectures`" == "i386" ]
    617 }