diff options
author | David Benjamin <davidben@google.com> | 2016-03-31 02:03:45 +0300 |
---|---|---|
committer | David Benjamin <davidben@google.com> | 2016-04-20 00:33:59 +0300 |
commit | 3ed24f0502ea3f38fa79306dfe263527f0491230 (patch) | |
tree | d5f6efa4fc2a72ff1026ac5eeb824655a9892b5d /crypto/thread_test.c | |
parent | 582d2847eda65671883649347f60f6916838a3d1 (diff) |
Test CRYPTO_once_t collisions.
The existing tests never actually tested this case.
Change-Id: Idb9cf0cbbe32fdf5cd353656a95fbedbaac09376
Reviewed-on: https://boringssl-review.googlesource.com/7612
Reviewed-by: Emily Stark (Dunn) <estark@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Diffstat (limited to 'crypto/thread_test.c')
-rw-r--r-- | crypto/thread_test.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/crypto/thread_test.c b/crypto/thread_test.c index e028b1be..aadd65e2 100644 --- a/crypto/thread_test.c +++ b/crypto/thread_test.c @@ -53,6 +53,7 @@ static int wait_for_thread(thread_t thread) { #else #include <pthread.h> +#include <unistd.h> typedef pthread_t thread_t; @@ -77,6 +78,14 @@ static unsigned g_once_init_called = 0; static void once_init(void) { g_once_init_called++; + + /* Sleep briefly so one |call_once_thread| instance will call |CRYPTO_once| + * while the other is running this function. */ +#if defined(OPENSSL_WINDOWS) + Sleep(1 /* milliseconds */); +#else + usleep(1000 /* microseconds */); +#endif } static CRYPTO_once_t g_test_once = CRYPTO_ONCE_INIT; @@ -91,9 +100,11 @@ static int test_once(void) { return 0; } - thread_t thread; - if (!run_thread(&thread, call_once_thread) || - !wait_for_thread(thread)) { + thread_t thread1, thread2; + if (!run_thread(&thread1, call_once_thread) || + !run_thread(&thread2, call_once_thread) || + !wait_for_thread(thread1) || + !wait_for_thread(thread2)) { fprintf(stderr, "thread failed.\n"); return 0; } |