Beispiel #1
0
int
main()
{
	try
	{
		run_with_time_limit(
			[]()
			{
				so_5::launch(
					[]( so_5::rt::environment_t & env )
					{
						for( int i = 0; i < 1024; ++i )
						{
							std::ostringstream ss;
							ss << "coop_" << i;

							env.register_agent_as_coop(
								ss.str(), new a_test_t( env ) );
						}
					} );
			},
			5,
			"SO Environment autoshutdown test" );
	}
	catch( const std::exception & ex )
	{
		std::cerr << "Error: " << ex.what() << std::endl;
		return 1;
	}

	return 0;
}
int
main()
{
	try
	{
		run_with_time_limit(
			[]()
			{
				counter_t counter = { 0 };
				so_5::launch( &init,
					[&counter]( so_5::environment_params_t & params ) {
						params.message_delivery_tracer(
								so_5::msg_tracing::tracer_unique_ptr_t{
										new tracer_t{ counter,
												so_5::msg_tracing::std_cout_tracer() } } );
					} );

				const unsigned int expected_value = 4;
				auto actual_value = counter.load( std::memory_order_acquire );
				if( expected_value != actual_value )
					throw std::runtime_error( "Unexpected count of trace messages: "
							"expected=" + std::to_string(expected_value) +
							", actual=" + std::to_string(actual_value) );
			},
			20,
			"simple tracing for limitless MPSC-mboxes" );
	}
	catch( const std::exception & ex )
	{
		std::cerr << "Error: " << ex.what() << std::endl;
		return 1;
	}

	return 0;
}
Beispiel #3
0
int
main()
{
	try
	{
		run_with_time_limit(
			[]()
			{
				so_5::wrapped_env_t env{
					[]( so_5::environment_t & env ) {
						env.introduce_coop( []( so_5::coop_t & coop ) {
							struct hello_sig : public so_5::signal_t {};

							auto a = coop.define_agent();
							a.on_start( [a] {
									so_5::send_delayed< hello_sig >( a,
											std::chrono::milliseconds( 25 ) );
								} );
							a.event< hello_sig >( a, [a] {
									std::cout << "Hello for agent" << std::endl;
									so_5::send_delayed< hello_sig >( a,
											std::chrono::milliseconds( 100 ) );
								} );
						} );
					}
				};

				std::this_thread::sleep_for( std::chrono::milliseconds(250) );

				env.stop();

				std::cout << "Stop signal is sent" << std::endl;

				env.join();

				std::cout << "Joined" << std::endl;
			},
			4,
			"test for stopping wrapped_env_t" );
	}
	catch( const std::exception & ex )
	{
		std::cerr << "Error: " << ex.what() << std::endl;
		return 1;
	}

	return 0;
}
int
main()
{
	try
	{
		run_with_time_limit(
			[]()
			{
				std::thread controller_thread( &controller );

				so_5::launch(
					[]( so_5::environment_t & env )
					{
						std::cout << "Starting agents..." << std::endl;

						environment.store( &env, std::memory_order_release );

						for( unsigned int i = 0; i < agents_count; ++i )
						{
							std::ostringstream ss;
							ss << "coop_" << i;

							env.register_agent_as_coop(
								ss.str(), new a_test_t( env ) );
						}
					},
					[]( so_5::environment_params_t & params )
					{
						params.disable_autoshutdown();
					} );

				environment.store( nullptr, std::memory_order_release );

				controller_thread.join();
			},
			20,
			"SO Environment autoshutdown disabled test" );
	}
	catch( const std::exception & ex )
	{
		std::cerr << "Error: " << ex.what() << std::endl;
		return 1;
	}

	return 0;
}
int
main()
{
	try
	{
		run_with_time_limit(
			[]()
			{
				so_5::launch( &init );
			},
			20,
			"simple delivery filter for service_request test" );
	}
	catch( const std::exception & ex )
	{
		std::cerr << "Error: " << ex.what() << std::endl;
		return 1;
	}

	return 0;
}
Beispiel #6
0
int
main()
{
	try
	{
		run_with_time_limit(
			[]()
			{
				so_5::launch( &init );
			},
			4,
			"delivery filter for MPSC-mboxes" );
	}
	catch( const std::exception & ex )
	{
		std::cerr << "Error: " << ex.what() << std::endl;
		return 1;
	}

	return 0;
}
Beispiel #7
0
int
main()
{
	try
	{
		run_with_time_limit(
			[]()
			{
				so_5::launch( &init );
			},
			4,
			"simple message drop test" );
	}
	catch( const std::exception & ex )
	{
		std::cerr << "Error: " << ex.what() << std::endl;
		return 1;
	}

	return 0;
}
Beispiel #8
0
void
do_test()
{
	using factory_info_t =
			std::pair< std::string, so_5::rt::subscription_storage_factory_t >;
	
	factory_info_t factories[] = {
		{ "vector[1]", so_5::rt::vector_based_subscription_storage_factory( 1 ) }
	,	{ "vector[8]", so_5::rt::vector_based_subscription_storage_factory( 8 ) }
	,	{ "vector[16]", so_5::rt::vector_based_subscription_storage_factory( 16 ) }
	,	{ "map", so_5::rt::map_based_subscription_storage_factory() }
	,	{ "hash_table", so_5::rt::hash_table_based_subscription_storage_factory() }
	,	{ "adaptive[1]", so_5::rt::adaptive_subscription_storage_factory( 1 ) }
	,	{ "adaptive[2]", so_5::rt::adaptive_subscription_storage_factory( 2 ) }
	,	{ "adaptive[3]", so_5::rt::adaptive_subscription_storage_factory( 3 ) }
	,	{ "adaptive[8]", so_5::rt::adaptive_subscription_storage_factory( 8 ) }
	,	{ "default", so_5::rt::default_subscription_storage_factory() }
	}; 

	for( auto & f : factories )
	{
		std::cout << "checking factory: " << f.first << " -> " << std::flush;

		run_with_time_limit(
			[f] {
				test_env_t test_env{ f.second };
				so_5::launch(
					[&]( so_5::rt::environment_t & env )
					{
						test_env.init( env );
					} );

				test_env.check_result();
			}, 
			5,
			"checking factory " + f.first );

		std::cout << "OK" << std::endl;
	}
}
int
main()
{
	try
	{
		std::set< std::string > names;

		run_with_time_limit( [&] {
			so_5::launch(
				[&]( so_5::environment_t & env )
				{
					create_and_register_agent( env, "", 0, 4, 0, 8 );
				},
				[&]( so_5::environment_params_t & params )
				{
					params.coop_listener( test_coop_listener_t::make( names ) );
				} );
			},
			240,
			"parent_child_2 test" );

		if( !names.empty() )
		{
			for( const auto & n : names )
				std::cout << "unregistered coop: '" << n << "'" << std::endl;

			throw std::runtime_error(
					"There are some not deregistered cooperations (" +
					std::to_string( names.size() ) + ")" );
		}
	}
	catch( const std::exception & ex )
	{
		std::cerr << "Error: " << ex.what() << std::endl;
		return 1;
	}

	return 0;
}
Beispiel #10
0
		void
		evt_child_destroyed(
			const so_5::msg_coop_deregistered & )
		{
			if( m_state != state_t::awaiting_destroying )
				throw std::runtime_error( "msg_coop_deregistered when "
						"m_state != state_t::awaiting_destroying" );

			if( m_destroy_received != m_max_agents )
				throw std::runtime_error( "not all agents destroyed before "
						"msg_coop_deregistered received" );

			// This action must not lead to any damages (like memory leaks).
			consume_some_memory();
			run_with_time_limit( [this] {
					for( auto & m : m_child_mboxes )
						m->deliver_signal< msg_ping >();
				},
				10,
				"attempts to send signal to MPSC mbox of destroyed agent" );

			--m_iterations_left;
			try_start_new_iteration();
		}