diff options
Diffstat (limited to 'test/basicserver')
-rw-r--r-- | test/basicserver/Makefile.extra | 8 | ||||
-rw-r--r-- | test/basicserver/TestCommands.cpp | 4 | ||||
-rw-r--r-- | test/basicserver/TestContext.cpp | 2 | ||||
-rw-r--r-- | test/basicserver/TestContext.h | 2 | ||||
-rw-r--r-- | test/basicserver/testbasicserver.cpp | 265 | ||||
-rw-r--r-- | test/basicserver/testfiles/srv4.conf | 2 |
6 files changed, 214 insertions, 69 deletions
diff --git a/test/basicserver/Makefile.extra b/test/basicserver/Makefile.extra index 51280db9..3feda961 100644 --- a/test/basicserver/Makefile.extra +++ b/test/basicserver/Makefile.extra @@ -6,16 +6,16 @@ GEN_CMD_CLI = $(MAKEPROTOCOL) Client testprotocol.txt # AUTOGEN SEEDING autogen_TestProtocolServer.cpp: $(MAKEPROTOCOL) testprotocol.txt - perl $(GEN_CMD_SRV) + $(PERL) $(GEN_CMD_SRV) autogen_TestProtocolServer.h: $(MAKEPROTOCOL) testprotocol.txt - perl $(GEN_CMD_SRV) + $(PERL) $(GEN_CMD_SRV) # AUTOGEN SEEDING autogen_TestProtocolClient.cpp: $(MAKEPROTOCOL) testprotocol.txt - perl $(GEN_CMD_CLI) + $(PERL) $(GEN_CMD_CLI) autogen_TestProtocolClient.h: $(MAKEPROTOCOL) testprotocol.txt - perl $(GEN_CMD_CLI) + $(PERL) $(GEN_CMD_CLI) diff --git a/test/basicserver/TestCommands.cpp b/test/basicserver/TestCommands.cpp index d879ff9d..09626238 100644 --- a/test/basicserver/TestCommands.cpp +++ b/test/basicserver/TestCommands.cpp @@ -1,4 +1,4 @@ -// distribution boxbackup-0.10 (svn version: 494) +// distribution boxbackup-0.11rc1 (svn version: 2023_2024) // // Copyright (c) 2003 - 2006 // Ben Summers and contributors. All rights reserved. @@ -39,7 +39,9 @@ #include "Box.h" +#ifdef HAVE_SYSLOG_H #include <syslog.h> +#endif #include "autogen_TestProtocolServer.h" #include "CollectInBufferStream.h" diff --git a/test/basicserver/TestContext.cpp b/test/basicserver/TestContext.cpp index 8c99dde7..042c4d78 100644 --- a/test/basicserver/TestContext.cpp +++ b/test/basicserver/TestContext.cpp @@ -1,4 +1,4 @@ -// distribution boxbackup-0.10 (svn version: 494) +// distribution boxbackup-0.11rc1 (svn version: 2023_2024) // // Copyright (c) 2003 - 2006 // Ben Summers and contributors. All rights reserved. diff --git a/test/basicserver/TestContext.h b/test/basicserver/TestContext.h index 27663e95..c606c72a 100644 --- a/test/basicserver/TestContext.h +++ b/test/basicserver/TestContext.h @@ -1,4 +1,4 @@ -// distribution boxbackup-0.10 (svn version: 494) +// distribution boxbackup-0.11rc1 (svn version: 2023_2024) // // Copyright (c) 2003 - 2006 // Ben Summers and contributors. All rights reserved. diff --git a/test/basicserver/testbasicserver.cpp b/test/basicserver/testbasicserver.cpp index 9045b34b..90d4bb79 100644 --- a/test/basicserver/testbasicserver.cpp +++ b/test/basicserver/testbasicserver.cpp @@ -1,4 +1,4 @@ -// distribution boxbackup-0.10 (svn version: 494) +// distribution boxbackup-0.11rc1 (svn version: 2023_2024) // // Copyright (c) 2003 - 2006 // Ben Summers and contributors. All rights reserved. @@ -66,10 +66,10 @@ #include "TestContext.h" #include "autogen_TestProtocolClient.h" #include "autogen_TestProtocolServer.h" +#include "ServerControl.h" #include "MemLeakFindOn.h" - #define SERVER_LISTEN_PORT 2003 // in ms @@ -100,10 +100,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 @@ -160,6 +164,25 @@ void testservers_connection(SocketStream &rStream) total += r; } TEST_THAT(total == LARGE_DATA_SIZE); + if (total != LARGE_DATA_SIZE) + { + BOX_ERROR("Expected " << + LARGE_DATA_SIZE << " bytes " << + "but was " << total); + return; + } + } + { + // Send lots of data again + char data[LARGE_DATA_BLOCK_SIZE]; + for(unsigned int y = 0; y < sizeof(data); y++) + { + data[y] = y & 0xff; + } + for(int s = 0; s < (LARGE_DATA_SIZE / LARGE_DATA_BLOCK_SIZE); ++s) + { + rStream.Write(data, sizeof(data)); + } } // next! @@ -379,6 +402,18 @@ void Srv2TestConversations(const std::vector<IOStream *> &conns) conns[c]->Write(data, sizeof(data)); } } + for(unsigned int c = 0; c < conns.size(); ++c) + { + // Receive lots of data again + char buf[1024]; + int total = 0; + int r = 0; + while(total < LARGE_DATA_SIZE && (r = conns[c]->Read(buf, sizeof(buf))) != 0) + { + total += r; + } + TEST_THAT(total == LARGE_DATA_SIZE); + } for(unsigned int c = 0; c < conns.size(); ++c) { @@ -441,108 +476,184 @@ int test(int argc, const char *argv[]) // Server launching stuff if(argc >= 2) { - if(strcmp(argv[1], "srv1") == 0) + // this is a quick hack to allow passing some options + // to the daemon + + const char* mode = argv[1]; + + if (test_args.length() > 0) + { + argv[1] = test_args.c_str(); + } + else + { + argc--; + argv++; + } + + if(strcmp(mode, "srv1") == 0) { // Run very basic daemon basicdaemon daemon; - return daemon.Main("doesnotexist", argc - 1, argv + 1); + return daemon.Main("doesnotexist", argc, argv); } - else if(strcmp(argv[1], "srv2") == 0) + else if(strcmp(mode, "srv2") == 0) { // Run daemon which accepts connections testserver daemon; - return daemon.Main("doesnotexist", argc - 1, argv + 1); + return daemon.Main("doesnotexist", argc, argv); } - else if(strcmp(argv[1], "srv3") == 0) + else if(strcmp(mode, "srv3") == 0) { testTLSserver daemon; - return daemon.Main("doesnotexist", argc - 1, argv + 1); + return daemon.Main("doesnotexist", argc, argv); } - else if(strcmp(argv[1], "srv4") == 0) + else if(strcmp(mode, "srv4") == 0) { testProtocolServer daemon; - return daemon.Main("doesnotexist", argc - 1, argv + 1); + return daemon.Main("doesnotexist", argc, argv); } } -//printf("SKIPPING TESTS------------------------\n"); -//goto protocolserver; + //printf("SKIPPING TESTS------------------------\n"); + //goto protocolserver; // Launch a basic server { - int pid = LaunchServer("./test srv1 testfiles/srv1.conf", "testfiles/srv1.pid"); + std::string cmd = "./test --test-daemon-args="; + cmd += test_args; + cmd += " srv1 testfiles/srv1.conf"; + int pid = LaunchServer(cmd, "testfiles/srv1.pid"); + 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); - // 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")); + #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" + DIRECTORY_SEPARATOR "srv1.test2")); + #endif // !WIN32 + // Kill it off TEST_THAT(KillServer(pid)); - TestRemoteProcessMemLeaks("generic-daemon.memleaks"); + + #ifndef WIN32 + TestRemoteProcessMemLeaks( + "generic-daemon.memleaks"); + #endif // !WIN32 } } // Launch a test forking server { - int pid = LaunchServer("./test srv2 testfiles/srv2.conf", "testfiles/srv2.pid"); + std::string cmd = "./test --test-daemon-args="; + cmd += test_args; + cmd += " srv2 testfiles/srv2.conf"; + int pid = LaunchServer(cmd, "testfiles/srv2.pid"); + TEST_THAT(pid != -1 && pid != 0); + if(pid > 0) { // Will it restart? TEST_THAT(ServerIsAlive(pid)); - TEST_THAT(HUPServer(pid)); - ::sleep(1); - 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); - SocketStream conn2; - conn2.Open(Socket::TypeUNIX, "testfiles/srv2.sock"); - SocketStream conn3; - conn3.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); + TEST_CHECK_THROWS(conn1.Open(Socket::TypeUNIX, + "testfiles/srv2.sock");, + ServerException, SocketAlreadyOpen); + // Stuff some data around std::vector<IOStream *> conns; conns.push_back(&conn1); - conns.push_back(&conn2); - conns.push_back(&conn3); + + #ifndef WIN32 + conns.push_back(&conn2); + conns.push_back(&conn3); + #endif // !WIN32 + Srv2TestConversations(conns); // Implicit close } - // HUP again - TEST_THAT(HUPServer(pid)); - ::sleep(1); - TEST_THAT(ServerIsAlive(pid)); + + #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)); - TestRemoteProcessMemLeaks("test-srv2.memleaks"); + + #ifndef WIN32 + TestRemoteProcessMemLeaks("test-srv2.memleaks"); + #endif // !WIN32 } } // Launch a test SSL server { - int pid = LaunchServer("./test srv3 testfiles/srv3.conf", "testfiles/srv3.pid"); + std::string cmd = "./test --test-daemon-args="; + cmd += test_args; + cmd += " srv3 testfiles/srv3.conf"; + int pid = LaunchServer(cmd, "testfiles/srv3.pid"); + TEST_THAT(pid != -1 && pid != 0); + if(pid > 0) { // Will it restart? TEST_THAT(ServerIsAlive(pid)); - TEST_THAT(HUPServer(pid)); - ::sleep(1); - TEST_THAT(ServerIsAlive(pid)); + + #ifndef WIN32 + TEST_THAT(HUPServer(pid)); + ::sleep(1); + TEST_THAT(ServerIsAlive(pid)); + #endif + // Make some connections { // SSL library @@ -557,37 +668,62 @@ int test(int argc, const char *argv[]) SocketStreamTLS conn1; conn1.Open(context, Socket::TypeINET, "localhost", 2003); - SocketStreamTLS conn2; - conn2.Open(context, Socket::TypeUNIX, "testfiles/srv3.sock"); - SocketStreamTLS conn3; - conn3.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); + TEST_CHECK_THROWS(conn1.Open(context, + Socket::TypeUNIX, + "testfiles/srv3.sock");, + ServerException, SocketAlreadyOpen); + // Stuff some data around std::vector<IOStream *> conns; conns.push_back(&conn1); - conns.push_back(&conn2); - conns.push_back(&conn3); + + #ifndef WIN32 + conns.push_back(&conn2); + conns.push_back(&conn3); + #endif + Srv2TestConversations(conns); // Implicit close } - // HUP again - TEST_THAT(HUPServer(pid)); - ::sleep(1); - TEST_THAT(ServerIsAlive(pid)); + + #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)); - TestRemoteProcessMemLeaks("test-srv3.memleaks"); + + #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"); + std::string cmd = "./test --test-daemon-args="; + cmd += test_args; + cmd += " srv4 testfiles/srv4.conf"; + int pid = LaunchServer(cmd, "testfiles/srv4.pid"); + TEST_THAT(pid != -1 && pid != 0); + if(pid > 0) { ::sleep(1); @@ -595,7 +731,11 @@ int test(int argc, const char *argv[]) // Open a connection to it SocketStream conn; - conn.Open(Socket::TypeUNIX, "testfiles/srv4.sock"); + #ifdef WIN32 + conn.Open(Socket::TypeINET, "localhost", 2003); + #else + conn.Open(Socket::TypeUNIX, "testfiles/srv4.sock"); + #endif // Create a protocol TestProtocolClient protocol(conn); @@ -658,7 +798,10 @@ int test(int argc, const char *argv[]) TEST_THAT(KillServer(pid)); ::sleep(1); TEST_THAT(!ServerIsAlive(pid)); - TestRemoteProcessMemLeaks("test-srv4.memleaks"); + + #ifndef WIN32 + TestRemoteProcessMemLeaks("test-srv4.memleaks"); + #endif } } diff --git a/test/basicserver/testfiles/srv4.conf b/test/basicserver/testfiles/srv4.conf index b4c5627c..f05dff75 100644 --- a/test/basicserver/testfiles/srv4.conf +++ b/test/basicserver/testfiles/srv4.conf @@ -1,6 +1,6 @@ Server { PidFile = testfiles/srv4.pid - ListenAddresses = unix:testfiles/srv4.sock + ListenAddresses = unix:testfiles/srv4.sock,inet:localhost } |