Sync libtest.
[m6w6/libmemcached] / libtest / server_container.cc
index 528fcd1fab180e288f45f9e356051e428f85f1c0..d406c16e497a15591739a58977c5d24bb9d7f665 100644 (file)
@@ -19,6 +19,7 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include <config.h>
 #include <libtest/common.h>
 
 #include <cassert>
@@ -81,7 +82,7 @@ bool server_startup_st::shutdown(uint32_t number_of_host)
   {
     Server* tmp= servers[number_of_host];
 
-    if (tmp and tmp->has_pid() and not tmp->kill(tmp->pid()))
+    if (tmp and tmp->has_pid() and tmp->kill() == false)
     { }
     else
     {
@@ -101,11 +102,24 @@ void server_startup_st::shutdown_and_remove()
   servers.clear();
 }
 
+bool server_startup_st::check() const
+{
+  for (std::vector<Server *>::const_iterator iter= servers.begin(); iter != servers.end(); iter++)
+  {
+    if ((*iter)->check()  == false)
+    {
+      return false;
+    }
+  }
+
+  return true;
+}
+
 void server_startup_st::shutdown()
 {
   for (std::vector<Server *>::iterator iter= servers.begin(); iter != servers.end(); iter++)
   {
-    if ((*iter)->has_pid() and not (*iter)->kill((*iter)->pid()))
+    if ((*iter)->has_pid() and (*iter)->kill() == false)
     {
       Error << "Unable to kill:" <<  *(*iter);
     }
@@ -120,11 +134,26 @@ void server_startup_st::restart()
   }
 }
 
+#define MAGIC_MEMORY 123575
+server_startup_st::server_startup_st() :
+  _magic(MAGIC_MEMORY),
+  _socket(false),
+  _sasl(false),
+  _count(5),
+  udp(0)
+{ }
+
 server_startup_st::~server_startup_st()
 {
   shutdown_and_remove();
 }
 
+bool server_startup_st::validate()
+{
+  return _magic == MAGIC_MEMORY;
+}
+
+
 bool server_startup_st::is_debug() const
 {
   return bool(getenv("LIBTEST_MANUAL_GDB"));
@@ -144,7 +173,10 @@ bool server_startup_st::is_helgrind() const
 bool server_startup(server_startup_st& construct, const std::string& server_type, in_port_t try_port, int argc, const char *argv[])
 {
   Outn();
-  (void)try_port;
+  if (try_port <= 0)
+  {
+    libtest::fatal(LIBYATL_DEFAULT_PARAM, "was passed the invalid port number %d", int(try_port));
+  }
 
   libtest::Server *server= NULL;
   if (0)
@@ -192,11 +224,20 @@ bool server_startup(server_startup_st& construct, const std::string& server_type
       }
     }
   }
+  else if (server_type.compare("memcached-light") == 0)
+  {
+    if (MEMCACHED_LIGHT_BINARY)
+    {
+      if (HAVE_LIBMEMCACHED)
+      {
+        server= build_memcached_light("localhost", try_port);
+      }
+    }
+  }
 
   if (server == NULL)
   {
-    Error << "Failure occured while creating server: " <<  server_type;
-    return false;
+    fatal_message("Launching of an unknown server was attempted");
   }
 
   /*
@@ -216,12 +257,13 @@ bool server_startup(server_startup_st& construct, const std::string& server_type
     Out << "Pausing for startup, hit return when ready.";
     std::string gdb_command= server->base_command();
     std::string options;
+#if 0
     Out << "run " << server->args(options);
+#endif
     getchar();
   }
   else if (server->start() == false)
   {
-    Error << "Failed to start " << *server;
     delete server;
     return false;
   }
@@ -299,7 +341,7 @@ bool server_startup_st::start_socket_server(const std::string& server_type, cons
   /*
     We will now cycle the server we have created.
   */
-  if (not server->cycle())
+  if (server->cycle() == false)
   {
     Error << "Could not start up server " << *server;
     delete server;
@@ -313,7 +355,9 @@ bool server_startup_st::start_socket_server(const std::string& server_type, cons
     Out << "Pausing for startup, hit return when ready.";
     std::string gdb_command= server->base_command();
     std::string options;
+#if 0
     Out << "run " << server->args(options);
+#endif
     getchar();
   }
   else if (not server->start())