Browse Source

Merge in work.

Brian Aker 13 years ago
parent
commit
1c8fb3e0c6
10 changed files with 513 additions and 463 deletions
  1. 1 0
      libtest/common.h
  2. 4 4
      libtest/comparison.hpp
  3. 1 1
      libtest/error.h
  4. 3 0
      libtest/include.am
  5. 36 6
      libtest/killpid.cc
  6. 8 1
      libtest/killpid.h
  7. 82 40
      libtest/memcached.cc
  8. 0 335
      libtest/server.cc
  9. 0 76
      libtest/server.h
  10. 378 0
      libtest/server_container.cc

+ 1 - 0
libtest/common.h

@@ -63,5 +63,6 @@ static inline bool is_pid_valid(const pid_t pid)
 #include <libtest/memcached.h>
 
 #include <libtest/libtool.hpp>
+#include <libtest/killpid.h>
 
 #include <libtest/test.hpp>

+ 4 - 4
libtest/comparison.hpp

@@ -24,11 +24,11 @@
 #include <typeinfo>
 #include <libtest/strerror.h>
 
-#if defined(LIBTEST_WITH_LIBMEMCACHED_SUPPORT) && LIBTEST_WITH_LIBMEMCACHED_SUPPORT
+#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
 #include <libmemcached/memcached.h>
 #endif
 
-#if defined(LIBTEST_WITH_LIBGEARMAN_SUPPORT) && LIBTEST_WITH_LIBGEARMAN_SUPPORT
+#if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
 #include <libgearman/gearman.h>
 #endif
 
@@ -62,7 +62,7 @@ bool _compare(const char *file, int line, const char *func, const T_comparable _
         << got_str
         << "\"";
     }
-#if (defined(LIBTEST_WITH_LIBMEMCACHED_SUPPORT) && LIBTEST_WITH_LIBMEMCACHED_SUPPORT)
+#if (defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED)
     else if (typeid(__expected) == typeid(memcached_return_t))
     {
       libtest::stream::make_cerr(file, line, func) << "Expected \"" 
@@ -71,7 +71,7 @@ bool _compare(const char *file, int line, const char *func, const T_comparable _
         << memcached_strerror(NULL, memcached_return_t(__actual)) << "\"";
     }
 #endif
-#if defined(LIBTEST_WITH_LIBGEARMAN_SUPPORT) && LIBTEST_WITH_LIBGEARMAN_SUPPORT
+#if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
     else if (typeid(__expected) == typeid(gearman_return_t))
     {
       libtest::stream::make_cerr(file, line, func) << "Expected \"" 

+ 1 - 1
libtest/error.h

@@ -23,7 +23,7 @@
 #pragma once
 
 enum test_return_t {
-  TEST_SUCCESS= 0, /* Backwards compatibility */
+  TEST_SUCCESS,
   TEST_FAILURE,
   TEST_MEMORY_ALLOCATION_FAILURE,
   TEST_SKIPPED,

+ 3 - 0
libtest/include.am

@@ -70,6 +70,7 @@ noinst_HEADERS+= \
 		 libtest/memcached.h \
 		 libtest/runner.h \
 		 libtest/server.h \
+		 libtest/server_container.h \
 		 libtest/signal.h \
 		 libtest/stats.h \
 		 libtest/stream.h \
@@ -88,6 +89,7 @@ libtest_libtest_la_SOURCES= \
 			    libtest/libtool.cc \
 			    libtest/runner.cc \
 			    libtest/server.cc \
+			    libtest/server_container.cc \
 			    libtest/signal.cc \
 			    libtest/test.cc
 
@@ -183,6 +185,7 @@ libtest_unittest_DEPENDENCIES+= libtest/libtest.la libtest_tmp_dir
 libtest_unittest_LDADD+= libtest/libtest.la
 libtest_unittest_SOURCES= libtest/unittest.cc
 check_PROGRAMS+= libtest/unittest
+noinst_PROGRAMS+= libtest/unittest
 test-unittest: libtest/unittest
 	@libtest/unittest
 

+ 36 - 6
libtest/killpid.cc

@@ -85,15 +85,43 @@ bool kill_pid(pid_t pid_arg)
   return true;
 }
 
-
-pid_t kill_file(const std::string &filename)
+bool check_pid(const std::string &filename)
 {
-  pid_t ret= -1;
+  if (filename.empty())
+  {
+    return false;
+  }
+
   FILE *fp;
+  if ((fp= fopen(filename.c_str(), "r")))
+  {
+    char pid_buffer[1024];
+
+    char *ptr= fgets(pid_buffer, sizeof(pid_buffer), fp);
+    fclose(fp);
 
+    if (ptr)
+    {
+      pid_t pid= (pid_t)atoi(pid_buffer);
+      if (pid > 0)
+      {
+        return (::kill(pid, 0) == 0);
+      }
+    }
+  }
+  
+  return false;
+}
+
+
+bool kill_file(const std::string &filename)
+{
   if (filename.empty())
-    return ret;
+  {
+    return true;
+  }
 
+  FILE *fp;
   if ((fp= fopen(filename.c_str(), "r")))
   {
     char pid_buffer[1024];
@@ -106,13 +134,15 @@ pid_t kill_file(const std::string &filename)
       pid_t pid= (pid_t)atoi(pid_buffer);
       if (pid != 0)
       {
-        kill_pid(pid);
+        bool ret= kill_pid(pid);
         unlink(filename.c_str()); // If this happens we may be dealing with a dead server that left its pid file.
+
+        return ret;
       }
     }
   }
   
-  return ret;
+  return false;
 }
 
 #define STRINGIFY(x) #x

+ 8 - 1
libtest/killpid.h

@@ -25,6 +25,13 @@
 
 bool kill_pid(pid_t pid_arg);
 
-pid_t kill_file(const std::string &filename);
+bool kill_file(const std::string &filename);
+
+bool check_pid(const std::string &filename);
 
 pid_t get_pid_from_file(const std::string &filename, std::stringstream& error_message);
+
+static inline bool check_pid(pid_t pid_arg)
+{
+  return (pid_arg > 1);
+}

+ 82 - 40
libtest/memcached.cc

@@ -97,28 +97,14 @@ public:
     }
 
     pid_t local_pid;
-    memcached_return_t rc;
+    memcached_return_t rc= MEMCACHED_SUCCESS;
     if (has_socket())
     {
-      if (username().empty())
-      {
-        local_pid= libmemcached_util_getpid(socket().c_str(), 0, &rc);
-      }
-      else
-      {
-        local_pid= libmemcached_util_getpid2(socket().c_str(), 0, username().c_str(), password().c_str(), &rc);
-      }
+      local_pid= libmemcached_util_getpid(socket().c_str(), 0, &rc);
     }
     else
     {
-      if (username().empty())
-      {
-        local_pid= libmemcached_util_getpid(hostname().c_str(), port(), &rc);
-      }
-      else
-      {
-        local_pid= libmemcached_util_getpid2(hostname().c_str(), port(), username().c_str(), password().c_str(), &rc);
-      }
+      local_pid= libmemcached_util_getpid(hostname().c_str(), port(), &rc);
     }
 
     if (error_is_ok and ((memcached_failed(rc) or not is_pid_valid(local_pid))))
@@ -148,37 +134,16 @@ public:
 
     if (has_socket())
     {
-      if (username().empty())
-      {
         ret= libmemcached_util_ping(socket().c_str(), 0, &rc);
-      }
-      else
-      {
-        ret= libmemcached_util_ping2(socket().c_str(), 0, username().c_str(), password().c_str(), &rc);
-      }
     }
     else
     {
-      if (username().empty())
-      {
-        ret= libmemcached_util_ping(hostname().c_str(), port(), &rc);
-      }
-      else
-      {
-        ret= libmemcached_util_ping2(hostname().c_str(), port(), username().c_str(), password().c_str(), &rc);
-      }
+      ret= libmemcached_util_ping(hostname().c_str(), port(), &rc);
     }
 
     if (memcached_failed(rc) or not ret)
     {
-      if (username().empty())
-      {
-        Error << "libmemcached_util_ping(" << hostname() << ", " << port() << ") error: " << memcached_strerror(NULL, rc);
-      }
-      else
-      {
-        Error << "libmemcached_util_ping2(" << hostname() << ", " << port() << ", " << username() << ", " << password() << ") error: " << memcached_strerror(NULL, rc);
-      }
+      Error << "libmemcached_util_ping(" << hostname() << ", " << port() << ") error: " << memcached_strerror(NULL, rc);
     }
 
     return ret;
@@ -260,6 +225,73 @@ public:
     return MEMCACHED_SASL_BINARY;
   }
 
+  pid_t get_pid(bool error_is_ok)
+  {
+    // Memcached is slow to start, so we need to do this
+    if (not pid_file().empty())
+    {
+      Wait wait(pid_file(), 0);
+
+      if (error_is_ok and not wait.successful())
+      {
+        Error << "Pidfile was not found:" << pid_file();
+        return -1;
+      }
+    }
+
+    pid_t local_pid;
+    memcached_return_t rc;
+    if (has_socket())
+    {
+      local_pid= libmemcached_util_getpid2(socket().c_str(), 0, username().c_str(), password().c_str(), &rc);
+    }
+    else
+    {
+      local_pid= libmemcached_util_getpid2(hostname().c_str(), port(), username().c_str(), password().c_str(), &rc);
+    }
+
+    if (error_is_ok and ((memcached_failed(rc) or not is_pid_valid(local_pid))))
+    {
+      Error << "libmemcached_util_getpid2(" << memcached_strerror(NULL, rc) << ") username: " << username() << " password: " << password() << " pid: " << local_pid << " for:" << *this;
+    }
+
+    return local_pid;
+  }
+
+  bool ping()
+  {
+    // Memcached is slow to start, so we need to do this
+    if (not pid_file().empty())
+    {
+      Wait wait(pid_file(), 0);
+
+      if (not wait.successful())
+      {
+        Error << "Pidfile was not found:" << pid_file();
+        return -1;
+      }
+    }
+
+    memcached_return_t rc;
+    bool ret;
+
+    if (has_socket())
+    {
+      ret= libmemcached_util_ping2(socket().c_str(), 0, username().c_str(), password().c_str(), &rc);
+    }
+    else
+    {
+      ret= libmemcached_util_ping2(hostname().c_str(), port(), username().c_str(), password().c_str(), &rc);
+    }
+
+    if (memcached_failed(rc) or not ret)
+    {
+      Error << "libmemcached_util_ping2(" << hostname() << ", " << port() << ", " << username() << ", " << password() << ") error: " << memcached_strerror(NULL, rc);
+    }
+
+    return ret;
+  }
+
 };
 
 
@@ -308,11 +340,21 @@ libtest::Server *build_memcached_socket(const std::string& socket_file, const in
 
 libtest::Server *build_memcached_sasl(const std::string& hostname, const in_port_t try_port, const std::string& username, const std::string &password)
 {
+  if (username.empty())
+  {
+    return new MemcachedSaSL(hostname, try_port, false,  "memcached", "memcached");
+  }
+
   return new MemcachedSaSL(hostname, try_port, false,  username, password);
 }
 
 libtest::Server *build_memcached_sasl_socket(const std::string& socket_file, const in_port_t try_port, const std::string& username, const std::string &password)
 {
+  if (username.empty())
+  {
+    return new MemcachedSaSL(socket_file, try_port, true, "memcached", "memcached");
+  }
+
   return new MemcachedSaSL(socket_file, try_port, true, username, password);
 }
 

+ 0 - 335
libtest/server.cc

@@ -113,13 +113,6 @@ Server::~Server()
   }
 }
 
-std::string server_startup_st::option_string() const
-{
-  std::string temp= server_list;
-  rtrim(temp);
-  return temp;
-}
-
 // If the server exists, kill it
 bool Server::cycle()
 {
@@ -445,332 +438,4 @@ bool Server::kill(pid_t pid_arg)
   return false;
 }
 
-void server_startup_st::push_server(Server *arg)
-{
-  servers.push_back(arg);
-
-  char port_str[NI_MAXSERV];
-  snprintf(port_str, sizeof(port_str), "%u", int(arg->port()));
-
-  std::string server_config_string;
-  if (arg->has_socket())
-  {
-    server_config_string+= "--socket=";
-    server_config_string+= '"';
-    server_config_string+= arg->socket();
-    server_config_string+= '"';
-    server_config_string+= " ";
-  }
-  else
-  {
-    server_config_string+= "--server=";
-    server_config_string+= arg->hostname();
-    server_config_string+= ":";
-    server_config_string+= port_str;
-    server_config_string+= " ";
-  }
-
-  server_list+= server_config_string;
-
-}
-
-Server* server_startup_st::pop_server()
-{
-  Server *tmp= servers.back();
-  servers.pop_back();
-  return tmp;
-}
-
-void server_startup_st::shutdown(bool remove)
-{
-  if (remove)
-  {
-    for (std::vector<Server *>::iterator iter= servers.begin(); iter != servers.end(); iter++)
-    {
-      delete *iter;
-    }
-    servers.clear();
-  }
-  else
-  {
-    for (std::vector<Server *>::iterator iter= servers.begin(); iter != servers.end(); iter++)
-    {
-      if ((*iter)->has_pid() and not (*iter)->kill((*iter)->pid()))
-      {
-        Error << "Unable to kill:" <<  *(*iter);
-      }
-    }
-  }
-}
-
-server_startup_st::~server_startup_st()
-{
-  shutdown(true);
-}
-
-bool server_startup_st::is_debug() const
-{
-  return bool(getenv("LIBTEST_MANUAL_GDB"));
-}
-
-bool server_startup_st::is_valgrind() const
-{
-  return bool(getenv("LIBTEST_MANUAL_VALGRIND"));
-}
-
-bool server_startup_st::is_helgrind() const
-{
-  return bool(getenv("LIBTEST_MANUAL_HELGRIND"));
-}
-
-
-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;
-
-  // Look to see if we are being provided ports to use
-  {
-    char variable_buffer[1024];
-    snprintf(variable_buffer, sizeof(variable_buffer), "LIBTEST_PORT_%lu", (unsigned long)construct.count());
-
-    char *var;
-    if ((var= getenv(variable_buffer)))
-    {
-      in_port_t tmp= in_port_t(atoi(var));
-
-      if (tmp > 0)
-        try_port= tmp;
-    }
-  }
-
-  libtest::Server *server= NULL;
-  if (0)
-  { }
-  else if (server_type.compare("gearmand") == 0)
-  {
-    if (GEARMAND_BINARY)
-    {
-      if (HAVE_LIBGEARMAN)
-      {
-        server= build_gearmand("localhost", try_port);
-      }
-      else
-      {
-        Error << "Libgearman was not found";
-      }
-    } 
-    else
-    {
-      Error << "No gearmand binary is available";
-    }
-  }
-  else if (server_type.compare("blobslap_worker") == 0)
-  {
-    if (GEARMAND_BINARY and GEARMAND_BLOBSLAP_WORKER)
-    {
-      if (HAVE_LIBGEARMAN)
-      {
-        server= build_blobslap_worker(try_port);
-      }
-      else
-      {
-        Error << "Libgearman was not found";
-      }
-    }
-    else
-    {
-      Error << "No gearmand binary is available";
-    }
-  }
-  else if (server_type.compare("memcached-sasl") == 0)
-  {
-    if (MEMCACHED_SASL_BINARY)
-    {
-      if (HAVE_LIBMEMCACHED)
-      {
-        server= build_memcached_sasl("localhost", try_port, construct.username(), construct.password());
-      }
-      else
-      {
-        Error << "Libmemcached was not found";
-      }
-    }
-    else
-    {
-      Error << "No memcached binary that was compiled with sasl is available";
-    }
-  }
-  else if (server_type.compare("memcached") == 0)
-  {
-    if (MEMCACHED_BINARY)
-    {
-      if (HAVE_LIBMEMCACHED)
-      {
-        server= build_memcached("localhost", try_port);
-      }
-      else
-      {
-        Error << "Libmemcached was not found";
-      }
-    }
-    else
-    {
-      Error << "No memcached binary is available";
-    }
-  }
-  else
-  {
-    Error << "Failed to start " << server_type << ", no support was found to be compiled in for it.";
-  }
-
-  if (server == NULL)
-  {
-    Error << "Failure occured while creating server: " <<  server_type;
-    return false;
-  }
-
-  /*
-    We will now cycle the server we have created.
-  */
-  if (not server->cycle())
-  {
-    Error << "Could not start up server " << *server;
-    delete server;
-    return false;
-  }
-
-  server->build(argc, argv);
-
-  if (construct.is_debug())
-  {
-    Out << "Pausing for startup, hit return when ready.";
-    std::string gdb_command= server->base_command();
-    std::string options;
-    Out << "run " << server->args(options);
-    getchar();
-  }
-  else if (not server->start())
-  {
-    Error << "Failed to start " << *server;
-    delete server;
-    return false;
-  }
-  else
-  {
-    Out << "STARTING SERVER(pid:" << server->pid() << "): " << server->running();
-  }
-
-  construct.push_server(server);
-
-  if (default_port() == 0)
-  {
-    assert(server->has_port());
-    set_default_port(server->port());
-  }
-
-  Outn();
-
-  return true;
-}
-
-bool server_startup_st::start_socket_server(const std::string& server_type, const in_port_t try_port, int argc, const char *argv[])
-{
-  (void)try_port;
-  Outn();
-
-  Server *server= NULL;
-  if (0)
-  { }
-  else if (server_type.compare("gearmand") == 0)
-  {
-    Error << "Socket files are not supported for gearmand yet";
-  }
-  else if (server_type.compare("memcached-sasl") == 0)
-  {
-    if (MEMCACHED_SASL_BINARY)
-    {
-      if (HAVE_LIBMEMCACHED)
-      {
-        server= build_memcached_sasl_socket("localhost", try_port, username(), password());
-      }
-      else
-      {
-        Error << "Libmemcached was not found";
-      }
-    }
-    else
-    {
-      Error << "No memcached binary is available";
-    }
-  }
-  else if (server_type.compare("memcached") == 0)
-  {
-    if (MEMCACHED_BINARY)
-    {
-      if (HAVE_LIBMEMCACHED)
-      {
-        server= build_memcached_socket("localhost", try_port);
-      }
-      else
-      {
-        Error << "Libmemcached was not found";
-      }
-    }
-    else
-    {
-      Error << "No memcached binary is available";
-    }
-  }
-  else
-  {
-    Error << "Failed to start " << server_type << ", no support was found to be compiled in for it.";
-  }
-
-  if (server == NULL)
-  {
-    Error << "Failure occured while creating server: " <<  server_type;
-    return false;
-  }
-
-  /*
-    We will now cycle the server we have created.
-  */
-  if (not server->cycle())
-  {
-    Error << "Could not start up server " << *server;
-    delete server;
-    return false;
-  }
-
-  server->build(argc, argv);
-
-  if (is_debug())
-  {
-    Out << "Pausing for startup, hit return when ready.";
-    std::string gdb_command= server->base_command();
-    std::string options;
-    Out << "run " << server->args(options);
-    getchar();
-  }
-  else if (not server->start())
-  {
-    Error << "Failed to start " << *server;
-    delete server;
-    return false;
-  }
-  else
-  {
-    Out << "STARTING SERVER(pid:" << server->pid() << "): " << server->running();
-  }
-
-  push_server(server);
-
-  set_default_socket(server->socket().c_str());
-
-  Outn();
-
-  return true;
-}
-
 } // namespace libtest

+ 0 - 76
libtest/server.h

@@ -185,82 +185,6 @@ private:
 
 std::ostream& operator<<(std::ostream& output, const libtest::Server &arg);
 
-class server_startup_st
-{
-private:
-  std::string server_list;
-  bool _socket;
-  bool _sasl;
-  std::string _username;
-  std::string _password;
-
-public:
-
-  uint8_t udp;
-  std::vector<Server *> servers;
-
-  server_startup_st() :
-    _socket(false),
-    _sasl(false),
-    udp(0)
-  { }
-
-  bool start_socket_server(const std::string& server_type, const in_port_t try_port, int argc, const char *argv[]);
-
-  std::string option_string() const;
-
-  size_t count() const
-  {
-    return servers.size();
-  }
-
-  const std::string& password() const
-  {
-    return _password;
-  }
-
-  const std::string& username() const
-  {
-    return _username;
-  }
-
-
-  bool is_debug() const;
-  bool is_helgrind() const;
-  bool is_valgrind() const;
-
-  bool socket()
-  {
-    return _socket;
-  }
-
-  bool sasl()
-  {
-    return _sasl;
-  }
-
-  void set_socket()
-  {
-    _socket= true;
-  }
-
-  void set_sasl(const std::string& username_arg, const std::string& password_arg)
-  {
-    _sasl= true;
-    _username= username_arg;
-    _password= password_arg;
-  }
-
-
-  void shutdown(bool remove= false);
-  void push_server(Server *);
-  Server *pop_server();
-
-  ~server_startup_st();
-};
-
-bool server_startup(server_startup_st&, const std::string&, in_port_t try_port, int argc, const char *argv[]);
-
 } // namespace libtest
 
 

+ 378 - 0
libtest/server_container.cc

@@ -0,0 +1,378 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  libtest
+ *
+ *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 3 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <libtest/common.h>
+
+#include <cassert>
+#include <cerrno>
+#include <cstdlib>
+#include <iostream>
+
+#include <algorithm> 
+#include <functional> 
+#include <locale>
+
+// trim from end 
+static inline std::string &rtrim(std::string &s)
+{ 
+  s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end()); 
+  return s; 
+}
+
+namespace libtest {
+
+void server_startup_st::push_server(Server *arg)
+{
+  servers.push_back(arg);
+
+  char port_str[NI_MAXSERV];
+  snprintf(port_str, sizeof(port_str), "%u", int(arg->port()));
+
+  std::string server_config_string;
+  if (arg->has_socket())
+  {
+    server_config_string+= "--socket=";
+    server_config_string+= '"';
+    server_config_string+= arg->socket();
+    server_config_string+= '"';
+    server_config_string+= " ";
+  }
+  else
+  {
+    server_config_string+= "--server=";
+    server_config_string+= arg->hostname();
+    server_config_string+= ":";
+    server_config_string+= port_str;
+    server_config_string+= " ";
+  }
+
+  server_list+= server_config_string;
+
+}
+
+Server* server_startup_st::pop_server()
+{
+  Server *tmp= servers.back();
+  servers.pop_back();
+  return tmp;
+}
+
+void server_startup_st::shutdown(bool remove)
+{
+  if (remove)
+  {
+    for (std::vector<Server *>::iterator iter= servers.begin(); iter != servers.end(); iter++)
+    {
+      delete *iter;
+    }
+    servers.clear();
+  }
+  else
+  {
+    for (std::vector<Server *>::iterator iter= servers.begin(); iter != servers.end(); iter++)
+    {
+      if ((*iter)->has_pid() and not (*iter)->kill((*iter)->pid()))
+      {
+        Error << "Unable to kill:" <<  *(*iter);
+      }
+    }
+  }
+}
+
+server_startup_st::~server_startup_st()
+{
+  shutdown(true);
+}
+
+bool server_startup_st::is_debug() const
+{
+  return bool(getenv("LIBTEST_MANUAL_GDB"));
+}
+
+bool server_startup_st::is_valgrind() const
+{
+  return bool(getenv("LIBTEST_MANUAL_VALGRIND"));
+}
+
+bool server_startup_st::is_helgrind() const
+{
+  return bool(getenv("LIBTEST_MANUAL_HELGRIND"));
+}
+
+
+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;
+
+  // Look to see if we are being provided ports to use
+  {
+    char variable_buffer[1024];
+    snprintf(variable_buffer, sizeof(variable_buffer), "LIBTEST_PORT_%lu", (unsigned long)construct.count());
+
+    char *var;
+    if ((var= getenv(variable_buffer)))
+    {
+      in_port_t tmp= in_port_t(atoi(var));
+
+      if (tmp > 0)
+        try_port= tmp;
+    }
+  }
+
+  libtest::Server *server= NULL;
+  if (0)
+  { }
+  else if (server_type.compare("gearmand") == 0)
+  {
+    if (GEARMAND_BINARY)
+    {
+      if (HAVE_LIBGEARMAN)
+      {
+        server= build_gearmand("localhost", try_port);
+      }
+      else
+      {
+        Error << "Libgearman was not found";
+      }
+    } 
+    else
+    {
+      Error << "No gearmand binary is available";
+    }
+  }
+  else if (server_type.compare("blobslap_worker") == 0)
+  {
+    if (GEARMAND_BINARY and GEARMAND_BLOBSLAP_WORKER)
+    {
+      if (HAVE_LIBGEARMAN)
+      {
+        server= build_blobslap_worker(try_port);
+      }
+      else
+      {
+        Error << "Libgearman was not found";
+      }
+    }
+    else
+    {
+      Error << "No gearmand binary is available";
+    }
+  }
+  else if (server_type.compare("memcached-sasl") == 0)
+  {
+    if (MEMCACHED_SASL_BINARY)
+    {
+      if (HAVE_LIBMEMCACHED)
+      {
+        server= build_memcached_sasl("localhost", try_port, construct.username(), construct.password());
+      }
+      else
+      {
+        Error << "Libmemcached was not found";
+      }
+    }
+    else
+    {
+      Error << "No memcached binary that was compiled with sasl is available";
+    }
+  }
+  else if (server_type.compare("memcached") == 0)
+  {
+    if (MEMCACHED_BINARY)
+    {
+      if (HAVE_LIBMEMCACHED)
+      {
+        server= build_memcached("localhost", try_port);
+      }
+      else
+      {
+        Error << "Libmemcached was not found";
+      }
+    }
+    else
+    {
+      Error << "No memcached binary is available";
+    }
+  }
+  else
+  {
+    Error << "Failed to start " << server_type << ", no support was found to be compiled in for it.";
+  }
+
+  if (server == NULL)
+  {
+    Error << "Failure occured while creating server: " <<  server_type;
+    return false;
+  }
+
+  /*
+    We will now cycle the server we have created.
+  */
+  if (not server->cycle())
+  {
+    Error << "Could not start up server " << *server;
+    delete server;
+    return false;
+  }
+
+  server->build(argc, argv);
+
+  if (construct.is_debug())
+  {
+    Out << "Pausing for startup, hit return when ready.";
+    std::string gdb_command= server->base_command();
+    std::string options;
+    Out << "run " << server->args(options);
+    getchar();
+  }
+  else if (not server->start())
+  {
+    Error << "Failed to start " << *server;
+    delete server;
+    return false;
+  }
+  else
+  {
+    Out << "STARTING SERVER(pid:" << server->pid() << "): " << server->running();
+  }
+
+  construct.push_server(server);
+
+  if (default_port() == 0)
+  {
+    assert(server->has_port());
+    set_default_port(server->port());
+  }
+
+  Outn();
+
+  return true;
+}
+
+bool server_startup_st::start_socket_server(const std::string& server_type, const in_port_t try_port, int argc, const char *argv[])
+{
+  (void)try_port;
+  Outn();
+
+  Server *server= NULL;
+  if (0)
+  { }
+  else if (server_type.compare("gearmand") == 0)
+  {
+    Error << "Socket files are not supported for gearmand yet";
+  }
+  else if (server_type.compare("memcached-sasl") == 0)
+  {
+    if (MEMCACHED_SASL_BINARY)
+    {
+      if (HAVE_LIBMEMCACHED)
+      {
+        server= build_memcached_sasl_socket("localhost", try_port, username(), password());
+      }
+      else
+      {
+        Error << "Libmemcached was not found";
+      }
+    }
+    else
+    {
+      Error << "No memcached binary is available";
+    }
+  }
+  else if (server_type.compare("memcached") == 0)
+  {
+    if (MEMCACHED_BINARY)
+    {
+      if (HAVE_LIBMEMCACHED)
+      {
+        server= build_memcached_socket("localhost", try_port);
+      }
+      else
+      {
+        Error << "Libmemcached was not found";
+      }
+    }
+    else
+    {
+      Error << "No memcached binary is available";
+    }
+  }
+  else
+  {
+    Error << "Failed to start " << server_type << ", no support was found to be compiled in for it.";
+  }
+
+  if (server == NULL)
+  {
+    Error << "Failure occured while creating server: " <<  server_type;
+    return false;
+  }
+
+  /*
+    We will now cycle the server we have created.
+  */
+  if (not server->cycle())
+  {
+    Error << "Could not start up server " << *server;
+    delete server;
+    return false;
+  }
+
+  server->build(argc, argv);
+
+  if (is_debug())
+  {
+    Out << "Pausing for startup, hit return when ready.";
+    std::string gdb_command= server->base_command();
+    std::string options;
+    Out << "run " << server->args(options);
+    getchar();
+  }
+  else if (not server->start())
+  {
+    Error << "Failed to start " << *server;
+    delete server;
+    return false;
+  }
+  else
+  {
+    Out << "STARTING SERVER(pid:" << server->pid() << "): " << server->running();
+  }
+
+  push_server(server);
+
+  set_default_socket(server->socket().c_str());
+
+  Outn();
+
+  return true;
+}
+
+std::string server_startup_st::option_string() const
+{
+  std::string temp= server_list;
+  rtrim(temp);
+  return temp;
+}
+
+
+} // namespace libtest

Some files were not shown because too many files changed in this diff