Commit c4e34572 authored by gejun's avatar gejun

fix UT on ESTOP temporarily (the impl. will be replaced in next commits)

parent a5532e30
......@@ -284,10 +284,16 @@ TEST(BthreadIdTest, join_after_destroy_before_unlock) {
ASSERT_EQ(1UL, non_null_ret);
}
void* stopped_waiter(void* arg) {
bthread_id_t id = { (uintptr_t)arg };
EXPECT_EQ(ESTOP, bthread_id_join(id));
EXPECT_EQ(get_version(id) + 4, bthread::id_value(id));
struct StoppedWaiterArgs {
bthread_id_t id;
bool thread_started;
};
void* stopped_waiter(void* void_arg) {
StoppedWaiterArgs* args = (StoppedWaiterArgs*)void_arg;
args->thread_started = true;
EXPECT_EQ(ESTOP, bthread_id_join(args->id));
EXPECT_EQ(get_version(args->id) + 4, bthread::id_value(args->id));
return NULL;
}
......@@ -300,18 +306,26 @@ TEST(BthreadIdTest, stop_a_wait_after_fight_before_signal) {
ASSERT_EQ(0, bthread_id_trylock(id1, &data));
ASSERT_EQ(&x, data);
bthread_t th[8];
StoppedWaiterArgs args[ARRAY_SIZE(th)];
for (size_t i = 0; i < ARRAY_SIZE(th); ++i) {
ASSERT_EQ(0, bthread_start_urgent(&th[i], NULL, stopped_waiter,
(void*)(intptr_t)id1.value));
args[i].id = id1;
args[i].thread_started = false;
ASSERT_EQ(0, bthread_start_urgent(&th[i], NULL, stopped_waiter, &args[i]));
}
for (size_t i = 0; i < ARRAY_SIZE(th); ++i) {
bthread_stop(th[i]);
if (!args[i].thread_started) {
bthread_usleep(1000);
}
}
// stop does not wake up bthread_id_join
for (size_t i = 0; i < ARRAY_SIZE(th); ++i) {
bthread_stop(th[i]);
}
bthread_usleep(10000);
for (size_t i = 0; i < ARRAY_SIZE(th); ++i) {
ASSERT_TRUE(bthread::TaskGroup::exists(th[i]));
}
// destroy the id to end the joinings.
ASSERT_EQ(0, bthread_id_unlock_and_destroy(id1));
for (size_t i = 0; i < ARRAY_SIZE(th); ++i) {
ASSERT_EQ(0, bthread_join(th[i], NULL));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment