diff options
author | Steve Huston <shuston@riverace.com> | 2001-12-20 16:45:54 +0000 |
---|---|---|
committer | Steve Huston <shuston@riverace.com> | 2001-12-20 16:45:54 +0000 |
commit | adfcfd43018253a5372b101427376951b8ac4d24 (patch) | |
tree | 53a16abe0118e8f36ee72ea6e4352e5cfeb7d5a2 /tests | |
parent | 01ef7732d30a596c4142246575f3c1d7cd0ef8f1 (diff) | |
download | ATCD-adfcfd43018253a5372b101427376951b8ac4d24.tar.gz |
ChangeLogTag:Thu Dec 20 11:43:29 2001 Steve Huston <shuston@riverace.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/SSL/Makefile | 64 | ||||
-rw-r--r-- | tests/SSL/Thread_Pool_Reactor_SSL_Test.cpp | 366 | ||||
-rw-r--r-- | tests/SSL/Thread_Pool_Reactor_SSL_Test.h | 51 | ||||
-rw-r--r-- | tests/SSL/dummy.pem | 15 | ||||
-rw-r--r-- | tests/SSL/key.pem | 15 |
5 files changed, 511 insertions, 0 deletions
diff --git a/tests/SSL/Makefile b/tests/SSL/Makefile new file mode 100644 index 00000000000..cd59d61702c --- /dev/null +++ b/tests/SSL/Makefile @@ -0,0 +1,64 @@ +#---------------------------------------------------------------------------- +# +# $Id$ +# +# Makefile for all the ACE SSL ``one-button' tests +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Local macros +#---------------------------------------------------------------------------- + +BIN = Thread_Pool_Reactor_SSL_Test + +PSRC=$(addsuffix .cpp,$(BIN)) +LDLIBS = -lACE_SSL +CPPFLAGS += -I.. + +#---------------------------------------------------------------------------- +# Include macros and targets +#---------------------------------------------------------------------------- + +include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU +include $(ACE_ROOT)/include/makeinclude/macros.GNU +include $(ACE_ROOT)/include/makeinclude/rules.common.GNU +include $(ACE_ROOT)/include/makeinclude/rules.nested.GNU +include $(ACE_ROOT)/include/makeinclude/rules.bin.GNU + +ifdef purify + #### SIGINT is used by Thread_Manager_Test. + #### SIGHUP and SIGTERM are used by Signal_Test. + PURELINK += -ignore-signals=SIGHUP,SIGINT,SIGTERM +endif # purify + +include $(ACE_ROOT)/include/makeinclude/rules.local.GNU + +# To build multiple executables in the same directory on AIX, it works +# best to wipe out any previously-created tempinc directory. +# The compiler/linker isn't too smart about instantiating templates... +ifdef TEMPINCDIR +COMPILE.cc := $(RM) -rf tempinc; $(COMPILE.cc) +endif + +#---------------------------------------------------------------------------- +# Local targets +#---------------------------------------------------------------------------- + +ifdef VXWORKS +all: run_test.vxworks + +run_test.vxworks: run_test.lst + run_test.pl -v -Config STATIC -Config CHECK_RESOURCES -o run_test.vxworks +endif + +realclean: clean + -$(RM) libDLL_Test.$(SOEXT) libService_Config_DLL.* + -$(RM) log/compilations.log* + +#---------------------------------------------------------------------------- +# Dependencies +#---------------------------------------------------------------------------- +# DO NOT DELETE THIS LINE -- g++dep uses it. +# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. + +# IF YOU PUT ANYTHING HERE IT WILL GO AWAY diff --git a/tests/SSL/Thread_Pool_Reactor_SSL_Test.cpp b/tests/SSL/Thread_Pool_Reactor_SSL_Test.cpp new file mode 100644 index 00000000000..70370967949 --- /dev/null +++ b/tests/SSL/Thread_Pool_Reactor_SSL_Test.cpp @@ -0,0 +1,366 @@ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// tests/SSL +// +// = FILENAME +// Thread_Pool_Reactor_Test.cpp +// +// = DESCRIPTION +// This program is a torture test of threaded SSL usage. It +// is based on the tests/Thread_Pool_Reactor_Test and adds +// SSL stuff submitted by Robert Handl <robert.handl@ehpt.com>. +// It starts by spawning several server threads waiting to handle +// events. Several other client threads are spawned right after +// to initiate connections to server threads. Each connection +// adds a new Svc_Handler into the TP_Reactor and sends out +// several "requests" to the server thread. After the connection +// is closed, the Svc_Handler is removed from the TP_Reactor. +// Each message is treated as a separate request by the server so +// two consecutive requests might be serviced by two different +// threads. +// +// Usage: Thread_Pool_Reactor_Test_SSL [-r <hostname:port#>] +// [-s <server thr#>] [-c <client thr#>] [-d <delay>] +// [-i <client conn attempt#>] [-n <client request# per conn>] +// +// Default value: +// <hostname:port#>: ACE_DEFAULT_RENDEZVOUS +// <server thr#>: ACE_MAX_THREADS +// <client thr#>: ACE_MAX_ITERATIONS +// <client conn attempt#>: ACE_MAX_ITERATIONS +// <client req# per conn>: ACE_MAX_THREADS +// <delay>: 50 usec +// +// = AUTHOR +// Irfan Pyarali <irfan@cs.wustl.edu> and +// Nanbor Wang <nanbor@cs.wustl.edu> +// +// ============================================================================ + +#include "tests/test_config.h" +#include "ace/Get_Opt.h" +#include "ace/Acceptor.h" +#include "ace/Thread_Manager.h" +#include "ace/TP_Reactor.h" +#include "ace/SSL/SSL_SOCK_Connector.h" +#include "ace/SSL/SSL_SOCK_Acceptor.h" + +ACE_RCSID(tests, Atomic_Op_Test, "$Id$") + +#if defined (ACE_HAS_THREADS) + +#include "Thread_Pool_Reactor_SSL_Test.h" +typedef ACE_Strategy_Acceptor <Request_Handler, ACE_SSL_SOCK_ACCEPTOR> + ACCEPTOR; + +// Accepting end point. This is actually "localhost:10010", but some +// platform couldn't resolve the name so we use the IP address +// directly here. +static const ACE_TCHAR *rendezvous = ACE_TEXT ("127.0.0.1:10010"); + +// Total number of server threads. +static size_t svr_thrno = ACE_MAX_THREADS; + +#if defined (CHORUS) // Add platforms that can't handle too many + // connection simultaneously here. +#define ACE_LOAD_FACTOR /2 +#else +#define ACE_LOAD_FACTOR +#endif + +// Total number of client threads. +static size_t cli_thrno = ACE_MAX_THREADS ACE_LOAD_FACTOR; + +// Total connection attemps of a client thread. +static size_t cli_conn_no = ACE_MAX_ITERATIONS ACE_LOAD_FACTOR; + +// Total requests a client thread sends. +static size_t cli_req_no = ACE_MAX_THREADS ACE_LOAD_FACTOR; + +// Delay before a thread sending the next request (in msec.) +static int req_delay = 50; + +static void +parse_arg (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt getopt (argc, argv, ACE_TEXT ("r:s:c:d:i:n:")); + + int c; + + while ((c = getopt ()) != -1) + { + switch (c) + { + case 'r': // hostname:port + rendezvous = getopt.optarg; + break; + case 's': + svr_thrno = ACE_OS::atoi (getopt.optarg); + break; + case 'c': + cli_thrno = ACE_OS::atoi (getopt.optarg); + break; + case 'd': + req_delay = ACE_OS::atoi (getopt.optarg); + break; + case 'i': + cli_conn_no = ACE_OS::atoi (getopt.optarg); + break; + case 'n': + cli_req_no = ACE_OS::atoi (getopt.optarg); + break; + default: + ACE_ERROR ((LM_ERROR, + "Usage: Thread_Pool_Reactor_Test [-r <hostname:port#>]" + "\t[-s <server thr#>] [-c <client thr#>] [-d <delay>]" + "\t[-i <client conn attempt#>]" + "[-n <client request# per conn>]\n")); + break; + } + } +} + +Request_Handler::Request_Handler (ACE_Thread_Manager *thr_mgr) + : ACE_Svc_Handler<ACE_SSL_SOCK_STREAM, ACE_MT_SYNCH> (thr_mgr), + nr_msgs_rcvd_(0) +{ + // Make sure we use TP_Reactor with this class (that's the whole + // point, right?) + this->reactor (ACE_Reactor::instance ()); +} + +int +Request_Handler::handle_input (ACE_HANDLE fd) +{ + ACE_TCHAR buffer[BUFSIZ]; + ACE_TCHAR len = 0; + ssize_t result = this->peer ().recv (&len, sizeof (ACE_TCHAR)); + + if (result > 0 + && this->peer ().recv_n (buffer, len * sizeof (ACE_TCHAR)) + == ACE_static_cast (ssize_t, len * sizeof (ACE_TCHAR))) + { + ++this->nr_msgs_rcvd_; + + ACE_DEBUG ((LM_DEBUG, + "(%t) svr input; fd: 0x%x; input: %s\n", + fd, + buffer)); + if (ACE_OS::strcmp (buffer, ACE_TEXT ("shutdown")) == 0) + ACE_Reactor::end_event_loop (); + return 0; + } + else + ACE_DEBUG ((LM_DEBUG, + "(%t) Request_Handler: 0x%x peer closed (0x%x)\n", + this, fd)); + return -1; +} + +int +Request_Handler::handle_close (ACE_HANDLE fd, ACE_Reactor_Mask) +{ + ACE_DEBUG ((LM_DEBUG, + "(%t) svr close; fd: 0x%x, rcvd %d msgs\n", + fd, + this->nr_msgs_rcvd_)); + if (this->nr_msgs_rcvd_ != cli_req_no) + ACE_ERROR((LM_ERROR, + "(%t) Handler 0x%x: Expected %d messages; got %d\n", + this, + cli_req_no, + this->nr_msgs_rcvd_)); + this->destroy (); + return 0; +} + +static int +reactor_event_hook (void *) +{ + ACE_DEBUG ((LM_DEBUG, + "(%t) handling events ....\n")); + + return 0; +} + +static void * +svr_worker (void *) +{ + // Server thread function. + int result = + ACE_Reactor::instance ()->run_reactor_event_loop (&reactor_event_hook); + + if (result == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "(%t) %p\n", + "Error handling events"), + 0); + + ACE_DEBUG ((LM_DEBUG, + "(%t) I am done handling events. Bye, bye\n")); + + return 0; +} + +static void * +cli_worker (void *arg) +{ + // Client thread function. + ACE_INET_Addr addr (rendezvous); + ACE_SSL_SOCK_Stream stream; + ACE_SSL_SOCK_Connector connect; + ACE_Time_Value delay (0, req_delay); + size_t len = * ACE_reinterpret_cast (ACE_TCHAR *, arg); + + for (size_t i = 0 ; i < cli_conn_no; i++) + { + if (connect.connect (stream, addr) < 0) + { + ACE_ERROR ((LM_ERROR, + "(%t) %p\n", + "connect")); + continue; + } + + for (size_t j = 0; j < cli_req_no; j++) + { + ACE_DEBUG ((LM_DEBUG, + "(%t) conn_worker handle 0x%x, req %d\n", + stream.get_handle (), + j+1)); + if (stream.send_n (arg, + (len + 1) * sizeof (ACE_TCHAR)) == -1) + { + ACE_ERROR ((LM_ERROR, + "(%t) %p\n", + "send_n")); + continue; + } + ACE_OS::sleep (delay); + } + + stream.close (); + } + + return 0; +} + +static void * +worker (void *) +{ + ACE_OS::sleep (3); + const ACE_TCHAR *msg = ACE_TEXT ("Message from Connection worker"); + ACE_TCHAR buf [BUFSIZ]; + buf[0] = ACE_OS::strlen (msg) + 1; + ACE_OS::strcpy (&buf[1], msg); + + ACE_INET_Addr addr (rendezvous); + + ACE_DEBUG((LM_DEBUG, + "(%t) Spawning %d client threads...\n", + cli_thrno)); + int grp = ACE_Thread_Manager::instance ()->spawn_n (cli_thrno, + &cli_worker, + buf); + ACE_ASSERT (grp != -1); + + ACE_Thread_Manager::instance ()->wait_grp (grp); + + ACE_DEBUG ((LM_DEBUG, + "(%t) Client threads done; shutting down...\n")); + ACE_SSL_SOCK_Stream stream; + ACE_SSL_SOCK_Connector connect; + + if (connect.connect (stream, addr) == -1) + ACE_ERROR ((LM_ERROR, + "(%t) %p Error while connecting\n", + "connect")); + + const ACE_TCHAR *sbuf = ACE_TEXT ("\011shutdown"); + + ACE_DEBUG ((LM_DEBUG, + "shutdown stream handle = %x\n", + stream.get_handle ())); + + if (stream.send_n (sbuf, (ACE_OS::strlen (sbuf) + 1) * sizeof (ACE_TCHAR)) == -1) + ACE_ERROR ((LM_ERROR, + "(%t) %p\n", + "send_n")); + + stream.close (); + + return 0; +} + +int +main (int argc, ACE_TCHAR *argv[]) +{ + ACE_START_TEST (ACE_TEXT ("Thread_Pool_Reactor_SSL_Test")); + + ACE_SSL_Context *context = ACE_SSL_Context::instance (); + context->certificate (ACE_TEXT ("dummy.pem"), SSL_FILETYPE_PEM); + context->private_key (ACE_TEXT ("key.pem"), SSL_FILETYPE_PEM); + + parse_arg (argc, argv); + + // Changed the default + ACE_TP_Reactor sr; + ACE_Reactor new_reactor (&sr); + ACE_Reactor::instance (&new_reactor); + + ACCEPTOR acceptor; + ACE_INET_Addr accept_addr (rendezvous); + + if (acceptor.open (accept_addr) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("open")), + 1); + + ACE_DEBUG((LM_DEBUG, + ACE_TEXT ("(%t) Spawning %d server threads...\n"), + svr_thrno)); + ACE_Thread_Manager::instance ()->spawn_n (svr_thrno, + svr_worker); + ACE_Thread_Manager::instance ()->spawn (worker); + + ACE_Thread_Manager::instance ()->wait (); + + ACE_END_TEST; + return 0; +} + +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) +template class ACE_Accept_Strategy<Request_Handler, ACE_SSL_SOCK_ACCEPTOR>; +template class ACE_Concurrency_Strategy<Request_Handler>; +template class ACE_Creation_Strategy<Request_Handler>; +template class ACE_Scheduling_Strategy<Request_Handler>; +template class ACE_Acceptor<Request_Handler, ACE_SSL_SOCK_ACCEPTOR>; +template class ACE_Strategy_Acceptor<Request_Handler, ACE_SSL_SOCK_ACCEPTOR>; +template class ACE_Svc_Handler<ACE_SSL_SOCK_STREAM, ACE_MT_SYNCH>; +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) +#pragma instantiate ACE_Accept_Strategy<Request_Handler, ACE_SSL_SOCK_ACCEPTOR> +#pragma instantiate ACE_Concurrency_Strategy<Request_Handler> +#pragma instantiate ACE_Creation_Strategy<Request_Handler> +#pragma instantiate ACE_Scheduling_Strategy<Request_Handler> +#pragma instantiate ACE_Acceptor<Request_Handler, ACE_SSL_SOCK_ACCEPTOR> +#pragma instantiate ACE_Strategy_Acceptor<Request_Handler, ACE_SSL_SOCK_ACCEPTOR> +#pragma instantiate ACE_Svc_Handler<ACE_SSL_SOCK_STREAM, ACE_MT_SYNCH> +#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ + +#else +int +main (int, ACE_TCHAR *[]) +{ + ACE_START_TEST (ACE_TEXT ("Thread_Pool_Reactor_SSL_Test")); + + ACE_ERROR ((LM_INFO, + "threads not supported on this platform\n")); + + ACE_END_TEST; + return 0; +} +#endif /* ACE_HAS_THREADS */ diff --git a/tests/SSL/Thread_Pool_Reactor_SSL_Test.h b/tests/SSL/Thread_Pool_Reactor_SSL_Test.h new file mode 100644 index 00000000000..76b07092bcf --- /dev/null +++ b/tests/SSL/Thread_Pool_Reactor_SSL_Test.h @@ -0,0 +1,51 @@ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// tests/SSL +// +// = FILENAME +// Thread_Pool_Reactor_Test_SSL.h +// +// = DESCRIPTION +// This class gets its own header file to work around AIX C++ +// compiler "features" related to template instantiation... It is +// only used by Thread_Pool_Reactor_Test_SSL.cpp. +// +// = AUTHOR +// Irfan Pyarali <irfan@cs.wustl.edu> +// Nanbor Wang <nanbor@cs.wustl.edu> +// +// ============================================================================ + +#ifndef ACE_TESTS_THREAD_POOL_REACTOR_TEST_SSL_H +#define ACE_TESTS_THREAD_POOL_REACTOR_TEST_SSL_H + +#include "ace/SSL/SSL_SOCK_Stream.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Svc_Handler.h" +#include "ace/Synch.h" + +class Request_Handler : public ACE_Svc_Handler<ACE_SSL_SOCK_STREAM, + ACE_MT_SYNCH> +{ + // = TITLE + // This class is the Svc_Handler used by <Acceptor>. +public: + Request_Handler (ACE_Thread_Manager *tm = 0); + // The default constructor makes sure the right reactor is used. + +protected: + virtual int handle_input (ACE_HANDLE fd = ACE_INVALID_HANDLE); + virtual int handle_close (ACE_HANDLE fd, ACE_Reactor_Mask = 0); + +private: + size_t nr_msgs_rcvd_; +}; + +#endif /* ACE_TESTS_THREAD_POOL_REACTOR_TEST_SSL_H */ diff --git a/tests/SSL/dummy.pem b/tests/SSL/dummy.pem new file mode 100644 index 00000000000..d631a33b956 --- /dev/null +++ b/tests/SSL/dummy.pem @@ -0,0 +1,15 @@ +-----BEGIN CERTIFICATE----- +MIICaTCCAdICAQAwDQYJKoZIhvcNAQEEBQAwcjELMAkGA1UEBhMCVVMxCzAJBgNV +BAgTAkNBMQ8wDQYDVQQHEwZJcnZpbmUxDDAKBgNVBAoTA09DSTEMMAoGA1UECxMD +VEFPMREwDwYDVQQDEwhwcml5YW5rYTEWMBQGCSqGSIb3DQEJARYHcGdvbnRsYTAe +Fw0wMTAzMjkwNDM4NDZaFw0wMTA0MjgwNDM4NDZaMIGHMQswCQYDVQQGEwJVUzEL +MAkGA1UECBMCQ0ExDzANBgNVBAcTBklydmluZTEdMBsGA1UEChMUT2JqZWN0IENv +bXB1dGluZyBJbmMxEDAOBgNVBAsTB09DSStUQU8xETAPBgNVBAMTCHByaXlhbmth +MRYwFAYJKoZIhvcNAQkBFgdwZ29udGxhMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB +iQKBgQClC6z/bX1JHF1Hg06NCnBmsikEjViEdJFuqLOH3rXSGbm+2Eo+IO4dHlFS +u6+Ntk4olBZTuf0DqzyEgrOiN7cnKXpxJzb1cwCmVkvDQISMygf4o66+CHtF8o8Z +Sbi9F5u9W+MILaoCexEIVZqfHffcGxvm5O2MorBSQNka3NcC3wIDAQABMA0GCSqG +SIb3DQEBBAUAA4GBADuKX6kllE2sNdQYMbSzt5C/lcpgcsK0BR6L01cQA95b5TvL +HsKMeeeRj2npR4EPXY2gqgWTrKHZvf01aoKE5LuyzSQ+qfFMuEfo7+p9SYIuIrLD +5+J0wOwN0R0YZAEY5gCAqRGw26dwWDai+PASPsx0YXV1y9jBB1FFtUFgrpR8 +-----END CERTIFICATE----- diff --git a/tests/SSL/key.pem b/tests/SSL/key.pem new file mode 100644 index 00000000000..54ff8f0f488 --- /dev/null +++ b/tests/SSL/key.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXAIBAAKBgQClC6z/bX1JHF1Hg06NCnBmsikEjViEdJFuqLOH3rXSGbm+2Eo+ +IO4dHlFSu6+Ntk4olBZTuf0DqzyEgrOiN7cnKXpxJzb1cwCmVkvDQISMygf4o66+ +CHtF8o8ZSbi9F5u9W+MILaoCexEIVZqfHffcGxvm5O2MorBSQNka3NcC3wIDAQAB +AoGALYq/PexUeewdwTH2ZuzOf0gCEYN/PW19A/ABOii2OzdmDcdZFTO5AMfw4Mdx +dcUsY/4Y+xmDO5Pwqw/1yXleTDqvEKCgIEHN4NWnYYSiZOy3LBzQ8XaMZ7/2PCqc +s4EtesuRB2kZ7PH2R1vJfyGIxZPaO5MOFbs3QFnpBUjqOmECQQDQCYgnBcshCEro +gsrTjxtZiVHjmXEo0Uo2m4CBQW1PLJmmUXBzivGkVFfhjKULjwvso3BePfmzy9wP +7YFjVXN9AkEAyxjBXi2kYCcXfGQiNuIrLkyVXeGR2YWnhzS2nL1TjNngmCBbnj48 +qvoqOUQgFK0AeTe/x7lb4Cf24ejWF5vmiwJALensorAkpKWv4qD7IrXy00/7QsAa +uWd3eZXYRq6p8U9mmc5fgyCnNB1pR95CjsqDVza7FhGXipbzepBwffveAQJBAMKc +mxYyqDMW4nNoxDxRJs17xxkpwAdvAiQWB/JTnQ737DX5s7EDtECl7PXo6NDHIhAF +srigToCR6wl4gkYnNpcCQHmlfa9Duf3VJI/XeHE9ZU8vS4qgx0Ikfh01xCqWlsaq +nPRmtfktt4P8gxlryZCEPpRs9l/XwQY6tnpHr5EmV2Y= +-----END RSA PRIVATE KEY----- |