Paul Bakker | b06819b | 2011-01-18 16:18:38 +0000 | [diff] [blame] | 1 | set(libs |
Raef Coles | 995c66f | 2020-10-13 16:30:41 +0100 | [diff] [blame] | 2 | ${mbedtls_target} |
Paul Bakker | b06819b | 2011-01-18 16:18:38 +0000 | [diff] [blame] | 3 | ) |
| 4 | |
Ashley Duncan | d85a7e9 | 2019-04-29 20:35:06 +1200 | [diff] [blame] | 5 | # Set the project root directory if it's not already defined, as may happen if |
| 6 | # the tests folder is included directly by a parent project, without including |
| 7 | # the top level CMakeLists.txt. |
| 8 | if(NOT DEFINED MBEDTLS_DIR) |
| 9 | set(MBEDTLS_DIR ${CMAKE_SOURCE_DIR}) |
| 10 | endif() |
| 11 | |
Paul Bakker | b06819b | 2011-01-18 16:18:38 +0000 | [diff] [blame] | 12 | if(USE_PKCS11_HELPER_LIBRARY) |
| 13 | set(libs ${libs} pkcs11-helper) |
| 14 | endif(USE_PKCS11_HELPER_LIBRARY) |
| 15 | |
Paul Bakker | 92eeea4 | 2012-07-03 15:10:33 +0000 | [diff] [blame] | 16 | if(ENABLE_ZLIB_SUPPORT) |
| 17 | set(libs ${libs} ${ZLIB_LIBRARIES}) |
| 18 | endif(ENABLE_ZLIB_SUPPORT) |
| 19 | |
okhowang(王沛文) | 3c1b090 | 2020-03-25 19:55:32 +0800 | [diff] [blame] | 20 | if(NOT MBEDTLS_PYTHON_EXECUTABLE) |
| 21 | message(FATAL_ERROR "Cannot build test suites without Python 3") |
Nicholas Wilson | 733676b | 2015-11-14 13:09:01 +0000 | [diff] [blame] | 22 | endif() |
| 23 | |
Nicholas Wilson | 2682edf | 2017-12-05 12:08:15 +0000 | [diff] [blame] | 24 | # Enable definition of various functions used throughout the testsuite |
Nicholas Wilson | 61fa436 | 2018-06-25 12:10:00 +0100 | [diff] [blame] | 25 | # (gethostname, strdup, fileno...) even when compiling with -std=c99. Harmless |
Nicholas Wilson | 2682edf | 2017-12-05 12:08:15 +0000 | [diff] [blame] | 26 | # on non-POSIX platforms. |
| 27 | add_definitions("-D_POSIX_C_SOURCE=200809L") |
| 28 | |
Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 29 | # Test suites caught by SKIP_TEST_SUITES are built but not executed. |
| 30 | # "foo" as a skip pattern skips "test_suite_foo" and "test_suite_foo.bar" |
| 31 | # but not "test_suite_foobar". |
| 32 | string(REGEX REPLACE "[ ,;]" "|" SKIP_TEST_SUITES_REGEX "${SKIP_TEST_SUITES}") |
| 33 | string(REPLACE "." "\\." SKIP_TEST_SUITES_REGEX "${SKIP_TEST_SUITES_REGEX}") |
| 34 | set(SKIP_TEST_SUITES_REGEX "^(${SKIP_TEST_SUITES_REGEX})(\$|\\.)") |
| 35 | |
Paul Bakker | 7304376 | 2011-07-13 15:03:10 +0000 | [diff] [blame] | 36 | function(add_test_suite suite_name) |
| 37 | if(ARGV1) |
Manuel Pégourié-Gonnard | 216a183 | 2015-06-25 09:20:03 +0200 | [diff] [blame] | 38 | set(data_name ${ARGV1}) |
Paul Bakker | 7304376 | 2011-07-13 15:03:10 +0000 | [diff] [blame] | 39 | else() |
Manuel Pégourié-Gonnard | 216a183 | 2015-06-25 09:20:03 +0200 | [diff] [blame] | 40 | set(data_name ${suite_name}) |
Paul Bakker | 46c1794 | 2011-07-13 14:54:54 +0000 | [diff] [blame] | 41 | endif() |
| 42 | |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 43 | add_custom_command( |
Paul Bakker | 7304376 | 2011-07-13 15:03:10 +0000 | [diff] [blame] | 44 | OUTPUT test_suite_${data_name}.c |
okhowang(王沛文) | 3c1b090 | 2020-03-25 19:55:32 +0800 | [diff] [blame] | 45 | COMMAND ${MBEDTLS_PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate_test_code.py -f ${CMAKE_CURRENT_SOURCE_DIR}/suites/test_suite_${suite_name}.function -d ${CMAKE_CURRENT_SOURCE_DIR}/suites/test_suite_${data_name}.data -t ${CMAKE_CURRENT_SOURCE_DIR}/suites/main_test.function -p ${CMAKE_CURRENT_SOURCE_DIR}/suites/host_test.function -s ${CMAKE_CURRENT_SOURCE_DIR}/suites --helpers-file ${CMAKE_CURRENT_SOURCE_DIR}/suites/helpers.function -o . |
Raef Coles | 995c66f | 2020-10-13 16:30:41 +0100 | [diff] [blame] | 46 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate_test_code.py ${mbedtls_target} ${CMAKE_CURRENT_SOURCE_DIR}/suites/helpers.function ${CMAKE_CURRENT_SOURCE_DIR}/suites/main_test.function ${CMAKE_CURRENT_SOURCE_DIR}/suites/host_test.function ${CMAKE_CURRENT_SOURCE_DIR}/suites/test_suite_${suite_name}.function ${CMAKE_CURRENT_SOURCE_DIR}/suites/test_suite_${data_name}.data |
Paul Bakker | 4c14a25 | 2010-06-18 22:54:05 +0000 | [diff] [blame] | 47 | ) |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 48 | |
Ronald Cron | f5ea29a | 2020-06-19 10:42:29 +0200 | [diff] [blame] | 49 | add_executable(test_suite_${data_name} test_suite_${data_name}.c $<TARGET_OBJECTS:mbedtls_test>) |
Paul Bakker | 7304376 | 2011-07-13 15:03:10 +0000 | [diff] [blame] | 50 | target_link_libraries(test_suite_${data_name} ${libs}) |
Gilles Peskine | 76dd3aa | 2020-07-02 15:58:37 +0200 | [diff] [blame] | 51 | # Include test-specific header files from ./include and private header |
| 52 | # files (used by some invasive tests) from ../library. Public header |
| 53 | # files are automatically included because the library targets declare |
| 54 | # them as PUBLIC. |
Ronald Cron | 8552741 | 2020-05-15 17:20:47 +0200 | [diff] [blame] | 55 | target_include_directories(test_suite_${data_name} |
| 56 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include |
| 57 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../library) |
| 58 | |
Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 59 | if(${data_name} MATCHES ${SKIP_TEST_SUITES_REGEX}) |
| 60 | message(STATUS "The test suite ${data_name} will not be executed.") |
| 61 | else() |
| 62 | add_test(${data_name}-suite test_suite_${data_name} --verbose) |
| 63 | endif() |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 64 | endfunction(add_test_suite) |
| 65 | |
Manuel Pégourié-Gonnard | 7e2d68c | 2015-07-01 13:41:35 +0200 | [diff] [blame] | 66 | if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) |
| 67 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function") |
| 68 | endif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 69 | |
Gilles Peskine | f29019f | 2021-02-23 13:44:41 +0100 | [diff] [blame] | 70 | if(CMAKE_COMPILER_IS_CLANG) |
| 71 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wdocumentation -Wno-documentation-deprecated-sync -Wunreachable-code") |
| 72 | endif(CMAKE_COMPILER_IS_CLANG) |
| 73 | |
Manuel Pégourié-Gonnard | 3083053 | 2015-07-01 17:06:28 +0200 | [diff] [blame] | 74 | if(MSVC) |
Simon B | 9b3e3c4 | 2016-11-03 01:12:50 +0000 | [diff] [blame] | 75 | # If a warning level has been defined, suppress all warnings for test code |
| 76 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W0") |
| 77 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX-") |
Manuel Pégourié-Gonnard | 3083053 | 2015-07-01 17:06:28 +0200 | [diff] [blame] | 78 | endif(MSVC) |
| 79 | |
Gilles Peskine | 3df1dae | 2022-01-25 22:30:25 +0100 | [diff] [blame^] | 80 | file(GLOB test_suites RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" suites/*.data) |
| 81 | list(SORT test_suites) |
| 82 | foreach(test_suite ${test_suites}) |
| 83 | get_filename_component(data_name ${test_suite} NAME) |
| 84 | string(REGEX REPLACE "\\.data\$" "" data_name "${data_name}") |
| 85 | string(REPLACE "test_suite_" "" data_name "${data_name}") |
| 86 | string(REGEX MATCH "[^.]*" function_name "${data_name}") |
| 87 | add_test_suite(${function_name} ${data_name}) |
| 88 | endforeach(test_suite) |
Paul Bakker | cd6d69a | 2014-02-06 15:43:21 +0100 | [diff] [blame] | 89 | |
Gilles Peskine | 8405257 | 2018-03-21 12:12:47 +0100 | [diff] [blame] | 90 | # Make scripts and data files needed for testing available in an |
| 91 | # out-of-source build. |
Paul Bakker | cd6d69a | 2014-02-06 15:43:21 +0100 | [diff] [blame] | 92 | if (NOT ${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) |
Andrzej Kurek | 4a71cfa | 2019-05-06 05:06:06 -0400 | [diff] [blame] | 93 | if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/seedfile") |
| 94 | link_to_source(seedfile) |
| 95 | endif() |
Gilles Peskine | 8405257 | 2018-03-21 12:12:47 +0100 | [diff] [blame] | 96 | link_to_source(compat.sh) |
David Brown | c744418 | 2020-10-16 13:19:49 -0600 | [diff] [blame] | 97 | link_to_source(context-info.sh) |
Gilles Peskine | 8405257 | 2018-03-21 12:12:47 +0100 | [diff] [blame] | 98 | link_to_source(data_files) |
| 99 | link_to_source(scripts) |
| 100 | link_to_source(ssl-opt.sh) |
Gilles Peskine | 6a78573 | 2019-01-02 17:29:04 +0100 | [diff] [blame] | 101 | link_to_source(suites) |
Paul Bakker | cd6d69a | 2014-02-06 15:43:21 +0100 | [diff] [blame] | 102 | endif() |