libcopp
1.1.0
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
test
case
coroutine_context_split_segment.cpp
Go to the documentation of this file.
1
#include <cstdio>
2
#include <cstring>
3
#include <iostream>
4
5
#include <
libcopp/coroutine/coroutine_context_container.h
>
6
#include <
libcopp/stack/allocator/stack_allocator_split_segment.h
>
7
8
#include "
frame/test_macros.h
"
9
#ifdef LIBCOPP_MACRO_USE_SEGMENTED_STACKS
10
11
typedef
copp::coroutine_context_container<copp::allocator::stack_allocator_split_segment>
test_split_segment_context;
12
13
class
test_split_segment_foo_runner {
14
private
:
15
void
stack_test(
int
loop) {
16
char
a = 100;
17
char
b[1024 * 1024] = {0};
18
char
c = 200;
19
CASE_EXPECT_TRUE
((&a > &c) == (&a > b));
20
end_addr_ = (intptr_t)(&c);
21
if
(loop > 0) stack_test(loop - 1);
22
}
23
24
public
:
25
int
operator()(
void
*) {
26
int
a = 0;
27
begin_addr_ = (intptr_t)(&a);
28
end_addr_ = begin_addr_;
29
30
stack_test(4);
31
32
copp::this_coroutine::get<test_split_segment_context>()->
yield
();
33
34
stack_test(20);
35
return
0;
36
}
37
38
intptr_t begin_addr_;
39
intptr_t end_addr_;
40
};
41
42
CASE_TEST
(coroutine, context_split_segment_stack) {
43
test_split_segment_foo_runner runner;
44
{
45
test_split_segment_context::ptr_t co = test_split_segment_context::create(&runner, 2 * 1024 * 1024);
46
47
co->start();
48
co->resume();
49
50
intptr_t dis =
51
(runner.end_addr_ > runner.begin_addr_) ? (runner.end_addr_ - runner.begin_addr_) : (runner.begin_addr_ - runner.end_addr_);
52
53
CASE_EXPECT_GE
(dis, 4 * 1024 * 1024);
54
}
55
}
56
57
#endif
coroutine_context_container.h
CASE_TEST
#define CASE_TEST(test_name, case_name)
Definition:
test_macros.h:43
test_macros.h
CASE_EXPECT_TRUE
#define CASE_EXPECT_TRUE(c)
Definition:
test_macros.h:60
copp::this_coroutine::yield
int yield(void **priv_data=UTIL_CONFIG_NULLPTR)
yield current coroutine
Definition:
coroutine_context.cpp:403
CASE_EXPECT_GE
#define CASE_EXPECT_GE(l, r)
Definition:
test_macros.h:67
copp::coroutine_context_container
coroutine container contain stack context, stack allocator and runtime fcontext
Definition:
coroutine_context_container.h:23
stack_allocator_split_segment.h
Generated by
1.8.11