cmake: Add support for test build

This commit is contained in:
Renz Bagaporo
2018-08-27 10:48:16 +08:00
parent 129d32772e
commit cc774111bf
54 changed files with 1290 additions and 66 deletions

View File

@@ -166,4 +166,10 @@ if(GCC_NOT_5_2_0)
PROPERTIES COMPILE_FLAGS
-Wno-implicit-fallthrough
)
endif()
endif()
set_source_files_properties(
${SRC}/randombytes/randombytes.c
PROPERTIES COMPILE_FLAGS
-DRANDOMBYTES_DEFAULT_IMPLEMENTATION
)

View File

@@ -0,0 +1,40 @@
if(TESTS_ALL EQUAL 1)
message("not linking libsodium tests, use '-T libsodium' to test it")
else()
get_filename_component(LS_TESTDIR "${CMAKE_CURRENT_LIST_DIR}/../libsodium/test/default" ABSOLUTE)
set(COMPONENT_ADD_INCLUDEDIRS "." "${LS_TESTDIR}/../quirks")
set(COMPONENT_REQUIRES unity libsodium)
set(TEST_CASES "chacha20;aead_chacha20poly1305;box;box2;ed25519_convert;sign;hash")
foreach(test_case ${TEST_CASES})
file(GLOB test_case_file "${LS_TESTDIR}/${test_case}.c")
list(APPEND TEST_CASES_FILES ${test_case_file})
endforeach()
set(COMPONENT_SRCS "${TEST_CASES_FILES};test_sodium.c")
register_component()
# The libsodium test suite is designed to be run each test case as an executable on a desktop computer and uses
# filesytem to write & then compare contents of each file.
#
# For now, use their "BROWSER_TEST" mode with these hacks so that
# multiple test cases can be combined into one ELF file.
#
# Run each test case from test_sodium.c as CASENAME_xmain().
foreach(test_case_file ${TEST_CASES_FILES})
get_filename_component(test_case ${test_case_file} NAME_WE)
set_source_files_properties(${test_case_file}
PROPERTIES COMPILE_FLAGS
# This would generate 'warning "main" redefined' warnings at runtime, which are
# silenced here. Only other solution involves patching libsodium's cmptest.h.
"-Dxmain=${test_case}_xmain -Dmain=${test_case}_main -Wp,-w")
endforeach()
# this seems odd, but it prevents the libsodium test harness from
# trying to write to a file!
add_definitions(-DBROWSER_TESTS)
endif()