From c7662795f519d2b6797e4b1ac7fa4a22afa26310 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 27 Jul 2006 23:18:35 +0000 Subject: * merge - This is my current patch queue. I think that all of these are safe to apply. This is just under half of the pending changes in chris/general (the easy half). --- test/basicserver/TestCommands.cpp | 2 + test/basicserver/testbasicserver.cpp | 99 ++++++++++++++++++++++++++++++++---- 2 files changed, 90 insertions(+), 11 deletions(-) (limited to 'test/basicserver') diff --git a/test/basicserver/TestCommands.cpp b/test/basicserver/TestCommands.cpp index b18a3326..657e79ea 100644 --- a/test/basicserver/TestCommands.cpp +++ b/test/basicserver/TestCommands.cpp @@ -1,7 +1,9 @@ #include "Box.h" +#ifdef HAVE_SYSLOG_H #include +#endif #include "autogen_TestProtocolServer.h" #include "CollectInBufferStream.h" diff --git a/test/basicserver/testbasicserver.cpp b/test/basicserver/testbasicserver.cpp index f5185b96..1403df42 100644 --- a/test/basicserver/testbasicserver.cpp +++ b/test/basicserver/testbasicserver.cpp @@ -31,7 +31,6 @@ #include "MemLeakFindOn.h" - #define SERVER_LISTEN_PORT 2003 // in ms @@ -62,10 +61,14 @@ void basicdaemon::Run() void testservers_pause_before_reply() { - struct timespec t; - t.tv_sec = 0; - t.tv_nsec = COMMS_SERVER_WAIT_BEFORE_REPLYING * 1000 * 1000; // convert to ns - ::nanosleep(&t, NULL); +#ifdef WIN32 + Sleep(COMMS_SERVER_WAIT_BEFORE_REPLYING); +#else + struct timespec t; + t.tv_sec = 0; + t.tv_nsec = COMMS_SERVER_WAIT_BEFORE_REPLYING * 1000 * 1000; // convert to ns + ::nanosleep(&t, NULL); +#endif } #define LARGE_DATA_BLOCK_SIZE 19870 @@ -427,84 +430,138 @@ int test(int argc, const char *argv[]) } } +#ifdef WIN32 + // Under win32 we must initialise the Winsock library + // before using sockets + + WSADATA info; + TEST_THAT(WSAStartup(0x0101, &info) != SOCKET_ERROR) +#endif + //printf("SKIPPING TESTS------------------------\n"); //goto protocolserver; // Launch a basic server { - int pid = LaunchServer("./test srv1 testfiles/srv1.conf", "testfiles/srv1.pid"); +#ifdef WIN32 + int pid = LaunchServer("test srv1 testfiles\\srv1.conf", + "testfiles\\srv1.pid"); +#else + int pid = LaunchServer("./test srv1 testfiles/srv1.conf", + "testfiles/srv1.pid"); +#endif + TEST_THAT(pid != -1 && pid != 0); if(pid > 0) { // Check that it's written the expected file - TEST_THAT(TestFileExists("testfiles/srv1.test1")); + TEST_THAT(TestFileExists("testfiles" + DIRECTORY_SEPARATOR "srv1.test1")); TEST_THAT(ServerIsAlive(pid)); // Move the config file over - TEST_THAT(::rename("testfiles/srv1b.conf", "testfiles/srv1.conf") != -1); +#ifdef WIN32 + TEST_THAT(::unlink("testfiles" DIRECTORY_SEPARATOR + "srv1.conf") != -1); +#endif + TEST_THAT(::rename( + "testfiles" DIRECTORY_SEPARATOR "srv1b.conf", + "testfiles" DIRECTORY_SEPARATOR "srv1.conf") + != -1); +#ifndef WIN32 // Get it to reread the config file TEST_THAT(HUPServer(pid)); ::sleep(1); TEST_THAT(ServerIsAlive(pid)); // Check that new file exists - TEST_THAT(TestFileExists("testfiles/srv1.test2")); + TEST_THAT(TestFileExists("testfiles" + DIRECTORY_SEPARATOR "srv1.test2")); +#endif // !WIN32 // Kill it off TEST_THAT(KillServer(pid)); +#ifndef WIN32 TestRemoteProcessMemLeaks("generic-daemon.memleaks"); +#endif // !WIN32 } } // Launch a test forking server { - int pid = LaunchServer("./test srv2 testfiles/srv2.conf", "testfiles/srv2.pid"); +#ifdef WIN32 + int pid = LaunchServer("test srv2 testfiles\\srv2.conf", + "testfiles\\srv2.pid"); +#else + int pid = LaunchServer("./test srv2 testfiles/srv2.conf", + "testfiles/srv2.pid"); +#endif + TEST_THAT(pid != -1 && pid != 0); if(pid > 0) { // Will it restart? TEST_THAT(ServerIsAlive(pid)); +#ifndef WIN32 TEST_THAT(HUPServer(pid)); ::sleep(1); TEST_THAT(ServerIsAlive(pid)); +#endif // !WIN32 // Make some connections { SocketStream conn1; conn1.Open(Socket::TypeINET, "localhost", 2003); +#ifndef WIN32 SocketStream conn2; conn2.Open(Socket::TypeUNIX, "testfiles/srv2.sock"); SocketStream conn3; conn3.Open(Socket::TypeINET, "localhost", 2003); +#endif // !WIN32 // Quick check that reconnections fail TEST_CHECK_THROWS(conn1.Open(Socket::TypeUNIX, "testfiles/srv2.sock");, ServerException, SocketAlreadyOpen); // Stuff some data around std::vector conns; conns.push_back(&conn1); +#ifndef WIN32 conns.push_back(&conn2); conns.push_back(&conn3); +#endif // !WIN32 Srv2TestConversations(conns); // Implicit close } +#ifndef WIN32 // HUP again TEST_THAT(HUPServer(pid)); ::sleep(1); TEST_THAT(ServerIsAlive(pid)); +#endif // !WIN32 // Kill it TEST_THAT(KillServer(pid)); ::sleep(1); TEST_THAT(!ServerIsAlive(pid)); +#ifndef WIN32 TestRemoteProcessMemLeaks("test-srv2.memleaks"); +#endif // !WIN32 } } // Launch a test SSL server { +#ifdef WIN32 + int pid = LaunchServer("test srv3 testfiles\\srv3.conf", + "testfiles\\srv3.pid"); +#else int pid = LaunchServer("./test srv3 testfiles/srv3.conf", "testfiles/srv3.pid"); +#endif TEST_THAT(pid != -1 && pid != 0); if(pid > 0) { // Will it restart? TEST_THAT(ServerIsAlive(pid)); + +#ifndef WIN32 TEST_THAT(HUPServer(pid)); ::sleep(1); TEST_THAT(ServerIsAlive(pid)); +#endif + // Make some connections { // SSL library @@ -519,36 +576,50 @@ int test(int argc, const char *argv[]) SocketStreamTLS conn1; conn1.Open(context, Socket::TypeINET, "localhost", 2003); +#ifndef WIN32 SocketStreamTLS conn2; conn2.Open(context, Socket::TypeUNIX, "testfiles/srv3.sock"); SocketStreamTLS conn3; conn3.Open(context, Socket::TypeINET, "localhost", 2003); +#endif // Quick check that reconnections fail TEST_CHECK_THROWS(conn1.Open(context, Socket::TypeUNIX, "testfiles/srv3.sock");, ServerException, SocketAlreadyOpen); // Stuff some data around std::vector conns; conns.push_back(&conn1); +#ifndef WIN32 conns.push_back(&conn2); conns.push_back(&conn3); +#endif Srv2TestConversations(conns); // Implicit close } +#ifndef WIN32 // HUP again TEST_THAT(HUPServer(pid)); ::sleep(1); TEST_THAT(ServerIsAlive(pid)); +#endif // Kill it TEST_THAT(KillServer(pid)); ::sleep(1); TEST_THAT(!ServerIsAlive(pid)); +#ifndef WIN32 TestRemoteProcessMemLeaks("test-srv3.memleaks"); +#endif } } //protocolserver: // Launch a test protocol handling server { - int pid = LaunchServer("./test srv4 testfiles/srv4.conf", "testfiles/srv4.pid"); +#ifdef WIN32 + int pid = LaunchServer("test srv4 testfiles\\srv4.conf", + "testfiles\\srv4.pid"); +#else + int pid = LaunchServer("./test srv4 testfiles/srv4.conf", + "testfiles/srv4.pid"); +#endif TEST_THAT(pid != -1 && pid != 0); if(pid > 0) { @@ -557,7 +628,11 @@ int test(int argc, const char *argv[]) // Open a connection to it SocketStream conn; +#ifdef WIN32 + conn.Open(Socket::TypeINET, "localhost", 2003); +#else conn.Open(Socket::TypeUNIX, "testfiles/srv4.sock"); +#endif // Create a protocol TestProtocolClient protocol(conn); @@ -620,7 +695,9 @@ int test(int argc, const char *argv[]) TEST_THAT(KillServer(pid)); ::sleep(1); TEST_THAT(!ServerIsAlive(pid)); +#ifndef WIN32 TestRemoteProcessMemLeaks("test-srv4.memleaks"); +#endif } } -- cgit v1.2.3