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

Function TEST

test/bthread_ping_pong_unittest.cpp:114–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

112}
113
114TEST(PingPongTest, ping_pong) {
115 signal(SIGINT, quit_handler);
116 stop = false;
117 PlayerArg* args[FLAGS_thread_num];
118
119 for (int i = 0; i < FLAGS_thread_num; ++i) {
120 int pipe1[2];
121 int pipe2[2];
122 if (!FLAGS_use_futex && !FLAGS_use_butex) {
123 ASSERT_EQ(0, pipe(pipe1));
124 ASSERT_EQ(0, pipe(pipe2));
125 }
126
127 PlayerArg* arg1 = new PlayerArg;
128 if (!FLAGS_use_futex && !FLAGS_use_butex) {
129 arg1->read_fd = pipe1[0];
130 arg1->write_fd = pipe2[1];
131 } else if (FLAGS_use_futex) {
132 AlignedIntWrapper* w1 = new AlignedIntWrapper;
133 w1->value = INITIAL_FUTEX_VALUE;
134 AlignedIntWrapper* w2 = new AlignedIntWrapper;
135 w2->value = INITIAL_FUTEX_VALUE;
136 arg1->wait_addr = &w1->value;
137 arg1->wake_addr = &w2->value;
138 } else if (FLAGS_use_butex) {
139 arg1->wait_addr = bthread::butex_create_checked<int>();
140 *arg1->wait_addr = INITIAL_FUTEX_VALUE;
141 arg1->wake_addr = bthread::butex_create_checked<int>();
142 *arg1->wake_addr = INITIAL_FUTEX_VALUE;
143 } else {
144 ASSERT_TRUE(false);
145 }
146 arg1->counter = 0;
147 arg1->wakeup = 0;
148 args[i] = arg1;
149
150 PlayerArg* arg2 = new PlayerArg;
151 if (!FLAGS_use_futex && !FLAGS_use_butex) {
152 arg2->read_fd = pipe2[0];
153 arg2->write_fd = pipe1[1];
154 } else {
155 arg2->wait_addr = arg1->wake_addr;
156 arg2->wake_addr = arg1->wait_addr;
157 }
158 arg2->counter = 0;
159 arg2->wakeup = 0;
160
161 pthread_t th1, th2;
162 bthread_t bth1, bth2;
163 if (!FLAGS_use_futex && !FLAGS_use_butex) {
164 ASSERT_EQ(0, pthread_create(&th1, NULL, pipe_player, arg1));
165 ASSERT_EQ(0, pthread_create(&th2, NULL, pipe_player, arg2));
166 } else if (FLAGS_use_futex) {
167 ASSERT_EQ(0, pthread_create(&th1, NULL, futex_player, arg1));
168 ASSERT_EQ(0, pthread_create(&th2, NULL, futex_player, arg2));
169 } else if (FLAGS_use_butex) {
170 ASSERT_EQ(0, bthread_start_background(&bth1, NULL, butex_player, arg1));
171 ASSERT_EQ(0, bthread_start_background(&bth2, NULL, butex_player, arg2));

Callers

nothing calls this directly

Calls 7

signalFunction · 0.85
bthread_start_backgroundFunction · 0.85
butex_wakeFunction · 0.85
m_elapsedMethod · 0.80
futex_wake_privateFunction · 0.50
startMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected