diff options
author | Steve Huston <shuston@riverace.com> | 2001-08-25 00:34:58 +0000 |
---|---|---|
committer | Steve Huston <shuston@riverace.com> | 2001-08-25 00:34:58 +0000 |
commit | b4640651ff905f53297d4b45eb623a562d66bed7 (patch) | |
tree | 4cc50691edf3de35225565a19b68e18ec9c4b59f /tests/MEM_Stream_Test.cpp | |
parent | 758c62878c017e4cfcd58f6cb678c21c490a87d7 (diff) | |
download | ATCD-b4640651ff905f53297d4b45eb623a562d66bed7.tar.gz |
ChangeLogTag:Fri Aug 24 20:32:39 2001 Steve Huston <shuston@riverace.com>
Diffstat (limited to 'tests/MEM_Stream_Test.cpp')
-rw-r--r-- | tests/MEM_Stream_Test.cpp | 194 |
1 files changed, 147 insertions, 47 deletions
diff --git a/tests/MEM_Stream_Test.cpp b/tests/MEM_Stream_Test.cpp index 2aaa9c5e884..b5124d30ab8 100644 --- a/tests/MEM_Stream_Test.cpp +++ b/tests/MEM_Stream_Test.cpp @@ -19,6 +19,7 @@ #include "test_config.h" #include "ace/OS.h" +#include "ace/Get_Opt.h" #include "ace/Thread_Manager.h" #include "ace/MEM_Connector.h" #include "ace/MEM_Acceptor.h" @@ -30,7 +31,16 @@ ACE_RCSID(tests, MEM_Stream_Test, "$Id$") -#if defined (ACE_HAS_THREADS) && (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1) +#if (defined (ACE_HAS_THREADS) || !defined (ACE_LACKS_FORK)) && \ + (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1) + +#if defined (ACE_LACKS_FORK) // Win32, et al +# define _TEST_USES_THREADS +#else +# define _TEST_USES_PROCESSES +# include "ace/Process.h" +# include "ace/Process_Manager.h" +#endif /* ACE_HAS_FORK */ #include "MEM_Stream_Test.h" // Defines Echo_Handler @@ -153,13 +163,13 @@ Echo_Handler::svc (void) return 0; } -void * -connect_client (void *arg) +static int +run_client (unsigned short port, ACE_MEM_IO::Signal_Strategy strategy) { - u_short sport = (*ACE_reinterpret_cast (u_short *, arg)); - ACE_MEM_Addr to_server (sport); + int status = 0; + ACE_MEM_Addr to_server (port); ACE_MEM_Connector connector; - connector.preferred_strategy (client_strategy); + connector.preferred_strategy (strategy); ACE_MEM_Stream stream; // connector.preferred_strategy (ACE_MEM_IO::MT); @@ -167,7 +177,7 @@ connect_client (void *arg) if (connector.connect (stream, to_server.get_remote_addr ()) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("connect_client")), - 0); + -1); ACE_TCHAR buf[MAXPATHLEN]; @@ -179,22 +189,38 @@ connect_client (void *arg) ssize_t slen = (ACE_OS::strlen (buf) + 1) * sizeof (ACE_TCHAR); if (stream.send (buf, slen) < slen) - ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), - ACE_TEXT ("In connect_client, send")), - 0); + { + ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), + ACE_TEXT ("In connect_client, send"))); + status = -1; + break; + } if (stream.recv (buf, MAXPATHLEN) == -1) - ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), - ACE_TEXT ("In connect_client, recv")), - 0); + { + ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), + ACE_TEXT ("In connect_client, recv"))); + status = -1; + break; + } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("connect_client, got echo %s\n"), buf)); } - stream.close (); + status = status == 0 ? stream.close () : status; + return status; +} + + +void * +connect_client (void *arg) +{ + u_short sport = (*ACE_reinterpret_cast (u_short *, arg)); + run_client (sport, client_strategy); return 0; } + void create_reactor (void) { @@ -218,10 +244,12 @@ create_reactor (void) ACE_Reactor::instance (reactor); } -int test_reactive (ACE_MEM_Addr &server_addr) +int test_reactive (const ACE_TCHAR *prog, ACE_MEM_Addr &server_addr) { ACE_DEBUG ((LM_DEBUG, "Testing Reactive MEM_Stream\n\n")); + int status = 0; + ACE_Accept_Strategy<Echo_Handler, ACE_MEM_ACCEPTOR> accept_strategy; ACE_Creation_Strategy<Echo_Handler> create_strategy; ACE_Reactive_Strategy<Echo_Handler> reactive_strategy (ACE_Reactor::instance ()); @@ -245,36 +273,52 @@ int test_reactive (ACE_MEM_Addr &server_addr) u_short sport = local_addr.get_port_number (); +#if defined (_TEST_USES_THREADS) ACE_Thread_Manager::instance ()->spawn_n (NO_OF_REACTIVE_CONNECTION, connect_client, &sport); +#else + ACE_Process_Options opts; + opts.command_line (ACE_TEXT ("%s -p%d -r"), prog, sport); + if (-1==ACE_Process_Manager::instance ()->spawn_n (NO_OF_REACTIVE_CONNECTION, + opts)) + ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("spawn"))); +#endif + ACE_Time_Value tv(60, 0); ACE_Reactor::instance ()->run_event_loop (tv); if (tv == ACE_Time_Value::zero) { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT("Reactor::run_event_loop timeout\n")), - 1); + ACE_ERROR ((LM_ERROR, + ACE_TEXT("Reactor::run_event_loop timeout\n"))); + status = 1; } ACE_DEBUG ((LM_DEBUG, "Reactor::run_event_loop finished\n")); +#if defined (_TEST_USES_THREADS) ACE_Thread_Manager::instance ()->wait (); +#else + ACE_Process_Manager::instance ()->wait (); +#endif if (acceptor.close () == -1) { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("MEM_Acceptor::close\n")), - 1); + ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), + ACE_TEXT ("MEM_Acceptor::close\n"))); + status = 1; } - return 0; + + return status; } -int test_multithreaded (ACE_MEM_Addr &server_addr) +int test_multithreaded (const ACE_TCHAR *prog, ACE_MEM_Addr &server_addr) { ACE_DEBUG ((LM_DEBUG, "Testing Multithreaded MEM_Stream\n\n")); + int status = 0; + client_strategy = ACE_MEM_IO::MT; ACE_Accept_Strategy<Echo_Handler, ACE_MEM_ACCEPTOR> accept_strategy; ACE_Creation_Strategy<Echo_Handler> create_strategy; @@ -304,60 +348,116 @@ int test_multithreaded (ACE_MEM_Addr &server_addr) u_short sport = local_addr.get_port_number (); - ACE_Thread_Manager::instance ()->spawn_n (NO_OF_MT_CONNECTION, +#if defined (_TEST_USES_THREADS) + ACE_Thread_Manager::instance ()->spawn_n (NO_OF_REACTIVE_CONNECTION, connect_client, &sport); +#else + ACE_Process_Options opts; + opts.command_line (ACE_TEXT ("%s -p%d -m"), prog, sport); + if (-1==ACE_Process_Manager::instance ()->spawn_n (NO_OF_REACTIVE_CONNECTION, + opts)) + ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("spawn"))); +#endif + ACE_Time_Value tv(60, 0); ACE_Reactor::instance ()->run_event_loop (tv); if (tv == ACE_Time_Value::zero) { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT("Reactor::run_event_loop timeout\n")), - 1); + ACE_ERROR ((LM_ERROR, + ACE_TEXT("Reactor::run_event_loop timeout\n"))); + status = 1; } + else + ACE_DEBUG ((LM_DEBUG, "Reactor::run_event_loop finished\n")); - ACE_DEBUG ((LM_DEBUG, "Reactor::run_event_loop finished\n")); - +#if defined (_TEST_USES_THREADS) ACE_Thread_Manager::instance ()->wait (); +#else + ACE_Process_Manager::instance ()->wait (); +#endif if (acceptor.close () == -1) { - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("MEM_Acceptor::close\n")), - 1); + ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), + ACE_TEXT ("MEM_Acceptor::close"))); + status = 1; } - return 0; + + return status; } int -main (int, ACE_TCHAR *[]) +main (int argc, ACE_TCHAR *argv[]) { - ACE_START_TEST (ACE_TEXT ("MEM_Stream_Test")); + unsigned short port = 0; - create_reactor (); + if (argc == 1) + { + ACE_START_TEST (ACE_TEXT ("MEM_Stream_Test")); - unsigned short port = 0; - ACE_MEM_Addr server_addr (port); + create_reactor (); - reset_handler (NO_OF_REACTIVE_CONNECTION); + ACE_MEM_Addr server_addr (port); - test_reactive (server_addr); + reset_handler (NO_OF_REACTIVE_CONNECTION); - ACE_Reactor::instance ()->reset_event_loop (); + test_reactive (argv[0], server_addr); + + ACE_Reactor::instance ()->reset_event_loop (); #if !defined (ACE_WIN32) && defined (_ACE_USE_SV_SEM) - ACE_ERROR ((LM_DEBUG, + ACE_ERROR ((LM_DEBUG, ACE_TEXT ("\n *** Platform only support non-scalable SysV semaphores ***\n\n"))); #endif /* !ACE_WIN32 && _ACE_USE_SV_SEM */ - reset_handler (NO_OF_MT_CONNECTION); + reset_handler (NO_OF_MT_CONNECTION); + + test_multithreaded (argv[0], server_addr); - test_multithreaded (server_addr); + ACE_END_TEST; + return 0; + } + // Here if this is a child process spawned for one of the test passes. + // command line is: -p <port> -r (reactive) | -m (multithreaded) + + ACE_TCHAR lognm[MAXPATHLEN]; + ACE_OS::sprintf(lognm, ACE_TEXT ("MEM_Stream_Test-%d"), ACE_OS::getpid()); + ACE_START_TEST (lognm); + + ACE_Get_Opt opts (argc, argv, ACE_TEXT ("p:rm")); + int opt, iport, status; + ACE_MEM_IO::Signal_Strategy model = ACE_MEM_IO::Reactive; + + while ((opt = opts()) != -1) + { + switch (opt) + { + case 'p': + iport = ACE_OS::atoi (opts.optarg); + port = ACE_static_cast (unsigned short, iport); + break; + + case 'r': + model = ACE_MEM_IO::Reactive; + break; + + case 'm': + model = ACE_MEM_IO::MT; + break; + + default: + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("Invalid option (-p <port> -r | -m)\n")), + 1); + } + } + status = run_client (port, model); ACE_END_TEST; - return 0; + return status; } #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) @@ -393,10 +493,10 @@ main (int, ACE_TCHAR *[]) ACE_START_TEST (ACE_TEXT ("MEM_Stream_Test")); ACE_ERROR ((LM_INFO, - ACE_TEXT ("threads or position independent pointers ") + ACE_TEXT ("position independent pointers ") ACE_TEXT ("not supported on this platform\n"))); ACE_END_TEST; return 0; } -#endif /* ACE_HAS_THREADS || ACE_HAS_POSITION_INDENDENT_POINTERS == 1 */ +#endif /* (ACE_HAS_THREADS || ACE_HAS_FORK) && ACE_HAS_POSITION_INDENDENT_POINTERS == 1 */ |