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