MCPcopy Create free account
hub / github.com/JRickey/BattleShip / test_nested

Function test_nested

port/coroutine_test.cpp:88–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86}
87
88void test_nested() {
89 g_nest_log = 0;
90 g_inner_co = port_coroutine_create(inner_entry, nullptr, 64 * 1024);
91 PortCoroutine *outer = port_coroutine_create(outer_entry, nullptr, 64 * 1024);
92 EXPECT(g_inner_co && outer);
93
94 port_coroutine_resume(outer);
95 /* By now: outer ran (1), resumed inner (2), inner yielded back to
96 * outer, outer continued (4), outer yielded back to main. So 0x07. */
97 EXPECT(g_nest_log == 0x07);
98
99 port_coroutine_resume(g_inner_co);
100 EXPECT((g_nest_log & 0x08) != 0);
101
102 port_coroutine_resume(outer);
103 EXPECT((g_nest_log & 0x10) != 0);
104
105 EXPECT(port_coroutine_is_finished(g_inner_co));
106 EXPECT(port_coroutine_is_finished(outer));
107
108 port_coroutine_destroy(g_inner_co);
109 port_coroutine_destroy(outer);
110}
111
112/* Stack hygiene: the worker writes a recognisable pattern to a chunk of
113 * its own stack, yields, runs again. The data must survive across the

Callers 1

mainFunction · 0.85

Calls 4

port_coroutine_createFunction · 0.70
port_coroutine_resumeFunction · 0.70
port_coroutine_destroyFunction · 0.70

Tested by

no test coverage detected