From 441d41fe583765902aa2f9641c0977e295e62be3 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Wed, 26 Nov 2008 13:41:29 +0000 Subject: [PATCH] libt2n: (tomj) added exception handling to every child after fork(). This is needed to make sure no two cppunit tests run at the same time\! --- test/callback.cpp | 156 +++++++++++++++++++++------------- test/cmdgroup.cpp | 32 +++++-- test/comm.cpp | 194 +++++++++++++++++++++++++---------------- test/hello.cpp | 211 ++++++++++++++++++++++++++++----------------- test/newserver.cpp | 36 +++++--- test/reconnect.cpp | 244 ++++++++++++++++++++++++++++++---------------------- test/reentrant.cpp | 3 + test/serialize.cpp | 16 +++- test/simplecmd.cpp | 64 ++++++++++---- test/timeout.cpp | 222 +++++++++++++++++++++++++++++++---------------- test/wrapper.cpp | 79 +++++++++++------- 11 files changed, 781 insertions(+), 476 deletions(-) diff --git a/test/callback.cpp b/test/callback.cpp index 257da83..60c9058 100644 --- a/test/callback.cpp +++ b/test/callback.cpp @@ -83,20 +83,26 @@ class test_callback : public TestFixture case 0: // child { - string data; - // wait till server is up - sleep(1); - + try { - socket_client_connection sc("./socket"); + string data; + // wait till server is up + sleep(1); - sc.write("ABC"); + { + socket_client_connection sc("./socket"); - // wait half a sec - sc.fill_buffer(500000); - sc.get_packet(data); + sc.write("ABC"); - // close the connection + // wait half a sec + sc.fill_buffer(500000); + sc.get_packet(data); + + // close the connection + } + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } // don't call atexit and stuff @@ -142,20 +148,26 @@ class test_callback : public TestFixture case 0: // child { - string data; - // wait till server is up - sleep(1); - + try { - socket_client_connection sc("./socket"); + string data; + // wait till server is up + sleep(1); - sc.write("ABC"); + { + socket_client_connection sc("./socket"); - // wait half a sec - sc.fill_buffer(500000); - sc.get_packet(data); + sc.write("ABC"); + + // wait half a sec + sc.fill_buffer(500000); + sc.get_packet(data); - // close the connection + // close the connection + } + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } // don't call atexit and stuff @@ -201,20 +213,26 @@ class test_callback : public TestFixture case 0: // child { - string data; - // wait till server is up - sleep(1); - + try { - socket_client_connection sc("./socket"); + string data; + // wait till server is up + sleep(1); - sc.write("ABC"); + { + socket_client_connection sc("./socket"); - // wait half a sec - sc.fill_buffer(500000); - sc.get_packet(data); + sc.write("ABC"); - // close the connection + // wait half a sec + sc.fill_buffer(500000); + sc.get_packet(data); + + // close the connection + } + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } // don't call atexit and stuff @@ -263,22 +281,28 @@ class test_callback : public TestFixture case 0: // child { - string data; - // wait till server is up - sleep(1); - + try { - socket_client_connection sc("./socket"); + string data; + // wait till server is up + sleep(1); - sc.write("1"); + { + socket_client_connection sc("./socket"); - // wait half a sec - sc.fill_buffer(500000); - sc.get_packet(data); + sc.write("1"); + + // wait half a sec + sc.fill_buffer(500000); + sc.get_packet(data); - sc.write("2"); + sc.write("2"); - // close the connection + // close the connection + } + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } // don't call atexit and stuff @@ -344,18 +368,25 @@ class test_callback : public TestFixture case 0: // child { - socket_server ss("./socket"); - - // max 3 sec - for (int i=0; i < 3; i++) + try { - ss.fill_buffer(1000000); + socket_server ss("./socket"); - string data; - unsigned int cid; - if(ss.get_packet(data,cid)) - break; + // max 3 sec + for (int i=0; i < 3; i++) + { + ss.fill_buffer(1000000); + + string data; + unsigned int cid; + if(ss.get_packet(data,cid)) + break; + } + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } + // don't call atexit and stuff _exit(0); } @@ -396,18 +427,25 @@ class test_callback : public TestFixture case 0: // child { - socket_server ss("./socket"); - - // max 3 sec - for (int i=0; i < 3; i++) + try { - ss.fill_buffer(1000000); + socket_server ss("./socket"); - string data; - unsigned int cid; - if(ss.get_packet(data,cid)) - break; + // max 3 sec + for (int i=0; i < 3; i++) + { + ss.fill_buffer(1000000); + + string data; + unsigned int cid; + if(ss.get_packet(data,cid)) + break; + } + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } + // don't call atexit and stuff _exit(0); } diff --git a/test/cmdgroup.cpp b/test/cmdgroup.cpp index 314e28d..eee54bf 100644 --- a/test/cmdgroup.cpp +++ b/test/cmdgroup.cpp @@ -193,12 +193,18 @@ class test_cmdgroup : public TestFixture case 0: // child { - socket_server ss("./socket"); - group_command_server cs(ss); + try + { + socket_server ss("./socket"); + group_command_server cs(ss); - // max 10 sec - for (int i=0; i < 10; i++) - cs.handle(1000000); + // max 10 sec + for (int i=0; i < 10; i++) + cs.handle(1000000); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } // don't call atexit and stuff _exit(0); @@ -234,12 +240,18 @@ class test_cmdgroup : public TestFixture case 0: // child { - socket_server ss("./socket"); - group_command_server cs(ss); + try + { + socket_server ss("./socket"); + group_command_server cs(ss); - // max 10 sec - for (int i=0; i < 10; i++) - cs.handle(1000000); + // max 10 sec + for (int i=0; i < 10; i++) + cs.handle(1000000); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } // don't call atexit and stuff _exit(0); diff --git a/test/comm.cpp b/test/comm.cpp index 7bd8b24..47ca385 100644 --- a/test/comm.cpp +++ b/test/comm.cpp @@ -69,10 +69,17 @@ class test_comm : public TestFixture case 0: // child { - // wait till server is up - sleep(1); - socket_client_connection sc("./socket"); - sc.write("hello"); + try + { + // wait till server is up + sleep(1); + socket_client_connection sc("./socket"); + sc.write("hello"); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } + // don't call atexit and stuff _exit(0); } @@ -109,32 +116,39 @@ class test_comm : public TestFixture case 0: // child { - socket_server ss("./socket"); - ss.set_logging(&cerr,debug); - - time_t t0 = time(NULL); - - // max 10 sec - while (time(NULL) < t0 + 10 ) + try { - ss.fill_buffer(1000000); + socket_server ss("./socket"); + ss.set_logging(&cerr,debug); - string data; - unsigned int cid; + time_t t0 = time(NULL); - if(ss.get_packet(data,cid)) + // max 10 sec + while (time(NULL) < t0 + 10 ) { - server_connection* con=ss.get_connection(cid); + ss.fill_buffer(1000000); - if (data=="QUIT") - break; + string data; + unsigned int cid; - if (data=="ABC") - con->write("DEF"); - else - con->write("xyz"); + if(ss.get_packet(data,cid)) + { + server_connection* con=ss.get_connection(cid); + + if (data=="QUIT") + break; + + if (data=="ABC") + con->write("DEF"); + else + con->write("xyz"); + } } + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } + // don't call atexit and stuff _exit(0); } @@ -179,30 +193,37 @@ class test_comm : public TestFixture case 0: // child { - socket_server ss("./socket"); - ss.set_logging(&cerr,debug); - - time_t t0 = time(NULL); - - // max 10 sec - while (time(NULL) < t0 + 10 ) + try { - ss.fill_buffer(1000000); + socket_server ss("./socket"); + ss.set_logging(&cerr,debug); - string data; - unsigned int cid; + time_t t0 = time(NULL); - if(ss.get_packet(data,cid)) + // max 10 sec + while (time(NULL) < t0 + 10 ) { - server_connection* con=ss.get_connection(cid); + ss.fill_buffer(1000000); - if (data=="QUIT") - break; + string data; + unsigned int cid; - con->write(string().insert(0,100*1024,'y')); + if(ss.get_packet(data,cid)) + { + server_connection* con=ss.get_connection(cid); + + if (data=="QUIT") + break; + + con->write(string().insert(0,100*1024,'y')); + } } + std::cerr << "child: OVER" << std::endl; + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } - std::cerr << "child: OVER" << std::endl; + // don't call atexit and stuff _exit(0); } @@ -242,10 +263,17 @@ class test_comm : public TestFixture case 0: // child { - // wait till server is up - sleep(1); - socket_client_connection sc(6666); - sc.write("hello"); + try + { + // wait till server is up + sleep(1); + socket_client_connection sc(6666); + sc.write("hello"); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } + // don't call atexit and stuff _exit(0); } @@ -282,31 +310,37 @@ class test_comm : public TestFixture case 0: // child { - socket_server ss(6666); - ss.set_logging(&cerr,debug); - - time_t t0 = time(NULL); - - // max 10 sec - while (time(NULL) < t0 + 10 ) + try { - ss.fill_buffer(1000000); + socket_server ss(6666); + ss.set_logging(&cerr,debug); - string data; - unsigned int cid; + time_t t0 = time(NULL); - if(ss.get_packet(data,cid)) + // max 10 sec + while (time(NULL) < t0 + 10 ) { - server_connection* con=ss.get_connection(cid); + ss.fill_buffer(1000000); + + string data; + unsigned int cid; - if (data=="QUIT") - break; + if(ss.get_packet(data,cid)) + { + server_connection* con=ss.get_connection(cid); - if (data=="ABC") - con->write("DEF"); - else - con->write("xyz"); + if (data=="QUIT") + break; + + if (data=="ABC") + con->write("DEF"); + else + con->write("xyz"); + } } + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } // don't call atexit and stuff _exit(0); @@ -352,31 +386,37 @@ class test_comm : public TestFixture case 0: // child { - socket_server ss(6666); - ss.set_logging(&cerr,debug); - - time_t t0 = time(NULL); - - // max 10 sec - while (time(NULL) < t0 + 10 ) + try { - ss.fill_buffer(1000000); + socket_server ss(6666); + ss.set_logging(&cerr,debug); - string data; - unsigned int cid; + time_t t0 = time(NULL); - if(ss.get_packet(data,cid)) + // max 10 sec + while (time(NULL) < t0 + 10 ) { - server_connection* con=ss.get_connection(cid); + ss.fill_buffer(1000000); - socket_handler* alias= dynamic_cast< socket_handler* >(con); + string data; + unsigned int cid; - if (data=="QUIT") - break; + if(ss.get_packet(data,cid)) + { + server_connection* con=ss.get_connection(cid); - alias->set_write_block_size( 4093 ); - con->write(string().insert(0,2048*1024,'y')); + socket_handler* alias= dynamic_cast< socket_handler* >(con); + + if (data=="QUIT") + break; + + alias->set_write_block_size( 4093 ); + con->write(string().insert(0,2048*1024,'y')); + } } + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } // don't call atexit and stuff _exit(0); diff --git a/test/hello.cpp b/test/hello.cpp index 1036e30..302fb48 100644 --- a/test/hello.cpp +++ b/test/hello.cpp @@ -97,19 +97,26 @@ class test_hello : public TestFixture case 0: // child { - socket_server ss("./socket"); + try + { + socket_server ss("./socket"); + + ostringstream hello; + hello << "T2Nv" << PROTOCOL_VERSION << ';'; + int byteordercheck=1; + hello.write((char*)&byteordercheck,sizeof(byteordercheck)); + hello << ';'; + + ss.add_callback(new_connection,bind(&test_hello::send_hello, boost::ref(*this), hello.str(),&ss, _1)); + + // max 10 sec + for (int i=0; i < 10; i++) + ss.fill_buffer(1000000); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } - ostringstream hello; - hello << "T2Nv" << PROTOCOL_VERSION << ';'; - int byteordercheck=1; - hello.write((char*)&byteordercheck,sizeof(byteordercheck)); - hello << ';'; - - ss.add_callback(new_connection,bind(&test_hello::send_hello, boost::ref(*this), hello.str(),&ss, _1)); - - // max 10 sec - for (int i=0; i < 10; i++) - ss.fill_buffer(1000000); // don't call atexit and stuff _exit(0); } @@ -139,16 +146,23 @@ class test_hello : public TestFixture case 0: // child { - socket_server ss("./socket"); + try + { + socket_server ss("./socket"); - ostringstream hello; - hello << "XYZ 123"; + ostringstream hello; + hello << "XYZ 123"; - ss.add_callback(new_connection,bind(&test_hello::send_hello, boost::ref(*this), hello.str(),&ss, _1)); + ss.add_callback(new_connection,bind(&test_hello::send_hello, boost::ref(*this), hello.str(),&ss, _1)); + + // max 10 sec + for (int i=0; i < 10; i++) + ss.fill_buffer(1000000); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } - // max 10 sec - for (int i=0; i < 10; i++) - ss.fill_buffer(1000000); // don't call atexit and stuff _exit(0); } @@ -187,20 +201,27 @@ class test_hello : public TestFixture case 0: // child { - socket_server ss("./socket"); - - ostringstream hello; - // lets hope we don't ever get near such a version number... - hello << "T2Nv" << 4982271 << ';'; - int byteordercheck=1; - hello.write((char*)&byteordercheck,sizeof(byteordercheck)); - hello << ';'; + try + { + socket_server ss("./socket"); + + ostringstream hello; + // lets hope we don't ever get near such a version number... + hello << "T2Nv" << 4982271 << ';'; + int byteordercheck=1; + hello.write((char*)&byteordercheck,sizeof(byteordercheck)); + hello << ';'; + + ss.add_callback(new_connection,bind(&test_hello::send_hello, boost::ref(*this), hello.str(),&ss, _1)); + + // max 10 sec + for (int i=0; i < 10; i++) + ss.fill_buffer(1000000); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } - ss.add_callback(new_connection,bind(&test_hello::send_hello, boost::ref(*this), hello.str(),&ss, _1)); - - // max 10 sec - for (int i=0; i < 10; i++) - ss.fill_buffer(1000000); // don't call atexit and stuff _exit(0); } @@ -239,19 +260,26 @@ class test_hello : public TestFixture case 0: // child { - socket_server ss("./socket"); - - ostringstream hello; - hello << "T2Nv" << PROTOCOL_VERSION; - int byteordercheck=1; - hello.write((char*)&byteordercheck,sizeof(byteordercheck)); - hello << ';'; - - ss.add_callback(new_connection,bind(&test_hello::send_hello, boost::ref(*this), hello.str(),&ss, _1)); + try + { + socket_server ss("./socket"); + + ostringstream hello; + hello << "T2Nv" << PROTOCOL_VERSION; + int byteordercheck=1; + hello.write((char*)&byteordercheck,sizeof(byteordercheck)); + hello << ';'; + + ss.add_callback(new_connection,bind(&test_hello::send_hello, boost::ref(*this), hello.str(),&ss, _1)); + + // max 10 sec + for (int i=0; i < 10; i++) + ss.fill_buffer(1000000); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } - // max 10 sec - for (int i=0; i < 10; i++) - ss.fill_buffer(1000000); // don't call atexit and stuff _exit(0); } @@ -290,28 +318,35 @@ class test_hello : public TestFixture case 0: // child { - socket_server ss("./socket"); + try + { + socket_server ss("./socket"); + + ostringstream hello; + hello << "T2Nv" << PROTOCOL_VERSION << ';'; + int byteordercheck=1; + int dst; + char* si=(char*)&byteordercheck; + char* di=(char*)&dst; + + di[0]=si[3]; + di[1]=si[2]; + di[2]=si[1]; + di[3]=si[0]; + + hello.write((char*)&dst,sizeof(dst)); + hello << ';'; + + ss.add_callback(new_connection,bind(&test_hello::send_hello, boost::ref(*this), hello.str(),&ss, _1)); + + // max 10 sec + for (int i=0; i < 10; i++) + ss.fill_buffer(1000000); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } - ostringstream hello; - hello << "T2Nv" << PROTOCOL_VERSION << ';'; - int byteordercheck=1; - int dst; - char* si=(char*)&byteordercheck; - char* di=(char*)&dst; - - di[0]=si[3]; - di[1]=si[2]; - di[2]=si[1]; - di[3]=si[0]; - - hello.write((char*)&dst,sizeof(dst)); - hello << ';'; - - ss.add_callback(new_connection,bind(&test_hello::send_hello, boost::ref(*this), hello.str(),&ss, _1)); - - // max 10 sec - for (int i=0; i < 10; i++) - ss.fill_buffer(1000000); // don't call atexit and stuff _exit(0); } @@ -350,17 +385,24 @@ class test_hello : public TestFixture case 0: // child { - socket_server ss("./socket"); + try + { + socket_server ss("./socket"); + + ostringstream hello; + // hmm, we got the wrong socket + hello << "* OK intradev.net.lan Cyrus IMAP4 v2.2.13 server ready"; - ostringstream hello; - // hmm, we got the wrong socket - hello << "* OK intradev.net.lan Cyrus IMAP4 v2.2.13 server ready"; + ss.add_callback(new_connection,bind(&test_hello::send_raw_socket, boost::ref(*this), hello.str(),&ss, _1)); - ss.add_callback(new_connection,bind(&test_hello::send_raw_socket, boost::ref(*this), hello.str(),&ss, _1)); + // max 3 sec + for (int i=0; i < 3; i++) + ss.fill_buffer(1000000); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } - // max 3 sec - for (int i=0; i < 3; i++) - ss.fill_buffer(1000000); // don't call atexit and stuff _exit(0); } @@ -399,17 +441,24 @@ class test_hello : public TestFixture case 0: // child { - socket_server ss("./socket"); + try + { + socket_server ss("./socket"); + + ostringstream hello; + // hmm, we got the wrong socket + hello << "READY"; - ostringstream hello; - // hmm, we got the wrong socket - hello << "READY"; + ss.add_callback(new_connection,bind(&test_hello::send_raw_socket, boost::ref(*this), hello.str(),&ss, _1)); - ss.add_callback(new_connection,bind(&test_hello::send_raw_socket, boost::ref(*this), hello.str(),&ss, _1)); + // max 3 sec + for (int i=0; i < 3; i++) + ss.fill_buffer(1000000); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } - // max 3 sec - for (int i=0; i < 3; i++) - ss.fill_buffer(1000000); // don't call atexit and stuff _exit(0); } diff --git a/test/newserver.cpp b/test/newserver.cpp index 59aa6ae..369d635 100644 --- a/test/newserver.cpp +++ b/test/newserver.cpp @@ -138,23 +138,29 @@ class test_newserver : public TestFixture case 0: // child { + try { - socket_server ss("./socket"); - command_server cs(ss); - - // handle new connection and just one command - cs.handle(10000000); - cs.handle(10000000); - } - // close socket, create new one + { + socket_server ss("./socket"); + command_server cs(ss); + + // handle new connection and just one command + cs.handle(10000000); + cs.handle(10000000); + } + // close socket, create new one + { + socket_server ss("./socket"); + ss.set_logging(&cerr,debug); + command_server cs(ss); + + // max 30 sec + for (int i=0; i < 30; i++) + cs.handle(1000000); + } + } catch(...) { - socket_server ss("./socket"); - ss.set_logging(&cerr,debug); - command_server cs(ss); - - // max 30 sec - for (int i=0; i < 30; i++) - cs.handle(1000000); + std::cerr << "exception in child. ignoring\n"; } // don't call atexit and stuff diff --git a/test/reconnect.cpp b/test/reconnect.cpp index 394ba25..6474b51 100644 --- a/test/reconnect.cpp +++ b/test/reconnect.cpp @@ -87,30 +87,36 @@ class test_reconnect : public TestFixture case 0: // child { - socket_server ss("./socket"); - - time_t t0 = time(NULL); - - // max 10 sec - while (time(NULL) < t0 + 10 ) + try { - ss.fill_buffer(1000000); + socket_server ss("./socket"); - string data; - unsigned int cid; + time_t t0 = time(NULL); - if(ss.get_packet(data,cid)) + // max 10 sec + while (time(NULL) < t0 + 10 ) { - server_connection* con=ss.get_connection(cid); + ss.fill_buffer(1000000); + + string data; + unsigned int cid; + + if(ss.get_packet(data,cid)) + { + server_connection* con=ss.get_connection(cid); - if (data=="QUIT") - break; + if (data=="QUIT") + break; - if (data=="x") - con->write(string().insert(0,100,'X')); - else - con->write(string().insert(0,100,'Y')); + if (data=="x") + con->write(string().insert(0,100,'X')); + else + con->write(string().insert(0,100,'Y')); + } } + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } // don't call atexit and stuff @@ -158,30 +164,36 @@ class test_reconnect : public TestFixture case 0: // child { - socket_server ss("./socket"); - - time_t t0 = time(NULL); - - // max 10 sec - while (time(NULL) < t0 + 10 ) + try { - ss.fill_buffer(1000000); + socket_server ss("./socket"); - string data; - unsigned int cid; + time_t t0 = time(NULL); - if(ss.get_packet(data,cid)) + // max 10 sec + while (time(NULL) < t0 + 10 ) { - server_connection* con=ss.get_connection(cid); + ss.fill_buffer(1000000); - if (data=="QUIT") - break; + string data; + unsigned int cid; - if (data=="x") - con->write(string().insert(0,100,'X')); - else - con->write(string().insert(0,100,'Y')); + if(ss.get_packet(data,cid)) + { + server_connection* con=ss.get_connection(cid); + + if (data=="QUIT") + break; + + if (data=="x") + con->write(string().insert(0,100,'X')); + else + con->write(string().insert(0,100,'Y')); + } } + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } // don't call atexit and stuff @@ -234,28 +246,34 @@ class test_reconnect : public TestFixture case 0: // child { - socket_server ss("./socket"); - - time_t t0 = time(NULL); - - // max 10 sec - while (time(NULL) < t0 + 10 ) + try { - ss.fill_buffer(1000000); + socket_server ss("./socket"); - string data; - unsigned int cid; + time_t t0 = time(NULL); - if(ss.get_packet(data,cid)) + // max 10 sec + while (time(NULL) < t0 + 10 ) { - server_connection* con=ss.get_connection(cid); + ss.fill_buffer(1000000); + + string data; + unsigned int cid; + + if(ss.get_packet(data,cid)) + { + server_connection* con=ss.get_connection(cid); - if (data=="QUIT") - break; + if (data=="QUIT") + break; - if (data=="x") - con->write(string().insert(0,100,'X')); + if (data=="x") + con->write(string().insert(0,100,'X')); + } } + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } // don't call atexit and stuff @@ -302,31 +320,37 @@ class test_reconnect : public TestFixture case 0: // child { - socket_server ss("./socket"); - - time_t t0 = time(NULL); - - // max 10 sec - while (time(NULL) < t0 + 10 ) + try { - ss.fill_buffer(1000000); + socket_server ss("./socket"); - string data; - unsigned int cid; + time_t t0 = time(NULL); - if(ss.get_packet(data,cid)) + // max 10 sec + while (time(NULL) < t0 + 10 ) { - server_connection* con=ss.get_connection(cid); + ss.fill_buffer(1000000); - if (data=="QUIT") - break; + string data; + unsigned int cid; - if (data=="x") + if(ss.get_packet(data,cid)) { - for (int i=0; iwrite(string().insert(0,100,'X')); + server_connection* con=ss.get_connection(cid); + + if (data=="QUIT") + break; + + if (data=="x") + { + for (int i=0; iwrite(string().insert(0,100,'X')); + } } } + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } // don't call atexit and stuff @@ -388,31 +412,37 @@ class test_reconnect : public TestFixture case 0: // child { - socket_server ss("./socket"); - - time_t t0 = time(NULL); - - // max 10 sec - while (time(NULL) < t0 + 10 ) + try { - ss.fill_buffer(1000000); + socket_server ss("./socket"); - string data; - unsigned int cid; + time_t t0 = time(NULL); - if(ss.get_packet(data,cid)) + // max 10 sec + while (time(NULL) < t0 + 10 ) { - server_connection* con=ss.get_connection(cid); + ss.fill_buffer(1000000); - if (data=="QUIT") - break; + string data; + unsigned int cid; - if (data=="x") + if(ss.get_packet(data,cid)) { - con->write(string().insert(0,100,'X')); - send_raw_socket("aaaab",&ss,cid); + server_connection* con=ss.get_connection(cid); + + if (data=="QUIT") + break; + + if (data=="x") + { + con->write(string().insert(0,100,'X')); + send_raw_socket("aaaab",&ss,cid); + } } } + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } // don't call atexit and stuff @@ -464,42 +494,48 @@ class test_reconnect : public TestFixture case 0: // child { - socket_server ss("./socket"); - - time_t t0 = time(NULL); - - // max 10 sec - while (time(NULL) < t0 + 10 ) + try { - ss.fill_buffer(1000000); + socket_server ss("./socket"); - string data; - unsigned int cid; + time_t t0 = time(NULL); - if(ss.get_packet(data,cid)) + // max 10 sec + while (time(NULL) < t0 + 10 ) { - server_connection* con=ss.get_connection(cid); + ss.fill_buffer(1000000); - if (data=="QUIT") - break; + string data; + unsigned int cid; - if (data=="x") + if(ss.get_packet(data,cid)) { - con->write(string().insert(0,100,'X')); + server_connection* con=ss.get_connection(cid); + + if (data=="QUIT") + break; - string blob=string().insert(0,100,'Y'); + if (data=="x") + { + con->write(string().insert(0,100,'X')); + + string blob=string().insert(0,100,'Y'); - // one byte will be missing... - int size=blob.size()+1; - char sizetransfer[sizeof(int)+1]; - memcpy(sizetransfer,(void*)&size,sizeof(int)); - sizetransfer[sizeof(int)+1]=0; + // one byte will be missing... + int size=blob.size()+1; + char sizetransfer[sizeof(int)+1]; + memcpy(sizetransfer,(void*)&size,sizeof(int)); + sizetransfer[sizeof(int)+1]=0; - string packet=string(sizetransfer)+blob; + string packet=string(sizetransfer)+blob; - send_raw_socket(packet,&ss,cid); + send_raw_socket(packet,&ss,cid); + } } } + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } // don't call atexit and stuff diff --git a/test/reentrant.cpp b/test/reentrant.cpp index c60baae..7442c31 100644 --- a/test/reentrant.cpp +++ b/test/reentrant.cpp @@ -188,6 +188,9 @@ class test_reentrant : public TestFixture } catch (exception &e) { cerr << "caught exception: " << e.what() << endl; + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } // don't call atexit and stuff diff --git a/test/serialize.cpp b/test/serialize.cpp index b7f3248..808ea08 100644 --- a/test/serialize.cpp +++ b/test/serialize.cpp @@ -144,12 +144,18 @@ class test_serialize : public TestFixture case 0: // child { - socket_server ss("./socket"); - command_server cs(ss); + try + { + socket_server ss("./socket"); + command_server cs(ss); - // max 10 sec - for (int i=0; i < 10; i++) - cs.handle(1000000); + // max 10 sec + for (int i=0; i < 10; i++) + cs.handle(1000000); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } // don't call atexit and stuff _exit(0); diff --git a/test/simplecmd.cpp b/test/simplecmd.cpp index 1c8e09e..99c720f 100644 --- a/test/simplecmd.cpp +++ b/test/simplecmd.cpp @@ -147,12 +147,18 @@ class test_simplecmd : public TestFixture case 0: // child { - socket_server ss("./socket"); - command_server cs(ss); + try + { + socket_server ss("./socket"); + command_server cs(ss); - // max 10 sec - for (int i=0; i < 10; i++) - cs.handle(1000000); + // max 10 sec + for (int i=0; i < 10; i++) + cs.handle(1000000); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } // don't call atexit and stuff _exit(0); @@ -189,12 +195,18 @@ class test_simplecmd : public TestFixture case 0: // child { - socket_server ss("./socket"); - command_server cs(ss); + try + { + socket_server ss("./socket"); + command_server cs(ss); - // max 10 sec - for (int i=0; i < 10; i++) - cs.handle(1000000); + // max 10 sec + for (int i=0; i < 10; i++) + cs.handle(1000000); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } // don't call atexit and stuff _exit(0); @@ -240,12 +252,18 @@ class test_simplecmd : public TestFixture case 0: // child { - socket_server ss("./socket"); - command_server cs(ss); + try + { + socket_server ss("./socket"); + command_server cs(ss); - // max 10 sec - for (int i=0; i < 10; i++) - cs.handle(1000000); + // max 10 sec + for (int i=0; i < 10; i++) + cs.handle(1000000); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } // don't call atexit and stuff _exit(0); @@ -281,12 +299,18 @@ class test_simplecmd : public TestFixture case 0: // child { - socket_server ss("./socket"); - command_server cs(ss); + try + { + socket_server ss("./socket"); + command_server cs(ss); - // max 60 sec - we need atleast 28 handle calls to transfer the buffer - for (int i=0; i < 60; i++) { - cs.handle(1000000); + // max 60 sec - we need atleast 28 handle calls to transfer the buffer + for (int i=0; i < 60; i++) { + cs.handle(1000000); + } + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } // don't call atexit and stuff diff --git a/test/timeout.cpp b/test/timeout.cpp index 5156869..3658d6d 100644 --- a/test/timeout.cpp +++ b/test/timeout.cpp @@ -195,7 +195,13 @@ class test_timeout : public TestFixture case 0: // child { - socket_server ss("./socket"); + try + { + socket_server ss("./socket"); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } // don't call atexit and stuff _exit(0); @@ -232,11 +238,18 @@ class test_timeout : public TestFixture case 0: // child { - socket_server ss("./socket"); + try + { + socket_server ss("./socket"); + + // max 10 sec + for (int i=0; i < 10; i++) + ss.fill_buffer(1000000); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } - // max 10 sec - for (int i=0; i < 10; i++) - ss.fill_buffer(1000000); // don't call atexit and stuff _exit(0); } @@ -274,24 +287,31 @@ class test_timeout : public TestFixture case 0: // child { - socket_server ss("./socket"); + try + { + socket_server ss("./socket"); - // create a valid packet - ostringstream hello; - hello << "T2Nv" << PROTOCOL_VERSION << ';'; - int byteordercheck=1; - hello.write((char*)&byteordercheck,sizeof(byteordercheck)); - hello << ';'; + // create a valid packet + ostringstream hello; + hello << "T2Nv" << PROTOCOL_VERSION << ';'; + int byteordercheck=1; + hello.write((char*)&byteordercheck,sizeof(byteordercheck)); + hello << ';'; - packet_size_indicator psize=htonl(hello.str().size()); - std::string send_data(hello.str()); - send_data.insert(0,(char*)&psize,sizeof(packet_size_indicator)); + packet_size_indicator psize=htonl(hello.str().size()); + std::string send_data(hello.str()); + send_data.insert(0,(char*)&psize,sizeof(packet_size_indicator)); - ss.add_callback(new_connection,bind(&test_timeout::send_slow_raw_socket, boost::ref(*this), send_data,&ss, _1)); + ss.add_callback(new_connection,bind(&test_timeout::send_slow_raw_socket, boost::ref(*this), send_data,&ss, _1)); + + // max 10 sec + for (int i=0; i < 10; i++) + ss.fill_buffer(1000000); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } - // max 10 sec - for (int i=0; i < 10; i++) - ss.fill_buffer(1000000); // don't call atexit and stuff _exit(0); } @@ -329,19 +349,26 @@ class test_timeout : public TestFixture case 0: // child { - socket_server ss("./socket"); + try + { + socket_server ss("./socket"); - ostringstream hello; - hello << "T2Nv" << PROTOCOL_VERSION << ';'; - int byteordercheck=1; - hello.write((char*)&byteordercheck,sizeof(byteordercheck)); - hello << ';'; + ostringstream hello; + hello << "T2Nv" << PROTOCOL_VERSION << ';'; + int byteordercheck=1; + hello.write((char*)&byteordercheck,sizeof(byteordercheck)); + hello << ';'; - ss.add_callback(new_connection,bind(&test_timeout::send_hello, boost::ref(*this), hello.str(),&ss, _1)); + ss.add_callback(new_connection,bind(&test_timeout::send_hello, boost::ref(*this), hello.str(),&ss, _1)); + + // max 10 sec + for (int i=0; i < 10; i++) + ss.fill_buffer(1000000); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } - // max 10 sec - for (int i=0; i < 10; i++) - ss.fill_buffer(1000000); // don't call atexit and stuff _exit(0); } @@ -386,34 +413,41 @@ class test_timeout : public TestFixture case 0: // child { - socket_server ss("./socket"); + try + { + socket_server ss("./socket"); - ostringstream hello; - hello << "T2Nv" << PROTOCOL_VERSION << ';'; - int byteordercheck=1; - hello.write((char*)&byteordercheck,sizeof(byteordercheck)); - hello << ';'; + ostringstream hello; + hello << "T2Nv" << PROTOCOL_VERSION << ';'; + int byteordercheck=1; + hello.write((char*)&byteordercheck,sizeof(byteordercheck)); + hello << ';'; - ss.add_callback(new_connection,bind(&test_timeout::send_hello, boost::ref(*this), hello.str(),&ss, _1)); + ss.add_callback(new_connection,bind(&test_timeout::send_hello, boost::ref(*this), hello.str(),&ss, _1)); - // max 10 sec - for (int i=0; i < 10; i++) - { - ss.fill_buffer(1000000); + // max 10 sec + for (int i=0; i < 10; i++) + { + ss.fill_buffer(1000000); - string data; - unsigned int cid; + string data; + unsigned int cid; - if(ss.get_packet(data,cid)) - { - // create a valid packet & send - string response="abcdefghijklmnopqrstuvwxyz"; - packet_size_indicator psize=htonl(response.size()); - std::string send_data(response); - send_data.insert(0,(char*)&psize,sizeof(packet_size_indicator)); - send_slow_raw_socket(send_data,&ss,cid); + if(ss.get_packet(data,cid)) + { + // create a valid packet & send + string response="abcdefghijklmnopqrstuvwxyz"; + packet_size_indicator psize=htonl(response.size()); + std::string send_data(response); + send_data.insert(0,(char*)&psize,sizeof(packet_size_indicator)); + send_slow_raw_socket(send_data,&ss,cid); + } } + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } + // don't call atexit and stuff _exit(0); } @@ -458,10 +492,17 @@ class test_timeout : public TestFixture case 0: // child { - socket_server ss("./socket"); + try + { + socket_server ss("./socket"); + + // bail out as soon as we get something + ss.fill_buffer(-1); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } - // bail out as soon as we get something - ss.fill_buffer(-1); // don't call atexit and stuff _exit(0); } @@ -508,11 +549,18 @@ class test_timeout : public TestFixture case 0: // child { - socket_server ss("./socket"); + try + { + socket_server ss("./socket"); + + // bail out as soon as we get something + ss.fill_buffer(-1); + ss.fill_buffer(-1); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } - // bail out as soon as we get something - ss.fill_buffer(-1); - ss.fill_buffer(-1); // don't call atexit and stuff _exit(0); } @@ -564,14 +612,20 @@ class test_timeout : public TestFixture case 0: // child { - // wait till server is up - sleep(1); + try + { + // wait till server is up + sleep(1); - socket_client_connection sc("./socket"); + socket_client_connection sc("./socket"); - // this is an evil hack to get access to real_write, don't ever do this in an app!!! - real_write_client_connection *rwc=(real_write_client_connection*)≻ - rwc->real_write(string(10000,'x')); + // this is an evil hack to get access to real_write, don't ever do this in an app!!! + real_write_client_connection *rwc=(real_write_client_connection*)≻ + rwc->real_write(string(10000,'x')); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } // don't call atexit and stuff _exit(0); @@ -608,10 +662,16 @@ class test_timeout : public TestFixture case 0: // child { - socket_client_connection *sc=new socket_client_connection("./socket"); - sc->write(string(10000,'x')); - delete sc; - // socket is closed regularly + try + { + socket_client_connection *sc=new socket_client_connection("./socket"); + sc->write(string(10000,'x')); + // socket is closed regularly + delete sc; + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } // don't run regular cleanup, otherwise cppunit stuff gets called _exit(0); @@ -655,11 +715,17 @@ class test_timeout : public TestFixture case 0: // child { - // wait till server is really up and waiting - sleep(2); + try + { + // wait till server is really up and waiting + sleep(2); - // connect with very tight timeout and only 1 retry - socket_client_connection sc("./socket",50,1); + // connect with very tight timeout and only 1 retry + socket_client_connection sc("./socket",50,1); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } // don't call atexit and stuff _exit(0); @@ -699,10 +765,16 @@ class test_timeout : public TestFixture case 0: // child { - socket_client_connection *sc=new socket_client_connection("./socket"); - sc->write(string(10000,'x')); - delete sc; - // socket is closed regularly + try + { + socket_client_connection *sc=new socket_client_connection("./socket"); + sc->write(string(10000,'x')); + delete sc; + // socket is closed regularly + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } // don't run regular cleanup, otherwise cppunit stuff gets called _exit(0); diff --git a/test/wrapper.cpp b/test/wrapper.cpp index 8a7c16d..17fb0ef 100644 --- a/test/wrapper.cpp +++ b/test/wrapper.cpp @@ -257,18 +257,24 @@ class test_wrapper : public TestFixture case 0: // child { - int i=0; - while(i < 10 && !kill_server) + try { - close_server=false; - - socket_server ss("./socket"); - group_command_server cs(ss); - ss.set_logging(&logstream,debug); - - // max 10 sec - for (; !close_server && !kill_server && i < 10; i++) - cs.handle(1000000); + int i=0; + while(i < 10 && !kill_server) + { + close_server=false; + + socket_server ss("./socket"); + group_command_server cs(ss); + ss.set_logging(&logstream,debug); + + // max 10 sec + for (; !close_server && !kill_server && i < 10; i++) + cs.handle(1000000); + } + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } // don't call atexit and stuff @@ -489,18 +495,24 @@ class test_wrapper_noserver : public TestFixture case 0: // child { - int i=0; - while(i < 10 && !kill_server) + try { - close_server=false; - - socket_server ss("./socket"); - group_command_server cs(ss); - ss.set_logging(&logstream,debug); - - // max 10 sec - for (; !close_server && !kill_server && i < 10; i++) - cs.handle(1000000); + int i=0; + while(i < 10 && !kill_server) + { + close_server=false; + + socket_server ss("./socket"); + group_command_server cs(ss); + ss.set_logging(&logstream,debug); + + // max 10 sec + for (; !close_server && !kill_server && i < 10; i++) + cs.handle(1000000); + } + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } // don't call atexit and stuff @@ -544,18 +556,25 @@ class test_wrapper_noserver : public TestFixture case 0: // child { - socket_server ss("./socket"); + try + { + socket_server ss("./socket"); - // server sends garbage + // server sends garbage - ostringstream hello; - hello << "XYZ 123"; + ostringstream hello; + hello << "XYZ 123"; - ss.add_callback(new_connection,bind(&test_wrapper_noserver::send_hello, boost::ref(*this), hello.str(),&ss, _1)); + ss.add_callback(new_connection,bind(&test_wrapper_noserver::send_hello, boost::ref(*this), hello.str(),&ss, _1)); + + // max 10 sec + for (int i=0; i < 10; i++) + ss.fill_buffer(1000000); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } - // max 10 sec - for (int i=0; i < 10; i++) - ss.fill_buffer(1000000); // don't call atexit and stuff _exit(0); } -- 1.7.1