Skip to content

Commit

Permalink
Fix unit test support for multi-thread, fix compile problem with mbedTLS
Browse files Browse the repository at this point in the history
  • Loading branch information
owent committed Nov 13, 2020
1 parent 9446b9c commit dd10eb2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/algorithm/crypto_dh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1832,10 +1832,16 @@ namespace util {
}

LIBATFRAME_UTILS_API int dh::read_public(const unsigned char *input, size_t ilen) {
if (!shared_context_ || NULL == shared_context_->get_dh_parameter().keygen_ctx) {
if (!shared_context_) {
return details::setup_errorno(*this, 0, error_code_t::NOT_INITED);
}

#if defined(CRYPTO_USE_OPENSSL) || defined(CRYPTO_USE_LIBRESSL) || defined(CRYPTO_USE_BORINGSSL)
if (NULL == shared_context_->get_dh_parameter().keygen_ctx) {
return details::setup_errorno(*this, 0, error_code_t::NOT_INITED);
}
#endif

if (NULL == input || ilen == 0) {
return details::setup_errorno(*this, 0, error_code_t::INVALID_PARAM);
}
Expand Down
10 changes: 7 additions & 3 deletions test/frame/test_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ namespace detail {
#endif
#endif

static test_manager_tls_block_t g_global_counter_cache = {0, 0};
test_manager_tls_block_t *get_test_manager_tls_block() {
static THREAD_TLS unsigned char ret[sizeof(test_manager_tls_block_t)] = {0};
return reinterpret_cast<test_manager_tls_block_t *>(ret);
static THREAD_TLS test_manager_tls_block_t ret = g_global_counter_cache;
return ret;
}
#else

Expand All @@ -76,11 +77,12 @@ namespace detail {
(void)pthread_key_create(&gt_test_manager_tls_block_key, dtor_pthread_test_manager_tls_block);
}

static test_manager_tls_block_t g_global_counter_cache;
test_manager_tls_block_t *get_test_manager_tls_block() {
(void)pthread_once(&gt_test_manager_tls_block_once, init_pthread_test_manager_tls_block);
test_manager_tls_block_t *block = reinterpret_cast<test_manager_tls_block_t *>(pthread_getspecific(gt_test_manager_tls_block_key));
if (NULL == block) {
block = new test_manager_tls_block_t();
block = new test_manager_tls_block_t(g_global_counter_cache);
pthread_setspecific(gt_test_manager_tls_block_key, block);
}
return block;
Expand Down Expand Up @@ -433,6 +435,8 @@ void test_manager::set_counter_ptr(int *success_counter_ptr, int *failed_counter
block->success_counter_ptr = success_counter_ptr;
block->failed_counter_ptr = failed_counter_ptr;
}
detail::g_global_counter_cache.success_counter_ptr = success_counter_ptr;
detail::g_global_counter_cache.failed_counter_ptr = failed_counter_ptr;
}

void test_manager::inc_success_counter() {
Expand Down

0 comments on commit dd10eb2

Please sign in to comment.