MCPcopy Create free account
hub / github.com/apache/brpc / TEST

Function TEST

test/thread_key_unittest.cpp:53–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51};
52
53TEST(ThreadLocalTest, sanity) {
54 {
55 ThreadKey key;
56 for (int i = 0; i < 5; ++i) {
57 std::unique_ptr<int> data(new int(1));
58 int *raw_data = data.get();
59 ASSERT_EQ(0, butil::thread_key_create(key, NULL));
60
61 ASSERT_EQ(NULL, butil::thread_getspecific(key));
62 ASSERT_EQ(0, butil::thread_setspecific(key, (void *)raw_data));
63 ASSERT_EQ(raw_data, butil::thread_getspecific(key));
64
65 ASSERT_EQ(0, butil::thread_key_delete(key));
66 ASSERT_EQ(NULL, butil::thread_getspecific(key));
67 ASSERT_NE(0, butil::thread_setspecific(key, (void *)raw_data));
68 }
69 }
70
71 for (int i = 0; i < 5; ++i) {
72 ThreadLocal<ThreadKeyData> tl;
73 ASSERT_TRUE(tl.get());
74 ASSERT_EQ(tl->a, 0);
75 auto data = new ThreadKeyData;
76 data->a = 1;
77 tl.reset(data); // tl owns data
78 ASSERT_EQ(data, tl.get());
79 ASSERT_EQ((*tl).a, 1);
80 tl.reset(); // data has been deleted
81 ASSERT_TRUE(tl.get());
82 }
83}
84
85TEST(ThreadLocalTest, thread_key_seq) {
86 std::vector<uint32_t> seqs;

Callers

nothing calls this directly

Calls 15

thread_key_createFunction · 0.85
thread_getspecificFunction · 0.85
thread_setspecificFunction · 0.85
thread_key_deleteFunction · 0.85
fast_rand_less_thanFunction · 0.85
ThreadKeyPerfTestFunction · 0.85
ThreadLocalPerfTestFunction · 0.85
getMethod · 0.45
resetMethod · 0.45
emptyMethod · 0.45
backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected