Skip to content

Commit

Permalink
Add test coverage for AWSLC_thread_local_clear
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Jan 19, 2024
1 parent 709d214 commit 8048b5a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions crypto/thread_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 8048b5a

Please sign in to comment.