diff --git a/crypto/thread_test.cc b/crypto/thread_test.cc index 29aa640d6ff..dc518b6ce7a 100644 --- a/crypto/thread_test.cc +++ b/crypto/thread_test.cc @@ -152,6 +152,34 @@ TEST(ThreadTest, RandState) { thread.join(); } +static void thread_task(bool *myFlag) { + EXPECT_EQ(1, AWSLC_thread_local_clear()); + EXPECT_EQ(1, AWSLC_thread_local_clear()); + uint8_t buf[8]; + EXPECT_EQ(1, RAND_bytes(buf, sizeof(buf))); + EXPECT_EQ(1, AWSLC_thread_local_clear()); + ERR_clear_error(); + EXPECT_EQ(1, AWSLC_thread_local_clear()); + EXPECT_EQ(1, AWSLC_thread_local_clear()); + *myFlag = true; +} + +TEST(ThreadTest, ClearState) { + const int kNumThreads = 10; + bool myFlags[kNumThreads]; + std::thread myThreads[kNumThreads]; + + for (int i = 0; i < kNumThreads; i++) { + bool* myFlag = &myFlags[i]; + *myFlag = false; + myThreads[i] = std::thread(thread_task, myFlag); + } + for (int i = 0; i < kNumThreads; i++) { + myThreads[i].join(); + ASSERT_TRUE(myFlags[i]) << "Thread " << i << " failed."; + } +} + TEST(ThreadTest, InitThreads) { constexpr size_t kNumThreads = 10;