libcopp  1.2.0
coroutine_context_split_segment.cpp
Go to the documentation of this file.
1 #include <cstdio>
2 #include <cstring>
3 #include <iostream>
4 
7 
8 #include "frame/test_macros.h"
9 #ifdef LIBCOPP_MACRO_USE_SEGMENTED_STACKS
10 
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
#define CASE_TEST(test_name, case_name)
Definition: test_macros.h:43
#define CASE_EXPECT_TRUE(c)
Definition: test_macros.h:60
int yield(void **priv_data=UTIL_CONFIG_NULLPTR)
yield current coroutine
#define CASE_EXPECT_GE(l, r)
Definition: test_macros.h:67
coroutine container contain stack context, stack allocator and runtime fcontext