MCPcopy Create free account
hub / github.com/alibaba/PhotonLibOS / TEST

Function TEST

thread/test/test-specific-key.cpp:39–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37static Value g_value;
38
39TEST(key, basic) {
40 photon::thread_key_t key0, key1, key2, key3, key4;
41 ASSERT_EQ(0, photon::thread_key_create(&key0, nullptr));
42 ASSERT_EQ(0, photon::thread_key_create(&key1, nullptr));
43 ASSERT_EQ(0, photon::thread_key_create(&key2, nullptr));
44 ASSERT_EQ(0UL, key0);
45 ASSERT_EQ(1UL, key1);
46 ASSERT_EQ(2UL, key2);
47 ASSERT_EQ(0, photon::thread_key_delete(key0));
48 ASSERT_EQ(0, photon::thread_key_create(&key3, nullptr));
49 ASSERT_EQ(0UL, key3);
50 ASSERT_EQ(0, photon::thread_key_delete(key2));
51 ASSERT_EQ(0, photon::thread_key_create(&key4, nullptr));
52 ASSERT_EQ(2UL, key4);
53 ASSERT_EQ(0, photon::thread_key_delete(key1));
54 ASSERT_EQ(0, photon::thread_key_delete(key3));
55 ASSERT_EQ(0, photon::thread_key_delete(key4));
56 ASSERT_EQ(EINVAL, photon::thread_key_delete(key4));
57 ASSERT_EQ(EINVAL, photon::thread_key_delete(10000));
58
59 ASSERT_EQ(nullptr, photon::thread_getspecific(0));
60 ASSERT_EQ(nullptr, photon::thread_getspecific(1));
61 ASSERT_EQ(nullptr, photon::thread_getspecific(2));
62 ASSERT_EQ(nullptr, photon::thread_getspecific(10000));
63 ASSERT_EQ(EINVAL, photon::thread_setspecific(1, &g_value));
64 ASSERT_EQ(EINVAL, photon::thread_setspecific(2, &g_value));
65 ASSERT_EQ(EINVAL, photon::thread_setspecific(10000, &g_value));
66
67 photon::thread_key_t key;
68 ASSERT_EQ(0, photon::thread_key_create(&key, nullptr));
69 ASSERT_EQ(0UL, key);
70 ASSERT_EQ(0, photon::thread_setspecific(key, &g_value));
71 ASSERT_EQ(&g_value, photon::thread_getspecific(key));
72 ASSERT_EQ(0, photon::thread_key_delete(key));
73 ASSERT_EQ(nullptr, photon::thread_getspecific(key));
74 ASSERT_EQ(EINVAL, photon::thread_setspecific(key, &g_value));
75}
76
77TEST(key, dtor) {
78 g_value.v = 0;

Callers

nothing calls this directly

Calls 7

thread_key_createFunction · 0.85
thread_key_deleteFunction · 0.85
thread_getspecificFunction · 0.85
thread_setspecificFunction · 0.85
thread_enable_joinFunction · 0.85
thread_joinFunction · 0.85
thread_create11Function · 0.50

Tested by

no test coverage detected