all.sh 129 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190
  1. #! /usr/bin/env bash
  2. # all.sh
  3. #
  4. # Copyright The Mbed TLS Contributors
  5. # SPDX-License-Identifier: Apache-2.0
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  8. # not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. ################################################################
  19. #### Documentation
  20. ################################################################
  21. # Purpose
  22. # -------
  23. #
  24. # To run all tests possible or available on the platform.
  25. #
  26. # Notes for users
  27. # ---------------
  28. #
  29. # Warning: the test is destructive. It includes various build modes and
  30. # configurations, and can and will arbitrarily change the current CMake
  31. # configuration. The following files must be committed into git:
  32. # * include/mbedtls/config.h
  33. # * Makefile, library/Makefile, programs/Makefile, tests/Makefile,
  34. # programs/fuzz/Makefile
  35. # After running this script, the CMake cache will be lost and CMake
  36. # will no longer be initialised.
  37. #
  38. # The script assumes the presence of a number of tools:
  39. # * Basic Unix tools (Windows users note: a Unix-style find must be before
  40. # the Windows find in the PATH)
  41. # * Perl
  42. # * GNU Make
  43. # * CMake
  44. # * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
  45. # * G++
  46. # * arm-gcc and mingw-gcc
  47. # * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
  48. # * OpenSSL and GnuTLS command line tools, recent enough for the
  49. # interoperability tests. If they don't support SSLv3 then a legacy
  50. # version of these tools must be present as well (search for LEGACY
  51. # below).
  52. # See the invocation of check_tools below for details.
  53. #
  54. # This script must be invoked from the toplevel directory of a git
  55. # working copy of Mbed TLS.
  56. #
  57. # The behavior on an error depends on whether --keep-going (alias -k)
  58. # is in effect.
  59. # * Without --keep-going: the script stops on the first error without
  60. # cleaning up. This lets you work in the configuration of the failing
  61. # component.
  62. # * With --keep-going: the script runs all requested components and
  63. # reports failures at the end. In particular the script always cleans
  64. # up on exit.
  65. #
  66. # Note that the output is not saved. You may want to run
  67. # script -c tests/scripts/all.sh
  68. # or
  69. # tests/scripts/all.sh >all.log 2>&1
  70. #
  71. # Notes for maintainers
  72. # ---------------------
  73. #
  74. # The bulk of the code is organized into functions that follow one of the
  75. # following naming conventions:
  76. # * pre_XXX: things to do before running the tests, in order.
  77. # * component_XXX: independent components. They can be run in any order.
  78. # * component_check_XXX: quick tests that aren't worth parallelizing.
  79. # * component_build_XXX: build things but don't run them.
  80. # * component_test_XXX: build and test.
  81. # * support_XXX: if support_XXX exists and returns false then
  82. # component_XXX is not run by default.
  83. # * post_XXX: things to do after running the tests.
  84. # * other: miscellaneous support functions.
  85. #
  86. # Each component must start by invoking `msg` with a short informative message.
  87. #
  88. # Warning: due to the way bash detects errors, the failure of a command
  89. # inside 'if' or '!' is not detected. Use the 'not' function instead of '!'.
  90. #
  91. # Each component is executed in a separate shell process. The component
  92. # fails if any command in it returns a non-zero status.
  93. #
  94. # The framework performs some cleanup tasks after each component. This
  95. # means that components can assume that the working directory is in a
  96. # cleaned-up state, and don't need to perform the cleanup themselves.
  97. # * Run `make clean`.
  98. # * Restore `include/mbedtks/config.h` from a backup made before running
  99. # the component.
  100. # * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
  101. # `tests/Makefile` and `programs/fuzz/Makefile` from git.
  102. # This cleans up after an in-tree use of CMake.
  103. #
  104. # The tests are roughly in order from fastest to slowest. This doesn't
  105. # have to be exact, but in general you should add slower tests towards
  106. # the end and fast checks near the beginning.
  107. ################################################################
  108. #### Initialization and command line parsing
  109. ################################################################
  110. # Abort on errors (even on the left-hand side of a pipe).
  111. # Treat uninitialised variables as errors.
  112. set -e -o pipefail -u
  113. pre_check_environment () {
  114. if [ -d library -a -d include -a -d tests ]; then :; else
  115. echo "Must be run from mbed TLS root" >&2
  116. exit 1
  117. fi
  118. }
  119. pre_initialize_variables () {
  120. CONFIG_H='include/mbedtls/config.h'
  121. CRYPTO_CONFIG_H='include/psa/crypto_config.h'
  122. # Files that are clobbered by some jobs will be backed up. Use a different
  123. # suffix from auxiliary scripts so that all.sh and auxiliary scripts can
  124. # independently decide when to remove the backup file.
  125. backup_suffix='.all.bak'
  126. # Files clobbered by config.py
  127. files_to_back_up="$CONFIG_H $CRYPTO_CONFIG_H"
  128. # Files clobbered by in-tree cmake
  129. files_to_back_up="$files_to_back_up Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile"
  130. append_outcome=0
  131. MEMORY=0
  132. FORCE=0
  133. QUIET=0
  134. KEEP_GOING=0
  135. # Seed value used with the --release-test option.
  136. #
  137. # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
  138. # both values are kept in sync. If you change the value here because it
  139. # breaks some tests, you'll definitely want to change it in
  140. # basic-build-test.sh as well.
  141. RELEASE_SEED=1
  142. : ${MBEDTLS_TEST_OUTCOME_FILE=}
  143. : ${MBEDTLS_TEST_PLATFORM="$(uname -s | tr -c \\n0-9A-Za-z _)-$(uname -m | tr -c \\n0-9A-Za-z _)"}
  144. export MBEDTLS_TEST_OUTCOME_FILE
  145. export MBEDTLS_TEST_PLATFORM
  146. # Default commands, can be overridden by the environment
  147. : ${OPENSSL:="openssl"}
  148. : ${OPENSSL_LEGACY:="$OPENSSL"}
  149. : ${OPENSSL_NEXT:="$OPENSSL"}
  150. : ${GNUTLS_CLI:="gnutls-cli"}
  151. : ${GNUTLS_SERV:="gnutls-serv"}
  152. : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
  153. : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
  154. : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
  155. : ${ARMC5_BIN_DIR:=/usr/bin}
  156. : ${ARMC6_BIN_DIR:=/usr/bin}
  157. : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
  158. : ${ARM_LINUX_GNUEABI_GCC_PREFIX:=arm-linux-gnueabi-}
  159. # if MAKEFLAGS is not set add the -j option to speed up invocations of make
  160. if [ -z "${MAKEFLAGS+set}" ]; then
  161. export MAKEFLAGS="-j$(all_sh_nproc)"
  162. fi
  163. # Include more verbose output for failing tests run by CMake or make
  164. export CTEST_OUTPUT_ON_FAILURE=1
  165. # CFLAGS and LDFLAGS for Asan builds that don't use CMake
  166. ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
  167. # Gather the list of available components. These are the functions
  168. # defined in this script whose name starts with "component_".
  169. # Parse the script with sed. This way we get the functions in the order
  170. # they are defined.
  171. ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
  172. # Exclude components that are not supported on this platform.
  173. SUPPORTED_COMPONENTS=
  174. for component in $ALL_COMPONENTS; do
  175. case $(type "support_$component" 2>&1) in
  176. *' function'*)
  177. if ! support_$component; then continue; fi;;
  178. esac
  179. SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
  180. done
  181. }
  182. # Test whether the component $1 is included in the command line patterns.
  183. is_component_included()
  184. {
  185. # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
  186. # only does word splitting.
  187. set -f
  188. for pattern in $COMMAND_LINE_COMPONENTS; do
  189. set +f
  190. case ${1#component_} in $pattern) return 0;; esac
  191. done
  192. set +f
  193. return 1
  194. }
  195. usage()
  196. {
  197. cat <<EOF
  198. Usage: $0 [OPTION]... [COMPONENT]...
  199. Run mbedtls release validation tests.
  200. By default, run all tests. With one or more COMPONENT, run only those.
  201. COMPONENT can be the name of a component or a shell wildcard pattern.
  202. Examples:
  203. $0 "check_*"
  204. Run all sanity checks.
  205. $0 --no-armcc --except test_memsan
  206. Run everything except builds that require armcc and MemSan.
  207. Special options:
  208. -h|--help Print this help and exit.
  209. --list-all-components List all available test components and exit.
  210. --list-components List components supported on this platform and exit.
  211. General options:
  212. -q|--quiet Only output component names, and errors if any.
  213. -f|--force Force the tests to overwrite any modified files.
  214. -k|--keep-going Run all tests and report errors at the end.
  215. -m|--memory Additional optional memory tests.
  216. --append-outcome Append to the outcome file (if used).
  217. --arm-none-eabi-gcc-prefix=<string>
  218. Prefix for a cross-compiler for arm-none-eabi
  219. (default: "${ARM_NONE_EABI_GCC_PREFIX}")
  220. --arm-linux-gnueabi-gcc-prefix=<string>
  221. Prefix for a cross-compiler for arm-linux-gnueabi
  222. (default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}")
  223. --armcc Run ARM Compiler builds (on by default).
  224. --restore First clean up the build tree, restoring backed up
  225. files. Do not run any components unless they are
  226. explicitly specified.
  227. --error-test Error test mode: run a failing function in addition
  228. to any specified component. May be repeated.
  229. --except Exclude the COMPONENTs listed on the command line,
  230. instead of running only those.
  231. --no-append-outcome Write a new outcome file and analyze it (default).
  232. --no-armcc Skip ARM Compiler builds.
  233. --no-force Refuse to overwrite modified files (default).
  234. --no-keep-going Stop at the first error (default).
  235. --no-memory No additional memory tests (default).
  236. --no-quiet Print full ouput from components.
  237. --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
  238. --outcome-file=<path> File where test outcomes are written (not done if
  239. empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
  240. --random-seed Use a random seed value for randomized tests (default).
  241. -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
  242. -s|--seed Integer seed value to use for this test run.
  243. Tool path options:
  244. --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
  245. --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
  246. --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
  247. --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
  248. --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
  249. --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
  250. --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
  251. --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
  252. --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
  253. EOF
  254. }
  255. # Cleanup before/after running a component.
  256. # Remove built files as well as the cmake cache/config.
  257. # Does not remove generated source files.
  258. cleanup()
  259. {
  260. command make clean
  261. # Remove CMake artefacts
  262. find . -name .git -prune -o \
  263. -iname CMakeFiles -exec rm -rf {} \+ -o \
  264. \( -iname cmake_install.cmake -o \
  265. -iname CTestTestfile.cmake -o \
  266. -iname CMakeCache.txt \) -exec rm {} \+
  267. # Recover files overwritten by in-tree CMake builds
  268. rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
  269. # Remove any artifacts from the component_test_cmake_as_subdirectory test.
  270. rm -rf programs/test/cmake_subproject/build
  271. rm -f programs/test/cmake_subproject/Makefile
  272. rm -f programs/test/cmake_subproject/cmake_subproject
  273. # Restore files that may have been clobbered by the job
  274. for x in $files_to_back_up; do
  275. cp -p "$x$backup_suffix" "$x"
  276. done
  277. }
  278. # Final cleanup when this script exits (except when exiting on a failure
  279. # in non-keep-going mode).
  280. final_cleanup () {
  281. cleanup
  282. for x in $files_to_back_up; do
  283. rm -f "$x$backup_suffix"
  284. done
  285. }
  286. # Executed on exit. May be redefined depending on command line options.
  287. final_report () {
  288. :
  289. }
  290. fatal_signal () {
  291. final_cleanup
  292. final_report $1
  293. trap - $1
  294. kill -$1 $$
  295. }
  296. trap 'fatal_signal HUP' HUP
  297. trap 'fatal_signal INT' INT
  298. trap 'fatal_signal TERM' TERM
  299. # Number of processors on this machine. Used as the default setting
  300. # for parallel make.
  301. all_sh_nproc ()
  302. {
  303. {
  304. nproc || # Linux
  305. sysctl -n hw.ncpuonline || # NetBSD, OpenBSD
  306. sysctl -n hw.ncpu || # FreeBSD
  307. echo 1
  308. } 2>/dev/null
  309. }
  310. msg()
  311. {
  312. if [ -n "${current_component:-}" ]; then
  313. current_section="${current_component#component_}: $1"
  314. else
  315. current_section="$1"
  316. fi
  317. if [ $QUIET -eq 1 ]; then
  318. return
  319. fi
  320. echo ""
  321. echo "******************************************************************"
  322. echo "* $current_section "
  323. printf "* "; date
  324. echo "******************************************************************"
  325. }
  326. armc6_build_test()
  327. {
  328. FLAGS="$1"
  329. msg "build: ARM Compiler 6 ($FLAGS)"
  330. ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
  331. WARNING_CFLAGS='-xc -std=c99' make lib
  332. msg "size: ARM Compiler 6 ($FLAGS)"
  333. "$ARMC6_FROMELF" -z library/*.o
  334. make clean
  335. }
  336. err_msg()
  337. {
  338. echo "$1" >&2
  339. }
  340. check_tools()
  341. {
  342. for TOOL in "$@"; do
  343. if ! `type "$TOOL" >/dev/null 2>&1`; then
  344. err_msg "$TOOL not found!"
  345. exit 1
  346. fi
  347. done
  348. }
  349. pre_parse_command_line () {
  350. COMMAND_LINE_COMPONENTS=
  351. all_except=0
  352. error_test=0
  353. restore_first=0
  354. no_armcc=
  355. # Note that legacy options are ignored instead of being omitted from this
  356. # list of options, so invocations that worked with previous version of
  357. # all.sh will still run and work properly.
  358. while [ $# -gt 0 ]; do
  359. case "$1" in
  360. --append-outcome) append_outcome=1;;
  361. --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
  362. --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
  363. --armcc) no_armcc=;;
  364. --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
  365. --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
  366. --error-test) error_test=$((error_test + 1));;
  367. --except) all_except=1;;
  368. --force|-f) FORCE=1;;
  369. --gnutls-cli) shift; GNUTLS_CLI="$1";;
  370. --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
  371. --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
  372. --gnutls-serv) shift; GNUTLS_SERV="$1";;
  373. --help|-h) usage; exit;;
  374. --keep-going|-k) KEEP_GOING=1;;
  375. --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
  376. --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
  377. --memory|-m) MEMORY=1;;
  378. --no-append-outcome) append_outcome=0;;
  379. --no-armcc) no_armcc=1;;
  380. --no-force) FORCE=0;;
  381. --no-keep-going) KEEP_GOING=0;;
  382. --no-memory) MEMORY=0;;
  383. --no-quiet) QUIET=0;;
  384. --openssl) shift; OPENSSL="$1";;
  385. --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
  386. --openssl-next) shift; OPENSSL_NEXT="$1";;
  387. --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
  388. --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
  389. --quiet|-q) QUIET=1;;
  390. --random-seed) unset SEED;;
  391. --release-test|-r) SEED=$RELEASE_SEED;;
  392. --restore) restore_first=1;;
  393. --seed|-s) shift; SEED="$1";;
  394. -*)
  395. echo >&2 "Unknown option: $1"
  396. echo >&2 "Run $0 --help for usage."
  397. exit 120
  398. ;;
  399. *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
  400. esac
  401. shift
  402. done
  403. # With no list of components, run everything.
  404. if [ -z "$COMMAND_LINE_COMPONENTS" ] && [ $restore_first -eq 0 ]; then
  405. all_except=1
  406. fi
  407. # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
  408. # Ignore it if components are listed explicitly on the command line.
  409. if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
  410. COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
  411. fi
  412. # Error out if an explicitly requested component doesn't exist.
  413. if [ $all_except -eq 0 ]; then
  414. unsupported=0
  415. # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
  416. # only does word splitting.
  417. set -f
  418. for component in $COMMAND_LINE_COMPONENTS; do
  419. set +f
  420. # If the requested name includes a wildcard character, don't
  421. # check it. Accept wildcard patterns that don't match anything.
  422. case $component in
  423. *[*?\[]*) continue;;
  424. esac
  425. case " $SUPPORTED_COMPONENTS " in
  426. *" $component "*) :;;
  427. *)
  428. echo >&2 "Component $component was explicitly requested, but is not known or not supported."
  429. unsupported=$((unsupported + 1));;
  430. esac
  431. done
  432. set +f
  433. if [ $unsupported -ne 0 ]; then
  434. exit 2
  435. fi
  436. fi
  437. # Build the list of components to run.
  438. RUN_COMPONENTS=
  439. for component in $SUPPORTED_COMPONENTS; do
  440. if is_component_included "$component"; [ $? -eq $all_except ]; then
  441. RUN_COMPONENTS="$RUN_COMPONENTS $component"
  442. fi
  443. done
  444. unset all_except
  445. unset no_armcc
  446. }
  447. pre_check_git () {
  448. if [ $FORCE -eq 1 ]; then
  449. rm -rf "$OUT_OF_SOURCE_DIR"
  450. git checkout-index -f -q $CONFIG_H
  451. cleanup
  452. else
  453. if [ -d "$OUT_OF_SOURCE_DIR" ]; then
  454. echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
  455. echo "You can either delete this directory manually, or force the test by rerunning"
  456. echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
  457. exit 1
  458. fi
  459. if ! git diff --quiet include/mbedtls/config.h; then
  460. err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
  461. echo "You can either delete or preserve your work, or force the test by rerunning the"
  462. echo "script as: $0 --force"
  463. exit 1
  464. fi
  465. fi
  466. }
  467. pre_restore_files () {
  468. # If the makefiles have been generated by a framework such as cmake,
  469. # restore them from git. If the makefiles look like modifications from
  470. # the ones checked into git, take care not to modify them. Whatever
  471. # this function leaves behind is what the script will restore before
  472. # each component.
  473. case "$(head -n1 Makefile)" in
  474. *[Gg]enerated*)
  475. git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
  476. git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
  477. ;;
  478. esac
  479. }
  480. pre_back_up () {
  481. for x in $files_to_back_up; do
  482. cp -p "$x" "$x$backup_suffix"
  483. done
  484. }
  485. pre_setup_keep_going () {
  486. failure_count=0 # Number of failed components
  487. last_failure_status=0 # Last failure status in this component
  488. # See err_trap
  489. previous_failure_status=0
  490. previous_failed_command=
  491. previous_failure_funcall_depth=0
  492. unset report_failed_command
  493. start_red=
  494. end_color=
  495. if [ -t 1 ]; then
  496. case "${TERM:-}" in
  497. *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
  498. start_red=$(printf '\033[31m')
  499. end_color=$(printf '\033[0m')
  500. ;;
  501. esac
  502. fi
  503. # Keep a summary of failures in a file. We'll print it out at the end.
  504. failure_summary_file=$PWD/all-sh-failures-$$.log
  505. : >"$failure_summary_file"
  506. # Whether it makes sense to keep a component going after the specified
  507. # command fails (test command) or not (configure or build).
  508. # This function normally receives the failing simple command
  509. # ($BASH_COMMAND) as an argument, but if $report_failed_command is set,
  510. # this is passed instead.
  511. # This doesn't have to be 100% accurate: all failures are recorded anyway.
  512. # False positives result in running things that can't be expected to
  513. # work. False negatives result in things not running after something else
  514. # failed even though they might have given useful feedback.
  515. can_keep_going_after_failure () {
  516. case "$1" in
  517. "msg "*) false;;
  518. "cd "*) false;;
  519. *make*[\ /]tests*) false;; # make tests, make CFLAGS=-I../tests, ...
  520. *test*) true;; # make test, tests/stuff, env V=v tests/stuff, ...
  521. *make*check*) true;;
  522. "grep "*) true;;
  523. "[ "*) true;;
  524. "! "*) true;;
  525. *) false;;
  526. esac
  527. }
  528. # This function runs if there is any error in a component.
  529. # It must either exit with a nonzero status, or set
  530. # last_failure_status to a nonzero value.
  531. err_trap () {
  532. # Save $? (status of the failing command). This must be the very
  533. # first thing, before $? is overridden.
  534. last_failure_status=$?
  535. failed_command=${report_failed_command-$BASH_COMMAND}
  536. if [[ $last_failure_status -eq $previous_failure_status &&
  537. "$failed_command" == "$previous_failed_command" &&
  538. ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
  539. then
  540. # The same command failed twice in a row, but this time one level
  541. # less deep in the function call stack. This happens when the last
  542. # command of a function returns a nonzero status, and the function
  543. # returns that same status. Ignore the second failure.
  544. previous_failure_funcall_depth=${#FUNCNAME[@]}
  545. return
  546. fi
  547. previous_failure_status=$last_failure_status
  548. previous_failed_command=$failed_command
  549. previous_failure_funcall_depth=${#FUNCNAME[@]}
  550. text="$current_section: $failed_command -> $last_failure_status"
  551. echo "${start_red}^^^^$text^^^^${end_color}" >&2
  552. echo "$text" >>"$failure_summary_file"
  553. # If the command is fatal (configure or build command), stop this
  554. # component. Otherwise (test command) keep the component running
  555. # (run more tests from the same build).
  556. if ! can_keep_going_after_failure "$failed_command"; then
  557. exit $last_failure_status
  558. fi
  559. }
  560. final_report () {
  561. if [ $failure_count -gt 0 ]; then
  562. echo
  563. echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  564. echo "${start_red}FAILED: $failure_count components${end_color}"
  565. cat "$failure_summary_file"
  566. echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  567. elif [ -z "${1-}" ]; then
  568. echo "SUCCESS :)"
  569. fi
  570. if [ -n "${1-}" ]; then
  571. echo "Killed by SIG$1."
  572. fi
  573. rm -f "$failure_summary_file"
  574. if [ $failure_count -gt 0 ]; then
  575. exit 1
  576. fi
  577. }
  578. }
  579. # record_status() and if_build_succeeded() are kept temporarily for backward
  580. # compatibility. Don't use them in new components.
  581. record_status () {
  582. "$@"
  583. }
  584. if_build_succeeded () {
  585. "$@"
  586. }
  587. # '! true' does not trigger the ERR trap. Arrange to trigger it, with
  588. # a reasonably informative error message (not just "$@").
  589. not () {
  590. if "$@"; then
  591. report_failed_command="! $*"
  592. false
  593. unset report_failed_command
  594. fi
  595. }
  596. pre_prepare_outcome_file () {
  597. case "$MBEDTLS_TEST_OUTCOME_FILE" in
  598. [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
  599. esac
  600. if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
  601. rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
  602. fi
  603. }
  604. pre_print_configuration () {
  605. if [ $QUIET -eq 1 ]; then
  606. return
  607. fi
  608. msg "info: $0 configuration"
  609. echo "MEMORY: $MEMORY"
  610. echo "FORCE: $FORCE"
  611. echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
  612. echo "SEED: ${SEED-"UNSET"}"
  613. echo
  614. echo "OPENSSL: $OPENSSL"
  615. echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
  616. echo "OPENSSL_NEXT: $OPENSSL_NEXT"
  617. echo "GNUTLS_CLI: $GNUTLS_CLI"
  618. echo "GNUTLS_SERV: $GNUTLS_SERV"
  619. echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
  620. echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
  621. echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
  622. echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
  623. }
  624. # Make sure the tools we need are available.
  625. pre_check_tools () {
  626. # Build the list of variables to pass to output_env.sh.
  627. set env
  628. case " $RUN_COMPONENTS " in
  629. # Require OpenSSL and GnuTLS if running any tests (as opposed to
  630. # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
  631. # is a good enough approximation in practice.
  632. *" test_"*)
  633. # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
  634. # and ssl-opt.sh, we just export the variables they require.
  635. export OPENSSL_CMD="$OPENSSL"
  636. export GNUTLS_CLI="$GNUTLS_CLI"
  637. export GNUTLS_SERV="$GNUTLS_SERV"
  638. # Avoid passing --seed flag in every call to ssl-opt.sh
  639. if [ -n "${SEED-}" ]; then
  640. export SEED
  641. fi
  642. set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
  643. set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
  644. set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
  645. set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
  646. check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
  647. "$GNUTLS_CLI" "$GNUTLS_SERV" \
  648. "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
  649. ;;
  650. esac
  651. case " $RUN_COMPONENTS " in
  652. *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
  653. esac
  654. case " $RUN_COMPONENTS " in
  655. *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
  656. esac
  657. case " $RUN_COMPONENTS " in
  658. *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
  659. esac
  660. case " $RUN_COMPONENTS " in
  661. *" test_zeroize "*) check_tools "gdb";;
  662. esac
  663. case " $RUN_COMPONENTS " in
  664. *_armcc*)
  665. ARMC5_CC="$ARMC5_BIN_DIR/armcc"
  666. ARMC5_AR="$ARMC5_BIN_DIR/armar"
  667. ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
  668. ARMC6_CC="$ARMC6_BIN_DIR/armclang"
  669. ARMC6_AR="$ARMC6_BIN_DIR/armar"
  670. ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
  671. check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
  672. "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
  673. esac
  674. # past this point, no call to check_tool, only printing output
  675. if [ $QUIET -eq 1 ]; then
  676. return
  677. fi
  678. msg "info: output_env.sh"
  679. case $RUN_COMPONENTS in
  680. *_armcc*)
  681. set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
  682. *) set "$@" RUN_ARMCC=0;;
  683. esac
  684. "$@" scripts/output_env.sh
  685. }
  686. ################################################################
  687. #### Basic checks
  688. ################################################################
  689. #
  690. # Test Suites to be executed
  691. #
  692. # The test ordering tries to optimize for the following criteria:
  693. # 1. Catch possible problems early, by running first tests that run quickly
  694. # and/or are more likely to fail than others (eg I use Clang most of the
  695. # time, so start with a GCC build).
  696. # 2. Minimize total running time, by avoiding useless rebuilds
  697. #
  698. # Indicative running times are given for reference.
  699. component_check_recursion () {
  700. msg "Check: recursion.pl" # < 1s
  701. tests/scripts/recursion.pl library/*.c
  702. }
  703. component_check_generated_files () {
  704. msg "Check: freshness of generated source files" # < 1s
  705. tests/scripts/check-generated-files.sh
  706. }
  707. component_check_doxy_blocks () {
  708. msg "Check: doxygen markup outside doxygen blocks" # < 1s
  709. tests/scripts/check-doxy-blocks.pl
  710. }
  711. component_check_files () {
  712. msg "Check: file sanity checks (permissions, encodings)" # < 1s
  713. tests/scripts/check_files.py
  714. }
  715. component_check_changelog () {
  716. msg "Check: changelog entries" # < 1s
  717. rm -f ChangeLog.new
  718. scripts/assemble_changelog.py -o ChangeLog.new
  719. if [ -e ChangeLog.new ]; then
  720. # Show the diff for information. It isn't an error if the diff is
  721. # non-empty.
  722. diff -u ChangeLog ChangeLog.new || true
  723. rm ChangeLog.new
  724. fi
  725. }
  726. component_check_names () {
  727. msg "Check: declared and exported names (builds the library)" # < 3s
  728. tests/scripts/check_names.py -v
  729. }
  730. component_check_test_cases () {
  731. msg "Check: test case descriptions" # < 1s
  732. if [ $QUIET -eq 1 ]; then
  733. opt='--quiet'
  734. else
  735. opt=''
  736. fi
  737. tests/scripts/check_test_cases.py $opt
  738. unset opt
  739. }
  740. component_check_doxygen_warnings () {
  741. msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
  742. tests/scripts/doxygen.sh
  743. }
  744. ################################################################
  745. #### Build and test many configurations and targets
  746. ################################################################
  747. component_test_default_out_of_box () {
  748. msg "build: make, default config (out-of-box)" # ~1min
  749. make
  750. # Disable fancy stuff
  751. SAVE_MBEDTLS_TEST_OUTCOME_FILE="$MBEDTLS_TEST_OUTCOME_FILE"
  752. unset MBEDTLS_TEST_OUTCOME_FILE
  753. msg "test: main suites make, default config (out-of-box)" # ~10s
  754. make test
  755. msg "selftest: make, default config (out-of-box)" # ~10s
  756. programs/test/selftest
  757. export MBEDTLS_TEST_OUTCOME_FILE="$SAVE_MBEDTLS_TEST_OUTCOME_FILE"
  758. unset SAVE_MBEDTLS_TEST_OUTCOME_FILE
  759. }
  760. component_test_default_cmake_gcc_asan () {
  761. msg "build: cmake, gcc, ASan" # ~ 1 min 50s
  762. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  763. make
  764. msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
  765. make test
  766. msg "test: selftest (ASan build)" # ~ 10s
  767. programs/test/selftest
  768. msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
  769. tests/ssl-opt.sh
  770. msg "test: compat.sh (ASan build)" # ~ 6 min
  771. tests/compat.sh
  772. msg "test: context-info.sh (ASan build)" # ~ 15 sec
  773. tests/context-info.sh
  774. }
  775. component_test_full_cmake_gcc_asan () {
  776. msg "build: full config, cmake, gcc, ASan"
  777. scripts/config.py full
  778. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  779. make
  780. msg "test: main suites (inc. selftests) (full config, ASan build)"
  781. make test
  782. msg "test: selftest (ASan build)" # ~ 10s
  783. programs/test/selftest
  784. msg "test: ssl-opt.sh (full config, ASan build)"
  785. tests/ssl-opt.sh
  786. msg "test: compat.sh (full config, ASan build)"
  787. tests/compat.sh
  788. msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
  789. tests/context-info.sh
  790. }
  791. component_test_psa_crypto_key_id_encodes_owner () {
  792. msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
  793. scripts/config.py full
  794. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  795. scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
  796. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  797. make
  798. msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
  799. make test
  800. }
  801. # check_renamed_symbols HEADER LIB
  802. # Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
  803. # name is LIB.
  804. check_renamed_symbols () {
  805. ! nm "$2" | sed 's/.* //' |
  806. grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
  807. }
  808. component_build_psa_crypto_spm () {
  809. msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
  810. scripts/config.py full
  811. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  812. scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
  813. scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
  814. scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
  815. # We can only compile, not link, since our test and sample programs
  816. # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
  817. # is active.
  818. make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
  819. # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
  820. # version is not present.
  821. echo "Checking for renamed symbols in the library"
  822. check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
  823. }
  824. component_test_psa_crypto_client () {
  825. msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
  826. scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
  827. scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
  828. scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
  829. make
  830. msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
  831. make test
  832. }
  833. component_test_zlib_make() {
  834. msg "build: zlib enabled, make"
  835. scripts/config.py set MBEDTLS_ZLIB_SUPPORT
  836. make ZLIB=1 CFLAGS='-Werror -O2'
  837. msg "test: main suites (zlib, make)"
  838. make test
  839. msg "test: ssl-opt.sh (zlib, make)"
  840. tests/ssl-opt.sh
  841. }
  842. support_test_zlib_make () {
  843. base=support_test_zlib_$$
  844. cat <<'EOF' > ${base}.c
  845. #include "zlib.h"
  846. int main(void) { return 0; }
  847. EOF
  848. gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
  849. ret=$?
  850. rm -f ${base}.*
  851. return $ret
  852. }
  853. component_test_zlib_cmake() {
  854. msg "build: zlib enabled, cmake"
  855. scripts/config.py set MBEDTLS_ZLIB_SUPPORT
  856. cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Release .
  857. make
  858. msg "test: main suites (zlib, cmake)"
  859. make test
  860. msg "test: ssl-opt.sh (zlib, cmake)"
  861. tests/ssl-opt.sh
  862. }
  863. support_test_zlib_cmake () {
  864. support_test_zlib_make "$@"
  865. }
  866. component_test_psa_crypto_rsa_no_genprime() {
  867. msg "build: default config minus MBEDTLS_GENPRIME"
  868. scripts/config.py unset MBEDTLS_GENPRIME
  869. make
  870. msg "test: default config minus MBEDTLS_GENPRIME"
  871. make test
  872. }
  873. component_test_ref_configs () {
  874. msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
  875. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  876. tests/scripts/test-ref-configs.pl
  877. }
  878. component_test_sslv3 () {
  879. msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
  880. scripts/config.py set MBEDTLS_SSL_PROTO_SSL3
  881. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  882. make
  883. msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
  884. make test
  885. msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
  886. tests/compat.sh -m 'tls1 tls1_1 tls12 dtls1 dtls12'
  887. env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
  888. msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
  889. tests/ssl-opt.sh
  890. msg "build: SSLv3 - context-info.sh (ASan build)" # ~ 15 sec
  891. tests/context-info.sh
  892. }
  893. component_test_no_renegotiation () {
  894. msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
  895. scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
  896. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  897. make
  898. msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
  899. make test
  900. msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
  901. tests/ssl-opt.sh
  902. }
  903. component_test_no_pem_no_fs () {
  904. msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
  905. scripts/config.py unset MBEDTLS_PEM_PARSE_C
  906. scripts/config.py unset MBEDTLS_FS_IO
  907. scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
  908. scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
  909. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  910. make
  911. msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
  912. make test
  913. msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
  914. tests/ssl-opt.sh
  915. }
  916. component_test_rsa_no_crt () {
  917. msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
  918. scripts/config.py set MBEDTLS_RSA_NO_CRT
  919. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  920. make
  921. msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
  922. make test
  923. msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
  924. tests/ssl-opt.sh -f RSA
  925. msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
  926. tests/compat.sh -t RSA
  927. msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
  928. tests/context-info.sh
  929. }
  930. component_test_no_ctr_drbg_classic () {
  931. msg "build: Full minus CTR_DRBG, classic crypto in TLS"
  932. scripts/config.py full
  933. scripts/config.py unset MBEDTLS_CTR_DRBG_C
  934. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  935. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  936. make
  937. msg "test: Full minus CTR_DRBG, classic crypto - main suites"
  938. make test
  939. # In this configuration, the TLS test programs use HMAC_DRBG.
  940. # The SSL tests are slow, so run a small subset, just enough to get
  941. # confidence that the SSL code copes with HMAC_DRBG.
  942. msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
  943. tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
  944. msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
  945. tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
  946. }
  947. component_test_no_ctr_drbg_use_psa () {
  948. msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
  949. scripts/config.py full
  950. scripts/config.py unset MBEDTLS_CTR_DRBG_C
  951. scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
  952. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  953. make
  954. msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
  955. make test
  956. # In this configuration, the TLS test programs use HMAC_DRBG.
  957. # The SSL tests are slow, so run a small subset, just enough to get
  958. # confidence that the SSL code copes with HMAC_DRBG.
  959. msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
  960. tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
  961. msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
  962. tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
  963. }
  964. component_test_no_hmac_drbg_classic () {
  965. msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
  966. scripts/config.py full
  967. scripts/config.py unset MBEDTLS_HMAC_DRBG_C
  968. scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
  969. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  970. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  971. make
  972. msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
  973. make test
  974. # Normally our ECDSA implementation uses deterministic ECDSA. But since
  975. # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
  976. # instead.
  977. # Test SSL with non-deterministic ECDSA. Only test features that
  978. # might be affected by how ECDSA signature is performed.
  979. msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
  980. tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
  981. # To save time, only test one protocol version, since this part of
  982. # the protocol is identical in (D)TLS up to 1.2.
  983. msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
  984. tests/compat.sh -m tls12 -t 'ECDSA'
  985. }
  986. component_test_no_hmac_drbg_use_psa () {
  987. msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
  988. scripts/config.py full
  989. scripts/config.py unset MBEDTLS_HMAC_DRBG_C
  990. scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
  991. scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
  992. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  993. make
  994. msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
  995. make test
  996. # Normally our ECDSA implementation uses deterministic ECDSA. But since
  997. # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
  998. # instead.
  999. # Test SSL with non-deterministic ECDSA. Only test features that
  1000. # might be affected by how ECDSA signature is performed.
  1001. msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
  1002. tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
  1003. # To save time, only test one protocol version, since this part of
  1004. # the protocol is identical in (D)TLS up to 1.2.
  1005. msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
  1006. tests/compat.sh -m tls12 -t 'ECDSA'
  1007. }
  1008. component_test_psa_external_rng_no_drbg_classic () {
  1009. msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
  1010. scripts/config.py full
  1011. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1012. scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
  1013. scripts/config.py unset MBEDTLS_ENTROPY_C
  1014. scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
  1015. scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
  1016. scripts/config.py unset MBEDTLS_CTR_DRBG_C
  1017. scripts/config.py unset MBEDTLS_HMAC_DRBG_C
  1018. scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
  1019. scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
  1020. # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
  1021. # the SSL test programs don't have an RNG and can't work. Explicitly
  1022. # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
  1023. make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
  1024. msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
  1025. make test
  1026. msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
  1027. tests/ssl-opt.sh -f 'Default'
  1028. }
  1029. component_test_psa_external_rng_no_drbg_use_psa () {
  1030. msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
  1031. scripts/config.py full
  1032. scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
  1033. scripts/config.py unset MBEDTLS_ENTROPY_C
  1034. scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
  1035. scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
  1036. scripts/config.py unset MBEDTLS_CTR_DRBG_C
  1037. scripts/config.py unset MBEDTLS_HMAC_DRBG_C
  1038. scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
  1039. scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
  1040. make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
  1041. msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
  1042. make test
  1043. msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
  1044. tests/ssl-opt.sh -f 'Default\|opaque'
  1045. }
  1046. component_test_psa_external_rng_use_psa_crypto () {
  1047. msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
  1048. scripts/config.py full
  1049. scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
  1050. scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
  1051. scripts/config.py unset MBEDTLS_CTR_DRBG_C
  1052. make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
  1053. msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
  1054. make test
  1055. msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
  1056. tests/ssl-opt.sh -f 'Default\|opaque'
  1057. }
  1058. component_test_ecp_no_internal_rng () {
  1059. msg "build: Default plus ECP_NO_INTERNAL_RNG minus DRBG modules"
  1060. scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
  1061. scripts/config.py unset MBEDTLS_CTR_DRBG_C
  1062. scripts/config.py unset MBEDTLS_HMAC_DRBG_C
  1063. scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
  1064. scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
  1065. scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
  1066. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  1067. make
  1068. msg "test: ECP_NO_INTERNAL_RNG, no DRBG module"
  1069. make test
  1070. # no SSL tests as they all depend on having a DRBG
  1071. }
  1072. component_test_ecp_restartable_no_internal_rng () {
  1073. msg "build: Default plus ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG"
  1074. scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
  1075. scripts/config.py set MBEDTLS_ECP_RESTARTABLE
  1076. scripts/config.py unset MBEDTLS_CTR_DRBG_C
  1077. scripts/config.py unset MBEDTLS_HMAC_DRBG_C
  1078. scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
  1079. scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires CTR_DRBG
  1080. scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
  1081. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  1082. make
  1083. msg "test: ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG module"
  1084. make test
  1085. # no SSL tests as they all depend on having a DRBG
  1086. }
  1087. component_test_new_ecdh_context () {
  1088. msg "build: new ECDH context (ASan build)" # ~ 6 min
  1089. scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
  1090. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  1091. make
  1092. msg "test: new ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
  1093. make test
  1094. msg "test: new ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
  1095. tests/ssl-opt.sh -f ECDH
  1096. msg "test: new ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
  1097. # Exclude some symmetric ciphers that are redundant here to gain time.
  1098. tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
  1099. }
  1100. component_test_everest () {
  1101. msg "build: Everest ECDH context (ASan build)" # ~ 6 min
  1102. scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
  1103. scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
  1104. CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
  1105. make
  1106. msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
  1107. make test
  1108. msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
  1109. tests/ssl-opt.sh -f ECDH
  1110. msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
  1111. # Exclude some symmetric ciphers that are redundant here to gain time.
  1112. tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
  1113. }
  1114. component_test_everest_curve25519_only () {
  1115. msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
  1116. scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
  1117. scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
  1118. scripts/config.py unset MBEDTLS_ECDSA_C
  1119. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
  1120. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
  1121. # Disable all curves
  1122. for c in $(sed -n 's/#define \(MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED\).*/\1/p' <"$CONFIG_H"); do
  1123. scripts/config.py unset "$c"
  1124. done
  1125. scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
  1126. make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
  1127. msg "test: Everest ECDH context, only Curve25519" # ~ 50s
  1128. make test
  1129. }
  1130. component_test_small_ssl_out_content_len () {
  1131. msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
  1132. scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
  1133. scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
  1134. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  1135. make
  1136. msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
  1137. tests/ssl-opt.sh -f "Max fragment\|Large packet"
  1138. }
  1139. component_test_small_ssl_in_content_len () {
  1140. msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
  1141. scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
  1142. scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
  1143. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  1144. make
  1145. msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
  1146. tests/ssl-opt.sh -f "Max fragment"
  1147. }
  1148. component_test_small_ssl_dtls_max_buffering () {
  1149. msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
  1150. scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
  1151. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  1152. make
  1153. msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
  1154. tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
  1155. }
  1156. component_test_small_mbedtls_ssl_dtls_max_buffering () {
  1157. msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
  1158. scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
  1159. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  1160. make
  1161. msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
  1162. tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
  1163. }
  1164. component_test_psa_collect_statuses () {
  1165. msg "build+test: psa_collect_statuses" # ~30s
  1166. scripts/config.py full
  1167. tests/scripts/psa_collect_statuses.py
  1168. # Check that psa_crypto_init() succeeded at least once
  1169. grep -q '^0:psa_crypto_init:' tests/statuses.log
  1170. rm -f tests/statuses.log
  1171. }
  1172. component_test_full_cmake_clang () {
  1173. msg "build: cmake, full config, clang" # ~ 50s
  1174. scripts/config.py full
  1175. CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release -D ENABLE_TESTING=On .
  1176. make
  1177. msg "test: main suites (full config, clang)" # ~ 5s
  1178. make test
  1179. msg "test: psa_constant_names (full config, clang)" # ~ 1s
  1180. tests/scripts/test_psa_constant_names.py
  1181. msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
  1182. tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
  1183. msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
  1184. env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '^$' -f 'NULL\|DES\|RC4\|ARCFOUR'
  1185. msg "test: compat.sh ARIA + ChachaPoly"
  1186. env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
  1187. }
  1188. component_test_memsan_constant_flow () {
  1189. # This tests both (1) accesses to undefined memory, and (2) branches or
  1190. # memory access depending on secret values. To distinguish between those:
  1191. # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
  1192. # - or alternatively, change the build type to MemSanDbg, which enables
  1193. # origin tracking and nicer stack traces (which are useful for debugging
  1194. # anyway), and check if the origin was TEST_CF_SECRET() or something else.
  1195. msg "build: cmake MSan (clang), full config with constant flow testing"
  1196. scripts/config.py full
  1197. scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
  1198. scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
  1199. CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
  1200. make
  1201. msg "test: main suites (Msan + constant flow)"
  1202. make test
  1203. }
  1204. component_test_valgrind_constant_flow () {
  1205. # This tests both (1) everything that valgrind's memcheck usually checks
  1206. # (heap buffer overflows, use of uninitialized memory, use-after-free,
  1207. # etc.) and (2) branches or memory access depending on secret values,
  1208. # which will be reported as uninitialized memory. To distinguish between
  1209. # secret and actually uninitialized:
  1210. # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
  1211. # - or alternatively, build with debug info and manually run the offending
  1212. # test suite with valgrind --track-origins=yes, then check if the origin
  1213. # was TEST_CF_SECRET() or something else.
  1214. msg "build: cmake release GCC, full config with constant flow testing"
  1215. scripts/config.py full
  1216. scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
  1217. cmake -D CMAKE_BUILD_TYPE:String=Release .
  1218. make
  1219. # this only shows a summary of the results (how many of each type)
  1220. # details are left in Testing/<date>/DynamicAnalysis.xml
  1221. msg "test: main suites (valgrind + constant flow)"
  1222. make memcheck
  1223. }
  1224. component_test_default_no_deprecated () {
  1225. # Test that removing the deprecated features from the default
  1226. # configuration leaves something consistent.
  1227. msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
  1228. scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
  1229. make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
  1230. msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
  1231. make test
  1232. }
  1233. component_test_full_no_deprecated () {
  1234. msg "build: make, full_no_deprecated config" # ~ 30s
  1235. scripts/config.py full_no_deprecated
  1236. make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
  1237. msg "test: make, full_no_deprecated config" # ~ 5s
  1238. make test
  1239. }
  1240. component_test_full_no_deprecated_deprecated_warning () {
  1241. # Test that there is nothing deprecated in "full_no_deprecated".
  1242. # A deprecated feature would trigger a warning (made fatal) from
  1243. # MBEDTLS_DEPRECATED_WARNING.
  1244. msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
  1245. scripts/config.py full_no_deprecated
  1246. scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
  1247. scripts/config.py set MBEDTLS_DEPRECATED_WARNING
  1248. make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
  1249. msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
  1250. make test
  1251. }
  1252. component_test_full_deprecated_warning () {
  1253. # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
  1254. # with only certain whitelisted types of warnings.
  1255. msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
  1256. scripts/config.py full
  1257. scripts/config.py set MBEDTLS_DEPRECATED_WARNING
  1258. # Expect warnings from '#warning' directives in check_config.h.
  1259. make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
  1260. msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
  1261. # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
  1262. # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
  1263. # Expect warnings from '#warning' directives in check_config.h and
  1264. # from the use of deprecated functions in test suites.
  1265. make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=deprecated-declarations -Wno-error=cpp -DMBEDTLS_TEST_DEPRECATED' tests
  1266. msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
  1267. make test
  1268. }
  1269. # Check that the specified libraries exist and are empty.
  1270. are_empty_libraries () {
  1271. nm "$@" >/dev/null 2>/dev/null
  1272. ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
  1273. }
  1274. component_build_crypto_default () {
  1275. msg "build: make, crypto only"
  1276. scripts/config.py crypto
  1277. make CFLAGS='-O1 -Werror'
  1278. are_empty_libraries library/libmbedx509.* library/libmbedtls.*
  1279. }
  1280. component_build_crypto_full () {
  1281. msg "build: make, crypto only, full config"
  1282. scripts/config.py crypto_full
  1283. make CFLAGS='-O1 -Werror'
  1284. are_empty_libraries library/libmbedx509.* library/libmbedtls.*
  1285. }
  1286. component_build_crypto_baremetal () {
  1287. msg "build: make, crypto only, baremetal config"
  1288. scripts/config.py crypto_baremetal
  1289. make CFLAGS='-O1 -Werror'
  1290. are_empty_libraries library/libmbedx509.* library/libmbedtls.*
  1291. }
  1292. component_test_depends_curves () {
  1293. msg "test/build: curves.pl (gcc)" # ~ 4 min
  1294. tests/scripts/curves.pl
  1295. }
  1296. component_test_depends_curves_psa () {
  1297. msg "test/build: curves.pl with MBEDTLS_USE_PSA_CRYPTO defined (gcc)"
  1298. scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
  1299. tests/scripts/curves.pl
  1300. }
  1301. component_test_depends_hashes () {
  1302. msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
  1303. tests/scripts/depends-hashes.pl
  1304. }
  1305. component_test_depends_hashes_psa () {
  1306. msg "test/build: depends-hashes.pl with MBEDTLS_USE_PSA_CRYPTO defined (gcc)"
  1307. scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
  1308. tests/scripts/depends-hashes.pl
  1309. }
  1310. component_test_depends_pkalgs () {
  1311. msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
  1312. tests/scripts/depends-pkalgs.pl
  1313. }
  1314. component_test_depends_pkalgs_psa () {
  1315. msg "test/build: depends-pkalgs.pl with MBEDTLS_USE_PSA_CRYPTO defined (gcc)"
  1316. scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
  1317. tests/scripts/depends-pkalgs.pl
  1318. }
  1319. component_build_key_exchanges () {
  1320. msg "test/build: key-exchanges (gcc)" # ~ 1 min
  1321. tests/scripts/key-exchanges.pl
  1322. }
  1323. component_test_make_cxx () {
  1324. msg "build: Unix make, full, gcc + g++"
  1325. scripts/config.py full
  1326. make TEST_CPP=1 lib programs
  1327. msg "test: cpp_dummy_build"
  1328. programs/test/cpp_dummy_build
  1329. }
  1330. component_test_no_use_psa_crypto_full_cmake_asan() {
  1331. # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
  1332. msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
  1333. scripts/config.py full
  1334. scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
  1335. scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
  1336. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1337. scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
  1338. scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
  1339. scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
  1340. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  1341. make
  1342. msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
  1343. make test
  1344. msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
  1345. tests/ssl-opt.sh
  1346. msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
  1347. tests/compat.sh
  1348. msg "test: compat.sh RC4, DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
  1349. env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '3DES\|DES-CBC3' -f 'NULL\|DES\|RC4\|ARCFOUR'
  1350. msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
  1351. env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
  1352. }
  1353. component_test_psa_crypto_config_accel_ecdsa () {
  1354. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
  1355. # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
  1356. # partial support for cipher operations in the driver test library.
  1357. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
  1358. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
  1359. # SHA384 needed for some ECDSA signature tests.
  1360. scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
  1361. loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA KEY_TYPE_ECC_KEY_PAIR KEY_TYPE_ECC_PUBLIC_KEY"
  1362. loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
  1363. make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
  1364. # Restore test driver base configuration
  1365. scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
  1366. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1367. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1368. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1369. scripts/config.py unset MBEDTLS_ECDSA_C
  1370. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
  1371. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
  1372. loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
  1373. make CFLAGS="$ASAN_CFLAGS -O -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
  1374. unset loc_accel_flags
  1375. unset loc_accel_list
  1376. if_build_succeeded not grep mbedtls_ecdsa_ library/ecdsa.o
  1377. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
  1378. make test
  1379. }
  1380. component_test_psa_crypto_config_accel_rsa_signature () {
  1381. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
  1382. # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
  1383. # partial support for cipher operations in the driver test library.
  1384. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
  1385. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
  1386. # It seems it is not possible to remove only the support for RSA signature
  1387. # in the library. Thus we have to remove all RSA support (signature and
  1388. # encryption/decryption). AS there is no driver support for asymmetric
  1389. # encryption/decryption so far remove RSA encryption/decryption from the
  1390. # application algorithm list.
  1391. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
  1392. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
  1393. # Make sure both the library and the test library support the SHA hash
  1394. # algorithms and only those ones (SHA256 is included by default). That way:
  1395. # - the test library can compute the RSA signatures even in the case of a
  1396. # composite RSA signature algorithm based on a SHA hash (no other hash
  1397. # used in the unit tests).
  1398. # - the dependency of RSA signature tests on PSA_WANT_ALG_SHA_xyz is
  1399. # fulfilled as the hash SHA algorithm is supported by the library, and
  1400. # thus the tests are run, not skipped.
  1401. # - when testing a signature key with an algorithm wildcard built from
  1402. # PSA_ALG_ANY_HASH as algorithm to test with the key, the chosen hash
  1403. # algorithm based on the hashes supported by the library is also
  1404. # supported by the test library.
  1405. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
  1406. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
  1407. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
  1408. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160_C
  1409. scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA1_C
  1410. scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
  1411. # We need PEM parsing in the test library as well to support the import
  1412. # of PEM encoded RSA keys.
  1413. scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_PEM_PARSE_C
  1414. scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_BASE64_C
  1415. loc_accel_list="ALG_RSA_PKCS1V15_SIGN ALG_RSA_PSS KEY_TYPE_RSA_KEY_PAIR KEY_TYPE_RSA_PUBLIC_KEY"
  1416. loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
  1417. make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
  1418. # Restore test driver base configuration
  1419. scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA1_C
  1420. scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
  1421. scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_PEM_PARSE_C
  1422. scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_BASE64_C
  1423. # Mbed TLS library build
  1424. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1425. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1426. # Remove RSA support and its dependencies
  1427. scripts/config.py unset MBEDTLS_PKCS1_V15
  1428. scripts/config.py unset MBEDTLS_PKCS1_V21
  1429. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
  1430. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
  1431. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
  1432. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
  1433. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
  1434. scripts/config.py unset MBEDTLS_RSA_C
  1435. scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
  1436. scripts/config.py unset MBEDTLS_MD2_C
  1437. scripts/config.py unset MBEDTLS_MD4_C
  1438. scripts/config.py unset MBEDTLS_MD5_C
  1439. scripts/config.py unset MBEDTLS_RIPEMD160_C
  1440. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
  1441. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
  1442. scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
  1443. loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
  1444. make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
  1445. unset loc_accel_flags
  1446. unset loc_accel_list
  1447. if_build_succeeded not grep mbedtls_rsa_rsassa_pkcs1_v15_sign library/rsa.o
  1448. if_build_succeeded not grep mbedtls_rsa_rsassa_pss_sign_ext library/rsa.o
  1449. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
  1450. make test
  1451. }
  1452. component_test_psa_crypto_config_accel_hash () {
  1453. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
  1454. # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
  1455. # partial support for cipher operations in the driver test library.
  1456. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
  1457. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
  1458. loc_accel_list="ALG_MD4 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
  1459. loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
  1460. make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
  1461. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1462. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1463. scripts/config.py unset MBEDTLS_MD2_C
  1464. scripts/config.py unset MBEDTLS_MD4_C
  1465. scripts/config.py unset MBEDTLS_MD5_C
  1466. scripts/config.py unset MBEDTLS_RIPEMD160_C
  1467. scripts/config.py unset MBEDTLS_SHA1_C
  1468. # Don't unset MBEDTLS_SHA256_C as it is needed by PSA crypto core.
  1469. scripts/config.py unset MBEDTLS_SHA512_C
  1470. # Unset MBEDTLS_SSL_PROTO_SSL3, MBEDTLS_SSL_PROTO_TLS1 and MBEDTLS_SSL_PROTO_TLS1_1 as they depend on MBEDTLS_SHA1_C
  1471. scripts/config.py unset MBEDTLS_SSL_PROTO_SSL3
  1472. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
  1473. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
  1474. # Unset MBEDTLS_SSL_CBC_RECORD_SPLITTING as it depends on MBEDTLS_SSL_PROTO_TLS1 in the default configuration.
  1475. scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
  1476. loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
  1477. make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
  1478. unset loc_accel_flags
  1479. unset loc_accel_list
  1480. if_build_succeeded not grep mbedtls_sha512_init library/sha512.o
  1481. if_build_succeeded not grep mbedtls_sha1_init library/sha1.o
  1482. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
  1483. make test
  1484. }
  1485. component_test_psa_crypto_config_accel_cipher () {
  1486. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
  1487. loc_accel_list="ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB ALG_OFB ALG_XTS KEY_TYPE_DES"
  1488. loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
  1489. make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
  1490. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1491. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1492. # There is no intended accelerator support for ALG STREAM_CIPHER and
  1493. # ALG_ECB_NO_PADDING. Therefore, asking for them in the build implies the
  1494. # inclusion of the Mbed TLS cipher operations. As we want to test here with
  1495. # cipher operations solely supported by accelerators, disabled those
  1496. # PSA configuration options.
  1497. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
  1498. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
  1499. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_CMAC
  1500. scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
  1501. scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
  1502. scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
  1503. scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
  1504. scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
  1505. scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
  1506. scripts/config.py unset MBEDTLS_DES_C
  1507. loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
  1508. make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
  1509. unset loc_accel_flags
  1510. unset loc_accel_list
  1511. if_build_succeeded not grep mbedtls_des* library/des.o
  1512. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
  1513. make test
  1514. }
  1515. component_test_psa_crypto_config_no_driver() {
  1516. # full plus MBEDTLS_PSA_CRYPTO_CONFIG
  1517. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
  1518. scripts/config.py full
  1519. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1520. scripts/config.py unset MBEDTLS_PSA_CRYPTO_DRIVERS
  1521. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1522. make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
  1523. msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
  1524. make test
  1525. }
  1526. component_test_psa_crypto_config_chachapoly_disabled() {
  1527. # full minus MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305
  1528. msg "build: full minus MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305"
  1529. scripts/config.py full
  1530. scripts/config.py unset MBEDTLS_CHACHAPOLY_C
  1531. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_GCM
  1532. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_CHACHA20_POLY1305
  1533. make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
  1534. msg "test: full minus MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305"
  1535. make test
  1536. }
  1537. # This should be renamed to test and updated once the accelerator ECDSA code is in place and ready to test.
  1538. component_build_psa_accel_alg_ecdsa() {
  1539. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_ECDSA
  1540. # without MBEDTLS_ECDSA_C
  1541. # PSA_WANT_ALG_ECDSA and PSA_WANT_ALG_DETERMINISTIC_ECDSA are already
  1542. # set in include/psa/crypto_config.h
  1543. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_ECDSA without MBEDTLS_ECDSA_C"
  1544. scripts/config.py full
  1545. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1546. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1547. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1548. scripts/config.py unset MBEDTLS_ECDSA_C
  1549. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
  1550. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
  1551. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  1552. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDSA -DMBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  1553. }
  1554. # This should be renamed to test and updated once the accelerator ECDH code is in place and ready to test.
  1555. component_build_psa_accel_alg_ecdh() {
  1556. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_ECDH
  1557. # without MBEDTLS_ECDH_C
  1558. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
  1559. scripts/config.py full
  1560. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1561. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1562. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1563. scripts/config.py unset MBEDTLS_ECDH_C
  1564. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
  1565. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
  1566. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
  1567. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
  1568. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
  1569. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  1570. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  1571. }
  1572. # This should be renamed to test and updated once the accelerator ECC key pair code is in place and ready to test.
  1573. component_build_psa_accel_key_type_ecc_key_pair() {
  1574. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
  1575. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR"
  1576. scripts/config.py full
  1577. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1578. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1579. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1580. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_KEY_PAIR 1
  1581. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
  1582. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  1583. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  1584. }
  1585. # This should be renamed to test and updated once the accelerator ECC public key code is in place and ready to test.
  1586. component_build_psa_accel_key_type_ecc_public_key() {
  1587. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY
  1588. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY"
  1589. scripts/config.py full
  1590. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1591. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1592. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1593. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
  1594. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
  1595. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  1596. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  1597. }
  1598. # This should be renamed to test and updated once the accelerator HMAC code is in place and ready to test.
  1599. component_build_psa_accel_alg_hmac() {
  1600. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HMAC
  1601. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HMAC"
  1602. scripts/config.py full
  1603. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1604. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1605. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1606. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  1607. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  1608. }
  1609. # This should be renamed to test and updated once the accelerator HKDF code is in place and ready to test.
  1610. component_build_psa_accel_alg_hkdf() {
  1611. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HKDF
  1612. # without MBEDTLS_HKDF_C
  1613. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
  1614. scripts/config.py full
  1615. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1616. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1617. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1618. scripts/config.py unset MBEDTLS_HKDF_C
  1619. # Make sure to unset TLS1_3_EXPERIMENTAL since it requires HKDF_C and will not build properly without it.
  1620. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
  1621. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  1622. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  1623. }
  1624. # This should be renamed to test and updated once the accelerator MD2 code is in place and ready to test.
  1625. component_build_psa_accel_alg_md2() {
  1626. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD2 without other hashes
  1627. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD2 - other hashes"
  1628. scripts/config.py full
  1629. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1630. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1631. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1632. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
  1633. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
  1634. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
  1635. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
  1636. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
  1637. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
  1638. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
  1639. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
  1640. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  1641. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD2 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  1642. }
  1643. # This should be renamed to test and updated once the accelerator MD4 code is in place and ready to test.
  1644. component_build_psa_accel_alg_md4() {
  1645. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD4 without other hashes
  1646. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD4 - other hashes"
  1647. scripts/config.py full
  1648. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1649. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1650. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1651. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
  1652. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
  1653. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
  1654. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
  1655. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
  1656. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
  1657. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
  1658. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
  1659. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  1660. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD4 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  1661. }
  1662. # This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
  1663. component_build_psa_accel_alg_md5() {
  1664. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD5 without other hashes
  1665. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD5 - other hashes"
  1666. scripts/config.py full
  1667. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1668. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1669. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1670. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
  1671. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
  1672. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
  1673. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
  1674. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
  1675. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
  1676. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
  1677. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
  1678. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  1679. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  1680. }
  1681. # This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
  1682. component_build_psa_accel_alg_ripemd160() {
  1683. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RIPEMD160 without other hashes
  1684. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RIPEMD160 - other hashes"
  1685. scripts/config.py full
  1686. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1687. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1688. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1689. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
  1690. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
  1691. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
  1692. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
  1693. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
  1694. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
  1695. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
  1696. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
  1697. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  1698. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  1699. }
  1700. # This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
  1701. component_build_psa_accel_alg_sha1() {
  1702. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_1 without other hashes
  1703. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_1 - other hashes"
  1704. scripts/config.py full
  1705. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1706. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1707. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1708. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
  1709. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
  1710. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
  1711. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
  1712. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
  1713. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
  1714. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
  1715. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
  1716. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  1717. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  1718. }
  1719. # This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
  1720. component_build_psa_accel_alg_sha224() {
  1721. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_224 without other hashes
  1722. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_224 - other hashes"
  1723. scripts/config.py full
  1724. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1725. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1726. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1727. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
  1728. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
  1729. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
  1730. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
  1731. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
  1732. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
  1733. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
  1734. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  1735. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  1736. }
  1737. # This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
  1738. component_build_psa_accel_alg_sha256() {
  1739. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_256 without other hashes
  1740. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_256 - other hashes"
  1741. scripts/config.py full
  1742. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1743. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1744. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1745. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
  1746. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
  1747. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
  1748. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
  1749. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
  1750. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
  1751. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
  1752. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
  1753. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  1754. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  1755. }
  1756. # This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
  1757. component_build_psa_accel_alg_sha384() {
  1758. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_384 without other hashes
  1759. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_384 - other hashes"
  1760. scripts/config.py full
  1761. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1762. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1763. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1764. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
  1765. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
  1766. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
  1767. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
  1768. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
  1769. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
  1770. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
  1771. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  1772. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  1773. }
  1774. # This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
  1775. component_build_psa_accel_alg_sha512() {
  1776. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_512 without other hashes
  1777. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_512 - other hashes"
  1778. scripts/config.py full
  1779. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1780. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1781. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1782. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
  1783. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
  1784. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
  1785. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
  1786. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
  1787. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
  1788. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
  1789. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
  1790. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  1791. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  1792. }
  1793. # This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
  1794. component_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
  1795. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
  1796. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PKCS1V15_CRYPT + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
  1797. scripts/config.py full
  1798. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1799. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1800. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1801. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
  1802. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
  1803. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
  1804. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
  1805. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  1806. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  1807. }
  1808. # This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
  1809. component_build_psa_accel_alg_rsa_pkcs1v15_sign() {
  1810. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_SIGN and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
  1811. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PKCS1V15_SIGN + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
  1812. scripts/config.py full
  1813. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1814. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1815. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1816. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
  1817. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
  1818. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
  1819. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
  1820. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  1821. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  1822. }
  1823. # This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
  1824. component_build_psa_accel_alg_rsa_oaep() {
  1825. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_OAEP and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
  1826. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_OAEP + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
  1827. scripts/config.py full
  1828. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1829. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1830. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1831. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_OAEP 1
  1832. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
  1833. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
  1834. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
  1835. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  1836. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  1837. }
  1838. # This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
  1839. component_build_psa_accel_alg_rsa_pss() {
  1840. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PSS and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
  1841. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PSS + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
  1842. scripts/config.py full
  1843. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1844. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1845. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1846. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
  1847. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
  1848. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
  1849. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
  1850. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  1851. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  1852. }
  1853. # This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
  1854. component_build_psa_accel_key_type_rsa_key_pair() {
  1855. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_KEY_PAIR and PSA_WANT_ALG_RSA_PSS
  1856. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR + PSA_WANT_ALG_RSA_PSS"
  1857. scripts/config.py full
  1858. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1859. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1860. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1861. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
  1862. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1
  1863. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  1864. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  1865. }
  1866. # This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
  1867. component_build_psa_accel_key_type_rsa_public_key() {
  1868. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY and PSA_WANT_ALG_RSA_PSS
  1869. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + PSA_WANT_ALG_RSA_PSS"
  1870. scripts/config.py full
  1871. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1872. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1873. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1874. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
  1875. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
  1876. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  1877. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  1878. }
  1879. component_test_check_params_functionality () {
  1880. msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
  1881. scripts/config.py full # includes CHECK_PARAMS
  1882. # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
  1883. scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
  1884. make CC=gcc CFLAGS='-Werror -O1' all test
  1885. }
  1886. component_test_check_params_without_platform () {
  1887. msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
  1888. scripts/config.py full # includes CHECK_PARAMS
  1889. # Keep MBEDTLS_PARAM_FAILED as assert.
  1890. scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
  1891. scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
  1892. scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
  1893. scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
  1894. scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
  1895. scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
  1896. scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
  1897. scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
  1898. scripts/config.py unset MBEDTLS_PLATFORM_C
  1899. make CC=gcc CFLAGS='-Werror -O1' all test
  1900. }
  1901. component_test_check_params_silent () {
  1902. msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
  1903. scripts/config.py full # includes CHECK_PARAMS
  1904. # Set MBEDTLS_PARAM_FAILED to nothing.
  1905. sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
  1906. make CC=gcc CFLAGS='-Werror -O1' all test
  1907. }
  1908. component_test_no_platform () {
  1909. # Full configuration build, without platform support, file IO and net sockets.
  1910. # This should catch missing mbedtls_printf definitions, and by disabling file
  1911. # IO, it should catch missing '#include <stdio.h>'
  1912. msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
  1913. scripts/config.py full
  1914. scripts/config.py unset MBEDTLS_PLATFORM_C
  1915. scripts/config.py unset MBEDTLS_NET_C
  1916. scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
  1917. scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
  1918. scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
  1919. scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
  1920. scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
  1921. scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
  1922. scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
  1923. scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
  1924. scripts/config.py unset MBEDTLS_FS_IO
  1925. scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
  1926. scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
  1927. scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
  1928. # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
  1929. # to re-enable platform integration features otherwise disabled in C99 builds
  1930. make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
  1931. make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
  1932. }
  1933. component_build_no_std_function () {
  1934. # catch compile bugs in _uninit functions
  1935. msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
  1936. scripts/config.py full
  1937. scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
  1938. scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
  1939. scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
  1940. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
  1941. make
  1942. }
  1943. component_build_no_ssl_srv () {
  1944. msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
  1945. scripts/config.py full
  1946. scripts/config.py unset MBEDTLS_SSL_SRV_C
  1947. make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
  1948. }
  1949. component_build_no_ssl_cli () {
  1950. msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
  1951. scripts/config.py full
  1952. scripts/config.py unset MBEDTLS_SSL_CLI_C
  1953. make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
  1954. }
  1955. component_build_no_sockets () {
  1956. # Note, C99 compliance can also be tested with the sockets support disabled,
  1957. # as that requires a POSIX platform (which isn't the same as C99).
  1958. msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
  1959. scripts/config.py full
  1960. scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
  1961. scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
  1962. make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
  1963. }
  1964. component_test_memory_buffer_allocator_backtrace () {
  1965. msg "build: default config with memory buffer allocator and backtrace enabled"
  1966. scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
  1967. scripts/config.py set MBEDTLS_PLATFORM_MEMORY
  1968. scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
  1969. scripts/config.py set MBEDTLS_MEMORY_DEBUG
  1970. CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
  1971. make
  1972. msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
  1973. make test
  1974. }
  1975. component_test_memory_buffer_allocator () {
  1976. msg "build: default config with memory buffer allocator"
  1977. scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
  1978. scripts/config.py set MBEDTLS_PLATFORM_MEMORY
  1979. CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
  1980. make
  1981. msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
  1982. make test
  1983. msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
  1984. # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
  1985. tests/ssl-opt.sh -e '^DTLS proxy'
  1986. }
  1987. component_test_no_max_fragment_length () {
  1988. # Run max fragment length tests with MFL disabled
  1989. msg "build: default config except MFL extension (ASan build)" # ~ 30s
  1990. scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
  1991. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  1992. make
  1993. msg "test: ssl-opt.sh, MFL-related tests"
  1994. tests/ssl-opt.sh -f "Max fragment length"
  1995. }
  1996. component_test_asan_remove_peer_certificate () {
  1997. msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
  1998. scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
  1999. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  2000. make
  2001. msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
  2002. make test
  2003. msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
  2004. tests/ssl-opt.sh
  2005. msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
  2006. tests/compat.sh
  2007. msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
  2008. tests/context-info.sh
  2009. }
  2010. component_test_no_max_fragment_length_small_ssl_out_content_len () {
  2011. msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
  2012. scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
  2013. scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
  2014. scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
  2015. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  2016. make
  2017. msg "test: MFL tests (disabled MFL extension case) & large packet tests"
  2018. tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
  2019. msg "test: context-info.sh (disabled MFL extension case)"
  2020. tests/context-info.sh
  2021. }
  2022. component_test_variable_ssl_in_out_buffer_len () {
  2023. msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
  2024. scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
  2025. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  2026. make
  2027. msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
  2028. make test
  2029. msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
  2030. tests/ssl-opt.sh
  2031. msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
  2032. tests/compat.sh
  2033. }
  2034. component_test_variable_ssl_in_out_buffer_len_CID () {
  2035. msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled (ASan build)"
  2036. scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
  2037. scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID
  2038. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  2039. make
  2040. msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID"
  2041. make test
  2042. msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
  2043. tests/ssl-opt.sh
  2044. msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
  2045. tests/compat.sh
  2046. }
  2047. component_test_variable_ssl_in_out_buffer_len_record_splitting () {
  2048. msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled (ASan build)"
  2049. scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
  2050. scripts/config.py set MBEDTLS_SSL_CBC_RECORD_SPLITTING
  2051. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  2052. make
  2053. msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING"
  2054. make test
  2055. msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
  2056. tests/ssl-opt.sh
  2057. msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
  2058. tests/compat.sh
  2059. }
  2060. component_test_ssl_alloc_buffer_and_mfl () {
  2061. msg "build: default config with memory buffer allocator and MFL extension"
  2062. scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
  2063. scripts/config.py set MBEDTLS_PLATFORM_MEMORY
  2064. scripts/config.py set MBEDTLS_MEMORY_DEBUG
  2065. scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
  2066. scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
  2067. CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
  2068. make
  2069. msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
  2070. make test
  2071. msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
  2072. tests/ssl-opt.sh -f "Handshake memory usage"
  2073. }
  2074. component_test_when_no_ciphersuites_have_mac () {
  2075. msg "build: when no ciphersuites have MAC"
  2076. scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
  2077. scripts/config.py unset MBEDTLS_ARC4_C
  2078. scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
  2079. make
  2080. msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
  2081. make test
  2082. msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
  2083. tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
  2084. }
  2085. component_test_null_entropy () {
  2086. msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
  2087. scripts/config.py set MBEDTLS_TEST_NULL_ENTROPY
  2088. scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
  2089. scripts/config.py set MBEDTLS_ENTROPY_C
  2090. scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
  2091. scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
  2092. scripts/config.py unset MBEDTLS_ENTROPY_HARDWARE_ALT
  2093. scripts/config.py unset MBEDTLS_HAVEGE_C
  2094. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
  2095. make
  2096. msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
  2097. make test
  2098. }
  2099. component_test_no_date_time () {
  2100. msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
  2101. scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
  2102. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
  2103. make
  2104. msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
  2105. make test
  2106. }
  2107. component_test_platform_calloc_macro () {
  2108. msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
  2109. scripts/config.py set MBEDTLS_PLATFORM_MEMORY
  2110. scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
  2111. scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
  2112. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  2113. make
  2114. msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
  2115. make test
  2116. }
  2117. component_test_malloc_0_null () {
  2118. msg "build: malloc(0) returns NULL (ASan+UBSan build)"
  2119. scripts/config.py full
  2120. make CC=gcc CFLAGS="'-DMBEDTLS_CONFIG_FILE=\"$PWD/tests/configs/config-wrapper-malloc-0-null.h\"' $ASAN_CFLAGS -O" LDFLAGS="$ASAN_CFLAGS"
  2121. msg "test: malloc(0) returns NULL (ASan+UBSan build)"
  2122. make test
  2123. msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
  2124. # Just the calloc selftest. "make test" ran the others as part of the
  2125. # test suites.
  2126. programs/test/selftest calloc
  2127. msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
  2128. # Run a subset of the tests. The choice is a balance between coverage
  2129. # and time (including time indirectly wasted due to flaky tests).
  2130. # The current choice is to skip tests whose description includes
  2131. # "proxy", which is an approximation of skipping tests that use the
  2132. # UDP proxy, which tend to be slower and flakier.
  2133. tests/ssl-opt.sh -e 'proxy'
  2134. }
  2135. component_test_aes_fewer_tables () {
  2136. msg "build: default config with AES_FEWER_TABLES enabled"
  2137. scripts/config.py set MBEDTLS_AES_FEWER_TABLES
  2138. make CC=gcc CFLAGS='-Werror -Wall -Wextra'
  2139. msg "test: AES_FEWER_TABLES"
  2140. make test
  2141. }
  2142. component_test_aes_rom_tables () {
  2143. msg "build: default config with AES_ROM_TABLES enabled"
  2144. scripts/config.py set MBEDTLS_AES_ROM_TABLES
  2145. make CC=gcc CFLAGS='-Werror -Wall -Wextra'
  2146. msg "test: AES_ROM_TABLES"
  2147. make test
  2148. }
  2149. component_test_aes_fewer_tables_and_rom_tables () {
  2150. msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
  2151. scripts/config.py set MBEDTLS_AES_FEWER_TABLES
  2152. scripts/config.py set MBEDTLS_AES_ROM_TABLES
  2153. make CC=gcc CFLAGS='-Werror -Wall -Wextra'
  2154. msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
  2155. make test
  2156. }
  2157. component_test_ctr_drbg_aes_256_sha_256 () {
  2158. msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
  2159. scripts/config.py full
  2160. scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
  2161. scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
  2162. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  2163. make
  2164. msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
  2165. make test
  2166. }
  2167. component_test_ctr_drbg_aes_128_sha_512 () {
  2168. msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
  2169. scripts/config.py full
  2170. scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
  2171. scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
  2172. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  2173. make
  2174. msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
  2175. make test
  2176. }
  2177. component_test_ctr_drbg_aes_128_sha_256 () {
  2178. msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
  2179. scripts/config.py full
  2180. scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
  2181. scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
  2182. scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
  2183. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  2184. make
  2185. msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
  2186. make test
  2187. }
  2188. component_test_se_default () {
  2189. msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
  2190. scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
  2191. make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
  2192. msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
  2193. make test
  2194. }
  2195. component_test_psa_crypto_drivers () {
  2196. msg "build: MBEDTLS_PSA_CRYPTO_DRIVERS w/ driver hooks"
  2197. scripts/config.py full
  2198. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2199. scripts/config.py set MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
  2200. loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
  2201. loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
  2202. loc_cflags="${loc_cflags} -I../tests/include -O2"
  2203. make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
  2204. unset loc_cflags
  2205. msg "test: full + MBEDTLS_PSA_CRYPTO_DRIVERS"
  2206. make test
  2207. }
  2208. component_test_make_shared () {
  2209. msg "build/test: make shared" # ~ 40s
  2210. make SHARED=1 all check
  2211. ldd programs/util/strerror | grep libmbedcrypto
  2212. programs/test/dlopen_demo.sh
  2213. }
  2214. component_test_cmake_shared () {
  2215. msg "build/test: cmake shared" # ~ 2min
  2216. cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
  2217. make
  2218. ldd programs/util/strerror | grep libmbedcrypto
  2219. make test
  2220. programs/test/dlopen_demo.sh
  2221. }
  2222. test_build_opt () {
  2223. info=$1 cc=$2; shift 2
  2224. for opt in "$@"; do
  2225. msg "build/test: $cc $opt, $info" # ~ 30s
  2226. make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
  2227. # We're confident enough in compilers to not run _all_ the tests,
  2228. # but at least run the unit tests. In particular, runs with
  2229. # optimizations use inline assembly whereas runs with -O0
  2230. # skip inline assembly.
  2231. make test # ~30s
  2232. make clean
  2233. done
  2234. }
  2235. component_test_clang_opt () {
  2236. scripts/config.py full
  2237. test_build_opt 'full config' clang -O0 -Os -O2
  2238. }
  2239. component_test_gcc_opt () {
  2240. scripts/config.py full
  2241. test_build_opt 'full config' gcc -O0 -Os -O2
  2242. }
  2243. component_build_mbedtls_config_file () {
  2244. msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
  2245. # Use the full config so as to catch a maximum of places where
  2246. # the check of MBEDTLS_CONFIG_FILE might be missing.
  2247. scripts/config.py full
  2248. sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
  2249. echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
  2250. make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
  2251. rm -f full_config.h
  2252. }
  2253. component_test_m32_o0 () {
  2254. # Build without optimization, so as to use portable C code (in a 32-bit
  2255. # build) and not the i386-specific inline assembly.
  2256. msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
  2257. scripts/config.py full
  2258. make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
  2259. msg "test: i386, make, gcc -O0 (ASan build)"
  2260. make test
  2261. }
  2262. support_test_m32_o0 () {
  2263. case $(uname -m) in
  2264. *64*) true;;
  2265. *) false;;
  2266. esac
  2267. }
  2268. component_test_m32_o2 () {
  2269. # Build with optimization, to use the i386 specific inline assembly
  2270. # and go faster for tests.
  2271. msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
  2272. scripts/config.py full
  2273. make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
  2274. msg "test: i386, make, gcc -O2 (ASan build)"
  2275. make test
  2276. msg "test ssl-opt.sh, i386, make, gcc-O2"
  2277. tests/ssl-opt.sh
  2278. }
  2279. support_test_m32_o2 () {
  2280. support_test_m32_o0 "$@"
  2281. }
  2282. component_test_m32_everest () {
  2283. msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
  2284. scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
  2285. scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
  2286. make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
  2287. msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
  2288. make test
  2289. msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
  2290. tests/ssl-opt.sh -f ECDH
  2291. msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
  2292. # Exclude some symmetric ciphers that are redundant here to gain time.
  2293. tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
  2294. }
  2295. support_test_m32_everest () {
  2296. support_test_m32_o0 "$@"
  2297. }
  2298. component_test_mx32 () {
  2299. msg "build: 64-bit ILP32, make, gcc" # ~ 30s
  2300. scripts/config.py full
  2301. make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
  2302. msg "test: 64-bit ILP32, make, gcc"
  2303. make test
  2304. }
  2305. support_test_mx32 () {
  2306. case $(uname -m) in
  2307. amd64|x86_64) true;;
  2308. *) false;;
  2309. esac
  2310. }
  2311. component_test_min_mpi_window_size () {
  2312. msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
  2313. scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
  2314. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  2315. make
  2316. msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
  2317. make test
  2318. }
  2319. component_test_have_int32 () {
  2320. msg "build: gcc, force 32-bit bignum limbs"
  2321. scripts/config.py unset MBEDTLS_HAVE_ASM
  2322. scripts/config.py unset MBEDTLS_AESNI_C
  2323. scripts/config.py unset MBEDTLS_PADLOCK_C
  2324. make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
  2325. msg "test: gcc, force 32-bit bignum limbs"
  2326. make test
  2327. }
  2328. component_test_have_int64 () {
  2329. msg "build: gcc, force 64-bit bignum limbs"
  2330. scripts/config.py unset MBEDTLS_HAVE_ASM
  2331. scripts/config.py unset MBEDTLS_AESNI_C
  2332. scripts/config.py unset MBEDTLS_PADLOCK_C
  2333. make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
  2334. msg "test: gcc, force 64-bit bignum limbs"
  2335. make test
  2336. }
  2337. component_test_no_udbl_division () {
  2338. msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
  2339. scripts/config.py full
  2340. scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
  2341. make CFLAGS='-Werror -O1'
  2342. msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
  2343. make test
  2344. }
  2345. component_test_no_64bit_multiplication () {
  2346. msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
  2347. scripts/config.py full
  2348. scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
  2349. make CFLAGS='-Werror -O1'
  2350. msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
  2351. make test
  2352. }
  2353. component_test_no_strings () {
  2354. msg "build: no strings" # ~10s
  2355. scripts/config.py full
  2356. # Disable options that activate a large amount of string constants.
  2357. scripts/config.py unset MBEDTLS_DEBUG_C
  2358. scripts/config.py unset MBEDTLS_ERROR_C
  2359. scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
  2360. scripts/config.py unset MBEDTLS_VERSION_FEATURES
  2361. make CFLAGS='-Werror -Os'
  2362. msg "test: no strings" # ~ 10s
  2363. make test
  2364. }
  2365. component_build_arm_none_eabi_gcc () {
  2366. msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1" # ~ 10s
  2367. scripts/config.py baremetal
  2368. 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
  2369. msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1"
  2370. ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
  2371. }
  2372. component_build_arm_linux_gnueabi_gcc_arm5vte () {
  2373. msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s
  2374. scripts/config.py baremetal
  2375. # Build for a target platform that's close to what Debian uses
  2376. # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
  2377. # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
  2378. # Build everything including programs, see for example
  2379. # https://github.com/ARMmbed/mbedtls/pull/3449#issuecomment-675313720
  2380. 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'
  2381. msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1"
  2382. ${ARM_LINUX_GNUEABI_GCC_PREFIX}size library/*.o
  2383. }
  2384. support_build_arm_linux_gnueabi_gcc_arm5vte () {
  2385. type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
  2386. }
  2387. component_build_arm_none_eabi_gcc_arm5vte () {
  2388. msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s
  2389. scripts/config.py baremetal
  2390. # This is an imperfect substitute for
  2391. # component_build_arm_linux_gnueabi_gcc_arm5vte
  2392. # in case the gcc-arm-linux-gnueabi toolchain is not available
  2393. 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
  2394. msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1"
  2395. ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
  2396. }
  2397. component_build_arm_none_eabi_gcc_m0plus () {
  2398. msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus" # ~ 10s
  2399. scripts/config.py baremetal
  2400. 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
  2401. msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os"
  2402. ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
  2403. }
  2404. component_build_arm_none_eabi_gcc_no_udbl_division () {
  2405. msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
  2406. scripts/config.py baremetal
  2407. scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
  2408. 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
  2409. echo "Checking that software 64-bit division is not required"
  2410. not grep __aeabi_uldiv library/*.o
  2411. }
  2412. component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
  2413. msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
  2414. scripts/config.py baremetal
  2415. scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
  2416. 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
  2417. echo "Checking that software 64-bit multiplication is not required"
  2418. not grep __aeabi_lmul library/*.o
  2419. }
  2420. component_build_armcc () {
  2421. msg "build: ARM Compiler 5"
  2422. scripts/config.py baremetal
  2423. make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
  2424. msg "size: ARM Compiler 5"
  2425. "$ARMC5_FROMELF" -z library/*.o
  2426. make clean
  2427. # ARM Compiler 6 - Target ARMv7-A
  2428. armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
  2429. # ARM Compiler 6 - Target ARMv7-M
  2430. armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
  2431. # ARM Compiler 6 - Target ARMv8-A - AArch32
  2432. armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
  2433. # ARM Compiler 6 - Target ARMv8-M
  2434. armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
  2435. # ARM Compiler 6 - Target ARMv8-A - AArch64
  2436. armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
  2437. }
  2438. component_build_ssl_hw_record_accel() {
  2439. msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
  2440. scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
  2441. make CFLAGS='-Werror -O1'
  2442. }
  2443. component_test_tls13_experimental () {
  2444. msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
  2445. scripts/config.pl set MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
  2446. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  2447. make
  2448. msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
  2449. make test
  2450. }
  2451. component_build_mingw () {
  2452. msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
  2453. make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs
  2454. # note Make tests only builds the tests, but doesn't run them
  2455. make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
  2456. make WINDOWS_BUILD=1 clean
  2457. msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
  2458. make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 lib programs
  2459. make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 tests
  2460. make WINDOWS_BUILD=1 clean
  2461. }
  2462. support_build_mingw() {
  2463. case $(i686-w64-mingw32-gcc -dumpversion) in
  2464. [0-5]*) false;;
  2465. *) true;;
  2466. esac
  2467. }
  2468. component_test_memsan () {
  2469. msg "build: MSan (clang)" # ~ 1 min 20s
  2470. scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
  2471. CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
  2472. make
  2473. msg "test: main suites (MSan)" # ~ 10s
  2474. make test
  2475. msg "test: ssl-opt.sh (MSan)" # ~ 1 min
  2476. tests/ssl-opt.sh
  2477. # Optional part(s)
  2478. if [ "$MEMORY" -gt 0 ]; then
  2479. msg "test: compat.sh (MSan)" # ~ 6 min 20s
  2480. tests/compat.sh
  2481. fi
  2482. }
  2483. component_test_valgrind () {
  2484. msg "build: Release (clang)"
  2485. CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
  2486. make
  2487. msg "test: main suites valgrind (Release)"
  2488. make memcheck
  2489. # Optional parts (slow; currently broken on OS X because programs don't
  2490. # seem to receive signals under valgrind on OS X).
  2491. if [ "$MEMORY" -gt 0 ]; then
  2492. msg "test: ssl-opt.sh --memcheck (Release)"
  2493. tests/ssl-opt.sh --memcheck
  2494. fi
  2495. if [ "$MEMORY" -gt 1 ]; then
  2496. msg "test: compat.sh --memcheck (Release)"
  2497. tests/compat.sh --memcheck
  2498. fi
  2499. if [ "$MEMORY" -gt 0 ]; then
  2500. msg "test: context-info.sh --memcheck (Release)"
  2501. tests/context-info.sh --memcheck
  2502. fi
  2503. }
  2504. support_test_cmake_out_of_source () {
  2505. distrib_id=""
  2506. distrib_ver=""
  2507. distrib_ver_minor=""
  2508. distrib_ver_major=""
  2509. # Attempt to parse lsb-release to find out distribution and version. If not
  2510. # found this should fail safe (test is supported).
  2511. if [[ -f /etc/lsb-release ]]; then
  2512. while read -r lsb_line; do
  2513. case "$lsb_line" in
  2514. "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
  2515. "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
  2516. esac
  2517. done < /etc/lsb-release
  2518. distrib_ver_major="${distrib_ver%%.*}"
  2519. distrib_ver="${distrib_ver#*.}"
  2520. distrib_ver_minor="${distrib_ver%%.*}"
  2521. fi
  2522. # Running the out of source CMake test on Ubuntu 16.04 using more than one
  2523. # processor (as the CI does) can create a race condition whereby the build
  2524. # fails to see a generated file, despite that file actually having been
  2525. # generated. This problem appears to go away with 18.04 or newer, so make
  2526. # the out of source tests unsupported on Ubuntu 16.04.
  2527. [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
  2528. }
  2529. component_test_cmake_out_of_source () {
  2530. msg "build: cmake 'out-of-source' build"
  2531. MBEDTLS_ROOT_DIR="$PWD"
  2532. mkdir "$OUT_OF_SOURCE_DIR"
  2533. cd "$OUT_OF_SOURCE_DIR"
  2534. cmake -D CMAKE_BUILD_TYPE:String=Check "$MBEDTLS_ROOT_DIR"
  2535. make
  2536. msg "test: cmake 'out-of-source' build"
  2537. make test
  2538. # Test an SSL option that requires an auxiliary script in test/scripts/.
  2539. # Also ensure that there are no error messages such as
  2540. # "No such file or directory", which would indicate that some required
  2541. # file is missing (ssl-opt.sh tolerates the absence of some files so
  2542. # may exit with status 0 but emit errors).
  2543. ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
  2544. cat ssl-opt.err >&2
  2545. # If ssl-opt.err is non-empty, record an error and keep going.
  2546. [ ! -s ssl-opt.err ]
  2547. rm ssl-opt.err
  2548. cd "$MBEDTLS_ROOT_DIR"
  2549. rm -rf "$OUT_OF_SOURCE_DIR"
  2550. }
  2551. component_test_cmake_as_subdirectory () {
  2552. msg "build: cmake 'as-subdirectory' build"
  2553. MBEDTLS_ROOT_DIR="$PWD"
  2554. cd programs/test/cmake_subproject
  2555. cmake .
  2556. make
  2557. ./cmake_subproject
  2558. cd "$MBEDTLS_ROOT_DIR"
  2559. unset MBEDTLS_ROOT_DIR
  2560. }
  2561. component_test_zeroize () {
  2562. # Test that the function mbedtls_platform_zeroize() is not optimized away by
  2563. # different combinations of compilers and optimization flags by using an
  2564. # auxiliary GDB script. Unfortunately, GDB does not return error values to the
  2565. # system in all cases that the script fails, so we must manually search the
  2566. # output to check whether the pass string is present and no failure strings
  2567. # were printed.
  2568. # Don't try to disable ASLR. We don't care about ASLR here. We do care
  2569. # about a spurious message if Gdb tries and fails, so suppress that.
  2570. gdb_disable_aslr=
  2571. if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
  2572. gdb_disable_aslr='set disable-randomization off'
  2573. fi
  2574. for optimization_flag in -O2 -O3 -Ofast -Os; do
  2575. for compiler in clang gcc; do
  2576. msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
  2577. make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
  2578. gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
  2579. grep "The buffer was correctly zeroized" test_zeroize.log
  2580. not grep -i "error" test_zeroize.log
  2581. rm -f test_zeroize.log
  2582. make clean
  2583. done
  2584. done
  2585. unset gdb_disable_aslr
  2586. }
  2587. component_test_psa_compliance () {
  2588. msg "build: make, default config + CMAC, libmbedcrypto.a only"
  2589. scripts/config.py set MBEDTLS_CMAC_C
  2590. make -C library libmbedcrypto.a
  2591. msg "unit test: test_psa_compliance.py"
  2592. ./tests/scripts/test_psa_compliance.py
  2593. }
  2594. support_test_psa_compliance () {
  2595. # psa-compliance-tests only supports CMake >= 3.10.0
  2596. ver="$(cmake --version)"
  2597. ver="${ver#cmake version }"
  2598. ver_major="${ver%%.*}"
  2599. ver="${ver#*.}"
  2600. ver_minor="${ver%%.*}"
  2601. [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
  2602. }
  2603. component_check_python_files () {
  2604. msg "Lint: Python scripts"
  2605. tests/scripts/check-python-files.sh
  2606. }
  2607. component_check_generate_test_code () {
  2608. msg "uint test: generate_test_code.py"
  2609. # unittest writes out mundane stuff like number or tests run on stderr.
  2610. # Our convention is to reserve stderr for actual errors, and write
  2611. # harmless info on stdout so it can be suppress with --quiet.
  2612. ./tests/scripts/test_generate_test_code.py 2>&1
  2613. }
  2614. ################################################################
  2615. #### Termination
  2616. ################################################################
  2617. post_report () {
  2618. msg "Done, cleaning up"
  2619. final_cleanup
  2620. final_report
  2621. }
  2622. ################################################################
  2623. #### Run all the things
  2624. ################################################################
  2625. # Function invoked by --error-test to test error reporting.
  2626. pseudo_component_error_test () {
  2627. msg "Testing error reporting $error_test_i"
  2628. if [ $KEEP_GOING -ne 0 ]; then
  2629. echo "Expect three failing commands."
  2630. fi
  2631. # If the component doesn't run in a subshell, changing error_test_i to an
  2632. # invalid integer will cause an error in the loop that runs this function.
  2633. error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell
  2634. # Expected error: 'grep non_existent /dev/null -> 1'
  2635. grep non_existent /dev/null
  2636. # Expected error: '! grep -q . tests/scripts/all.sh -> 1'
  2637. not grep -q . "$0"
  2638. # Expected error: 'make unknown_target -> 2'
  2639. make unknown_target
  2640. false "this should not be executed"
  2641. }
  2642. # Run one component and clean up afterwards.
  2643. run_component () {
  2644. current_component="$1"
  2645. export MBEDTLS_TEST_CONFIGURATION="$current_component"
  2646. # Unconditionally create a seedfile that's sufficiently long.
  2647. # Do this before each component, because a previous component may
  2648. # have messed it up or shortened it.
  2649. local dd_cmd
  2650. dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
  2651. case $OSTYPE in
  2652. linux*|freebsd*|openbsd*|darwin*) dd_cmd+=(status=none)
  2653. esac
  2654. "${dd_cmd[@]}"
  2655. # Run the component in a subshell, with error trapping and output
  2656. # redirection set up based on the relevant options.
  2657. if [ $KEEP_GOING -eq 1 ]; then
  2658. # We want to keep running if the subshell fails, so 'set -e' must
  2659. # be off when the subshell runs.
  2660. set +e
  2661. fi
  2662. (
  2663. if [ $QUIET -eq 1 ]; then
  2664. # msg() will be silenced, so just print the component name here.
  2665. echo "${current_component#component_}"
  2666. exec >/dev/null
  2667. fi
  2668. if [ $KEEP_GOING -eq 1 ]; then
  2669. # Keep "set -e" off, and run an ERR trap instead to record failures.
  2670. set -E
  2671. trap err_trap ERR
  2672. fi
  2673. # The next line is what runs the component
  2674. "$@"
  2675. if [ $KEEP_GOING -eq 1 ]; then
  2676. trap - ERR
  2677. exit $last_failure_status
  2678. fi
  2679. )
  2680. component_status=$?
  2681. if [ $KEEP_GOING -eq 1 ]; then
  2682. set -e
  2683. if [ $component_status -ne 0 ]; then
  2684. failure_count=$((failure_count + 1))
  2685. fi
  2686. fi
  2687. # Restore the build tree to a clean state.
  2688. cleanup
  2689. unset current_component
  2690. }
  2691. # Preliminary setup
  2692. pre_check_environment
  2693. pre_initialize_variables
  2694. pre_parse_command_line "$@"
  2695. pre_check_git
  2696. pre_restore_files
  2697. pre_back_up
  2698. build_status=0
  2699. if [ $KEEP_GOING -eq 1 ]; then
  2700. pre_setup_keep_going
  2701. fi
  2702. pre_prepare_outcome_file
  2703. pre_print_configuration
  2704. pre_check_tools
  2705. cleanup
  2706. # Run the requested tests.
  2707. for ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do
  2708. run_component pseudo_component_error_test
  2709. done
  2710. unset error_test_i
  2711. for component in $RUN_COMPONENTS; do
  2712. run_component "component_$component"
  2713. done
  2714. # We're done.
  2715. post_report