11 typedef copp::coroutine_context_container<copp::allocator::stack_allocator_memory>
23 copp::this_coroutine::get<test_context_base_coroutine_context_test_type>()->yield();
31 unsigned char *stack_buff =
new unsigned char[128 * 1024];
38 copp::stack_context test_move_alloc;
40 copp::allocator::stack_allocator_memory alloc_created(stack_buff, 128 * 1024);
41 copp::allocator::stack_allocator_memory alloc(alloc_created);
43 alloc_created.allocate(test_move_alloc, 64 * 1024);
46 test_context_base_coroutine_context_test_type::ptr_t co =
47 test_context_base_coroutine_context_test_type::create(&runner, alloc);
69 copp::stack_context test_move_alloc;
71 copp::allocator::stack_allocator_memory alloc_created;
72 alloc_created.attach(stack_buff, 128 * 1024);
73 copp::allocator::stack_allocator_memory alloc;
74 alloc = alloc_created;
76 alloc_created.allocate(test_move_alloc, 64 * 1024);
79 test_context_base_coroutine_context_test_type::ptr_t co =
80 test_context_base_coroutine_context_test_type::create(&runner, alloc);
104 const int stack_len = 128 * 1024;
105 unsigned char *stack_buff =
new unsigned char[4 * stack_len];
114 test_context_base_coroutine_context_test_type::ptr_t co[4];
115 for (
int i = 0; i < 4; ++i) {
116 copp::allocator::stack_allocator_memory alloc(stack_buff + i * stack_len, stack_len);
117 co[i] = test_context_base_coroutine_context_test_type::create(&runner, alloc);
123 for (
int i = 0; i < 4; ++i) {
135 CASE_TEST(coroutine, coroutine_context_container_create_failed) {
136 unsigned char *stack_buff =
new unsigned char[128 * 1024];
140 copp::stack_context test_move_alloc;
142 copp::allocator::stack_allocator_memory alloc_created(stack_buff, 128 * 1024);
143 copp::allocator::stack_allocator_memory alloc(alloc_created);
145 alloc_created.allocate(test_move_alloc, 64 * 1024);
148 test_context_base_coroutine_context_test_type::ptr_t co =
149 test_context_base_coroutine_context_test_type::create(&runner, alloc, 32 * 1024, 16 * 1024, 16 * 1024);
157 unsigned char *stack_buff =
new unsigned char[128 * 1024];
159 copp::coroutine_context *placement_new_addr =
reinterpret_cast<copp::coroutine_context *
>(stack_buff + 112 * 1024);
162 copp::stack_context callee_stack;
163 callee_stack.sp =
reinterpret_cast<void *
>(stack_buff + 120 * 1024);
164 callee_stack.size = 120 * 1024;
167 copp::coroutine_context::create(
nullptr, std::move(runner), callee_stack, 4096, 4096));
171 copp::stack_context callee_stack;
172 callee_stack.sp =
reinterpret_cast<void *
>(stack_buff + 120 * 1024);
173 callee_stack.size = 120 * 1024;
176 copp::coroutine_context::create(placement_new_addr, std::move(runner), callee_stack, 4096, 4095));
180 copp::stack_context callee_stack;
181 callee_stack.sp =
reinterpret_cast<void *
>(stack_buff + 120 * 1024);
182 callee_stack.size = 120 * 1024;
185 copp::coroutine_context::create(placement_new_addr, std::move(runner), callee_stack, 4095, 4096));
189 copp::stack_context callee_stack;
190 callee_stack.sp =
nullptr;
191 callee_stack.size = 120 * 1024;
194 copp::coroutine_context::create(placement_new_addr, std::move(runner), callee_stack, 4096, 4096));
198 copp::stack_context callee_stack;
199 callee_stack.sp =
reinterpret_cast<void *
>(stack_buff + 120 * 1024);
200 callee_stack.size = 8192;
203 copp::coroutine_context::create(placement_new_addr, std::move(runner), callee_stack, 4096, 4096));
207 copp::stack_context callee_stack;
208 callee_stack.sp =
reinterpret_cast<void *
>(stack_buff + 120 * 1024);
209 callee_stack.size = 120 * 1024;
211 copp::coroutine_context *placement_invalid_addr =
212 reinterpret_cast<copp::coroutine_context *
>(stack_buff + 116 * 1024);
214 callee_stack, 4096, 4096));
220 #if defined(LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR) && LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR
221 static int test_context_base_foo_runner_throw_exception(
void *) {
return static_cast<int>(std::string().at(1)); }
223 CASE_TEST(coroutine, coroutine_context_throw_exception) {
224 unsigned char *stack_buff =
new unsigned char[128 * 1024];
227 copp::stack_context test_move_alloc;
229 copp::allocator::stack_allocator_memory alloc_created(stack_buff, 128 * 1024);
230 copp::allocator::stack_allocator_memory alloc(alloc_created);
232 alloc_created.allocate(test_move_alloc, 64 * 1024);
235 test_context_base_coroutine_context_test_type::ptr_t co =
236 test_context_base_coroutine_context_test_type::create(test_context_base_foo_runner_throw_exception, alloc);
243 }
catch (
const std::exception &e) {
244 CASE_MSG_INFO() <<
"Caught exception \"" << e.what() <<
"\"" << std::endl;
test_context_base_foo_runner()
CASE_TEST(coroutine, context_base)
static int g_test_coroutine_base_status
copp::coroutine_context_container< copp::allocator::stack_allocator_memory > test_context_base_coroutine_context_test_type
@ COPP_EC_NOT_READY
COPP_EC_NOT_READY.
@ COPP_EC_ALREADY_EXIST
COPP_EC_ALREADY_EXIST.
@ COPP_EC_ARGS_ERROR
COPP_EC_ARGS_ERROR.
@ COPP_EC_NOT_RUNNING
COPP_EC_NOT_RUNNING.
#define CASE_EXPECT_EQ(l, r)
#define CASE_EXPECT_TRUE(c)