X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=test%2Fcomm.cpp;h=7bd8b242a2ea86d79ffc19ca3ea73765f32d16cc;hp=5bba916297461a5d437473453f882398f78d85c4;hb=b592218402bfa779c024da2f32c4c782d52eaf88;hpb=517d1214577af263bb4d6821e4e7ad9ba8c94901 diff --git a/test/comm.cpp b/test/comm.cpp index 5bba916..7bd8b24 100644 --- a/test/comm.cpp +++ b/test/comm.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -40,20 +41,25 @@ class test_comm : public TestFixture CPPUNIT_TEST_SUITE_END(); + pid_t child_pid; + public: void setUp() { } void tearDown() - { } + { + // make sure the server-child is dead before the next test runs + kill(child_pid,SIGKILL); + sleep(1); + } void UnixCommToServer() { - pid_t pid; string data; - switch(pid=fork()) + switch(child_pid=fork()) { case -1: { @@ -76,8 +82,10 @@ class test_comm : public TestFixture { socket_server ss("./socket"); + time_t t0 = time(NULL); + // max 10 sec - for (int i=0; i < 10; i++) + while (time(NULL) < t0 + 10 ) { ss.fill_buffer(1000000); @@ -91,9 +99,7 @@ class test_comm : public TestFixture void UnixCommToServerAndBack() { - pid_t pid; - - switch(pid=fork()) + switch(child_pid=fork()) { case -1: { @@ -106,8 +112,10 @@ class test_comm : public TestFixture socket_server ss("./socket"); ss.set_logging(&cerr,debug); + time_t t0 = time(NULL); + // max 10 sec - for (int i=0; i < 10; i++) + while (time(NULL) < t0 + 10 ) { ss.fill_buffer(1000000); @@ -161,9 +169,7 @@ class test_comm : public TestFixture void UnixCommToServerAndBackBig() { - pid_t pid; - - switch(pid=fork()) + switch(child_pid=fork()) { case -1: { @@ -176,8 +182,10 @@ class test_comm : public TestFixture socket_server ss("./socket"); ss.set_logging(&cerr,debug); + time_t t0 = time(NULL); + // max 10 sec - for (int i=0; i < 10; i++) + while (time(NULL) < t0 + 10 ) { ss.fill_buffer(1000000); @@ -194,6 +202,7 @@ class test_comm : public TestFixture con->write(string().insert(0,100*1024,'y')); } } + std::cerr << "child: OVER" << std::endl; // don't call atexit and stuff _exit(0); } @@ -221,10 +230,9 @@ class test_comm : public TestFixture void IPCommToServer() { - pid_t pid; string data; - switch(pid=fork()) + switch(child_pid=fork()) { case -1: { @@ -247,8 +255,10 @@ class test_comm : public TestFixture { socket_server ss(6666); + time_t t0 = time(NULL); + // max 10 sec - for (int i=0; i < 10; i++) + while (time(NULL) < t0 + 10 ) { ss.fill_buffer(1000000); @@ -262,9 +272,7 @@ class test_comm : public TestFixture void IPCommToServerAndBack() { - pid_t pid; - - switch(pid=fork()) + switch(child_pid=fork()) { case -1: { @@ -277,8 +285,10 @@ class test_comm : public TestFixture socket_server ss(6666); ss.set_logging(&cerr,debug); + time_t t0 = time(NULL); + // max 10 sec - for (int i=0; i < 10; i++) + while (time(NULL) < t0 + 10 ) { ss.fill_buffer(1000000); @@ -332,9 +342,7 @@ class test_comm : public TestFixture void IPCommToServerAndBackBig() { - pid_t pid; - - switch(pid=fork()) + switch(child_pid=fork()) { case -1: { @@ -347,8 +355,10 @@ class test_comm : public TestFixture socket_server ss(6666); ss.set_logging(&cerr,debug); + time_t t0 = time(NULL); + // max 10 sec - for (int i=0; i < 10; i++) + while (time(NULL) < t0 + 10 ) { ss.fill_buffer(1000000); @@ -392,9 +402,6 @@ class test_comm : public TestFixture } } } // eo IPCommToServerAndBackBig() - - - }; CPPUNIT_TEST_SUITE_REGISTRATION(test_comm);