Run the test_kem and test_sig tests on a thread when possible

This commit is contained in:
Douglas Stebila 2020-03-19 14:57:18 -04:00
parent 734477f19e
commit 4cc03987b1
4 changed files with 58 additions and 6 deletions

View File

@ -37,6 +37,10 @@ if(CMAKE_C_COMPILER_ID MATCHES "Clang")
add_compile_options(-fomit-frame-pointer)
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set(OQS_USE_PTHREADS_IN_TESTS 1)
elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Werror)
add_compile_options(-Wall)
@ -75,6 +79,10 @@ elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
endif ()
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set(OQS_USE_PTHREADS_IN_TESTS 1)
elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
# Warning C4146 is raised when a unary minus operator is applied to an
# unsigned type; this has nonetheless been standard and portable for as

View File

@ -9,6 +9,8 @@
#cmakedefine OQS_USE_SHA2_OPENSSL 1
#cmakedefine OQS_USE_SHA3_OPENSSL 1
#cmakedefine OQS_USE_PTHREADS_IN_TESTS 1
#cmakedefine OQS_USE_AES_INSTRUCTIONS 1
#cmakedefine OQS_USE_AVX_INSTRUCTIONS 1
#cmakedefine OQS_USE_AVX2_INSTRUCTIONS 1

View File

@ -5,6 +5,10 @@
#include <oqs/oqs.h>
#if OQS_USE_PTHREADS_IN_TESTS
#include <pthread.h>
#endif
#include "system_info.c"
/* Displays hexadecimal strings */
@ -43,8 +47,8 @@ static OQS_STATUS kem_test_correctness(const char *method_name) {
kem = OQS_KEM_new(method_name);
if (kem == NULL) {
// should always succeed since we don't call this function on KEMs that aren't enabled
return OQS_ERROR;
fprintf(stderr, "ERROR: OQS_KEM_new failed\n");
goto err;
}
printf("================================================================================\n");
@ -123,6 +127,10 @@ cleanup:
OQS_MEM_insecure_free(ciphertext);
OQS_KEM_free(kem);
#ifdef OQS_USE_PTHREADS_IN_TESTS
pthread_exit((void *) ret);
#endif
return ret;
}
@ -150,7 +158,20 @@ int main(int argc, char **argv) {
if (!OQS_KEM_alg_is_enabled(alg_name)) {
return EXIT_FAILURE;
}
OQS_STATUS rc = kem_test_correctness(alg_name);
OQS_STATUS rc;
#if OQS_USE_PTHREADS_IN_TESTS
pthread_t thread;
void *status;
int trc = pthread_create(&thread, NULL, (void *(*)(void *)) &kem_test_correctness, alg_name);
if (trc) {
fprintf(stderr, "ERROR: Creating pthread\n");
return EXIT_FAILURE;
}
pthread_join(thread, &status);
rc = (OQS_STATUS) status;
#else
rc = kem_test_correctness(alg_name);
#endif
if (rc != OQS_SUCCESS) {
return EXIT_FAILURE;
}

View File

@ -8,6 +8,10 @@
#include <oqs/oqs.h>
#if OQS_USE_PTHREADS_IN_TESTS
#include <pthread.h>
#endif
#include "system_info.c"
static OQS_STATUS sig_test_correctness(const char *method_name) {
@ -23,8 +27,8 @@ static OQS_STATUS sig_test_correctness(const char *method_name) {
sig = OQS_SIG_new(method_name);
if (sig == NULL) {
// should always succeed since we don't call this function on KEMs that aren't enabled
return OQS_ERROR;
fprintf(stderr, "ERROR: OQS_SIG_new failed\n");
goto err;
}
printf("================================================================================\n");
@ -84,6 +88,10 @@ cleanup:
OQS_MEM_insecure_free(signature);
OQS_SIG_free(sig);
#ifdef OQS_USE_PTHREADS_IN_TESTS
pthread_exit((void *) ret);
#endif
return ret;
}
@ -111,7 +119,20 @@ int main(int argc, char **argv) {
if (!OQS_SIG_alg_is_enabled(alg_name)) {
return EXIT_FAILURE;
}
OQS_STATUS rc = sig_test_correctness(alg_name);
OQS_STATUS rc;
#if OQS_USE_PTHREADS_IN_TESTS
pthread_t thread;
void *status;
int trc = pthread_create(&thread, NULL, (void *(*)(void *)) &sig_test_correctness, alg_name);
if (trc) {
fprintf(stderr, "ERROR: Creating pthread\n");
return EXIT_FAILURE;
}
pthread_join(thread, &status);
rc = (OQS_STATUS) status;
#else
rc = sig_test_correctness(alg_name);
#endif
if (rc != OQS_SUCCESS) {
return EXIT_FAILURE;
}