all.sh 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805
  1. #! /usr/bin/env sh
  2. # all.sh
  3. #
  4. # Copyright The Mbed TLS Contributors
  5. # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  6. #
  7. # This file is provided under the Apache License 2.0, or the
  8. # GNU General Public License v2.0 or later.
  9. #
  10. # **********
  11. # Apache License 2.0:
  12. #
  13. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  14. # not use this file except in compliance with the License.
  15. # You may obtain a copy of the License at
  16. #
  17. # http://www.apache.org/licenses/LICENSE-2.0
  18. #
  19. # Unless required by applicable law or agreed to in writing, software
  20. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  21. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. # See the License for the specific language governing permissions and
  23. # limitations under the License.
  24. #
  25. # **********
  26. #
  27. # **********
  28. # GNU General Public License v2.0 or later:
  29. #
  30. # This program is free software; you can redistribute it and/or modify
  31. # it under the terms of the GNU General Public License as published by
  32. # the Free Software Foundation; either version 2 of the License, or
  33. # (at your option) any later version.
  34. #
  35. # This program is distributed in the hope that it will be useful,
  36. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  37. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  38. # GNU General Public License for more details.
  39. #
  40. # You should have received a copy of the GNU General Public License along
  41. # with this program; if not, write to the Free Software Foundation, Inc.,
  42. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  43. #
  44. # **********
  45. ################################################################
  46. #### Documentation
  47. ################################################################
  48. # Purpose
  49. # -------
  50. #
  51. # To run all tests possible or available on the platform.
  52. #
  53. # Notes for users
  54. # ---------------
  55. #
  56. # Warning: the test is destructive. It includes various build modes and
  57. # configurations, and can and will arbitrarily change the current CMake
  58. # configuration. The following files must be committed into git:
  59. # * include/mbedtls/config.h
  60. # * Makefile, library/Makefile, programs/Makefile, tests/Makefile
  61. # After running this script, the CMake cache will be lost and CMake
  62. # will no longer be initialised.
  63. #
  64. # The script assumes the presence of a number of tools:
  65. # * Basic Unix tools (Windows users note: a Unix-style find must be before
  66. # the Windows find in the PATH)
  67. # * Perl
  68. # * GNU Make
  69. # * CMake
  70. # * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
  71. # * G++
  72. # * arm-gcc and mingw-gcc
  73. # * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
  74. # * OpenSSL and GnuTLS command line tools, recent enough for the
  75. # interoperability tests. If they don't support SSLv3 then a legacy
  76. # version of these tools must be present as well (search for LEGACY
  77. # below).
  78. # See the invocation of check_tools below for details.
  79. #
  80. # This script must be invoked from the toplevel directory of a git
  81. # working copy of Mbed TLS.
  82. #
  83. # Note that the output is not saved. You may want to run
  84. # script -c tests/scripts/all.sh
  85. # or
  86. # tests/scripts/all.sh >all.log 2>&1
  87. #
  88. # Notes for maintainers
  89. # ---------------------
  90. #
  91. # The bulk of the code is organized into functions that follow one of the
  92. # following naming conventions:
  93. # * pre_XXX: things to do before running the tests, in order.
  94. # * component_XXX: independent components. They can be run in any order.
  95. # * component_check_XXX: quick tests that aren't worth parallelizing.
  96. # * component_build_XXX: build things but don't run them.
  97. # * component_test_XXX: build and test.
  98. # * support_XXX: if support_XXX exists and returns false then
  99. # component_XXX is not run by default.
  100. # * post_XXX: things to do after running the tests.
  101. # * other: miscellaneous support functions.
  102. #
  103. # Each component must start by invoking `msg` with a short informative message.
  104. #
  105. # The framework performs some cleanup tasks after each component. This
  106. # means that components can assume that the working directory is in a
  107. # cleaned-up state, and don't need to perform the cleanup themselves.
  108. # * Run `make clean`.
  109. # * Restore `include/mbedtks/config.h` from a backup made before running
  110. # the component.
  111. # * Check out `Makefile`, `library/Makefile`, `programs/Makefile` and
  112. # `tests/Makefile` from git. This cleans up after an in-tree use of
  113. # CMake.
  114. #
  115. # Any command that is expected to fail must be protected so that the
  116. # script keeps running in --keep-going mode despite `set -e`. In keep-going
  117. # mode, if a protected command fails, this is logged as a failure and the
  118. # script will exit with a failure status once it has run all components.
  119. # Commands can be protected in any of the following ways:
  120. # * `make` is a function which runs the `make` command with protection.
  121. # Note that you must write `make VAR=value`, not `VAR=value make`,
  122. # because the `VAR=value make` syntax doesn't work with functions.
  123. # * Put `report_status` before the command to protect it.
  124. # * Put `if_build_successful` before a command. This protects it, and
  125. # additionally skips it if a prior invocation of `make` in the same
  126. # component failed.
  127. #
  128. # The tests are roughly in order from fastest to slowest. This doesn't
  129. # have to be exact, but in general you should add slower tests towards
  130. # the end and fast checks near the beginning.
  131. ################################################################
  132. #### Initialization and command line parsing
  133. ################################################################
  134. # Abort on errors (and uninitialised variables)
  135. set -eu
  136. pre_check_environment () {
  137. if [ -d library -a -d include -a -d tests ]; then :; else
  138. echo "Must be run from mbed TLS root" >&2
  139. exit 1
  140. fi
  141. }
  142. pre_initialize_variables () {
  143. CONFIG_H='include/mbedtls/config.h'
  144. CONFIG_BAK="$CONFIG_H.bak"
  145. MEMORY=0
  146. FORCE=0
  147. QUIET=0
  148. KEEP_GOING=0
  149. # Seed value used with the --release-test option.
  150. #
  151. # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
  152. # both values are kept in sync. If you change the value here because it
  153. # breaks some tests, you'll definitely want to change it in
  154. # basic-build-test.sh as well.
  155. RELEASE_SEED=1
  156. # Default commands, can be overridden by the environment
  157. : ${OPENSSL:="openssl"}
  158. : ${OPENSSL_LEGACY:="$OPENSSL"}
  159. : ${OPENSSL_NEXT:="$OPENSSL"}
  160. : ${GNUTLS_CLI:="gnutls-cli"}
  161. : ${GNUTLS_SERV:="gnutls-serv"}
  162. : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
  163. : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
  164. : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
  165. : ${ARMC5_BIN_DIR:=/usr/bin}
  166. : ${ARMC6_BIN_DIR:=/usr/bin}
  167. : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
  168. # if MAKEFLAGS is not set add the -j option to speed up invocations of make
  169. if [ -z "${MAKEFLAGS+set}" ]; then
  170. export MAKEFLAGS="-j"
  171. fi
  172. # Include more verbose output for failing tests run by CMake
  173. export CTEST_OUTPUT_ON_FAILURE=1
  174. # CFLAGS and LDFLAGS for Asan builds that don't use CMake
  175. ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
  176. # Gather the list of available components. These are the functions
  177. # defined in this script whose name starts with "component_".
  178. # Parse the script with sed, because in sh there is no way to list
  179. # defined functions.
  180. ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
  181. # Exclude components that are not supported on this platform.
  182. SUPPORTED_COMPONENTS=
  183. for component in $ALL_COMPONENTS; do
  184. case $(type "support_$component" 2>&1) in
  185. *' function'*)
  186. if ! support_$component; then continue; fi;;
  187. esac
  188. SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
  189. done
  190. }
  191. # Test whether the component $1 is included in the command line patterns.
  192. is_component_included()
  193. {
  194. set -f
  195. for pattern in $COMMAND_LINE_COMPONENTS; do
  196. set +f
  197. case ${1#component_} in $pattern) return 0;; esac
  198. done
  199. set +f
  200. return 1
  201. }
  202. usage()
  203. {
  204. cat <<EOF
  205. Usage: $0 [OPTION]... [COMPONENT]...
  206. Run mbedtls release validation tests.
  207. By default, run all tests. With one or more COMPONENT, run only those.
  208. COMPONENT can be the name of a component or a shell wildcard pattern.
  209. Examples:
  210. $0 "check_*"
  211. Run all sanity checks.
  212. $0 --no-armcc --except test_memsan
  213. Run everything except builds that require armcc and MemSan.
  214. Special options:
  215. -h|--help Print this help and exit.
  216. --list-all-components List all available test components and exit.
  217. --list-components List components supported on this platform and exit.
  218. General options:
  219. -q|--quiet Only output component names, and errors if any.
  220. -f|--force Force the tests to overwrite any modified files.
  221. -k|--keep-going Run all tests and report errors at the end.
  222. -m|--memory Additional optional memory tests.
  223. --arm-none-eabi-gcc-prefix=<string>
  224. Prefix for a cross-compiler for arm-none-eabi
  225. (default: "${ARM_NONE_EABI_GCC_PREFIX}")
  226. --armcc Run ARM Compiler builds (on by default).
  227. --except Exclude the COMPONENTs listed on the command line,
  228. instead of running only those.
  229. --no-armcc Skip ARM Compiler builds.
  230. --no-force Refuse to overwrite modified files (default).
  231. --no-keep-going Stop at the first error (default).
  232. --no-memory No additional memory tests (default).
  233. --no-quiet Print full ouput from components.
  234. --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
  235. --random-seed Use a random seed value for randomized tests (default).
  236. -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
  237. -s|--seed Integer seed value to use for this test run.
  238. Tool path options:
  239. --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
  240. --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
  241. --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
  242. --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
  243. --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
  244. --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
  245. --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
  246. --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
  247. --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
  248. EOF
  249. }
  250. # remove built files as well as the cmake cache/config
  251. cleanup()
  252. {
  253. if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
  254. cd "$MBEDTLS_ROOT_DIR"
  255. fi
  256. command make clean
  257. # Remove CMake artefacts
  258. find . -name .git -prune \
  259. -iname CMakeFiles -exec rm -rf {} \+ -o \
  260. \( -iname cmake_install.cmake -o \
  261. -iname CTestTestfile.cmake -o \
  262. -iname CMakeCache.txt \) -exec rm {} \+
  263. # Recover files overwritten by in-tree CMake builds
  264. rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
  265. git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile
  266. git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile
  267. if [ -f "$CONFIG_BAK" ]; then
  268. mv "$CONFIG_BAK" "$CONFIG_H"
  269. fi
  270. }
  271. # Executed on exit. May be redefined depending on command line options.
  272. final_report () {
  273. :
  274. }
  275. fatal_signal () {
  276. cleanup
  277. final_report $1
  278. trap - $1
  279. kill -$1 $$
  280. }
  281. trap 'fatal_signal HUP' HUP
  282. trap 'fatal_signal INT' INT
  283. trap 'fatal_signal TERM' TERM
  284. msg()
  285. {
  286. if [ -n "${current_component:-}" ]; then
  287. current_section="${current_component#component_}: $1"
  288. else
  289. current_section="$1"
  290. fi
  291. if [ $QUIET -eq 1 ]; then
  292. return
  293. fi
  294. echo ""
  295. echo "******************************************************************"
  296. echo "* $current_section "
  297. printf "* "; date
  298. echo "******************************************************************"
  299. }
  300. armc6_build_test()
  301. {
  302. FLAGS="$1"
  303. msg "build: ARM Compiler 6 ($FLAGS)"
  304. ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
  305. WARNING_CFLAGS='-xc -std=c99' make lib
  306. msg "size: ARM Compiler 6 ($FLAGS)"
  307. "$ARMC6_FROMELF" -z library/*.o
  308. make clean
  309. }
  310. err_msg()
  311. {
  312. echo "$1" >&2
  313. }
  314. check_tools()
  315. {
  316. for TOOL in "$@"; do
  317. if ! `type "$TOOL" >/dev/null 2>&1`; then
  318. err_msg "$TOOL not found!"
  319. exit 1
  320. fi
  321. done
  322. }
  323. check_headers_in_cpp () {
  324. ls include/mbedtls | grep "\.h$" >headers.txt
  325. <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
  326. sort |
  327. diff headers.txt -
  328. rm headers.txt
  329. }
  330. pre_parse_command_line () {
  331. COMMAND_LINE_COMPONENTS=
  332. all_except=0
  333. no_armcc=
  334. while [ $# -gt 0 ]; do
  335. case "$1" in
  336. --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
  337. --armcc) no_armcc=;;
  338. --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
  339. --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
  340. --except) all_except=1;;
  341. --force|-f) FORCE=1;;
  342. --gnutls-cli) shift; GNUTLS_CLI="$1";;
  343. --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
  344. --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
  345. --gnutls-serv) shift; GNUTLS_SERV="$1";;
  346. --help|-h) usage; exit;;
  347. --keep-going|-k) KEEP_GOING=1;;
  348. --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
  349. --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
  350. --memory|-m) MEMORY=1;;
  351. --no-armcc) no_armcc=1;;
  352. --no-force) FORCE=0;;
  353. --no-keep-going) KEEP_GOING=0;;
  354. --no-memory) MEMORY=0;;
  355. --no-quiet) QUIET=0;;
  356. --openssl) shift; OPENSSL="$1";;
  357. --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
  358. --openssl-next) shift; OPENSSL_NEXT="$1";;
  359. --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
  360. --quiet|-q) QUIET=1;;
  361. --random-seed) unset SEED;;
  362. --release-test|-r) SEED=$RELEASE_SEED;;
  363. --seed|-s) shift; SEED="$1";;
  364. -*)
  365. echo >&2 "Unknown option: $1"
  366. echo >&2 "Run $0 --help for usage."
  367. exit 120
  368. ;;
  369. *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
  370. esac
  371. shift
  372. done
  373. # With no list of components, run everything.
  374. if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
  375. all_except=1
  376. fi
  377. # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
  378. # Ignore it if components are listed explicitly on the command line.
  379. if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
  380. COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
  381. fi
  382. # Build the list of components to run.
  383. RUN_COMPONENTS=
  384. for component in $SUPPORTED_COMPONENTS; do
  385. if is_component_included "$component"; [ $? -eq $all_except ]; then
  386. RUN_COMPONENTS="$RUN_COMPONENTS $component"
  387. fi
  388. done
  389. unset all_except
  390. unset no_armcc
  391. }
  392. pre_check_git () {
  393. if [ $FORCE -eq 1 ]; then
  394. rm -rf "$OUT_OF_SOURCE_DIR"
  395. git checkout-index -f -q $CONFIG_H
  396. cleanup
  397. else
  398. if [ -d "$OUT_OF_SOURCE_DIR" ]; then
  399. echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
  400. echo "You can either delete this directory manually, or force the test by rerunning"
  401. echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
  402. exit 1
  403. fi
  404. if ! git diff --quiet include/mbedtls/config.h; then
  405. err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
  406. echo "You can either delete or preserve your work, or force the test by rerunning the"
  407. echo "script as: $0 --force"
  408. exit 1
  409. fi
  410. fi
  411. }
  412. pre_setup_keep_going () {
  413. failure_summary=
  414. failure_count=0
  415. start_red=
  416. end_color=
  417. if [ -t 1 ]; then
  418. case "${TERM:-}" in
  419. *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
  420. start_red=$(printf '\033[31m')
  421. end_color=$(printf '\033[0m')
  422. ;;
  423. esac
  424. fi
  425. record_status () {
  426. if "$@"; then
  427. last_status=0
  428. else
  429. last_status=$?
  430. text="$current_section: $* -> $last_status"
  431. failure_summary="$failure_summary
  432. $text"
  433. failure_count=$((failure_count + 1))
  434. echo "${start_red}^^^^$text^^^^${end_color}" >&2
  435. fi
  436. }
  437. make () {
  438. case "$*" in
  439. *test|*check)
  440. if [ $build_status -eq 0 ]; then
  441. record_status command make "$@"
  442. else
  443. echo "(skipped because the build failed)"
  444. fi
  445. ;;
  446. *)
  447. record_status command make "$@"
  448. build_status=$last_status
  449. ;;
  450. esac
  451. }
  452. final_report () {
  453. if [ $failure_count -gt 0 ]; then
  454. echo
  455. echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  456. echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
  457. echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  458. exit 1
  459. elif [ -z "${1-}" ]; then
  460. echo "SUCCESS :)"
  461. fi
  462. if [ -n "${1-}" ]; then
  463. echo "Killed by SIG$1."
  464. fi
  465. }
  466. }
  467. if_build_succeeded () {
  468. if [ $build_status -eq 0 ]; then
  469. record_status "$@"
  470. fi
  471. }
  472. # to be used instead of ! for commands run with
  473. # record_status or if_build_succeeded
  474. not() {
  475. ! "$@"
  476. }
  477. pre_setup_quiet_redirect () {
  478. if [ $QUIET -ne 1 ]; then
  479. redirect_out () {
  480. "$@"
  481. }
  482. else
  483. redirect_out () {
  484. "$@" >/dev/null
  485. }
  486. fi
  487. }
  488. pre_print_configuration () {
  489. if [ $QUIET -eq 1 ]; then
  490. return
  491. fi
  492. msg "info: $0 configuration"
  493. echo "MEMORY: $MEMORY"
  494. echo "FORCE: $FORCE"
  495. echo "SEED: ${SEED-"UNSET"}"
  496. echo "OPENSSL: $OPENSSL"
  497. echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
  498. echo "OPENSSL_NEXT: $OPENSSL_NEXT"
  499. echo "GNUTLS_CLI: $GNUTLS_CLI"
  500. echo "GNUTLS_SERV: $GNUTLS_SERV"
  501. echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
  502. echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
  503. echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
  504. echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
  505. }
  506. # Make sure the tools we need are available.
  507. pre_check_tools () {
  508. # Build the list of variables to pass to output_env.sh.
  509. set env
  510. case " $RUN_COMPONENTS " in
  511. # Require OpenSSL and GnuTLS if running any tests (as opposed to
  512. # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
  513. # is a good enough approximation in practice.
  514. *" test_"*)
  515. # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
  516. # and ssl-opt.sh, we just export the variables they require.
  517. export OPENSSL_CMD="$OPENSSL"
  518. export GNUTLS_CLI="$GNUTLS_CLI"
  519. export GNUTLS_SERV="$GNUTLS_SERV"
  520. # Avoid passing --seed flag in every call to ssl-opt.sh
  521. if [ -n "${SEED-}" ]; then
  522. export SEED
  523. fi
  524. set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
  525. set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
  526. set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
  527. set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
  528. check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
  529. "$GNUTLS_CLI" "$GNUTLS_SERV" \
  530. "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
  531. ;;
  532. esac
  533. case " $RUN_COMPONENTS " in
  534. *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
  535. esac
  536. case " $RUN_COMPONENTS " in
  537. *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
  538. esac
  539. case " $RUN_COMPONENTS " in
  540. *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
  541. esac
  542. case " $RUN_COMPONENTS " in
  543. *" test_zeroize "*) check_tools "gdb";;
  544. esac
  545. case " $RUN_COMPONENTS " in
  546. *_armcc*)
  547. ARMC5_CC="$ARMC5_BIN_DIR/armcc"
  548. ARMC5_AR="$ARMC5_BIN_DIR/armar"
  549. ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
  550. ARMC6_CC="$ARMC6_BIN_DIR/armclang"
  551. ARMC6_AR="$ARMC6_BIN_DIR/armar"
  552. ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
  553. check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
  554. "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
  555. esac
  556. # past this point, no call to check_tool, only printing output
  557. if [ $QUIET -eq 1 ]; then
  558. return
  559. fi
  560. msg "info: output_env.sh"
  561. case $RUN_COMPONENTS in
  562. *_armcc*)
  563. set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
  564. *) set "$@" RUN_ARMCC=0;;
  565. esac
  566. "$@" scripts/output_env.sh
  567. }
  568. ################################################################
  569. #### Basic checks
  570. ################################################################
  571. #
  572. # Test Suites to be executed
  573. #
  574. # The test ordering tries to optimize for the following criteria:
  575. # 1. Catch possible problems early, by running first tests that run quickly
  576. # and/or are more likely to fail than others (eg I use Clang most of the
  577. # time, so start with a GCC build).
  578. # 2. Minimize total running time, by avoiding useless rebuilds
  579. #
  580. # Indicative running times are given for reference.
  581. component_check_recursion () {
  582. msg "test: recursion.pl" # < 1s
  583. record_status tests/scripts/recursion.pl library/*.c
  584. }
  585. component_check_generated_files () {
  586. msg "test: freshness of generated source files" # < 1s
  587. record_status tests/scripts/check-generated-files.sh
  588. }
  589. component_check_doxy_blocks () {
  590. msg "test: doxygen markup outside doxygen blocks" # < 1s
  591. record_status tests/scripts/check-doxy-blocks.pl
  592. }
  593. component_check_files () {
  594. msg "Check: file sanity checks (permissions, encodings)" # < 1s
  595. record_status tests/scripts/check_files.py
  596. }
  597. component_check_changelog () {
  598. msg "Check: changelog entries" # < 1s
  599. rm -f ChangeLog.new
  600. record_status scripts/assemble_changelog.py -o ChangeLog.new
  601. if [ -e ChangeLog.new ]; then
  602. # Show the diff for information. It isn't an error if the diff is
  603. # non-empty.
  604. diff -u ChangeLog ChangeLog.new || true
  605. rm ChangeLog.new
  606. fi
  607. }
  608. component_check_names () {
  609. msg "test/build: declared and exported names" # < 3s
  610. record_status tests/scripts/check-names.sh -v
  611. }
  612. component_check_doxygen_warnings () {
  613. msg "test: doxygen warnings" # ~ 3s
  614. record_status tests/scripts/doxygen.sh
  615. }
  616. ################################################################
  617. #### Build and test many configurations and targets
  618. ################################################################
  619. component_test_large_ecdsa_key_signature () {
  620. SMALL_MPI_MAX_SIZE=136 # Small enough to interfere with the EC signatures
  621. msg "build: cmake + MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE}, gcc, ASan" # ~ 1 min 50s
  622. scripts/config.pl set MBEDTLS_MPI_MAX_SIZE $SMALL_MPI_MAX_SIZE
  623. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  624. make
  625. INEVITABLY_PRESENT_FILE=Makefile
  626. SIGNATURE_FILE="${INEVITABLY_PRESENT_FILE}.sig" # Warning, this is rm -f'ed below
  627. msg "test: pk_sign secp521r1_prv.der for MBEDTLS_MPI_MAX_SIZE=${SMALL_MPI_MAX_SIZE} (ASan build)" # ~ 5s
  628. if_build_succeeded programs/pkey/pk_sign tests/data_files/secp521r1_prv.der $INEVITABLY_PRESENT_FILE
  629. rm -f $SIGNATURE_FILE
  630. }
  631. component_test_default_out_of_box () {
  632. msg "build: make, default config (out-of-box)" # ~1min
  633. make
  634. msg "test: main suites make, default config (out-of-box)" # ~10s
  635. make test
  636. msg "selftest: make, default config (out-of-box)" # ~10s
  637. if_build_succeeded programs/test/selftest
  638. }
  639. component_test_default_cmake_gcc_asan () {
  640. msg "build: cmake, gcc, ASan" # ~ 1 min 50s
  641. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  642. make
  643. msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
  644. make test
  645. msg "test: selftest (ASan build)" # ~ 10s
  646. if_build_succeeded programs/test/selftest
  647. msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
  648. if_build_succeeded tests/ssl-opt.sh
  649. msg "test: compat.sh (ASan build)" # ~ 6 min
  650. if_build_succeeded tests/compat.sh
  651. }
  652. component_test_full_cmake_gcc_asan () {
  653. msg "build: full config, cmake, gcc, ASan"
  654. scripts/config.pl full
  655. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  656. make
  657. msg "test: main suites (inc. selftests) (full config, ASan build)"
  658. make test
  659. msg "test: selftest (ASan build)" # ~ 10s
  660. if_build_succeeded programs/test/selftest
  661. msg "test: ssl-opt.sh (full config, ASan build)"
  662. if_build_succeeded tests/ssl-opt.sh
  663. msg "test: compat.sh (full config, ASan build)"
  664. if_build_succeeded tests/compat.sh
  665. }
  666. component_test_zlib_make() {
  667. msg "build: zlib enabled, make"
  668. scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
  669. make ZLIB=1 CFLAGS='-Werror -O1'
  670. msg "test: main suites (zlib, make)"
  671. make test
  672. msg "test: ssl-opt.sh (zlib, make)"
  673. if_build_succeeded tests/ssl-opt.sh
  674. }
  675. support_test_zlib_make () {
  676. base=support_test_zlib_$$
  677. cat <<'EOF' > ${base}.c
  678. #include "zlib.h"
  679. int main(void) { return 0; }
  680. EOF
  681. gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
  682. ret=$?
  683. rm -f ${base}.*
  684. return $ret
  685. }
  686. component_test_zlib_cmake() {
  687. msg "build: zlib enabled, cmake"
  688. scripts/config.pl set MBEDTLS_ZLIB_SUPPORT
  689. cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Check .
  690. make
  691. msg "test: main suites (zlib, cmake)"
  692. make test
  693. msg "test: ssl-opt.sh (zlib, cmake)"
  694. if_build_succeeded tests/ssl-opt.sh
  695. }
  696. support_test_zlib_cmake () {
  697. support_test_zlib_make "$@"
  698. }
  699. component_test_ref_configs () {
  700. msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
  701. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  702. record_status tests/scripts/test-ref-configs.pl
  703. }
  704. component_test_sslv3 () {
  705. msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
  706. scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3
  707. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  708. make
  709. msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
  710. make test
  711. msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
  712. if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
  713. if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
  714. msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
  715. if_build_succeeded tests/ssl-opt.sh
  716. }
  717. component_test_no_renegotiation () {
  718. msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
  719. scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION
  720. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  721. make
  722. msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
  723. make test
  724. msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
  725. if_build_succeeded tests/ssl-opt.sh
  726. }
  727. component_test_no_pem_no_fs () {
  728. msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
  729. scripts/config.pl unset MBEDTLS_PEM_PARSE_C
  730. scripts/config.pl unset MBEDTLS_FS_IO
  731. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  732. make
  733. msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
  734. make test
  735. msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
  736. if_build_succeeded tests/ssl-opt.sh
  737. }
  738. component_test_rsa_no_crt () {
  739. msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
  740. scripts/config.pl set MBEDTLS_RSA_NO_CRT
  741. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  742. make
  743. msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
  744. make test
  745. msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
  746. if_build_succeeded tests/ssl-opt.sh -f RSA
  747. msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
  748. if_build_succeeded tests/compat.sh -t RSA
  749. }
  750. component_test_no_ctr_drbg () {
  751. msg "build: Full minus CTR_DRBG"
  752. scripts/config.pl full
  753. scripts/config.pl unset MBEDTLS_CTR_DRBG_C
  754. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  755. make
  756. msg "test: no CTR_DRBG"
  757. make test
  758. # no ssl-opt.sh/compat.sh as they all depend on CTR_DRBG so far
  759. }
  760. component_test_no_hmac_drbg () {
  761. msg "build: Full minus HMAC_DRBG"
  762. scripts/config.pl full
  763. scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
  764. scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
  765. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  766. make
  767. msg "test: Full minus HMAC_DRBG - main suites"
  768. make test
  769. # Normally our ECDSA implementation uses deterministic ECDSA. But since
  770. # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
  771. # instead.
  772. # Test SSL with non-deterministic ECDSA. Only test features that
  773. # might be affected by how ECDSA signature is performed.
  774. msg "test: Full minus HMAC_DRBG - ssl-opt.sh (subset)"
  775. if_build_succeeded tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
  776. # To save time, only test one protocol version, since this part of
  777. # the protocol is identical in (D)TLS up to 1.2.
  778. msg "test: Full minus HMAC_DRBG - compat.sh (ECDSA)"
  779. if_build_succeeded tests/compat.sh -m tls1_2 -t 'ECDSA'
  780. }
  781. component_test_no_drbg_all_hashes () {
  782. # this tests the internal ECP DRBG using a KDF based on SHA-512
  783. msg "build: Default minus DRBGs"
  784. scripts/config.pl unset MBEDTLS_CTR_DRBG_C
  785. scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
  786. scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
  787. scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
  788. scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
  789. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  790. make
  791. msg "test: Default minus DRBGs"
  792. make test
  793. # no SSL tests as they all depend on having a DRBG
  794. }
  795. component_test_no_drbg_no_sha512 () {
  796. # this tests the internal ECP DRBG using a KDF based on SHA-256
  797. msg "build: Default minus DRBGs minus SHA-512"
  798. scripts/config.pl unset MBEDTLS_CTR_DRBG_C
  799. scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
  800. scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
  801. scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
  802. scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
  803. scripts/config.pl unset MBEDTLS_SHA512_C
  804. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  805. make
  806. msg "test: Default minus DRBGs minus SHA-512"
  807. make test
  808. # no SSL tests as they all depend on having a DRBG
  809. }
  810. component_test_ecp_no_internal_rng () {
  811. msg "build: Default plus ECP_NO_INTERNAL_RNG minus DRBG modules"
  812. scripts/config.pl set MBEDTLS_ECP_NO_INTERNAL_RNG
  813. scripts/config.pl unset MBEDTLS_CTR_DRBG_C
  814. scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
  815. scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
  816. scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
  817. scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
  818. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  819. make
  820. msg "test: ECP_NO_INTERNAL_RNG, no DRBG module"
  821. make test
  822. # no SSL tests as they all depend on having a DRBG
  823. }
  824. component_test_ecp_restartable_no_internal_rng () {
  825. msg "build: Default plus ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG"
  826. scripts/config.pl set MBEDTLS_ECP_NO_INTERNAL_RNG
  827. scripts/config.pl set MBEDTLS_ECP_RESTARTABLE
  828. scripts/config.pl unset MBEDTLS_CTR_DRBG_C
  829. scripts/config.pl unset MBEDTLS_HMAC_DRBG_C
  830. scripts/config.pl unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
  831. scripts/config.pl unset MBEDTLS_PSA_CRYPTO_C # requires CTR_DRBG
  832. scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
  833. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  834. make
  835. msg "test: ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG module"
  836. make test
  837. # no SSL tests as they all depend on having a DRBG
  838. }
  839. component_test_small_ssl_out_content_len () {
  840. msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
  841. scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
  842. scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
  843. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  844. make
  845. msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
  846. if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
  847. }
  848. component_test_small_ssl_in_content_len () {
  849. msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
  850. scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 4096
  851. scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
  852. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  853. make
  854. msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
  855. if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
  856. }
  857. component_test_small_ssl_dtls_max_buffering () {
  858. msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
  859. scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
  860. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  861. make
  862. msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
  863. if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
  864. }
  865. component_test_small_mbedtls_ssl_dtls_max_buffering () {
  866. msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
  867. scripts/config.pl set MBEDTLS_SSL_DTLS_MAX_BUFFERING 240
  868. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  869. make
  870. msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
  871. if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
  872. }
  873. component_test_full_cmake_clang () {
  874. msg "build: cmake, full config, clang" # ~ 50s
  875. scripts/config.pl full
  876. CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
  877. make
  878. msg "test: main suites (full config)" # ~ 5s
  879. make test
  880. msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
  881. if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
  882. msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
  883. if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '^$' -f 'NULL\|DES\|RC4\|ARCFOUR'
  884. msg "test: compat.sh ARIA + ChachaPoly"
  885. if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
  886. }
  887. component_test_memsan_constant_flow () {
  888. # This tests both (1) accesses to undefined memory, and (2) branches or
  889. # memory access depending on secret values. To distinguish between those:
  890. # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
  891. # - or alternatively, change the build type to MemSanDbg, which enables
  892. # origin tracking and nicer stack traces (which are useful for debugging
  893. # anyway), and check if the origin was TEST_CF_SECRET() or something else.
  894. msg "build: cmake MSan (clang), full config with constant flow testing"
  895. scripts/config.pl full
  896. scripts/config.pl set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
  897. scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
  898. CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
  899. make
  900. msg "test: main suites (Msan + constant flow)"
  901. make test
  902. }
  903. component_test_valgrind_constant_flow () {
  904. # This tests both (1) everything that valgrind's memcheck usually checks
  905. # (heap buffer overflows, use of uninitialized memory, use-after-free,
  906. # etc.) and (2) branches or memory access depending on secret values,
  907. # which will be reported as uninitialized memory. To distinguish between
  908. # secret and actually uninitialized:
  909. # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
  910. # - or alternatively, build with debug info and manually run the offending
  911. # test suite with valgrind --track-origins=yes, then check if the origin
  912. # was TEST_CF_SECRET() or something else.
  913. msg "build: cmake release GCC, full config with constant flow testing"
  914. scripts/config.pl full
  915. scripts/config.pl set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
  916. cmake -D CMAKE_BUILD_TYPE:String=Release .
  917. make
  918. # this only shows a summary of the results (how many of each type)
  919. # details are left in Testing/<date>/DynamicAnalysis.xml
  920. msg "test: main suites (valgrind + constant flow)"
  921. make memcheck
  922. }
  923. component_test_default_no_deprecated () {
  924. # Test that removing the deprecated features from the default
  925. # configuration leaves something consistent.
  926. msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
  927. scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED
  928. make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
  929. msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
  930. make test
  931. }
  932. component_test_full_deprecated_warning () {
  933. # Test that there is nothing deprecated in the full configuration.
  934. # A deprecated feature would trigger a warning (made fatal) from
  935. # MBEDTLS_DEPRECATED_WARNING.
  936. msg "build: make, full + MBEDTLS_DEPRECATED_WARNING" # ~ 30s
  937. scripts/config.pl full
  938. scripts/config.pl unset MBEDTLS_DEPRECATED_REMOVED
  939. scripts/config.pl set MBEDTLS_DEPRECATED_WARNING
  940. # There are currently no tests for any deprecated feature.
  941. # If some are added, 'make test' would trigger warnings here.
  942. make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
  943. msg "test: make, full + MBEDTLS_DEPRECATED_WARNING" # ~ 5s
  944. make test
  945. }
  946. component_test_depends_curves () {
  947. msg "test/build: curves.pl (gcc)" # ~ 4 min
  948. record_status tests/scripts/curves.pl
  949. }
  950. component_test_depends_hashes () {
  951. msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
  952. record_status tests/scripts/depends-hashes.pl
  953. }
  954. component_test_depends_pkalgs () {
  955. msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
  956. record_status tests/scripts/depends-pkalgs.pl
  957. }
  958. component_build_key_exchanges () {
  959. msg "test/build: key-exchanges (gcc)" # ~ 1 min
  960. record_status tests/scripts/key-exchanges.pl
  961. }
  962. component_build_default_make_gcc_and_cxx () {
  963. msg "build: Unix make, -Os (gcc)" # ~ 30s
  964. make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
  965. msg "test: verify header list in cpp_dummy_build.cpp"
  966. record_status check_headers_in_cpp
  967. msg "build: Unix make, incremental g++"
  968. make TEST_CPP=1
  969. }
  970. component_test_check_params_functionality () {
  971. msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
  972. scripts/config.pl full # includes CHECK_PARAMS
  973. # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
  974. scripts/config.pl unset MBEDTLS_CHECK_PARAMS_ASSERT
  975. # Only build and run tests. Do not build sample programs, because
  976. # they don't have a mbedtls_param_failed() function.
  977. make CC=gcc CFLAGS='-Werror -O1' lib test
  978. }
  979. component_test_check_params_without_platform () {
  980. msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
  981. scripts/config.pl full # includes CHECK_PARAMS
  982. # Keep MBEDTLS_PARAM_FAILED as assert.
  983. scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
  984. scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
  985. scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
  986. scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
  987. scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
  988. scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
  989. scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
  990. scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
  991. scripts/config.pl unset MBEDTLS_PLATFORM_C
  992. make CC=gcc CFLAGS='-Werror -O1' all test
  993. }
  994. component_test_check_params_silent () {
  995. msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
  996. scripts/config.pl full # includes CHECK_PARAMS
  997. # Set MBEDTLS_PARAM_FAILED to nothing.
  998. sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
  999. make CC=gcc CFLAGS='-Werror -O1' all test
  1000. }
  1001. component_test_no_platform () {
  1002. # Full configuration build, without platform support, file IO and net sockets.
  1003. # This should catch missing mbedtls_printf definitions, and by disabling file
  1004. # IO, it should catch missing '#include <stdio.h>'
  1005. msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
  1006. scripts/config.pl full
  1007. scripts/config.pl unset MBEDTLS_PLATFORM_C
  1008. scripts/config.pl unset MBEDTLS_NET_C
  1009. scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY
  1010. scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT
  1011. scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT
  1012. scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT
  1013. scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
  1014. scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
  1015. scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
  1016. scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
  1017. scripts/config.pl unset MBEDTLS_FS_IO
  1018. # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
  1019. # to re-enable platform integration features otherwise disabled in C99 builds
  1020. make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
  1021. make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
  1022. }
  1023. component_build_no_std_function () {
  1024. # catch compile bugs in _uninit functions
  1025. msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
  1026. scripts/config.pl full
  1027. scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
  1028. scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
  1029. scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
  1030. make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
  1031. }
  1032. component_build_no_ssl_srv () {
  1033. msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
  1034. scripts/config.pl full
  1035. scripts/config.pl unset MBEDTLS_SSL_SRV_C
  1036. make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
  1037. }
  1038. component_build_no_ssl_cli () {
  1039. msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
  1040. scripts/config.pl full
  1041. scripts/config.pl unset MBEDTLS_SSL_CLI_C
  1042. make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
  1043. }
  1044. component_build_no_sockets () {
  1045. # Note, C99 compliance can also be tested with the sockets support disabled,
  1046. # as that requires a POSIX platform (which isn't the same as C99).
  1047. msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
  1048. scripts/config.pl full
  1049. scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
  1050. scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
  1051. make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
  1052. }
  1053. component_test_memory_buffer_allocator_backtrace () {
  1054. msg "build: default config with memory buffer allocator and backtrace enabled"
  1055. scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
  1056. scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
  1057. scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE
  1058. scripts/config.pl set MBEDTLS_MEMORY_DEBUG
  1059. CC=gcc cmake .
  1060. make
  1061. msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
  1062. make test
  1063. }
  1064. component_test_memory_buffer_allocator () {
  1065. msg "build: default config with memory buffer allocator"
  1066. scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
  1067. scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
  1068. CC=gcc cmake .
  1069. make
  1070. msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
  1071. make test
  1072. msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
  1073. # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
  1074. if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
  1075. }
  1076. component_test_no_max_fragment_length () {
  1077. # Run max fragment length tests with MFL disabled
  1078. msg "build: default config except MFL extension (ASan build)" # ~ 30s
  1079. scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
  1080. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  1081. make
  1082. msg "test: ssl-opt.sh, MFL-related tests"
  1083. if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
  1084. }
  1085. component_test_no_max_fragment_length_small_ssl_out_content_len () {
  1086. msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
  1087. scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
  1088. scripts/config.pl set MBEDTLS_SSL_IN_CONTENT_LEN 16384
  1089. scripts/config.pl set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
  1090. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  1091. make
  1092. msg "test: MFL tests (disabled MFL extension case) & large packet tests"
  1093. if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
  1094. }
  1095. component_test_null_entropy () {
  1096. msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
  1097. scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY
  1098. scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
  1099. scripts/config.pl set MBEDTLS_ENTROPY_C
  1100. scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
  1101. scripts/config.pl unset MBEDTLS_PLATFORM_NV_SEED_ALT
  1102. scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT
  1103. scripts/config.pl unset MBEDTLS_HAVEGE_C
  1104. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
  1105. make
  1106. msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
  1107. make test
  1108. }
  1109. component_test_no_date_time () {
  1110. msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
  1111. scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE
  1112. CC=gcc cmake
  1113. make
  1114. msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
  1115. make test
  1116. }
  1117. component_test_platform_calloc_macro () {
  1118. msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
  1119. scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
  1120. scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
  1121. scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free
  1122. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  1123. make
  1124. msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
  1125. make test
  1126. }
  1127. component_test_malloc_0_null () {
  1128. msg "build: malloc(0) returns NULL (ASan+UBSan build)"
  1129. scripts/config.pl full
  1130. scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
  1131. make CC=gcc CFLAGS="'-DMBEDTLS_CONFIG_FILE=\"$PWD/tests/configs/config-wrapper-malloc-0-null.h\"' -O $ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
  1132. msg "test: malloc(0) returns NULL (ASan+UBSan build)"
  1133. make test
  1134. msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
  1135. # Just the calloc selftest. "make test" ran the others as part of the
  1136. # test suites.
  1137. if_build_succeeded programs/test/selftest calloc
  1138. }
  1139. component_test_aes_fewer_tables () {
  1140. msg "build: default config with AES_FEWER_TABLES enabled"
  1141. scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
  1142. make CC=gcc CFLAGS='-Werror -Wall -Wextra'
  1143. msg "test: AES_FEWER_TABLES"
  1144. make test
  1145. }
  1146. component_test_aes_rom_tables () {
  1147. msg "build: default config with AES_ROM_TABLES enabled"
  1148. scripts/config.pl set MBEDTLS_AES_ROM_TABLES
  1149. make CC=gcc CFLAGS='-Werror -Wall -Wextra'
  1150. msg "test: AES_ROM_TABLES"
  1151. make test
  1152. }
  1153. component_test_aes_fewer_tables_and_rom_tables () {
  1154. msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
  1155. scripts/config.pl set MBEDTLS_AES_FEWER_TABLES
  1156. scripts/config.pl set MBEDTLS_AES_ROM_TABLES
  1157. make CC=gcc CFLAGS='-Werror -Wall -Wextra'
  1158. msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
  1159. make test
  1160. }
  1161. component_test_make_shared () {
  1162. msg "build/test: make shared" # ~ 40s
  1163. make SHARED=1 all check
  1164. ldd programs/util/strerror | grep libmbedcrypto
  1165. }
  1166. component_test_cmake_shared () {
  1167. msg "build/test: cmake shared" # ~ 2min
  1168. cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
  1169. make
  1170. ldd programs/util/strerror | grep libmbedcrypto
  1171. make test
  1172. }
  1173. test_build_opt () {
  1174. info=$1 cc=$2; shift 2
  1175. for opt in "$@"; do
  1176. msg "build/test: $cc $opt, $info" # ~ 30s
  1177. make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
  1178. # We're confident enough in compilers to not run _all_ the tests,
  1179. # but at least run the unit tests. In particular, runs with
  1180. # optimizations use inline assembly whereas runs with -O0
  1181. # skip inline assembly.
  1182. make test # ~30s
  1183. make clean
  1184. done
  1185. }
  1186. component_test_clang_opt () {
  1187. scripts/config.pl full
  1188. test_build_opt 'full config' clang -O0 -Os -O2
  1189. }
  1190. component_test_gcc_opt () {
  1191. scripts/config.pl full
  1192. test_build_opt 'full config' gcc -O0 -Os -O2
  1193. }
  1194. component_build_mbedtls_config_file () {
  1195. msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
  1196. # Use the full config so as to catch a maximum of places where
  1197. # the check of MBEDTLS_CONFIG_FILE might be missing.
  1198. scripts/config.pl full
  1199. sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
  1200. echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
  1201. make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
  1202. rm -f full_config.h
  1203. }
  1204. component_test_m32_o0 () {
  1205. # Build once with -O0, to compile out the i386 specific inline assembly
  1206. msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
  1207. scripts/config.pl full
  1208. make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
  1209. msg "test: i386, make, gcc -O0 (ASan build)"
  1210. make test
  1211. }
  1212. support_test_m32_o0 () {
  1213. case $(uname -m) in
  1214. *64*) true;;
  1215. *) false;;
  1216. esac
  1217. }
  1218. component_test_m32_o1 () {
  1219. # Build again with -O1, to compile in the i386 specific inline assembly
  1220. msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
  1221. scripts/config.pl full
  1222. make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
  1223. msg "test: i386, make, gcc -O1 (ASan build)"
  1224. make test
  1225. msg "test ssl-opt.sh, i386, make, gcc-O1"
  1226. if_build_succeeded tests/ssl-opt.sh
  1227. }
  1228. support_test_m32_o1 () {
  1229. support_test_m32_o0 "$@"
  1230. }
  1231. component_test_mx32 () {
  1232. msg "build: 64-bit ILP32, make, gcc" # ~ 30s
  1233. scripts/config.pl full
  1234. make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
  1235. msg "test: 64-bit ILP32, make, gcc"
  1236. make test
  1237. }
  1238. support_test_mx32 () {
  1239. case $(uname -m) in
  1240. amd64|x86_64) true;;
  1241. *) false;;
  1242. esac
  1243. }
  1244. component_test_min_mpi_window_size () {
  1245. msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
  1246. scripts/config.pl set MBEDTLS_MPI_WINDOW_SIZE 1
  1247. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  1248. make
  1249. msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
  1250. make test
  1251. }
  1252. component_test_have_int32 () {
  1253. msg "build: gcc, force 32-bit bignum limbs"
  1254. scripts/config.pl unset MBEDTLS_HAVE_ASM
  1255. scripts/config.pl unset MBEDTLS_AESNI_C
  1256. scripts/config.pl unset MBEDTLS_PADLOCK_C
  1257. make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
  1258. msg "test: gcc, force 32-bit bignum limbs"
  1259. make test
  1260. }
  1261. component_test_have_int64 () {
  1262. msg "build: gcc, force 64-bit bignum limbs"
  1263. scripts/config.pl unset MBEDTLS_HAVE_ASM
  1264. scripts/config.pl unset MBEDTLS_AESNI_C
  1265. scripts/config.pl unset MBEDTLS_PADLOCK_C
  1266. make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
  1267. msg "test: gcc, force 64-bit bignum limbs"
  1268. make test
  1269. }
  1270. component_test_no_udbl_division () {
  1271. msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
  1272. scripts/config.pl full
  1273. scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
  1274. make CFLAGS='-Werror -O1'
  1275. msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
  1276. make test
  1277. }
  1278. component_test_no_64bit_multiplication () {
  1279. msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
  1280. scripts/config.pl full
  1281. scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
  1282. make CFLAGS='-Werror -O1'
  1283. msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
  1284. make test
  1285. }
  1286. component_test_no_strings () {
  1287. msg "build: no strings" # ~10s
  1288. scripts/config.pl full
  1289. # Disable options that activate a large amount of string constants.
  1290. scripts/config.pl unset MBEDTLS_DEBUG_C
  1291. scripts/config.pl unset MBEDTLS_ERROR_C
  1292. scripts/config.pl set MBEDTLS_ERROR_STRERROR_DUMMY
  1293. scripts/config.pl unset MBEDTLS_VERSION_FEATURES
  1294. make CFLAGS='-Werror -Os'
  1295. msg "test: no strings" # ~ 10s
  1296. make test
  1297. }
  1298. component_build_arm_none_eabi_gcc () {
  1299. msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1" # ~ 10s
  1300. scripts/config.pl baremetal
  1301. make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra -O1' lib
  1302. msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1"
  1303. ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
  1304. }
  1305. component_build_arm_none_eabi_gcc_arm5vte () {
  1306. msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s
  1307. scripts/config.pl baremetal
  1308. # Build for a target platform that's close to what Debian uses
  1309. # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
  1310. # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
  1311. # It would be better to build with arm-linux-gnueabi-gcc but
  1312. # we don't have that on our CI at this time.
  1313. make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
  1314. msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1"
  1315. ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
  1316. }
  1317. component_build_arm_none_eabi_gcc_m0plus () {
  1318. msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus" # ~ 10s
  1319. scripts/config.pl baremetal
  1320. make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra -mthumb -mcpu=cortex-m0plus -Os' lib
  1321. msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os"
  1322. ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
  1323. }
  1324. component_build_arm_none_eabi_gcc_no_udbl_division () {
  1325. msg "build: ${ARM_NONE_EABI_GCC_PREFIX} -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
  1326. scripts/config.pl baremetal
  1327. scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION
  1328. make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -Wall -Wextra' lib
  1329. echo "Checking that software 64-bit division is not required"
  1330. if_build_succeeded not grep __aeabi_uldiv library/*.o
  1331. }
  1332. component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
  1333. msg "build: ${ARM_NONE_EABI_GCC_PREFIX} MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
  1334. scripts/config.pl baremetal
  1335. scripts/config.pl set MBEDTLS_NO_64BIT_MULTIPLICATION
  1336. make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-Werror -O1 -march=armv6-m -mthumb' lib
  1337. echo "Checking that software 64-bit multiplication is not required"
  1338. if_build_succeeded not grep __aeabi_lmul library/*.o
  1339. }
  1340. component_build_armcc () {
  1341. msg "build: ARM Compiler 5"
  1342. scripts/config.pl baremetal
  1343. make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
  1344. msg "size: ARM Compiler 5"
  1345. "$ARMC5_FROMELF" -z library/*.o
  1346. make clean
  1347. # ARM Compiler 6 - Target ARMv7-A
  1348. armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
  1349. # ARM Compiler 6 - Target ARMv7-M
  1350. armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
  1351. # ARM Compiler 6 - Target ARMv8-A - AArch32
  1352. armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
  1353. # ARM Compiler 6 - Target ARMv8-M
  1354. armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
  1355. # ARM Compiler 6 - Target ARMv8-A - AArch64
  1356. armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
  1357. }
  1358. component_build_ssl_hw_record_accel() {
  1359. msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
  1360. scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
  1361. make CFLAGS='-Werror -O1'
  1362. }
  1363. component_test_allow_sha1 () {
  1364. msg "build: allow SHA1 in certificates by default"
  1365. scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
  1366. make CFLAGS='-Werror -Wall -Wextra'
  1367. msg "test: allow SHA1 in certificates by default"
  1368. make test
  1369. if_build_succeeded tests/ssl-opt.sh -f SHA-1
  1370. }
  1371. component_build_mingw () {
  1372. msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
  1373. 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
  1374. # note Make tests only builds the tests, but doesn't run them
  1375. make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
  1376. make WINDOWS_BUILD=1 clean
  1377. msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
  1378. 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
  1379. 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
  1380. make WINDOWS_BUILD=1 clean
  1381. }
  1382. component_test_memsan () {
  1383. msg "build: MSan (clang)" # ~ 1 min 20s
  1384. scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm
  1385. CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
  1386. make
  1387. msg "test: main suites (MSan)" # ~ 10s
  1388. make test
  1389. msg "test: ssl-opt.sh (MSan)" # ~ 1 min
  1390. if_build_succeeded tests/ssl-opt.sh
  1391. # Optional part(s)
  1392. if [ "$MEMORY" -gt 0 ]; then
  1393. msg "test: compat.sh (MSan)" # ~ 6 min 20s
  1394. if_build_succeeded tests/compat.sh
  1395. fi
  1396. }
  1397. component_test_valgrind () {
  1398. msg "build: Release (clang)"
  1399. CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
  1400. make
  1401. msg "test: main suites valgrind (Release)"
  1402. make memcheck
  1403. # Optional parts (slow; currently broken on OS X because programs don't
  1404. # seem to receive signals under valgrind on OS X).
  1405. if [ "$MEMORY" -gt 0 ]; then
  1406. msg "test: ssl-opt.sh --memcheck (Release)"
  1407. if_build_succeeded tests/ssl-opt.sh --memcheck
  1408. fi
  1409. if [ "$MEMORY" -gt 1 ]; then
  1410. msg "test: compat.sh --memcheck (Release)"
  1411. if_build_succeeded tests/compat.sh --memcheck
  1412. fi
  1413. }
  1414. component_test_cmake_out_of_source () {
  1415. msg "build: cmake 'out-of-source' build"
  1416. MBEDTLS_ROOT_DIR="$PWD"
  1417. mkdir "$OUT_OF_SOURCE_DIR"
  1418. cd "$OUT_OF_SOURCE_DIR"
  1419. cmake "$MBEDTLS_ROOT_DIR"
  1420. make
  1421. msg "test: cmake 'out-of-source' build"
  1422. make test
  1423. # Test an SSL option that requires an auxiliary script in test/scripts/.
  1424. # Also ensure that there are no error messages such as
  1425. # "No such file or directory", which would indicate that some required
  1426. # file is missing (ssl-opt.sh tolerates the absence of some files so
  1427. # may exit with status 0 but emit errors).
  1428. if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
  1429. if [ -s ssl-opt.err ]; then
  1430. cat ssl-opt.err >&2
  1431. record_status [ ! -s ssl-opt.err ]
  1432. rm ssl-opt.err
  1433. fi
  1434. cd "$MBEDTLS_ROOT_DIR"
  1435. rm -rf "$OUT_OF_SOURCE_DIR"
  1436. unset MBEDTLS_ROOT_DIR
  1437. }
  1438. component_test_zeroize () {
  1439. # Test that the function mbedtls_platform_zeroize() is not optimized away by
  1440. # different combinations of compilers and optimization flags by using an
  1441. # auxiliary GDB script. Unfortunately, GDB does not return error values to the
  1442. # system in all cases that the script fails, so we must manually search the
  1443. # output to check whether the pass string is present and no failure strings
  1444. # were printed.
  1445. # Don't try to disable ASLR. We don't care about ASLR here. We do care
  1446. # about a spurious message if Gdb tries and fails, so suppress that.
  1447. gdb_disable_aslr=
  1448. if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
  1449. gdb_disable_aslr='set disable-randomization off'
  1450. fi
  1451. for optimization_flag in -O2 -O3 -Ofast -Os; do
  1452. for compiler in clang gcc; do
  1453. msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
  1454. make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
  1455. if_build_succeeded gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
  1456. if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
  1457. if_build_succeeded not grep -i "error" test_zeroize.log
  1458. rm -f test_zeroize.log
  1459. make clean
  1460. done
  1461. done
  1462. unset gdb_disable_aslr
  1463. }
  1464. component_check_python_files () {
  1465. msg "Lint: Python scripts"
  1466. record_status tests/scripts/check-python-files.sh
  1467. }
  1468. component_check_generate_test_code () {
  1469. msg "uint test: generate_test_code.py"
  1470. # unittest writes out mundane stuff like number or tests run on stderr.
  1471. # Our convention is to reserve stderr for actual errors, and write
  1472. # harmless info on stdout so it can be suppress with --quiet.
  1473. record_status ./tests/scripts/test_generate_test_code.py 2>&1
  1474. }
  1475. ################################################################
  1476. #### Termination
  1477. ################################################################
  1478. post_report () {
  1479. msg "Done, cleaning up"
  1480. cleanup
  1481. final_report
  1482. }
  1483. ################################################################
  1484. #### Run all the things
  1485. ################################################################
  1486. # Run one component and clean up afterwards.
  1487. run_component () {
  1488. # Back up the configuration in case the component modifies it.
  1489. # The cleanup function will restore it.
  1490. cp -p "$CONFIG_H" "$CONFIG_BAK"
  1491. current_component="$1"
  1492. # Run the component code.
  1493. if [ $QUIET -eq 1 ]; then
  1494. # msg() is silenced, so just print the component name here
  1495. echo "${current_component#component_}"
  1496. fi
  1497. redirect_out "$@"
  1498. # Restore the build tree to a clean state.
  1499. cleanup
  1500. unset current_component
  1501. }
  1502. # Preliminary setup
  1503. pre_check_environment
  1504. pre_initialize_variables
  1505. pre_parse_command_line "$@"
  1506. pre_check_git
  1507. build_status=0
  1508. if [ $KEEP_GOING -eq 1 ]; then
  1509. pre_setup_keep_going
  1510. else
  1511. record_status () {
  1512. "$@"
  1513. }
  1514. fi
  1515. pre_setup_quiet_redirect
  1516. pre_print_configuration
  1517. pre_check_tools
  1518. cleanup
  1519. # Run the requested tests.
  1520. for component in $RUN_COMPONENTS; do
  1521. run_component "component_$component"
  1522. done
  1523. # We're done.
  1524. post_report