[complement-svn] SF.net SVN: complement:[1977] trunk/complement/explore/lib/sockios/ut
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2008-10-13 10:39:16
|
Revision: 1977 http://complement.svn.sourceforge.net/complement/?rev=1977&view=rev Author: complement Date: 2008-10-13 10:39:06 +0000 (Mon, 13 Oct 2008) Log Message: ----------- test for trail-of-data with client and server in different processes Result negative: as in case of the single process for client and server, sometimes I can't read trailing data. Further investigation required. Allow srv_sigpipe test: it pass at fighter. disconnect test fail and lead to deadlock. read0 (i.e. test with SIGCHLD signal on read) pass at fighter. Modified Paths: -------------- trunk/complement/explore/lib/sockios/ut/sockios2_test.cc trunk/complement/explore/lib/sockios/ut/sockios2_test.h trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc Modified: trunk/complement/explore/lib/sockios/ut/sockios2_test.cc =================================================================== --- trunk/complement/explore/lib/sockios/ut/sockios2_test.cc 2008-10-13 10:38:22 UTC (rev 1976) +++ trunk/complement/explore/lib/sockios/ut/sockios2_test.cc 2008-10-13 10:39:06 UTC (rev 1977) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/10/08 22:42:20 yeti> +// -*- C++ -*- Time-stamp: <08/10/09 01:43:37 ptr> /* * @@ -440,6 +440,26 @@ return EXAM_RESULT; } + +/* + * If server and client both in the same process (sure?), server can + * see signal about close client socket _before_ it receive the rest of data + * (tcp stack implemenation dependent?). + * So sockios2_test::processor_core_income_data may not fill line + * with "Hello, world!". + * + * But if server and client situated in different processes, server will see + * FYN _after_ it read all data. + * + * Tests processor_core_income_data and income_data (below) are the same, + * except first has client and server in the same process, while second + * has server in child process. See commented line: + * // EXAM_CHECK( worker::line == "Hello, world!" ); // <-- may fail + * in the first test. + * + * Good text above. But wrong. + */ + int EXAM_IMPL(sockios2_test::processor_core_income_data) { // check after sockstream was closed, i.e. ensure, that all data available @@ -474,6 +494,88 @@ return EXAM_RESULT; } +int EXAM_IMPL(sockios2_test::income_data) +{ + const char fname[] = "/tmp/sockios2_test.shm"; + + // worker::lock.lock(); + worker::visits = 0; + worker::line = ""; + worker::rd = 0; + // worker::lock.unlock(); + + try { + xmt::shm_alloc<0> seg; + seg.allocate( fname, 4096, xmt::shm_base::create | xmt::shm_base::exclusive, 0660 ); + + xmt::allocator_shm<barrier_ip,0> shm; + barrier_ip& b = *new ( shm.allocate( 1 ) ) barrier_ip(); + + try { + + EXAM_CHECK( worker::visits == 0 ); + + this_thread::fork(); + + int res = 0; + { + connect_processor<worker> prss( 2008 ); + + EXAM_CHECK_ASYNC_F( worker::visits == 0, res ); + + b.wait(); // -- align here + + EXAM_CHECK_ASYNC_F( prss.good(), res ); + EXAM_CHECK_ASYNC_F( prss.is_open(), res ); + + { + unique_lock<mutex> lk( worker::lock ); + EXAM_CHECK_ASYNC_F( worker::line_cnd.timed_wait( lk, milliseconds( 500 ), worker::rd_counter1 ), res ); + } + + { + unique_lock<mutex> lksrv( worker::lock ); + EXAM_CHECK_ASYNC_F( worker::cnd.timed_wait( lksrv, milliseconds( 500 ), worker::counter0 ), res ); + } + + EXAM_CHECK_ASYNC_F( worker::line == "Hello, world!", res ); // <-- may fail + } + + exit( res ); + } + catch ( std::tr2::fork_in_parent& child ) { + b.wait(); // -- align here + + { + sockstream s1( "localhost", 2008 ); + + EXAM_CHECK( s1.good() ); + EXAM_CHECK( s1.is_open() ); + + s1 << "Hello, world!" << endl; + } + + int stat = -1; + EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + if ( WIFEXITED(stat) ) { + EXAM_CHECK( WEXITSTATUS(stat) == 0 ); + } else { + EXAM_ERROR( "child interrupted" ); + } + + EXAM_CHECK( worker::visits == 0 ); + } + shm.deallocate( &b ); + seg.deallocate(); + unlink( fname ); + } + catch ( xmt::shm_bad_alloc& err ) { + EXAM_ERROR( err.what() ); + } + + return EXAM_RESULT; +} + class srv_reader { public: @@ -550,7 +652,7 @@ s.rdbuf()->shutdown( sock_base::stop_in | sock_base::stop_out ); - // s.close(); // should work with this line commened, but sorry + s.close(); // should work with this line commened, but sorry int stat = -1; EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); @@ -696,7 +798,7 @@ int EXAM_IMPL(sockios2_test::srv_sigpipe) { - throw exam::skip_exception(); + // throw exam::skip_exception(); const char fname[] = "/tmp/sockios2_test.shm"; try { @@ -754,9 +856,9 @@ EXAM_CHECK( r.good() ); EXAM_CHECK( r.is_open() ); - for ( int i = 0; i < 64; ++i ) { // give chance for system - std::tr2::this_thread::yield(); - } + // for ( int i = 0; i < 64; ++i ) { // give chance for system + // std::tr2::this_thread::yield(); + // } } shm.deallocate( &b ); seg.deallocate(); @@ -779,16 +881,16 @@ int n = 1; - cerr << "align 3\n"; + // cerr << "align 3\n"; bb->wait(); // <-- align 3 - cerr << "align 3 pass\n"; + // cerr << "align 3 pass\n"; s.write( (const char *)&n, sizeof( int ) ).flush(); EXAM_CHECK_ASYNC( s.good() ); } ~interrupted_writer() - { cerr << "~~\n"; } + { /* cerr << "~~\n"; */ } void connect( sockstream& s ) { } @@ -798,12 +900,12 @@ sockstream s( "localhost", 2008 ); int buff = 0; - cerr << "align 2" << endl; + // cerr << "align 2" << endl; b->wait(); // <-- align 2 - cerr << "align 2 pass" << endl; + // cerr << "align 2 pass" << endl; EXAM_CHECK_ASYNC( s.read( (char *)&buff, sizeof(int) ).good() ); // <---- key line - cerr << "read pass" << endl; + // cerr << "read pass" << endl; EXAM_CHECK_ASYNC( buff == 1 ); } @@ -835,12 +937,12 @@ bb.wait(); // <-- align 2 - cerr << "system" << endl; + // cerr << "system" << endl; system( "echo > /dev/null" ); // <------ key line - cerr << "after system" << endl; + // cerr << "after system" << endl; bnew.wait(); // <-- align 3 - cerr << "after align 3" << endl; + // cerr << "after align 3" << endl; t.join(); Modified: trunk/complement/explore/lib/sockios/ut/sockios2_test.h =================================================================== --- trunk/complement/explore/lib/sockios/ut/sockios2_test.h 2008-10-13 10:38:22 UTC (rev 1976) +++ trunk/complement/explore/lib/sockios/ut/sockios2_test.h 2008-10-13 10:39:06 UTC (rev 1977) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/10/06 13:28:39 ptr> +// -*- C++ -*- Time-stamp: <08/10/09 00:36:27 ptr> /* * @@ -28,6 +28,7 @@ int EXAM_DECL(processor_core_getline); int EXAM_DECL(processor_core_income_data); int EXAM_DECL(fork); + int EXAM_DECL(income_data); int EXAM_DECL(srv_sigpipe); int EXAM_DECL(read0); }; Modified: trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc =================================================================== --- trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc 2008-10-13 10:38:22 UTC (rev 1976) +++ trunk/complement/explore/lib/sockios/ut/sockios_test_suite.cc 2008-10-13 10:39:06 UTC (rev 1977) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/10/06 13:30:03 ptr> +// -*- C++ -*- Time-stamp: <08/10/09 00:39:27 ptr> /* * @@ -32,7 +32,7 @@ int main( int argc, const char** argv ) { - exam::test_suite::test_case_type tc[4]; + exam::test_suite::test_case_type tc[5]; exam::test_suite t( "libsockios test" ); @@ -79,7 +79,7 @@ t.add( &sockios2_test::read0, test2, "sockios2_test::read0", t.add( &sockios2_test::srv_sigpipe, test2, "sockios2_test::srv_sigpipe", - t.add( &sockios2_test::fork, test2, "sockios2_test::fork", + tc[4] = t.add( &sockios2_test::fork, test2, "sockios2_test::fork", tc[3] = t.add( &sockios2_test::processor_core_income_data, test2, "all data available after sockstream was closed", t.add( &sockios2_test::processor_core_getline, test2, "check income data before sockstream was closed", t.add( &sockios2_test::processor_core_two_local, test2, "two local connects to connection processor", @@ -88,6 +88,7 @@ t.add( &sockios2_test::srv_core, test2, "sockios2_test::srv_core" ) ) ) ) ) ) ) ) ); t.add( &sockios2_test::disconnect, test2, "sockios2_test::disconnect", tc[3] ); + t.add( &sockios2_test::income_data, test2, "all data available after sockstream was closed, different processes", tc[4] ); Opts opts; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |