blob: ecf6f34b2f17a7f6d92acaa55246f719e3f3250c [file] [log] [blame]
Paul Bakkerb06819b2011-01-18 16:18:38 +00001set(libs
Manuel Pégourié-Gonnard216a1832015-06-25 09:20:03 +02002 mbedtls
Paul Bakkerb06819b2011-01-18 16:18:38 +00003)
4
5if(USE_PKCS11_HELPER_LIBRARY)
6 set(libs ${libs} pkcs11-helper)
7endif(USE_PKCS11_HELPER_LIBRARY)
8
Paul Bakker92eeea42012-07-03 15:10:33 +00009if(ENABLE_ZLIB_SUPPORT)
10 set(libs ${libs} ${ZLIB_LIBRARIES})
11endif(ENABLE_ZLIB_SUPPORT)
12
Nicholas Wilson733676b2015-11-14 13:09:01 +000013find_package(Perl)
14if(NOT PERL_FOUND)
15 message(FATAL_ERROR "Cannot build test suites without Perl")
16endif()
17
Nicholas Wilson2682edf2017-12-05 12:08:15 +000018# Enable definition of various functions used throughout the testsuite
Nicholas Wilson61fa4362018-06-25 12:10:00 +010019# (gethostname, strdup, fileno...) even when compiling with -std=c99. Harmless
Nicholas Wilson2682edf2017-12-05 12:08:15 +000020# on non-POSIX platforms.
21add_definitions("-D_POSIX_C_SOURCE=200809L")
22
Gilles Peskineac372cc2018-11-29 10:15:06 +000023# 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".
26string(REGEX REPLACE "[ ,;]" "|" SKIP_TEST_SUITES_REGEX "${SKIP_TEST_SUITES}")
27string(REPLACE "." "\\." SKIP_TEST_SUITES_REGEX "${SKIP_TEST_SUITES_REGEX}")
28set(SKIP_TEST_SUITES_REGEX "^(${SKIP_TEST_SUITES_REGEX})(\$|\\.)")
29
Paul Bakker73043762011-07-13 15:03:10 +000030function(add_test_suite suite_name)
31 if(ARGV1)
Manuel Pégourié-Gonnard216a1832015-06-25 09:20:03 +020032 set(data_name ${ARGV1})
Paul Bakker73043762011-07-13 15:03:10 +000033 else()
Manuel Pégourié-Gonnard216a1832015-06-25 09:20:03 +020034 set(data_name ${suite_name})
Paul Bakker46c17942011-07-13 14:54:54 +000035 endif()
36
Paul Bakker367dae42009-06-28 21:50:27 +000037 add_custom_command(
Paul Bakker73043762011-07-13 15:03:10 +000038 OUTPUT test_suite_${data_name}.c
Azim Khan63ab5012018-06-29 15:00:11 +010039 COMMAND ${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 .
Mohammad Azim Khan78befd92018-03-06 11:49:41 +000040 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate_test_code.py mbedtls ${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 Bakker4c14a252010-06-18 22:54:05 +000041 )
Paul Bakker19343182013-08-16 13:31:10 +020042
Paul Bakker4c14a252010-06-18 22:54:05 +000043 include_directories(${CMAKE_CURRENT_SOURCE_DIR})
Paul Bakker73043762011-07-13 15:03:10 +000044 add_executable(test_suite_${data_name} test_suite_${data_name}.c)
45 target_link_libraries(test_suite_${data_name} ${libs})
Gilles Peskineac372cc2018-11-29 10:15:06 +000046 if(${data_name} MATCHES ${SKIP_TEST_SUITES_REGEX})
47 message(STATUS "The test suite ${data_name} will not be executed.")
48 else()
49 add_test(${data_name}-suite test_suite_${data_name} --verbose)
50 endif()
Paul Bakker367dae42009-06-28 21:50:27 +000051endfunction(add_test_suite)
52
Manuel Pégourié-Gonnard7e2d68c2015-07-01 13:41:35 +020053if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
54 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
55endif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
Paul Bakker367dae42009-06-28 21:50:27 +000056
Manuel Pégourié-Gonnard30830532015-07-01 17:06:28 +020057if(MSVC)
Simon B9b3e3c42016-11-03 01:12:50 +000058 # If a warning level has been defined, suppress all warnings for test code
59 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W0")
60 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX-")
Manuel Pégourié-Gonnard30830532015-07-01 17:06:28 +020061endif(MSVC)
62
Jack Lloyd274024f2019-04-04 07:59:33 -070063add_test_suite(debug)
64add_test_suite(ssl)
65add_test_suite(version)
66add_test_suite(x509parse)
67add_test_suite(x509write)
Paul Bakkercd6d69a2014-02-06 15:43:21 +010068
Gilles Peskine84052572018-03-21 12:12:47 +010069# Make scripts and data files needed for testing available in an
70# out-of-source build.
Paul Bakkercd6d69a2014-02-06 15:43:21 +010071if (NOT ${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
Andrzej Kurek4a71cfa2019-05-06 05:06:06 -040072 if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/seedfile")
73 link_to_source(seedfile)
74 endif()
Gilles Peskine84052572018-03-21 12:12:47 +010075 link_to_source(compat.sh)
76 link_to_source(data_files)
77 link_to_source(scripts)
78 link_to_source(ssl-opt.sh)
Paul Bakkercd6d69a2014-02-06 15:43:21 +010079endif()