| 56 | } |
| 57 | |
| 58 | void test_single_thread(bool use_pthread) { |
| 59 | int64_t result = 0; |
| 60 | int64_t expected_result = 0; |
| 61 | stopped = false; |
| 62 | bthread::ExecutionQueueId<LongIntTask> queue_id; |
| 63 | bthread::ExecutionQueueOptions options; |
| 64 | options.use_pthread = use_pthread; |
| 65 | if (options.use_pthread) { |
| 66 | LOG(INFO) << "================ pthread ================"; |
| 67 | } else { |
| 68 | LOG(INFO) << "================ bthread ================"; |
| 69 | } |
| 70 | ASSERT_EQ(0, bthread::execution_queue_start(&queue_id, &options, |
| 71 | add, &result)); |
| 72 | for (int i = 0; i < 100; ++i) { |
| 73 | expected_result += i; |
| 74 | ASSERT_EQ(0, bthread::execution_queue_execute(queue_id, i)); |
| 75 | } |
| 76 | LOG(INFO) << "stop"; |
| 77 | ASSERT_EQ(0, bthread::execution_queue_stop(queue_id)); |
| 78 | ASSERT_NE(0, bthread::execution_queue_execute(queue_id, 0)); |
| 79 | ASSERT_EQ(0, bthread::execution_queue_join(queue_id)); |
| 80 | ASSERT_EQ(expected_result, result); |
| 81 | ASSERT_TRUE(stopped); |
| 82 | } |
| 83 | |
| 84 | TEST_F(ExecutionQueueTest, single_thread) { |
| 85 | for (int i = 0; i < 2; ++i) { |
no test coverage detected