From 17c119a5e30631716773eb96ce3e8b507daf4a41 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Fri, 8 Dec 2023 16:55:03 +0000 Subject: [PATCH 01/13] Migrate to threading_helpers.h Signed-off-by: Paul Elliott --- programs/ssl/ssl_test_lib.c | 2 +- programs/test/metatest.c | 1 + tests/include/test/helpers.h | 24 +------------- tests/include/test/threading_helpers.h | 45 ++++++++++++++++++++++++++ tests/src/threading_helpers.c | 1 + tests/suites/helpers.function | 1 + 6 files changed, 50 insertions(+), 24 deletions(-) create mode 100644 tests/include/test/threading_helpers.h diff --git a/programs/ssl/ssl_test_lib.c b/programs/ssl/ssl_test_lib.c index b49dd67c2..d562cb156 100644 --- a/programs/ssl/ssl_test_lib.c +++ b/programs/ssl/ssl_test_lib.c @@ -13,7 +13,7 @@ #include "ssl_test_lib.h" #if defined(MBEDTLS_TEST_HOOKS) -#include "test/helpers.h" +#include "test/threading_helpers.h" #endif #if !defined(MBEDTLS_SSL_TEST_IMPOSSIBLE) diff --git a/programs/test/metatest.c b/programs/test/metatest.c index b8dffa9bb..82ecf953b 100644 --- a/programs/test/metatest.c +++ b/programs/test/metatest.c @@ -31,6 +31,7 @@ #include #include #include "test/helpers.h" +#include "test/threading_helpers.h" #include "test/macros.h" #include diff --git a/tests/include/test/helpers.h b/tests/include/test/helpers.h index 7c962a283..b2b07cfa8 100644 --- a/tests/include/test/helpers.h +++ b/tests/include/test/helpers.h @@ -35,11 +35,7 @@ # endif #endif -#if defined(MBEDTLS_THREADING_C) && defined(MBEDTLS_THREADING_PTHREAD) && \ - defined(MBEDTLS_TEST_HOOKS) -#define MBEDTLS_TEST_MUTEX_USAGE -#endif - +#include "test/threading_helpers.h" #include "mbedtls/platform.h" #include @@ -254,24 +250,6 @@ int mbedtls_test_hexcmp(uint8_t *a, uint8_t *b, #include "test/fake_external_rng_for_test.h" #endif -#if defined(MBEDTLS_TEST_MUTEX_USAGE) -/** - * Activate the mutex usage verification framework. See threading_helpers.c for - * information. - * */ -void mbedtls_test_mutex_usage_init(void); - -/** - * Deactivate the mutex usage verification framework. See threading_helpers.c - * for information. - */ -void mbedtls_test_mutex_usage_end(void); - -/** Call this function after executing a test case to check for mutex usage - * errors. */ -void mbedtls_test_mutex_usage_check(void); -#endif /* MBEDTLS_TEST_MUTEX_USAGE */ - #if defined(MBEDTLS_TEST_HOOKS) /** * \brief Check that only a pure high-level error code is being combined with diff --git a/tests/include/test/threading_helpers.h b/tests/include/test/threading_helpers.h new file mode 100644 index 000000000..3c4d44126 --- /dev/null +++ b/tests/include/test/threading_helpers.h @@ -0,0 +1,45 @@ +/** + * \file threading_helpers.h + * + * \brief This file contains the prototypes of helper functions for the purpose + * of testing threading. + */ + +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + */ + +#ifndef THREADING_HELPERS_H +#define THREADING_HELPERS_H + +#if defined MBEDTLS_THREADING_C + +#if defined(MBEDTLS_THREADING_PTHREAD) && defined(MBEDTLS_TEST_HOOKS) +#define MBEDTLS_TEST_MUTEX_USAGE +#endif + +#if defined(MBEDTLS_TEST_MUTEX_USAGE) +/** + * Activate the mutex usage verification framework. See threading_helpers.c for + * information. + */ +void mbedtls_test_mutex_usage_init(void); + +/** + * Deactivate the mutex usage verification framework. See threading_helpers.c + * for information. + */ +void mbedtls_test_mutex_usage_end(void); + +/** + * Call this function after executing a test case to check for mutex usage + * errors. + */ +void mbedtls_test_mutex_usage_check(void); +#endif /* MBEDTLS_TEST_MUTEX_USAGE */ + +#endif /* MBEDTLS_THREADING_C */ + +#endif /* THREADING_HELPERS_H */ + diff --git a/tests/src/threading_helpers.c b/tests/src/threading_helpers.c index 5fbf65b2d..38059343d 100644 --- a/tests/src/threading_helpers.c +++ b/tests/src/threading_helpers.c @@ -6,6 +6,7 @@ */ #include +#include #include #if defined(MBEDTLS_TEST_MUTEX_USAGE) diff --git a/tests/suites/helpers.function b/tests/suites/helpers.function index 86ff5b489..b5f5796e4 100644 --- a/tests/suites/helpers.function +++ b/tests/suites/helpers.function @@ -8,6 +8,7 @@ #include #include #include +#include #include #include From 3a4d2f14a8c05a4f16a86d4ebf3d46f2d9f59a0a Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Fri, 8 Dec 2023 20:49:47 +0000 Subject: [PATCH 02/13] Add test thread create/join abstraction Signed-off-by: Paul Elliott --- tests/include/test/threading_helpers.h | 61 ++++++++++++++++++++++- tests/src/threading_helpers.c | 67 ++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 1 deletion(-) diff --git a/tests/include/test/threading_helpers.h b/tests/include/test/threading_helpers.h index 3c4d44126..9b7ced519 100644 --- a/tests/include/test/threading_helpers.h +++ b/tests/include/test/threading_helpers.h @@ -15,6 +15,66 @@ #if defined MBEDTLS_THREADING_C +#include "mbedtls/private_access.h" +#include "mbedtls/build_info.h" + +/* Most fields of publicly available structs are private and are wrapped with + * MBEDTLS_PRIVATE macro. This define allows tests to access the private fields + * directly (without using the MBEDTLS_PRIVATE wrapper). */ +#define MBEDTLS_ALLOW_PRIVATE_ACCESS + +#define MBEDTLS_ERR_THREADING_THREAD_ERROR -0x001F + +#if defined(MBEDTLS_THREADING_PTHREAD) +#include + +typedef struct mbedtls_test_thread_t { + pthread_t MBEDTLS_PRIVATE(thread); +} mbedtls_test_thread_t; + +#endif /* MBEDTLS_THREADING_PTHREAD */ + +#if defined(MBEDTLS_THREADING_ALT) +/* You should define the mbedtls_test_thread_t type in your header */ +#include "threading_alt.h" + +/** + * \brief Set your alternate threading implementation + * function pointers fgr test threads. If used, + * this function must be called once in the main thread + * before any other MbedTLS function is called. + * + * \note These functions are part of the testing API only and + * thus not considered part of the public API of + * MbedTLS and thus may change without notice. + * + * \param thread_create The thread create function implementation + * \param thread_join The thread join function implementation + + */ +void mbedtls_test_thread_set_alt(int (*thread_create)(mbedtls_test_thread_t *thread, + void *(*thread_func)( + void *), + void *thread_data), + int (*thread_join)(mbedtls_test_thread_t *thread)); + +#endif /* MBEDTLS_THREADING_ALT*/ + +/** + * \brief The function pointers for thread create and thread + * join. + * + * \note These functions are part of the testing API only and + * thus not considered part of the public API of + * MbedTLS and thus may change without notice. + * + * \note All these functions are expected to work or + * the result will be undefined. + */ +extern int (*mbedtls_test_thread_create)(mbedtls_test_thread_t *thread, + void *(*thread_func)(void *), void *thread_data); +extern int (*mbedtls_test_thread_join)(mbedtls_test_thread_t *thread); + #if defined(MBEDTLS_THREADING_PTHREAD) && defined(MBEDTLS_TEST_HOOKS) #define MBEDTLS_TEST_MUTEX_USAGE #endif @@ -42,4 +102,3 @@ void mbedtls_test_mutex_usage_check(void); #endif /* MBEDTLS_THREADING_C */ #endif /* THREADING_HELPERS_H */ - diff --git a/tests/src/threading_helpers.c b/tests/src/threading_helpers.c index 38059343d..5a871e102 100644 --- a/tests/src/threading_helpers.c +++ b/tests/src/threading_helpers.c @@ -9,6 +9,71 @@ #include #include +#include "mbedtls/threading.h" + +#if defined(MBEDTLS_THREADING_C) + +#if defined(MBEDTLS_THREADING_PTHREAD) + +static int threading_thread_create_pthread(mbedtls_test_thread_t *thread, void *(*thread_func)( + void *), void *thread_data) +{ + if (thread == NULL || thread_func == NULL) { + return MBEDTLS_ERR_THREADING_BAD_INPUT_DATA; + } + + if (pthread_create(&thread->thread, NULL, thread_func, thread_data)) { + return MBEDTLS_ERR_THREADING_THREAD_ERROR; + } + + return 0; +} + +static int threading_thread_join_pthread(mbedtls_test_thread_t *thread) +{ + if (thread == NULL) { + return MBEDTLS_ERR_THREADING_BAD_INPUT_DATA; + } + + if (pthread_join(thread->thread, NULL) != 0) { + return MBEDTLS_ERR_THREADING_THREAD_ERROR; + } + + return 0; +} + +int (*mbedtls_test_thread_create)(mbedtls_test_thread_t *thread, void *(*thread_func)(void *), + void *thread_data) = threading_thread_create_pthread; +int (*mbedtls_test_thread_join)(mbedtls_test_thread_t *thread) = threading_thread_join_pthread; + +#endif /* MBEDTLS_THREADING_PTHREAD */ + +#if defined(MBEDTLS_THREADING_ALT) + +static int threading_thread_create_fail(mbedtls_test_thread_t *thread, + void *(*thread_func)(void *), + void *thread_data) +{ + (void) thread; + (void) thread_func; + (void) thread_data; + + return MBEDTLS_ERR_THREADING_BAD_INPUT_DATA; +} + +static int threading_thread_join_fail(mbedtls_test_thread_t *thread) +{ + (void) thread; + + return MBEDTLS_ERR_THREADING_BAD_INPUT_DATA; +} + +int (*mbedtls_test_thread_create)(mbedtls_test_thread_t *thread, void *(*thread_func)(void *), + void *thread_data) = threading_thread_create_fail; +int (*mbedtls_test_thread_join)(mbedtls_test_thread_t *thread) = threading_thread_join_fail; + +#endif /* MBEDTLS_THREADING_ALT */ + #if defined(MBEDTLS_TEST_MUTEX_USAGE) #include "mbedtls/threading.h" @@ -258,3 +323,5 @@ void mbedtls_test_mutex_usage_end(void) } #endif /* MBEDTLS_TEST_MUTEX_USAGE */ + +#endif /* MBEDTLS_THREADING_C */ From 3dce2327ab55525bdecdf69f73805d016fbd08d5 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Fri, 8 Dec 2023 21:13:42 +0000 Subject: [PATCH 03/13] Use new thread abstraction for ctr_drbg tests Signed-off-by: Paul Elliott --- tests/suites/test_suite_ctr_drbg.function | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/suites/test_suite_ctr_drbg.function b/tests/suites/test_suite_ctr_drbg.function index 1f0a072c7..492a65f7d 100644 --- a/tests/suites/test_suite_ctr_drbg.function +++ b/tests/suites/test_suite_ctr_drbg.function @@ -346,7 +346,7 @@ exit: void ctr_drbg_threads(data_t *expected_result, int reseed, int arg_thread_count) { size_t thread_count = (size_t) arg_thread_count; - pthread_t *threads = NULL; + mbedtls_test_thread_t *threads = NULL; unsigned char out[16]; unsigned char *entropy = NULL; @@ -358,7 +358,7 @@ void ctr_drbg_threads(data_t *expected_result, int reseed, int arg_thread_count) AES_PSA_INIT(); - TEST_CALLOC(threads, sizeof(pthread_t) * thread_count); + TEST_CALLOC(threads, sizeof(mbedtls_test_thread_t) * thread_count); memset(out, 0, sizeof(out)); mbedtls_ctr_drbg_context ctx; @@ -392,13 +392,13 @@ void ctr_drbg_threads(data_t *expected_result, int reseed, int arg_thread_count) for (size_t i = 0; i < thread_count; i++) { TEST_EQUAL( - pthread_create(&threads[i], NULL, - thread_random_function, (void *) &ctx), + mbedtls_test_thread_create(&threads[i], + thread_random_function, (void *) &ctx), 0); } for (size_t i = 0; i < thread_count; i++) { - TEST_EQUAL(pthread_join(threads[i], NULL), 0); + TEST_EQUAL(mbedtls_test_thread_join(&threads[i]), 0); } /* Take a last output for comparing and thus verifying the DRBG state */ From 4068c7e47cf7180550c7a52e3c5f6513392c7720 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Fri, 15 Dec 2023 17:14:34 +0000 Subject: [PATCH 04/13] Link programs with pthread via cmake All programs are now linked directly with all test code, thus adding a pthread abstraction into the test code means having to link the programs with pthread (if the library is found under cmake). Signed-off-by: Paul Elliott --- programs/aes/CMakeLists.txt | 4 +++- programs/cipher/CMakeLists.txt | 4 +++- programs/fuzz/CMakeLists.txt | 3 +++ programs/fuzz/Makefile | 4 ++++ programs/hash/CMakeLists.txt | 4 +++- programs/pkey/CMakeLists.txt | 6 ++++-- programs/psa/CMakeLists.txt | 4 +++- programs/random/CMakeLists.txt | 4 +++- programs/ssl/CMakeLists.txt | 2 +- programs/test/CMakeLists.txt | 8 +++++--- programs/test/cmake_subproject/CMakeLists.txt | 4 +++- programs/util/CMakeLists.txt | 4 +++- programs/x509/CMakeLists.txt | 4 +++- 13 files changed, 41 insertions(+), 14 deletions(-) diff --git a/programs/aes/CMakeLists.txt b/programs/aes/CMakeLists.txt index 85bcd5fca..457a0fc26 100644 --- a/programs/aes/CMakeLists.txt +++ b/programs/aes/CMakeLists.txt @@ -1,10 +1,12 @@ +find_package(Threads) + set(executables crypt_and_hash ) foreach(exe IN LISTS executables) add_executable(${exe} ${exe}.c $) - target_link_libraries(${exe} ${mbedcrypto_target}) + target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) endforeach() diff --git a/programs/cipher/CMakeLists.txt b/programs/cipher/CMakeLists.txt index 93e5f31ee..c047dd69e 100644 --- a/programs/cipher/CMakeLists.txt +++ b/programs/cipher/CMakeLists.txt @@ -1,10 +1,12 @@ +find_package(Threads) + set(executables cipher_aead_demo ) foreach(exe IN LISTS executables) add_executable(${exe} ${exe}.c $) - target_link_libraries(${exe} ${mbedcrypto_target}) + target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) endforeach() diff --git a/programs/fuzz/CMakeLists.txt b/programs/fuzz/CMakeLists.txt index 7747744cd..a0eba0fd0 100644 --- a/programs/fuzz/CMakeLists.txt +++ b/programs/fuzz/CMakeLists.txt @@ -1,5 +1,8 @@ +find_package(Threads) + set(libs ${mbedtls_target} + ${CMAKE_THREAD_LIBS_INIT} ) find_library(FUZZINGENGINE_LIB FuzzingEngine) diff --git a/programs/fuzz/Makefile b/programs/fuzz/Makefile index b4fc76ae1..3b9b50df8 100644 --- a/programs/fuzz/Makefile +++ b/programs/fuzz/Makefile @@ -29,6 +29,10 @@ endif ifdef WINDOWS_BUILD LOCAL_LDFLAGS += -lbcrypt +else +ifeq ($(THREADING),pthread) +LOCAL_LDFLAGS += -lpthread +endif endif # A test application is built for each suites/test_suite_*.data file. diff --git a/programs/hash/CMakeLists.txt b/programs/hash/CMakeLists.txt index da9818844..3d6989cca 100644 --- a/programs/hash/CMakeLists.txt +++ b/programs/hash/CMakeLists.txt @@ -1,3 +1,5 @@ +find_package(Threads) + set(executables generic_sum hello @@ -6,7 +8,7 @@ set(executables foreach(exe IN LISTS executables) add_executable(${exe} ${exe}.c $) - target_link_libraries(${exe} ${mbedcrypto_target}) + target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) endforeach() diff --git a/programs/pkey/CMakeLists.txt b/programs/pkey/CMakeLists.txt index 3ad56436e..e2fb40402 100644 --- a/programs/pkey/CMakeLists.txt +++ b/programs/pkey/CMakeLists.txt @@ -1,3 +1,5 @@ +find_package(Threads) + set(executables_mbedtls dh_client dh_server @@ -5,7 +7,7 @@ set(executables_mbedtls foreach(exe IN LISTS executables_mbedtls) add_executable(${exe} ${exe}.c $) - target_link_libraries(${exe} ${mbedtls_target}) + target_link_libraries(${exe} ${mbedtls_target} ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) endforeach() @@ -32,7 +34,7 @@ set(executables_mbedcrypto foreach(exe IN LISTS executables_mbedcrypto) add_executable(${exe} ${exe}.c $) - target_link_libraries(${exe} ${mbedcrypto_target}) + target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) endforeach() diff --git a/programs/psa/CMakeLists.txt b/programs/psa/CMakeLists.txt index c8ee626d8..d86f29e2c 100644 --- a/programs/psa/CMakeLists.txt +++ b/programs/psa/CMakeLists.txt @@ -1,3 +1,5 @@ +find_package(Threads) + set(executables aead_demo crypto_examples @@ -28,7 +30,7 @@ endif() foreach(exe IN LISTS executables) add_executable(${exe} ${exe}.c $) - target_link_libraries(${exe} ${mbedcrypto_target}) + target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) endforeach() diff --git a/programs/random/CMakeLists.txt b/programs/random/CMakeLists.txt index e5edf7b58..a4c99f561 100644 --- a/programs/random/CMakeLists.txt +++ b/programs/random/CMakeLists.txt @@ -1,3 +1,5 @@ +find_package(Threads) + set(executables gen_entropy gen_random_ctr_drbg @@ -5,7 +7,7 @@ set(executables foreach(exe IN LISTS executables) add_executable(${exe} ${exe}.c $) - target_link_libraries(${exe} ${mbedcrypto_target}) + target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) endforeach() diff --git a/programs/ssl/CMakeLists.txt b/programs/ssl/CMakeLists.txt index 280bbcf3d..8ffa85464 100644 --- a/programs/ssl/CMakeLists.txt +++ b/programs/ssl/CMakeLists.txt @@ -39,7 +39,7 @@ foreach(exe IN LISTS executables) endif() add_executable(${exe} ${exe}.c $ ${extra_sources}) - target_link_libraries(${exe} ${libs}) + target_link_libraries(${exe} ${libs} ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) if(exe STREQUAL "ssl_client2" OR exe STREQUAL "ssl_server2") if(GEN_FILES) diff --git a/programs/test/CMakeLists.txt b/programs/test/CMakeLists.txt index 077873112..a7260452f 100644 --- a/programs/test/CMakeLists.txt +++ b/programs/test/CMakeLists.txt @@ -1,3 +1,5 @@ +find_package(Threads) + set(libs ${mbedtls_target} ) @@ -26,7 +28,7 @@ if(TEST_CPP) ) add_executable(cpp_dummy_build "${cpp_dummy_build_cpp}") target_include_directories(cpp_dummy_build PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../include) - target_link_libraries(cpp_dummy_build ${mbedcrypto_target}) + target_link_libraries(cpp_dummy_build ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT}) endif() if(USE_SHARED_MBEDTLS_LIBRARY AND @@ -81,9 +83,9 @@ foreach(exe IN LISTS executables_libs executables_mbedcrypto) # This emulates "if ( ... IN_LIST ... )" which becomes available in CMake 3.3 list(FIND executables_libs ${exe} exe_index) if (${exe_index} GREATER -1) - target_link_libraries(${exe} ${libs}) + target_link_libraries(${exe} ${libs} ${CMAKE_THREAD_LIBS_INIT}) else() - target_link_libraries(${exe} ${mbedcrypto_target}) + target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT}) endif() endforeach() diff --git a/programs/test/cmake_subproject/CMakeLists.txt b/programs/test/cmake_subproject/CMakeLists.txt index 3c3cba3c2..dd23d6165 100644 --- a/programs/test/cmake_subproject/CMakeLists.txt +++ b/programs/test/cmake_subproject/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required(VERSION 3.5.1) +find_package(Threads) + # Test the target renaming support by adding a prefix to the targets built set(MBEDTLS_TARGET_PREFIX subproject_test_) @@ -20,4 +22,4 @@ set(libs ) add_executable(cmake_subproject cmake_subproject.c) -target_link_libraries(cmake_subproject ${libs}) +target_link_libraries(cmake_subproject ${libs} ${CMAKE_THREAD_LIBS_INIT}) diff --git a/programs/util/CMakeLists.txt b/programs/util/CMakeLists.txt index 7fc58cbcf..920f69e88 100644 --- a/programs/util/CMakeLists.txt +++ b/programs/util/CMakeLists.txt @@ -1,3 +1,5 @@ +find_package(Threads) + set(libs ${mbedcrypto_target} ) @@ -9,7 +11,7 @@ set(executables foreach(exe IN LISTS executables) add_executable(${exe} ${exe}.c $) - target_link_libraries(${exe} ${libs}) + target_link_libraries(${exe} ${libs} ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) endforeach() diff --git a/programs/x509/CMakeLists.txt b/programs/x509/CMakeLists.txt index 5876b8d21..c507de2a7 100644 --- a/programs/x509/CMakeLists.txt +++ b/programs/x509/CMakeLists.txt @@ -1,3 +1,5 @@ +find_package(Threads) + set(libs ${mbedx509_target} ) @@ -13,7 +15,7 @@ set(executables foreach(exe IN LISTS executables) add_executable(${exe} ${exe}.c $) - target_link_libraries(${exe} ${libs}) + target_link_libraries(${exe} ${libs} ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) endforeach() From 7ed1cf57ba67c736cf311663ba995805d4428b2f Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Fri, 5 Jan 2024 18:10:44 +0000 Subject: [PATCH 05/13] Enable common.make to be included by programs/fuzz Signed-off-by: Paul Elliott --- scripts/common.make | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/scripts/common.make b/scripts/common.make index 6c95b4235..2714bcd32 100644 --- a/scripts/common.make +++ b/scripts/common.make @@ -1,25 +1,29 @@ # To compile on SunOS: add "-lsocket -lnsl" to LDFLAGS +ifndef MBEDTLS_PATH +MBEDTLS_PATH := .. +endif + CFLAGS ?= -O2 WARNING_CFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral WARNING_CXXFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral LDFLAGS ?= -LOCAL_CFLAGS = $(WARNING_CFLAGS) -I$(MBEDTLS_TEST_PATH)/include -I../include -D_FILE_OFFSET_BITS=64 -LOCAL_CXXFLAGS = $(WARNING_CXXFLAGS) -I../include -I../tests/include -D_FILE_OFFSET_BITS=64 +LOCAL_CFLAGS = $(WARNING_CFLAGS) -I$(MBEDTLS_TEST_PATH)/include -I$(MBEDTLS_PATH)/include -D_FILE_OFFSET_BITS=64 +LOCAL_CXXFLAGS = $(WARNING_CXXFLAGS) -I$(MBEDTLS_PATH)/include -I$(MBEDTLS_PATH)/tests/include -D_FILE_OFFSET_BITS=64 LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} \ - -L../library \ + -L$(MBEDTLS_PATH)/library \ -lmbedtls$(SHARED_SUFFIX) \ -lmbedx509$(SHARED_SUFFIX) \ -lmbedcrypto$(SHARED_SUFFIX) -include ../3rdparty/Makefile.inc +include $(MBEDTLS_PATH)/3rdparty/Makefile.inc LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES) ifndef SHARED -MBEDLIBS=../library/libmbedcrypto.a ../library/libmbedx509.a ../library/libmbedtls.a +MBEDLIBS=$(MBEDTLS_PATH)/library/libmbedcrypto.a $(MBEDTLS_PATH)/library/libmbedx509.a $(MBEDTLS_PATH)/library/libmbedtls.a else -MBEDLIBS=../library/libmbedcrypto.$(DLEXT) ../library/libmbedx509.$(DLEXT) ../library/libmbedtls.$(DLEXT) +MBEDLIBS=$(MBEDTLS_PATH)/library/libmbedcrypto.$(DLEXT) $(MBEDTLS_PATH)/library/libmbedx509.$(DLEXT) $(MBEDTLS_PATH)/library/libmbedtls.$(DLEXT) endif ifdef DEBUG @@ -97,7 +101,7 @@ endif default: all $(MBEDLIBS): - $(MAKE) -C ../library + $(MAKE) -C $(MBEDTLS_PATH)/library neat: clean ifndef WINDOWS From 053db696b37dfccb4e251ebd22c532438f92b0ef Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Fri, 5 Jan 2024 18:11:32 +0000 Subject: [PATCH 06/13] Allow programs/fuzz to be linked against pthread Use the same mechanisms used to link other programs against pthread with make, i.e. include common.make, and remove common code from programs/ fuzz/Makefile Signed-off-by: Paul Elliott --- programs/fuzz/Makefile | 34 ++++------------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/programs/fuzz/Makefile b/programs/fuzz/Makefile index 3b9b50df8..afe80b7d5 100644 --- a/programs/fuzz/Makefile +++ b/programs/fuzz/Makefile @@ -1,40 +1,17 @@ -MBEDTLS_TEST_PATH:=../../tests/src -MBEDTLS_TEST_OBJS:=$(patsubst %.c,%.o,$(wildcard ${MBEDTLS_TEST_PATH}/*.c ${MBEDTLS_TEST_PATH}/drivers/*.c)) +MBEDTLS_TEST_PATH:=../../tests -CFLAGS ?= -O2 -WARNING_CFLAGS ?= -Wall -Wextra LOCAL_CFLAGS = $(WARNING_CFLAGS) -I../../tests/include -I../../include -D_FILE_OFFSET_BITS=64 -LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} \ - -L../../library \ - -lmbedtls$(SHARED_SUFFIX) \ - -lmbedx509$(SHARED_SUFFIX) \ - -lmbedcrypto$(SHARED_SUFFIX) +MBEDTLS_PATH := ../.. +include ../../scripts/common.make LOCAL_CFLAGS += $(patsubst -I../%,-I../../%,$(THIRDPARTY_INCLUDES)) -ifndef SHARED -DEP=../../library/libmbedcrypto.a ../../library/libmbedx509.a ../../library/libmbedtls.a -else -DEP=../../library/libmbedcrypto.$(DLEXT) ../../library/libmbedx509.$(DLEXT) ../../library/libmbedtls.$(DLEXT) -endif - - -DLEXT ?= so -EXEXT= -SHARED_SUFFIX= +DEP=${MBEDLIBS} ifdef FUZZINGENGINE LOCAL_LDFLAGS += -lFuzzingEngine endif -ifdef WINDOWS_BUILD -LOCAL_LDFLAGS += -lbcrypt -else -ifeq ($(THREADING),pthread) -LOCAL_LDFLAGS += -lpthread -endif -endif - # A test application is built for each suites/test_suite_*.data file. # Application name is same as .data file's base name and can be # constructed by stripping path 'suites/' and extension .data. @@ -49,9 +26,6 @@ BINARIES := $(addsuffix $(EXEXT),$(APPS)) all: $(BINARIES) -$(DEP): - $(MAKE) -C ../../library - C_FILES := $(addsuffix .c,$(APPS)) %.o: %.c From 85ea3e623b0f9f9d84928cc3b191f345dfdf0e66 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Fri, 19 Jan 2024 15:57:22 +0000 Subject: [PATCH 07/13] Set preferences before finding Threads in CMake Signed-off-by: Paul Elliott --- programs/aes/CMakeLists.txt | 2 ++ programs/cipher/CMakeLists.txt | 2 ++ programs/fuzz/CMakeLists.txt | 2 ++ programs/hash/CMakeLists.txt | 2 ++ programs/pkey/CMakeLists.txt | 2 ++ programs/psa/CMakeLists.txt | 2 ++ programs/random/CMakeLists.txt | 2 ++ programs/ssl/CMakeLists.txt | 2 ++ programs/test/CMakeLists.txt | 2 ++ programs/test/cmake_subproject/CMakeLists.txt | 2 ++ programs/util/CMakeLists.txt | 2 ++ programs/x509/CMakeLists.txt | 2 ++ tests/CMakeLists.txt | 2 ++ 13 files changed, 26 insertions(+) diff --git a/programs/aes/CMakeLists.txt b/programs/aes/CMakeLists.txt index 457a0fc26..81741020f 100644 --- a/programs/aes/CMakeLists.txt +++ b/programs/aes/CMakeLists.txt @@ -1,3 +1,5 @@ +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads) set(executables diff --git a/programs/cipher/CMakeLists.txt b/programs/cipher/CMakeLists.txt index c047dd69e..b497e8a48 100644 --- a/programs/cipher/CMakeLists.txt +++ b/programs/cipher/CMakeLists.txt @@ -1,3 +1,5 @@ +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads) set(executables diff --git a/programs/fuzz/CMakeLists.txt b/programs/fuzz/CMakeLists.txt index a0eba0fd0..97b8fd2eb 100644 --- a/programs/fuzz/CMakeLists.txt +++ b/programs/fuzz/CMakeLists.txt @@ -1,3 +1,5 @@ +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads) set(libs diff --git a/programs/hash/CMakeLists.txt b/programs/hash/CMakeLists.txt index 3d6989cca..504a4052f 100644 --- a/programs/hash/CMakeLists.txt +++ b/programs/hash/CMakeLists.txt @@ -1,3 +1,5 @@ +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads) set(executables diff --git a/programs/pkey/CMakeLists.txt b/programs/pkey/CMakeLists.txt index e2fb40402..2f55c6122 100644 --- a/programs/pkey/CMakeLists.txt +++ b/programs/pkey/CMakeLists.txt @@ -1,3 +1,5 @@ +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads) set(executables_mbedtls diff --git a/programs/psa/CMakeLists.txt b/programs/psa/CMakeLists.txt index d86f29e2c..dd1b1a2a8 100644 --- a/programs/psa/CMakeLists.txt +++ b/programs/psa/CMakeLists.txt @@ -1,3 +1,5 @@ +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads) set(executables diff --git a/programs/random/CMakeLists.txt b/programs/random/CMakeLists.txt index a4c99f561..c1184d118 100644 --- a/programs/random/CMakeLists.txt +++ b/programs/random/CMakeLists.txt @@ -1,3 +1,5 @@ +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads) set(executables diff --git a/programs/ssl/CMakeLists.txt b/programs/ssl/CMakeLists.txt index 8ffa85464..8047b9f15 100644 --- a/programs/ssl/CMakeLists.txt +++ b/programs/ssl/CMakeLists.txt @@ -1,4 +1,6 @@ set(THREADS_USE_PTHREADS_WIN32 true) +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads) set(libs diff --git a/programs/test/CMakeLists.txt b/programs/test/CMakeLists.txt index a7260452f..3709276f5 100644 --- a/programs/test/CMakeLists.txt +++ b/programs/test/CMakeLists.txt @@ -1,3 +1,5 @@ +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads) set(libs diff --git a/programs/test/cmake_subproject/CMakeLists.txt b/programs/test/cmake_subproject/CMakeLists.txt index dd23d6165..2f8ab2a3a 100644 --- a/programs/test/cmake_subproject/CMakeLists.txt +++ b/programs/test/cmake_subproject/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required(VERSION 3.5.1) +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads) # Test the target renaming support by adding a prefix to the targets built diff --git a/programs/util/CMakeLists.txt b/programs/util/CMakeLists.txt index 920f69e88..6a8659e9b 100644 --- a/programs/util/CMakeLists.txt +++ b/programs/util/CMakeLists.txt @@ -1,3 +1,5 @@ +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads) set(libs diff --git a/programs/x509/CMakeLists.txt b/programs/x509/CMakeLists.txt index c507de2a7..e41b4069e 100644 --- a/programs/x509/CMakeLists.txt +++ b/programs/x509/CMakeLists.txt @@ -1,3 +1,5 @@ +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads) set(libs diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 68bc57f5a..cb54ea408 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,3 +1,5 @@ +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads) set(libs From a8f6192f9a382d93b8418be29bfccef1ec9bd6f8 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Fri, 19 Jan 2024 16:41:05 +0000 Subject: [PATCH 08/13] Remove unneeded lines from fuzz/Makefile Signed-off-by: Paul Elliott --- programs/fuzz/Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/programs/fuzz/Makefile b/programs/fuzz/Makefile index afe80b7d5..828e5184a 100644 --- a/programs/fuzz/Makefile +++ b/programs/fuzz/Makefile @@ -1,11 +1,8 @@ MBEDTLS_TEST_PATH:=../../tests -LOCAL_CFLAGS = $(WARNING_CFLAGS) -I../../tests/include -I../../include -D_FILE_OFFSET_BITS=64 MBEDTLS_PATH := ../.. include ../../scripts/common.make -LOCAL_CFLAGS += $(patsubst -I../%,-I../../%,$(THIRDPARTY_INCLUDES)) - DEP=${MBEDLIBS} ifdef FUZZINGENGINE From ed3ba3cc8e23c0776ca23293a25d747b7183e10e Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Fri, 19 Jan 2024 16:44:23 +0000 Subject: [PATCH 09/13] Fix documentation typos. Signed-off-by: Paul Elliott --- tests/include/test/threading_helpers.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/include/test/threading_helpers.h b/tests/include/test/threading_helpers.h index 9b7ced519..ba965c877 100644 --- a/tests/include/test/threading_helpers.h +++ b/tests/include/test/threading_helpers.h @@ -40,16 +40,16 @@ typedef struct mbedtls_test_thread_t { /** * \brief Set your alternate threading implementation - * function pointers fgr test threads. If used, - * this function must be called once in the main thread + * function pointers for test threads. If used, this + * function must be called once in the main thread * before any other MbedTLS function is called. * * \note These functions are part of the testing API only and * thus not considered part of the public API of * MbedTLS and thus may change without notice. * - * \param thread_create The thread create function implementation - * \param thread_join The thread join function implementation + * \param thread_create The thread create function implementation. + * \param thread_join The thread join function implementation. */ void mbedtls_test_thread_set_alt(int (*thread_create)(mbedtls_test_thread_t *thread, From 7fd162ec262408e4700f95bfe90638dca5247967 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Wed, 24 Jan 2024 18:05:53 +0000 Subject: [PATCH 10/13] Refactor common PThreads CMake code Move the flags and find of Threads to root CMakeLists.txt, rather than duplicate these everywhere. Make explicit linking of library with PThreads use the same mechanism. Signed-off-by: Paul Elliott --- CMakeLists.txt | 5 +++++ library/CMakeLists.txt | 2 +- programs/aes/CMakeLists.txt | 4 ---- programs/cipher/CMakeLists.txt | 4 ---- programs/fuzz/CMakeLists.txt | 4 ---- programs/hash/CMakeLists.txt | 4 ---- programs/pkey/CMakeLists.txt | 4 ---- programs/psa/CMakeLists.txt | 4 ---- programs/random/CMakeLists.txt | 4 ---- programs/ssl/CMakeLists.txt | 3 --- programs/test/CMakeLists.txt | 4 ---- programs/test/cmake_subproject/CMakeLists.txt | 4 ---- programs/util/CMakeLists.txt | 4 ---- programs/x509/CMakeLists.txt | 4 ---- tests/CMakeLists.txt | 4 ---- 15 files changed, 6 insertions(+), 52 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ad056466a..68dfcb03d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -114,6 +114,11 @@ if(MBEDTLS_PYTHON_EXECUTABLE) endif() +# We now potentially need to link all executables against PThreads, if available +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) +find_package(Threads) + # If this is the root project add longer list of available CMAKE_BUILD_TYPE values if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 5c297e0a1..49803416d 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -231,7 +231,7 @@ if(HAIKU) endif(HAIKU) if(LINK_WITH_PTHREAD) - set(libs ${libs} pthread) + set(libs ${libs} ${CMAKE_THREAD_LIBS_INIT}) endif() if(LINK_WITH_TRUSTED_STORAGE) diff --git a/programs/aes/CMakeLists.txt b/programs/aes/CMakeLists.txt index 81741020f..ccb8db564 100644 --- a/programs/aes/CMakeLists.txt +++ b/programs/aes/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(executables crypt_and_hash ) diff --git a/programs/cipher/CMakeLists.txt b/programs/cipher/CMakeLists.txt index b497e8a48..e925524f6 100644 --- a/programs/cipher/CMakeLists.txt +++ b/programs/cipher/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(executables cipher_aead_demo ) diff --git a/programs/fuzz/CMakeLists.txt b/programs/fuzz/CMakeLists.txt index 97b8fd2eb..c389029bc 100644 --- a/programs/fuzz/CMakeLists.txt +++ b/programs/fuzz/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(libs ${mbedtls_target} ${CMAKE_THREAD_LIBS_INIT} diff --git a/programs/hash/CMakeLists.txt b/programs/hash/CMakeLists.txt index 504a4052f..fcacf3ba4 100644 --- a/programs/hash/CMakeLists.txt +++ b/programs/hash/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(executables generic_sum hello diff --git a/programs/pkey/CMakeLists.txt b/programs/pkey/CMakeLists.txt index 2f55c6122..cd0387a88 100644 --- a/programs/pkey/CMakeLists.txt +++ b/programs/pkey/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(executables_mbedtls dh_client dh_server diff --git a/programs/psa/CMakeLists.txt b/programs/psa/CMakeLists.txt index dd1b1a2a8..a8e4b0e37 100644 --- a/programs/psa/CMakeLists.txt +++ b/programs/psa/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(executables aead_demo crypto_examples diff --git a/programs/random/CMakeLists.txt b/programs/random/CMakeLists.txt index c1184d118..594039535 100644 --- a/programs/random/CMakeLists.txt +++ b/programs/random/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(executables gen_entropy gen_random_ctr_drbg diff --git a/programs/ssl/CMakeLists.txt b/programs/ssl/CMakeLists.txt index 8047b9f15..ec2c86fb4 100644 --- a/programs/ssl/CMakeLists.txt +++ b/programs/ssl/CMakeLists.txt @@ -1,6 +1,3 @@ -set(THREADS_USE_PTHREADS_WIN32 true) -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads) set(libs diff --git a/programs/test/CMakeLists.txt b/programs/test/CMakeLists.txt index 3709276f5..f91f786b9 100644 --- a/programs/test/CMakeLists.txt +++ b/programs/test/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(libs ${mbedtls_target} ) diff --git a/programs/test/cmake_subproject/CMakeLists.txt b/programs/test/cmake_subproject/CMakeLists.txt index 2f8ab2a3a..78bd5e792 100644 --- a/programs/test/cmake_subproject/CMakeLists.txt +++ b/programs/test/cmake_subproject/CMakeLists.txt @@ -1,9 +1,5 @@ cmake_minimum_required(VERSION 3.5.1) -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - # Test the target renaming support by adding a prefix to the targets built set(MBEDTLS_TARGET_PREFIX subproject_test_) diff --git a/programs/util/CMakeLists.txt b/programs/util/CMakeLists.txt index 6a8659e9b..cb6bc3d2d 100644 --- a/programs/util/CMakeLists.txt +++ b/programs/util/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(libs ${mbedcrypto_target} ) diff --git a/programs/x509/CMakeLists.txt b/programs/x509/CMakeLists.txt index e41b4069e..43437f070 100644 --- a/programs/x509/CMakeLists.txt +++ b/programs/x509/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(libs ${mbedx509_target} ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cb54ea408..70f5bc929 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(libs ${mbedtls_target} ${CMAKE_THREAD_LIBS_INIT} From 0c847bcbe79c11a74b5b1d1fec687d75888dfab5 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Wed, 24 Jan 2024 19:08:31 +0000 Subject: [PATCH 11/13] Fix Make issues with Everest enabled Apply Gilles suggestion to fix the problem with make on the CI when everest is enabled, i.e. use $(THIRDPARTY_DIR) instead of a fuzz specific hack involving $(THIRDPARTY_INCLUDES) Signed-off-by: Paul Elliott --- 3rdparty/everest/Makefile.inc | 8 ++++---- 3rdparty/p256-m/Makefile.inc | 6 +++--- programs/Makefile | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/3rdparty/everest/Makefile.inc b/3rdparty/everest/Makefile.inc index 77a6b4965..8055ce950 100644 --- a/3rdparty/everest/Makefile.inc +++ b/3rdparty/everest/Makefile.inc @@ -1,6 +1,6 @@ -THIRDPARTY_INCLUDES+=-I../3rdparty/everest/include -I../3rdparty/everest/include/everest -I../3rdparty/everest/include/everest/kremlib +THIRDPARTY_INCLUDES+=-I$(THIRDPARTY_DIR)/everest/include -I$(THIRDPARTY_DIR)/everest/include/everest -I$(THIRDPARTY_DIR)/everest/include/everest/kremlib THIRDPARTY_CRYPTO_OBJECTS+= \ - ../3rdparty/everest/library/everest.o \ - ../3rdparty/everest/library/x25519.o \ - ../3rdparty/everest/library/Hacl_Curve25519_joined.o + $(THIRDPARTY_DIR)/everest/library/everest.o \ + $(THIRDPARTY_DIR)/everest/library/x25519.o \ + $(THIRDPARTY_DIR)/everest/library/Hacl_Curve25519_joined.o diff --git a/3rdparty/p256-m/Makefile.inc b/3rdparty/p256-m/Makefile.inc index fc8f73bf8..53bb55b54 100644 --- a/3rdparty/p256-m/Makefile.inc +++ b/3rdparty/p256-m/Makefile.inc @@ -1,5 +1,5 @@ -THIRDPARTY_INCLUDES+=-I../3rdparty/p256-m/p256-m/include -I../3rdparty/p256-m/p256-m/include/p256-m -I../3rdparty/p256-m/p256-m_driver_interface +THIRDPARTY_INCLUDES+=-I$(THIRDPARTY_DIR)/p256-m/p256-m/include -I$(THIRDPARTY_DIR)/p256-m/p256-m/include/p256-m -I$(THIRDPARTY_DIR)/p256-m/p256-m_driver_interface THIRDPARTY_CRYPTO_OBJECTS+= \ - ../3rdparty/p256-m//p256-m_driver_entrypoints.o \ - ../3rdparty/p256-m//p256-m/p256-m.o + $(THIRDPARTY_DIR)/p256-m//p256-m_driver_entrypoints.o \ + $(THIRDPARTY_DIR)/p256-m//p256-m/p256-m.o diff --git a/programs/Makefile b/programs/Makefile index 82c856996..6baf4651a 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -114,7 +114,7 @@ all: fuzz endif fuzz: ${MBEDTLS_TEST_OBJS} - $(MAKE) -C fuzz THIRDPARTY_INCLUDES=$(THIRDPARTY_INCLUDES) + $(MAKE) -C fuzz ${MBEDTLS_TEST_OBJS}: $(MAKE) -C ../tests mbedtls_test From 24e9a32c83ac07c08260060e62eba432ae1fb4c1 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Thu, 1 Feb 2024 12:26:23 +0000 Subject: [PATCH 12/13] Refactor to help future other implementations Improve the definition of mbedtls_test_thread_t to assist adding future threading implementations, when they happen. Signed-off-by: Paul Elliott --- tests/include/test/threading_helpers.h | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/tests/include/test/threading_helpers.h b/tests/include/test/threading_helpers.h index ba965c877..0054358ea 100644 --- a/tests/include/test/threading_helpers.h +++ b/tests/include/test/threading_helpers.h @@ -27,11 +27,6 @@ #if defined(MBEDTLS_THREADING_PTHREAD) #include - -typedef struct mbedtls_test_thread_t { - pthread_t MBEDTLS_PRIVATE(thread); -} mbedtls_test_thread_t; - #endif /* MBEDTLS_THREADING_PTHREAD */ #if defined(MBEDTLS_THREADING_ALT) @@ -58,17 +53,30 @@ void mbedtls_test_thread_set_alt(int (*thread_create)(mbedtls_test_thread_t *thr void *thread_data), int (*thread_join)(mbedtls_test_thread_t *thread)); +#else /* MBEDTLS_THREADING_ALT*/ + +typedef struct mbedtls_test_thread_t { + +#if defined(MBEDTLS_THREADING_PTHREAD) + pthread_t MBEDTLS_PRIVATE(thread); +#else /* MBEDTLS_THREADING_PTHREAD */ + /* Make sure this struct is always non-empty */ + unsigned dummy; +#endif + +} mbedtls_test_thread_t; + #endif /* MBEDTLS_THREADING_ALT*/ /** - * \brief The function pointers for thread create and thread + * \brief The function pointers for thread create and thread * join. * - * \note These functions are part of the testing API only and + * \note These functions are part of the testing API only and * thus not considered part of the public API of * MbedTLS and thus may change without notice. * - * \note All these functions are expected to work or + * \note All these functions are expected to work or * the result will be undefined. */ extern int (*mbedtls_test_thread_create)(mbedtls_test_thread_t *thread, From ae942ece478f7909f679699f08109556ac40c44c Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Thu, 1 Feb 2024 12:44:01 +0000 Subject: [PATCH 13/13] Fix style issues Signed-off-by: Paul Elliott --- tests/include/test/threading_helpers.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/include/test/threading_helpers.h b/tests/include/test/threading_helpers.h index 0054358ea..79bc6c0de 100644 --- a/tests/include/test/threading_helpers.h +++ b/tests/include/test/threading_helpers.h @@ -69,14 +69,14 @@ typedef struct mbedtls_test_thread_t { #endif /* MBEDTLS_THREADING_ALT*/ /** - * \brief The function pointers for thread create and thread + * \brief The function pointers for thread create and thread * join. * - * \note These functions are part of the testing API only and - * thus not considered part of the public API of + * \note These functions are part of the testing API only + * and thus not considered part of the public API of * MbedTLS and thus may change without notice. * - * \note All these functions are expected to work or + * \note All these functions are expected to work or * the result will be undefined. */ extern int (*mbedtls_test_thread_create)(mbedtls_test_thread_t *thread,