[complement-svn] SF.net SVN: complement: [1486] trunk/complement/explore/test/sockios
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-01-30 15:09:58
|
Revision: 1486 http://svn.sourceforge.net/complement/?rev=1486&view=rev Author: complement Date: 2007-01-30 07:09:56 -0800 (Tue, 30 Jan 2007) Log Message: ----------- use shared memory segment for sync (named objects, if required); remove delays and reduce amount of threads for some tests, to reduce test suite time; test for problem: two 'connect', but no 'close' on closed sockstream Modified Paths: -------------- trunk/complement/explore/test/sockios/client-wc.cc trunk/complement/explore/test/sockios/read0_on_exec.cc trunk/complement/explore/test/sockios/sockios_test.cc trunk/complement/explore/test/sockios/sockios_test.h trunk/complement/explore/test/sockios/sockios_test_suite.cc trunk/complement/explore/test/sockios/unit_test.cc Modified: trunk/complement/explore/test/sockios/client-wc.cc =================================================================== --- trunk/complement/explore/test/sockios/client-wc.cc 2007-01-30 15:06:35 UTC (rev 1485) +++ trunk/complement/explore/test/sockios/client-wc.cc 2007-01-30 15:09:56 UTC (rev 1486) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/15 10:49:16 ptr> +// -*- C++ -*- Time-stamp: <07/01/29 17:48:29 ptr> /* * Copyright (c) 2004, 2006 @@ -28,6 +28,7 @@ Suspicious processing with FreeBSD and OpenBSD servers. */ +static Condition cnd_close; class Srv // { @@ -42,10 +43,11 @@ { s << "hello" << endl; - xmt::delay( xmt::timespec( 1, 0 ) ); + // xmt::delay( xmt::timespec( 1, 0 ) ); s.close(); // ::shutdown( s.rdbuf()->fd(), 2 ); + cnd_close.set( true ); } void Srv::connect( std::sockstream& ) @@ -104,7 +106,7 @@ BOOST_CHECK( buf == "hello" ); pr_lock.unlock(); - xmt::delay( xmt::timespec( 5, 0 ) ); + // xmt::delay( xmt::timespec( 5, 0 ) ); // sock << 'a' << endl; @@ -113,6 +115,8 @@ and no other solution! (another solution is nonblock sockets or aio, but this is another story) */ + cnd_close.try_wait(); + char a; sock.read( &a, 1 ); @@ -132,6 +136,7 @@ void srv_close_connection_test() { Thread srv( server_proc ); + cnd_close.set( false ); Thread client( client_proc ); client.join(); Modified: trunk/complement/explore/test/sockios/read0_on_exec.cc =================================================================== --- trunk/complement/explore/test/sockios/read0_on_exec.cc 2007-01-30 15:06:35 UTC (rev 1485) +++ trunk/complement/explore/test/sockios/read0_on_exec.cc 2007-01-30 15:09:56 UTC (rev 1486) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <06/12/15 10:50:48 ptr> +// -*- C++ -*- Time-stamp: <07/01/29 19:17:54 ptr> /* - * Copyright (c) 2006 + * Copyright (c) 2006, 2007 * Petr Ovtchenkov * * Licensed under the Academic Free License Version 3.0 @@ -21,7 +21,7 @@ #include <sys/types.h> #include <sys/wait.h> -#include <sys/shm.h> +#include <mt/shm.h> using namespace std; using namespace xmt; @@ -122,63 +122,61 @@ void test_read0() { - shmid_ds ds; - int id = shmget( 5000, 1024, IPC_CREAT | IPC_EXCL | 0600 ); - if ( id == -1 ) { - cerr << "Error on shmget" << endl; - } - if ( shmctl( id, IPC_STAT, &ds ) == -1 ) { - cerr << "Error on shmctl" << endl; - } - void *buf = shmat( id, 0, 0 ); - if ( buf == reinterpret_cast<void *>(-1) ) { - cerr << "Error on shmat" << endl; - } + const char fname[] = "/tmp/sockios_test.shm"; + try { + xmt::shm_alloc<0> seg; - Semaphore& sem = *new( buf ) Semaphore( 1, true ); + seg.allocate( fname, 4*4096, xmt::shm_base::create | xmt::shm_base::exclusive, 0600 ); + // xmt::shm_name_mgr<0>& nm = seg.name_mgr(); - try { - // cerr << "** 1" << endl; - // cndf.set( false ); + xmt::allocator_shm<xmt::__Condition<true>,0> shm; - xmt::fork(); // <---- key line - sem.wait(); // wait server for listen us - // cerr << "** 2" << endl; + xmt::__Condition<true>& fcnd = *new ( shm.allocate( 1 ) ) xmt::__Condition<true>(); + // nm.named( fcnd, 1 ); + fcnd.set( false ); - Condition cnd; - cnd.set( false ); + try { + xmt::fork(); // <---- key line + fcnd.try_wait(); // wait server for listen us - xmt::Thread thr( thread_entry, &cnd ); + Condition cnd; + cnd.set( false ); - cnd.try_wait(); // wait for read call + xmt::Thread thr( thread_entry, &cnd ); - delay( xmt::timespec(1,0) ); + cnd.try_wait(); // wait for read call - // cerr << "system" << endl; - system( "echo > /dev/null" ); // <------ key line - // cerr << "after system" << endl; + delay( xmt::timespec(1,0) ); - thr.join(); - // cerr << "exit child" << endl; - exit( 0 ); - } - catch ( xmt::fork_in_parent& child ) { - // cerr << "** 3" << endl; - sockmgr_stream_MP<ConnectionProcessor5> srv( ::port ); // start server + // cerr << "system" << endl; + system( "echo > /dev/null" ); // <------ key line + // cerr << "after system" << endl; - // cndf.set( true ); // server wait, I hope - sem.post(); - int stat; - // cerr << "wait " << child.pid() << endl; - waitpid( child.pid(), &stat, 0 ); - // cerr << "close all" << endl; - srv.close(); - srv.wait(); - } - (&sem)->~Semaphore(); + thr.join(); + // cerr << "exit child" << endl; + exit( 0 ); + } + catch ( xmt::fork_in_parent& child ) { + // cerr << "** 3" << endl; + sockmgr_stream_MP<ConnectionProcessor5> srv( ::port ); // start server - shmdt( buf ); - shmctl( id, IPC_RMID, &ds ); + fcnd.set( true ); + + int stat; + waitpid( child.pid(), &stat, 0 ); + srv.close(); + srv.wait(); + } + + (&fcnd)->~__Condition<true>(); + shm.deallocate( &fcnd, 1 ); + + seg.deallocate(); + unlink( fname ); + } + catch ( xmt::shm_bad_alloc& err ) { + BOOST_CHECK_MESSAGE( false, "error report: " << err.what() ); + } } class ConnectionProcessor6 // dummy variant @@ -190,7 +188,7 @@ void close(); }; -static Semaphore *sem2; +static __Semaphore<true> *sem2; ConnectionProcessor6::ConnectionProcessor6( std::sockstream& s ) { @@ -216,55 +214,53 @@ void test_read0_srv() { - shmid_ds ds; - int id = shmget( 5000, 1024, IPC_CREAT | IPC_EXCL | 0600 ); - if ( id == -1 ) { - cerr << "Error on shmget" << endl; - } - if ( shmctl( id, IPC_STAT, &ds ) == -1 ) { - cerr << "Error on shmctl" << endl; - } - void *buf = shmat( id, 0, 0 ); - if ( buf == reinterpret_cast<void *>(-1) ) { - cerr << "Error on shmat" << endl; - } + const char fname[] = "/tmp/sockios_test.shm"; + try { + xmt::shm_alloc<0> seg; - sem2 = new( buf ) Semaphore( 2, true ); + seg.allocate( fname, 4*4096, xmt::shm_base::create | xmt::shm_base::exclusive, 0600 ); + xmt::allocator_shm<xmt::__Semaphore<true>,0> shm; - sockmgr_stream_MP<ConnectionProcessor6> srv( ::port ); + sem2 = new ( shm.allocate( 1 ) ) xmt::__Semaphore<true>( 2 ); - { - // It should work as before system call... - sockstream s( "localhost", ::port ); + sockmgr_stream_MP<ConnectionProcessor6> srv( ::port ); - s << "1" << endl; + { + // It should work as before system call... + sockstream s( "localhost", ::port ); - BOOST_CHECK( s.good() ); + s << "1" << endl; - sem2->wait(); - } + BOOST_CHECK( s.good() ); - system( "echo > /dev/null" ); // <------ key line + sem2->wait(); + } - { - // ... as after system call. - sockstream s( "localhost", ::port ); + system( "echo > /dev/null" ); // <------ key line - s << "1" << endl; + { + // ... as after system call. + sockstream s( "localhost", ::port ); - BOOST_CHECK( s.good() ); + s << "1" << endl; - sem2->wait(); - } + BOOST_CHECK( s.good() ); - BOOST_CHECK( srv.good() ); // server must correctly process interrupt during system call + sem2->wait(); + } - srv.close(); + BOOST_CHECK( srv.good() ); // server must correctly process interrupt during system call - srv.wait(); + srv.close(); - sem2->~Semaphore(); + srv.wait(); - shmdt( buf ); - shmctl( id, IPC_RMID, &ds ); + sem2->~__Semaphore<true>(); + shm.deallocate( sem2, 1 ); + seg.deallocate(); + unlink( fname ); + } + catch ( xmt::shm_bad_alloc& err ) { + BOOST_CHECK_MESSAGE( false, "error report: " << err.what() ); + } } Modified: trunk/complement/explore/test/sockios/sockios_test.cc =================================================================== --- trunk/complement/explore/test/sockios/sockios_test.cc 2007-01-30 15:06:35 UTC (rev 1485) +++ trunk/complement/explore/test/sockios/sockios_test.cc 2007-01-30 15:09:56 UTC (rev 1486) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/18 18:51:17 ptr> +// -*- C++ -*- Time-stamp: <07/01/30 11:45:52 ptr> /* * @@ -21,7 +21,9 @@ #include <arpa/inet.h> -#include <sys/shm.h> +#include <mt/shm.h> + +// #include <sys/shm.h> #include <sys/wait.h> #include <signal.h> @@ -276,79 +278,193 @@ void sockios_test::sigpipe() { - shmid_ds ds; - int id = shmget( 5000, 1024, IPC_CREAT | IPC_EXCL | 0600 ); - BOOST_REQUIRE( id != -1 ); - // if ( id == -1 ) { - // cerr << "Error on shmget" << endl; - // } - BOOST_REQUIRE( shmctl( id, IPC_STAT, &ds ) != -1 ); - // if ( shmctl( id, IPC_STAT, &ds ) == -1 ) { - // cerr << "Error on shmctl" << endl; - // } - void *buf = shmat( id, 0, 0 ); - BOOST_REQUIRE( buf != reinterpret_cast<void *>(-1) ); - // if ( buf == reinterpret_cast<void *>(-1) ) { - // cerr << "Error on shmat" << endl; - // } + const char fname[] = "/tmp/sockios_test.shm"; + enum { + in_Child_Condition = 1, + threads_Started_Condition = 2 + }; + try { + xmt::shm_alloc<0> seg; - xmt::__Condition<true>& fcnd = *new( buf ) xmt::__Condition<true>(); - fcnd.set( false ); - xmt::__Condition<true>& tcnd = *new( (char *)buf + sizeof(xmt::__Condition<true>) ) xmt::__Condition<true>(); - tcnd.set( false ); + seg.allocate( fname, 4*4096, xmt::shm_base::create | xmt::shm_base::exclusive, 0600 ); + xmt::shm_name_mgr<0>& nm = seg.name_mgr(); - try { - xmt::fork(); + xmt::allocator_shm<xmt::__Condition<true>,0> shm; - fcnd.try_wait(); + xmt::__Condition<true>& fcnd = *new ( shm.allocate( 1 ) ) xmt::__Condition<true>(); + nm.named( fcnd, in_Child_Condition ); + fcnd.set( false ); + xmt::__Condition<true>& tcnd = *new ( shm.allocate( 1 ) ) xmt::__Condition<true>(); + nm.named( tcnd, threads_Started_Condition ); + tcnd.set( false ); + try { - /* - * This process will be killed, - * so I don't care about safe termination. - */ - xmt::Thread *th1 = new xmt::Thread( client_thr ); - for ( int i = 0; i < 10; ++i ) { - new xmt::Thread( client_thr ); - new xmt::Thread( client_thr ); - new xmt::Thread( client_thr ); - new xmt::Thread( client_thr ); + xmt::fork(); + + fcnd.try_wait(); + + try { + /* + * This process will be killed, + * so I don't care about safe termination. + */ + xmt::Thread *th1 = new xmt::Thread( client_thr ); + for ( int i = 0; i < /* 10 */ 2; ++i ) { + new xmt::Thread( client_thr ); + new xmt::Thread( client_thr ); + new xmt::Thread( client_thr ); + new xmt::Thread( client_thr ); + } + + xmt::delay( xmt::timespec(1,0) ); + + tcnd.set( true ); + + th1->join(); + + exit( 0 ); } + catch ( ... ) { + } + } + catch ( xmt::fork_in_parent& child ) { + try { + xmt::signal_handler( SIGPIPE, &sigpipe_handler ); + sockmgr_stream_MP<loader> srv( port ); - xmt::delay( xmt::timespec(5,0) ); + fcnd.set( true ); - tcnd.set( true ); + tcnd.try_wait(); - th1->join(); + kill( child.pid(), SIGTERM ); - exit( 0 ); + int stat; + waitpid( child.pid(), &stat, 0 ); + + srv.close(); + srv.wait(); + } + catch ( ... ) { + } } - catch ( ... ) { - } + + (&tcnd)->~__Condition<true>(); + shm.deallocate( &tcnd, 1 ); + (&fcnd)->~__Condition<true>(); + shm.deallocate( &fcnd, 1 ); + + seg.deallocate(); + unlink( fname ); } - catch ( xmt::fork_in_parent& child ) { + catch ( xmt::shm_bad_alloc& err ) { + BOOST_CHECK_MESSAGE( false, "error report: " << err.what() ); + } +} + +class long_msg_processor // +{ + public: + long_msg_processor( std::sockstream& ); + + void connect( std::sockstream& ); + void close(); + + static xmt::__Condition<true> *cnd; +}; + +long_msg_processor::long_msg_processor( std::sockstream& ) +{ + cerr << "long_msg_processor::long_msg_processor" << endl; +} + +void long_msg_processor::connect( std::sockstream& s ) +{ + cerr << "long_msg_processor::connect" << endl; + + string l; + + getline( s, l ); + + cerr << "Is good? " << s.good() << endl; +} + +void long_msg_processor::close() +{ + cerr << "long_msg_processor::close()" << endl; + cnd->set( true ); +} + +xmt::__Condition<true> *long_msg_processor::cnd; + +void sockios_test::long_msg_test() +{ + const char fname[] = "/tmp/sockios_test.shm"; + try { + xmt::shm_alloc<0> seg; + + seg.allocate( fname, 4*4096, xmt::shm_base::create | xmt::shm_base::exclusive, 0600 ); + xmt::shm_name_mgr<0>& nm = seg.name_mgr(); + + xmt::allocator_shm<xmt::__Condition<true>,0> shm; + + xmt::__Condition<true>& fcnd = *new ( shm.allocate( 1 ) ) xmt::__Condition<true>(); + fcnd.set( false ); + + xmt::__Condition<true>& srv_cnd = *new ( shm.allocate( 1 ) ) xmt::__Condition<true>(); + srv_cnd.set( false ); + + long_msg_processor::cnd = &srv_cnd; + try { - xmt::signal_handler( SIGPIPE, &sigpipe_handler ); - sockmgr_stream_MP<loader> srv( port ); + xmt::fork(); - fcnd.set( true ); + fcnd.try_wait(); - tcnd.try_wait(); + { + sockstream s( "localhost", port ); - kill( child.pid(), SIGTERM ); + s << "POST /test.php HTTP/1.1\r\n" + << "xmlrequest=<?xml version=\"1.0\"?>\ +<RWRequest><REQUEST domain=\"network\" service=\"ComplexReport\" nocache=\"n\" \ +contact_id=\"1267\" entity=\"1\" filter_entity_id=\"1\" \ +clientName=\"ui.ent\"><ROWS><ROW type=\"group\" priority=\"1\" ref=\"entity_id\" \ +includeascolumn=\"n\"/><ROW type=\"group\" priority=\"2\" \ +ref=\"advertiser_line_item_id\" includeascolumn=\"n\"/><ROW type=\"total\"/></ROWS><COLUMNS><COLUMN \ +ref=\"advertiser_line_item_name\"/><COLUMN ref=\"seller_imps\"/><COLUMN \ +ref=\"seller_clicks\"/><COLUMN ref=\"seller_convs\"/><COLUMN \ +ref=\"click_rate\"/><COLUMN ref=\"conversion_rate\"/><COLUMN ref=\"roi\"/><COLUMN \ +ref=\"network_revenue\"/><COLUMN ref=\"network_gross_cost\"/><COLUMN \ +ref=\"network_gross_profit\"/><COLUMN ref=\"network_revenue_ecpm\"/><COLUMN \ +ref=\"network_gross_cost_ecpm\"/><COLUMN \ +ref=\"network_gross_profit_ecpm\"/></COLUMNS><FILTERS><FILTER ref=\"time\" \ +macro=\"yesterday\"/></FILTERS></REQUEST></RWRequest>"; + s.flush(); + } + exit( 0 ); + } + catch ( xmt::fork_in_parent& child ) { + sockmgr_stream_MP<long_msg_processor> srv( port ); + fcnd.set( true ); - int stat; - waitpid( child.pid(), &stat, 0 ); + srv_cnd.try_wait(); srv.close(); srv.wait(); + } - catch ( ... ) { - } + + (&fcnd)->~__Condition<true>(); + shm.deallocate( &fcnd, 1 ); + + (&srv_cnd)->~__Condition<true>(); + shm.deallocate( &srv_cnd, 1 ); + + seg.deallocate(); + unlink( fname ); } + catch ( xmt::shm_bad_alloc& err ) { + BOOST_CHECK_MESSAGE( false, "error report: " << err.what() ); + } - (&fcnd)->~__Condition<true>(); - - shmdt( buf ); - shmctl( id, IPC_RMID, &ds ); } Modified: trunk/complement/explore/test/sockios/sockios_test.h =================================================================== --- trunk/complement/explore/test/sockios/sockios_test.h 2007-01-30 15:06:35 UTC (rev 1485) +++ trunk/complement/explore/test/sockios/sockios_test.h 2007-01-30 15:09:56 UTC (rev 1486) @@ -1,8 +1,8 @@ -// -*- C++ -*- Time-stamp: <06/12/18 16:54:00 ptr> +// -*- C++ -*- Time-stamp: <07/01/30 10:55:51 ptr> /* * - * Copyright (c) 2002, 2003, 2005, 2006 + * Copyright (c) 2002, 2003, 2005, 2006, 2007 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -24,6 +24,7 @@ void ctor_dtor(); void sigpipe(); + void long_msg_test(); }; #endif // __sockios_test_h Modified: trunk/complement/explore/test/sockios/sockios_test_suite.cc =================================================================== --- trunk/complement/explore/test/sockios/sockios_test_suite.cc 2007-01-30 15:06:35 UTC (rev 1485) +++ trunk/complement/explore/test/sockios/sockios_test_suite.cc 2007-01-30 15:09:56 UTC (rev 1486) @@ -1,8 +1,8 @@ -// -*- C++ -*- Time-stamp: <06/12/18 17:10:02 ptr> +// -*- C++ -*- Time-stamp: <07/01/30 10:57:38 ptr> /* * - * Copyright (c) 2002, 2003, 2005, 2006 + * Copyright (c) 2002, 2003, 2005, 2006, 2007 * Petr Ovtchenkov * * Licensed under the Academic Free License version 3.0 @@ -29,6 +29,7 @@ test_case *hostaddr3_tc = BOOST_CLASS_TEST_CASE( &sockios_test::hostaddr_test3, instance ); test_case *ctor_dtor_tc = BOOST_CLASS_TEST_CASE( &sockios_test::ctor_dtor, instance ); test_case *sigpipe_tc = BOOST_CLASS_TEST_CASE( &sockios_test::sigpipe, instance ); + test_case *long_msg_tc = BOOST_CLASS_TEST_CASE( &sockios_test::long_msg_test, instance ); // hostaddr2_tc->depends_on( hostaddr1_tc ); @@ -40,4 +41,5 @@ add( hostaddr3_tc ); add( ctor_dtor_tc ); add( sigpipe_tc ); + add( long_msg_tc ); } Modified: trunk/complement/explore/test/sockios/unit_test.cc =================================================================== --- trunk/complement/explore/test/sockios/unit_test.cc 2007-01-30 15:06:35 UTC (rev 1485) +++ trunk/complement/explore/test/sockios/unit_test.cc 2007-01-30 15:09:56 UTC (rev 1486) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/18 16:41:59 ptr> +// -*- C++ -*- Time-stamp: <07/01/29 19:19:10 ptr> /* * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |