CMakeLists.txt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. if(TESTS_ALL EQUAL 1)
  2. message("not linking libsodium tests, use '-T libsodium' to test it")
  3. else()
  4. get_filename_component(LS_TESTDIR "${CMAKE_CURRENT_LIST_DIR}/../libsodium/test/default" ABSOLUTE)
  5. set(TEST_CASES "chacha20;aead_chacha20poly1305;box;box2;ed25519_convert;sign;hash")
  6. foreach(test_case ${TEST_CASES})
  7. file(GLOB test_case_file "${LS_TESTDIR}/${test_case}.c")
  8. list(APPEND TEST_CASES_FILES ${test_case_file})
  9. endforeach()
  10. idf_component_register(SRCS "${TEST_CASES_FILES}" "test_sodium.c"
  11. PRIV_INCLUDE_DIRS "." "${LS_TESTDIR}/../quirks"
  12. PRIV_REQUIRES cmock libsodium)
  13. # The libsodium test suite is designed to be run each test case as an executable on a desktop computer and uses
  14. # filesytem to write & then compare contents of each file.
  15. #
  16. # For now, use their "BROWSER_TEST" mode with these hacks so that
  17. # multiple test cases can be combined into one ELF file.
  18. #
  19. # Run each test case from test_sodium.c as CASENAME_xmain().
  20. foreach(test_case_file ${TEST_CASES_FILES})
  21. get_filename_component(test_case ${test_case_file} NAME_WE)
  22. set_source_files_properties(${test_case_file}
  23. PROPERTIES COMPILE_FLAGS
  24. # This would generate 'warning "main" redefined' warnings at runtime, which are
  25. # silenced here. Only other solution involves patching libsodium's cmptest.h.
  26. "-Dxmain=${test_case}_xmain -Dmain=${test_case}_main -Wp,-w")
  27. endforeach()
  28. # this seems odd, but it prevents the libsodium test harness from
  29. # trying to write to a file!
  30. add_definitions(-DBROWSER_TESTS)
  31. endif()