Skip to content

Commit 77a8dd2

Browse files
committed
New feature of introduce_coop/introduce_child_coop is used in tests.
--HG-- branch : intro-coop-ret-val
1 parent 75d0ee1 commit 77a8dd2

File tree

23 files changed

+130
-152
lines changed

23 files changed

+130
-152
lines changed

.hgignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dev/__*.vim
99
dev/local-build.rb
1010
dev/doc
1111
doxygen/doxygen.log
12+
dev/*.log
1213
o/*
1314
cmake_build/*
1415
*.sublime-project

dev/test/so_5/bench/agent_ring/main.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,7 @@ create_coop(
398398
measure_result_t & result,
399399
so_5::environment_t & env )
400400
{
401-
so_5::mbox_t first_agent_mbox;
402-
403-
env.introduce_coop(
401+
so_5::mbox_t first_agent_mbox = env.introduce_coop(
404402
create_disp_binder( env, cfg ),
405403
[&]( so_5::coop_t & coop )
406404
{
@@ -428,7 +426,7 @@ create_coop(
428426
mboxes[ (i + 1) % cfg.m_ring_size ] );
429427
}
430428

431-
first_agent_mbox = mboxes[ 0 ];
429+
return mboxes[ 0 ];
432430
} );
433431

434432
so_5::send< a_ring_member_t::msg_start >( first_agent_mbox );

dev/test/so_5/disp/prio_dt_one_per_prio/contexts/main.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,8 @@ class a_child_t final : public so_5::agent_t
8585
void
8686
init( so_5::environment_t & env )
8787
{
88-
so_5::mbox_t supervisor_mbox;
89-
env.introduce_coop( [&]( so_5::coop_t & coop ) {
90-
auto a = coop.make_agent< a_supervisor_t >();
91-
supervisor_mbox = a->so_direct_mbox();
88+
so_5::mbox_t supervisor_mbox = env.introduce_coop( [&]( so_5::coop_t & coop ) {
89+
return coop.make_agent< a_supervisor_t >()->so_direct_mbox();
9290
} );
9391

9492
using namespace so_5::disp::prio_dedicated_threads::one_per_prio;

dev/test/so_5/env_infrastructure/simple_mtsafe_st/delayed_msg/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ main()
3737
}
3838
};
3939

40-
env.introduce_coop( [&]( so_5::coop_t & coop ) {
40+
env.introduce_coop( []( so_5::coop_t & coop ) {
4141
coop.make_agent< actor_t >();
4242
} );
4343
},

dev/test/so_5/env_infrastructure/simple_mtsafe_st/delayed_msg_from_outside/main.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ main()
3535

3636
so_5::launch(
3737
[&]( so_5::environment_t & env ) {
38-
so_5::mbox_t test_mbox;
39-
env.introduce_coop( [&]( so_5::coop_t & coop ) {
40-
test_mbox = coop.make_agent< a_test_t >()->so_direct_mbox();
41-
} );
38+
so_5::mbox_t test_mbox = env.introduce_coop(
39+
[&]( so_5::coop_t & coop ) {
40+
return coop.make_agent< a_test_t >()->so_direct_mbox();
41+
} );
4242

4343
outside_thread = thread( [test_mbox] {
4444
this_thread::sleep_for( chrono::milliseconds( 350 ) );

dev/test/so_5/env_infrastructure/simple_mtsafe_st/periodic_msg_from_outside/main.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ main()
3939

4040
so_5::launch(
4141
[&]( so_5::environment_t & env ) {
42-
so_5::mbox_t test_mbox;
43-
env.introduce_coop( [&]( so_5::coop_t & coop ) {
44-
test_mbox = coop.make_agent< a_test_t >()->so_direct_mbox();
45-
} );
42+
so_5::mbox_t test_mbox = env.introduce_coop(
43+
[&]( so_5::coop_t & coop ) {
44+
return coop.make_agent< a_test_t >()->so_direct_mbox();
45+
} );
4646

4747
outside_thread = thread( [test_mbox] {
4848
this_thread::sleep_for( chrono::milliseconds( 350 ) );

dev/test/so_5/env_infrastructure/simple_mtsafe_st/timer_factories/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ launch_with(
3737
}
3838
};
3939

40-
env.introduce_coop( [&]( so_5::coop_t & coop ) {
40+
env.introduce_coop( []( so_5::coop_t & coop ) {
4141
coop.make_agent< actor_t >();
4242
} );
4343
},

dev/test/so_5/env_infrastructure/simple_not_mtsafe_st/delayed_msg/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ main()
3838
}
3939
};
4040

41-
env.introduce_coop( [&]( so_5::coop_t & coop ) {
41+
env.introduce_coop( []( so_5::coop_t & coop ) {
4242
coop.make_agent< actor_t >();
4343
} );
4444
},

dev/test/so_5/env_infrastructure/simple_not_mtsafe_st/timer_factories/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ launch_with(
3838
}
3939
};
4040

41-
env.introduce_coop( [&]( so_5::coop_t & coop ) {
41+
env.introduce_coop( []( so_5::coop_t & coop ) {
4242
coop.make_agent< actor_t >();
4343
} );
4444
},

dev/test/so_5/mpsc_queue_traits/agent_ring/main.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,7 @@ create_coop(
277277
so_5::environment_t & env,
278278
case_setter_t & setter )
279279
{
280-
so_5::mbox_t first_agent_mbox;
281-
282-
env.introduce_coop(
280+
so_5::mbox_t first_agent_mbox = env.introduce_coop(
283281
[&]( so_5::coop_t & coop )
284282
{
285283
const std::size_t ring_size = 16;
@@ -304,7 +302,7 @@ create_coop(
304302
mboxes[ (i + 1) % ring_size ] );
305303
}
306304

307-
first_agent_mbox = mboxes[ 0 ];
305+
return mboxes[ 0 ];
308306
} );
309307

310308
so_5::send< a_ring_member_t::msg_start >( first_agent_mbox );

dev/test/so_5/testing/v1/impact_as_message/main.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ UT_UNIT_TEST( impact_as_message )
6262
{
6363
tests::testing_env_t env;
6464

65-
so_5::agent_t * test_agent;
66-
env.environment().introduce_coop( [&](so_5::coop_t & coop) {
67-
test_agent = coop.make_agent< test_agent_t >();
68-
} );
65+
so_5::agent_t * test_agent = env.environment().introduce_coop(
66+
[](so_5::coop_t & coop) {
67+
return coop.make_agent< test_agent_t >();
68+
} );
6969

7070
define_step< hello >( env, "hello", *test_agent );
7171
define_step< so_msg >( env, "so_msg", *test_agent, 1 );

dev/test/so_5/testing/v1/inline_ns/main.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,17 @@ UT_UNIT_TEST( workers_and_manager )
7171
{
7272
tests::testing_env_t env;
7373

74-
so_5::agent_t * first_worker{};
75-
so_5::agent_t * second_worker{};
76-
so_5::agent_t * manager{};
77-
7874
const auto control_mbox = env.environment().create_mbox();
7975

80-
env.environment().introduce_coop( [&](so_5::coop_t & coop) {
81-
first_worker = coop.make_agent< worker_t >( control_mbox );
82-
second_worker = coop.make_agent< worker_t >( control_mbox );
76+
auto [first_worker, second_worker] =
77+
env.environment().introduce_coop(
78+
[&](so_5::coop_t & coop) {
79+
coop.make_agent< manager_t >( control_mbox );
8380

84-
manager = coop.make_agent< manager_t >( control_mbox );
85-
} );
81+
return std::make_tuple(
82+
coop.make_agent< worker_t >( control_mbox ),
83+
coop.make_agent< worker_t >( control_mbox ) );
84+
} );
8685

8786
auto scenario = env.scenario();
8887

dev/test/so_5/testing/v1/testenv_constraints/main.cpp

+40-45
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include <test/3rd_party/utest_helper/helper.hpp>
77

8+
using namespace std::chrono_literals;
9+
810
namespace tests = so_5::experimental::testing::v1;
911

1012
struct hello_1 final : public so_5::signal_t {};
@@ -55,19 +57,18 @@ UT_UNIT_TEST( not_before_1 )
5557
{
5658
tests::testing_env_t env;
5759

58-
so_5::agent_t * test_agent;
59-
env.environment().introduce_coop( [&](so_5::coop_t & coop) {
60-
test_agent = coop.make_agent< test_agent_t >(
61-
std::chrono::milliseconds(200) );
60+
so_5::agent_t * test_agent = env.environment().introduce_coop(
61+
[&](so_5::coop_t & coop) {
62+
return coop.make_agent< test_agent_t >( 200ms );
6263
} );
6364

6465
define_hello_1_step( env, *test_agent );
6566

6667
env.scenario().define_step( "hello_2" )
67-
.constraints( tests::not_before( std::chrono::milliseconds(500) ) )
68+
.constraints( tests::not_before( 500ms ) )
6869
.when( *test_agent & tests::reacts_to<hello_2>() );
6970

70-
env.scenario().run_for( std::chrono::milliseconds(1000) );
71+
env.scenario().run_for( 1000ms );
7172

7273
UT_CHECK_NE( tests::completed(), env.scenario().result() );
7374
},
@@ -81,19 +82,18 @@ UT_UNIT_TEST( not_before_2 )
8182
{
8283
tests::testing_env_t env;
8384

84-
so_5::agent_t * test_agent;
85-
env.environment().introduce_coop( [&](so_5::coop_t & coop) {
86-
test_agent = coop.make_agent< test_agent_t >(
87-
std::chrono::milliseconds(700) );
85+
so_5::agent_t * test_agent = env.environment().introduce_coop(
86+
[](so_5::coop_t & coop) {
87+
return coop.make_agent< test_agent_t >( 700ms );
8888
} );
8989

9090
define_hello_1_step( env, *test_agent );
9191

9292
env.scenario().define_step( "hello_2" )
93-
.constraints( tests::not_before( std::chrono::milliseconds(300) ) )
93+
.constraints( tests::not_before( 300ms ) )
9494
.when( *test_agent & tests::reacts_to<hello_2>() );
9595

96-
env.scenario().run_for( std::chrono::milliseconds(1000) );
96+
env.scenario().run_for( 1000ms );
9797

9898
UT_CHECK_EQ( tests::completed(), env.scenario().result() );
9999
},
@@ -107,19 +107,18 @@ UT_UNIT_TEST( not_after_1 )
107107
{
108108
tests::testing_env_t env;
109109

110-
so_5::agent_t * test_agent;
111-
env.environment().introduce_coop( [&](so_5::coop_t & coop) {
112-
test_agent = coop.make_agent< test_agent_t >(
113-
std::chrono::milliseconds(200) );
110+
so_5::agent_t * test_agent = env.environment().introduce_coop(
111+
[](so_5::coop_t & coop) {
112+
return coop.make_agent< test_agent_t >( 200ms );
114113
} );
115114

116115
define_hello_1_step( env, *test_agent );
117116

118117
env.scenario().define_step( "hello_2" )
119-
.constraints( tests::not_after( std::chrono::milliseconds(400) ) )
118+
.constraints( tests::not_after( 400ms ) )
120119
.when( *test_agent & tests::reacts_to<hello_2>() );
121120

122-
env.scenario().run_for( std::chrono::milliseconds(1000) );
121+
env.scenario().run_for( 1000ms );
123122

124123
UT_CHECK_EQ( tests::completed(), env.scenario().result() );
125124
},
@@ -133,19 +132,18 @@ UT_UNIT_TEST( not_after_2 )
133132
{
134133
tests::testing_env_t env;
135134

136-
so_5::agent_t * test_agent;
137-
env.environment().introduce_coop( [&](so_5::coop_t & coop) {
138-
test_agent = coop.make_agent< test_agent_t >(
139-
std::chrono::milliseconds(500) );
135+
so_5::agent_t * test_agent = env.environment().introduce_coop(
136+
[](so_5::coop_t & coop) {
137+
return coop.make_agent< test_agent_t >( 500ms );
140138
} );
141139

142140
define_hello_1_step( env, *test_agent );
143141

144142
env.scenario().define_step( "hello_2" )
145-
.constraints( tests::not_after( std::chrono::milliseconds(250) ) )
143+
.constraints( tests::not_after( 250ms ) )
146144
.when( *test_agent & tests::reacts_to<hello_2>() );
147145

148-
env.scenario().run_for( std::chrono::milliseconds(1000) );
146+
env.scenario().run_for( 1000ms );
149147

150148
UT_CHECK_NE( tests::completed(), env.scenario().result() );
151149
},
@@ -159,21 +157,20 @@ UT_UNIT_TEST( not_before_not_after_1 )
159157
{
160158
tests::testing_env_t env;
161159

162-
so_5::agent_t * test_agent;
163-
env.environment().introduce_coop( [&](so_5::coop_t & coop) {
164-
test_agent = coop.make_agent< test_agent_t >(
165-
std::chrono::milliseconds(200) );
160+
so_5::agent_t * test_agent = env.environment().introduce_coop(
161+
[](so_5::coop_t & coop) {
162+
return coop.make_agent< test_agent_t >( 200ms );
166163
} );
167164

168165
define_hello_1_step( env, *test_agent );
169166

170167
env.scenario().define_step( "hello_2" )
171168
.constraints(
172-
tests::not_before( std::chrono::milliseconds(400) ),
173-
tests::not_after( std::chrono::milliseconds(600) ) )
169+
tests::not_before( 400ms ),
170+
tests::not_after( 600ms ) )
174171
.when( *test_agent & tests::reacts_to<hello_2>() );
175172

176-
env.scenario().run_for( std::chrono::milliseconds(1000) );
173+
env.scenario().run_for( 1000ms );
177174

178175
UT_CHECK_NE( tests::completed(), env.scenario().result() );
179176
},
@@ -187,21 +184,20 @@ UT_UNIT_TEST( not_before_not_after_2 )
187184
{
188185
tests::testing_env_t env;
189186

190-
so_5::agent_t * test_agent;
191-
env.environment().introduce_coop( [&](so_5::coop_t & coop) {
192-
test_agent = coop.make_agent< test_agent_t >(
193-
std::chrono::milliseconds(400) );
187+
so_5::agent_t * test_agent = env.environment().introduce_coop(
188+
[](so_5::coop_t & coop) {
189+
return coop.make_agent< test_agent_t >( 400ms );
194190
} );
195191

196192
define_hello_1_step( env, *test_agent );
197193

198194
env.scenario().define_step( "hello_2" )
199195
.constraints(
200-
tests::not_before( std::chrono::milliseconds(150) ),
201-
tests::not_after( std::chrono::milliseconds(200) ) )
196+
tests::not_before( 150ms ),
197+
tests::not_after( 200ms ) )
202198
.when( *test_agent & tests::reacts_to<hello_2>() );
203199

204-
env.scenario().run_for( std::chrono::milliseconds(1000) );
200+
env.scenario().run_for( 1000ms );
205201

206202
UT_CHECK_NE( tests::completed(), env.scenario().result() );
207203
},
@@ -215,21 +211,20 @@ UT_UNIT_TEST( not_before_not_after_3 )
215211
{
216212
tests::testing_env_t env;
217213

218-
so_5::agent_t * test_agent;
219-
env.environment().introduce_coop( [&](so_5::coop_t & coop) {
220-
test_agent = coop.make_agent< test_agent_t >(
221-
std::chrono::milliseconds(250) );
214+
so_5::agent_t * test_agent = env.environment().introduce_coop(
215+
[](so_5::coop_t & coop) {
216+
return coop.make_agent< test_agent_t >( 250ms );
222217
} );
223218

224219
define_hello_1_step( env, *test_agent );
225220

226221
env.scenario().define_step( "hello_2" )
227222
.constraints(
228-
tests::not_before( std::chrono::milliseconds(100) ),
229-
tests::not_after( std::chrono::milliseconds(500) ) )
223+
tests::not_before( 100ms ),
224+
tests::not_after( 500ms ) )
230225
.when( *test_agent & tests::reacts_to<hello_2>() );
231226

232-
env.scenario().run_for( std::chrono::milliseconds(1000) );
227+
env.scenario().run_for( 1000ms );
233228

234229
UT_CHECK_EQ( tests::completed(), env.scenario().result() );
235230
},

dev/test/so_5/testing/v1/testenv_constructors/main.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ UT_UNIT_TEST( env_params_tuner )
3131
so_5::msg_tracing::std_cout_tracer() );
3232
} };
3333

34-
so_5::agent_t * test_agent;
35-
env.environment().introduce_coop( [&](so_5::coop_t & coop) {
36-
test_agent = coop.make_agent< test_agent_t >();
34+
so_5::agent_t * test_agent = env.environment().introduce_coop(
35+
[](so_5::coop_t & coop) {
36+
return coop.make_agent< test_agent_t >();
3737
} );
3838

3939
env.scenario().define_step( "hello" )
@@ -63,9 +63,9 @@ UT_UNIT_TEST( prepared_params )
6363
{
6464
tests::testing_env_t env{ params_maker() };
6565

66-
so_5::agent_t * test_agent;
67-
env.environment().introduce_coop( [&](so_5::coop_t & coop) {
68-
test_agent = coop.make_agent< test_agent_t >();
66+
so_5::agent_t * test_agent = env.environment().introduce_coop(
67+
[](so_5::coop_t & coop) {
68+
return coop.make_agent< test_agent_t >();
6969
} );
7070

7171
env.scenario().define_step( "hello" )

0 commit comments

Comments
 (0)