forked from Mbed-TLS/TF-PSA-Crypto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Mbed-TLS#88 from tom-daubney-arm/add_component_tes…
…t_cmake_support Add component_test_cmake_* support
- Loading branch information
Showing
6 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
add_subdirectory(psa) | ||
add_subdirectory(test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
if(USE_SHARED_TF_PSA_CRYPTO_LIBRARY AND | ||
NOT ${CMAKE_SYSTEM_NAME} MATCHES "[Ww][Ii][Nn]") | ||
add_executable(dlopen "dlopen.c") | ||
target_include_directories(dlopen PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../include) | ||
target_include_directories(dlopen PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../drivers/builtin/include) | ||
target_link_libraries(dlopen ${CMAKE_DL_LIBS}) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Test dynamic loading of libtfpsacrypto | ||
* | ||
* Copyright The Mbed TLS Contributors | ||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later | ||
*/ | ||
|
||
#include "psa/build_info.h" | ||
#include "psa/crypto.h" | ||
#include "tf_psa_crypto/platform.h" | ||
|
||
#if defined(__APPLE__) | ||
#define SO_SUFFIX ".dylib" | ||
#else | ||
#define SO_SUFFIX ".so" | ||
#endif | ||
|
||
#define CRYPTO_SO_FILENAME "libtfpsacrypto" SO_SUFFIX | ||
#define CRYPTO_SO_PATH "core/" CRYPTO_SO_FILENAME | ||
#include <stdlib.h> | ||
#include <dlfcn.h> | ||
|
||
#define CHECK_DLERROR(function, argument) \ | ||
do \ | ||
{ \ | ||
char *CHECK_DLERROR_error = dlerror(); \ | ||
if (CHECK_DLERROR_error != NULL) \ | ||
{ \ | ||
fprintf(stderr, "Dynamic loading error for %s(%s): %s\n", \ | ||
function, argument, CHECK_DLERROR_error); \ | ||
tf_psa_crypto_exit(TF_PSA_CRYPTO_EXIT_FAILURE); \ | ||
} \ | ||
} \ | ||
while (0) | ||
|
||
int main(void) | ||
{ | ||
void *crypto_so = dlopen(CRYPTO_SO_PATH, RTLD_NOW); | ||
CHECK_DLERROR("dlopen", CRYPTO_SO_PATH); | ||
|
||
psa_status_t (*psa_crypto_init_ptr)(void) = dlsym(crypto_so, "psa_crypto_init"); | ||
CHECK_DLERROR("dlsym", "psa_crypto_init"); | ||
|
||
psa_status_t status = psa_crypto_init_ptr(); | ||
if (status == PSA_SUCCESS) | ||
{ | ||
tf_psa_crypto_printf("dlopen(%s): Call to psa_crypto_init was successful.\n", | ||
CRYPTO_SO_FILENAME); | ||
} | ||
else | ||
{ | ||
tf_psa_crypto_printf("dlopen(%s): Call to psa_crypto_init failed.\n", | ||
CRYPTO_SO_FILENAME); | ||
} | ||
|
||
dlclose(crypto_so); | ||
CHECK_DLERROR("dlclose", CRYPTO_SO_PATH); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters