CMakeLists.txt 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. set(libs
  2. ${mbedtls_target}
  3. )
  4. # Set the project root directory if it's not already defined, as may happen if
  5. # the tests folder is included directly by a parent project, without including
  6. # the top level CMakeLists.txt.
  7. if(NOT DEFINED MBEDTLS_DIR)
  8. set(MBEDTLS_DIR ${CMAKE_SOURCE_DIR})
  9. endif()
  10. if(USE_PKCS11_HELPER_LIBRARY)
  11. set(libs ${libs} pkcs11-helper)
  12. endif(USE_PKCS11_HELPER_LIBRARY)
  13. if(ENABLE_ZLIB_SUPPORT)
  14. set(libs ${libs} ${ZLIB_LIBRARIES})
  15. endif(ENABLE_ZLIB_SUPPORT)
  16. if(NOT MBEDTLS_PYTHON_EXECUTABLE)
  17. message(FATAL_ERROR "Cannot build test suites without Python 3")
  18. endif()
  19. # Enable definition of various functions used throughout the testsuite
  20. # (gethostname, strdup, fileno...) even when compiling with -std=c99. Harmless
  21. # on non-POSIX platforms.
  22. add_definitions("-D_POSIX_C_SOURCE=200809L")
  23. # Test suites caught by SKIP_TEST_SUITES are built but not executed.
  24. # "foo" as a skip pattern skips "test_suite_foo" and "test_suite_foo.bar"
  25. # but not "test_suite_foobar".
  26. string(REGEX REPLACE "[ ,;]" "|" SKIP_TEST_SUITES_REGEX "${SKIP_TEST_SUITES}")
  27. string(REPLACE "." "\\." SKIP_TEST_SUITES_REGEX "${SKIP_TEST_SUITES_REGEX}")
  28. set(SKIP_TEST_SUITES_REGEX "^(${SKIP_TEST_SUITES_REGEX})(\$|\\.)")
  29. function(add_test_suite suite_name)
  30. if(ARGV1)
  31. set(data_name ${ARGV1})
  32. else()
  33. set(data_name ${suite_name})
  34. endif()
  35. add_custom_command(
  36. OUTPUT test_suite_${data_name}.c
  37. 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 .
  38. 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
  39. )
  40. add_executable(test_suite_${data_name} test_suite_${data_name}.c $<TARGET_OBJECTS:mbedtls_test>)
  41. target_link_libraries(test_suite_${data_name} ${libs})
  42. # Include test-specific header files from ./include and private header
  43. # files (used by some invasive tests) from ../library. Public header
  44. # files are automatically included because the library targets declare
  45. # them as PUBLIC.
  46. target_include_directories(test_suite_${data_name}
  47. PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
  48. PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../library)
  49. if(${data_name} MATCHES ${SKIP_TEST_SUITES_REGEX})
  50. message(STATUS "The test suite ${data_name} will not be executed.")
  51. else()
  52. add_test(${data_name}-suite test_suite_${data_name} --verbose)
  53. endif()
  54. endfunction(add_test_suite)
  55. if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
  56. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
  57. endif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
  58. if(CMAKE_COMPILER_IS_CLANG)
  59. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wdocumentation -Wno-documentation-deprecated-sync -Wunreachable-code")
  60. endif(CMAKE_COMPILER_IS_CLANG)
  61. if(MSVC)
  62. # If a warning level has been defined, suppress all warnings for test code
  63. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W0")
  64. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX-")
  65. endif(MSVC)
  66. add_test_suite(aes aes.cbc)
  67. add_test_suite(aes aes.cfb)
  68. add_test_suite(aes aes.ecb)
  69. add_test_suite(aes aes.ofb)
  70. add_test_suite(aes aes.rest)
  71. add_test_suite(aes aes.xts)
  72. add_test_suite(arc4)
  73. add_test_suite(aria)
  74. add_test_suite(asn1parse)
  75. add_test_suite(asn1write)
  76. add_test_suite(base64)
  77. add_test_suite(blowfish)
  78. add_test_suite(camellia)
  79. add_test_suite(ccm)
  80. add_test_suite(chacha20)
  81. add_test_suite(chachapoly)
  82. add_test_suite(cipher cipher.aes)
  83. add_test_suite(cipher cipher.arc4)
  84. add_test_suite(cipher cipher.blowfish)
  85. add_test_suite(cipher cipher.camellia)
  86. add_test_suite(cipher cipher.ccm)
  87. add_test_suite(cipher cipher.chacha20)
  88. add_test_suite(cipher cipher.chachapoly)
  89. add_test_suite(cipher cipher.des)
  90. add_test_suite(cipher cipher.gcm)
  91. add_test_suite(cipher cipher.misc)
  92. add_test_suite(cipher cipher.nist_kw)
  93. add_test_suite(cipher cipher.null)
  94. add_test_suite(cipher cipher.padding)
  95. add_test_suite(cmac)
  96. add_test_suite(ctr_drbg)
  97. add_test_suite(debug)
  98. add_test_suite(des)
  99. add_test_suite(dhm)
  100. add_test_suite(ecdh)
  101. add_test_suite(ecdsa)
  102. add_test_suite(ecjpake)
  103. add_test_suite(ecp)
  104. add_test_suite(entropy)
  105. add_test_suite(error)
  106. add_test_suite(gcm gcm.aes128_de)
  107. add_test_suite(gcm gcm.aes128_en)
  108. add_test_suite(gcm gcm.aes192_de)
  109. add_test_suite(gcm gcm.aes192_en)
  110. add_test_suite(gcm gcm.aes256_de)
  111. add_test_suite(gcm gcm.aes256_en)
  112. add_test_suite(gcm gcm.camellia)
  113. add_test_suite(gcm gcm.misc)
  114. add_test_suite(hkdf)
  115. add_test_suite(hmac_drbg hmac_drbg.misc)
  116. add_test_suite(hmac_drbg hmac_drbg.no_reseed)
  117. add_test_suite(hmac_drbg hmac_drbg.nopr)
  118. add_test_suite(hmac_drbg hmac_drbg.pr)
  119. add_test_suite(md)
  120. add_test_suite(mdx)
  121. add_test_suite(memory_buffer_alloc)
  122. add_test_suite(mpi)
  123. add_test_suite(mps)
  124. add_test_suite(net)
  125. add_test_suite(nist_kw)
  126. add_test_suite(oid)
  127. add_test_suite(pem)
  128. add_test_suite(pk)
  129. add_test_suite(pkcs1_v15)
  130. add_test_suite(pkcs1_v21)
  131. add_test_suite(pkcs5)
  132. add_test_suite(pkcs12)
  133. add_test_suite(pkparse)
  134. add_test_suite(pkwrite)
  135. add_test_suite(poly1305)
  136. add_test_suite(psa_crypto)
  137. add_test_suite(psa_crypto_attributes)
  138. add_test_suite(psa_crypto_entropy)
  139. add_test_suite(psa_crypto_hash)
  140. add_test_suite(psa_crypto_init)
  141. add_test_suite(psa_crypto_metadata)
  142. add_test_suite(psa_crypto_not_supported psa_crypto_not_supported.generated)
  143. add_test_suite(psa_crypto_not_supported psa_crypto_not_supported.misc)
  144. add_test_suite(psa_crypto_persistent_key)
  145. add_test_suite(psa_crypto_se_driver_hal)
  146. add_test_suite(psa_crypto_se_driver_hal_mocks)
  147. add_test_suite(psa_crypto_slot_management)
  148. add_test_suite(psa_crypto_storage_format psa_crypto_storage_format.misc)
  149. add_test_suite(psa_crypto_storage_format psa_crypto_storage_format.current)
  150. add_test_suite(psa_crypto_storage_format psa_crypto_storage_format.v0)
  151. add_test_suite(psa_its)
  152. add_test_suite(random)
  153. add_test_suite(rsa)
  154. add_test_suite(shax)
  155. add_test_suite(ssl)
  156. add_test_suite(timing)
  157. add_test_suite(version)
  158. add_test_suite(x509parse)
  159. add_test_suite(x509write)
  160. add_test_suite(xtea)
  161. # Make scripts and data files needed for testing available in an
  162. # out-of-source build.
  163. if (NOT ${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
  164. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/seedfile")
  165. link_to_source(seedfile)
  166. endif()
  167. link_to_source(compat.sh)
  168. link_to_source(context-info.sh)
  169. link_to_source(data_files)
  170. link_to_source(scripts)
  171. link_to_source(ssl-opt.sh)
  172. link_to_source(suites)
  173. endif()