cleanup from merge of updates from libgearman's libtest.
authorBrian Aker <brian@tangent.org>
Mon, 27 Feb 2012 14:39:54 +0000 (06:39 -0800)
committerBrian Aker <brian@tangent.org>
Mon, 27 Feb 2012 14:39:54 +0000 (06:39 -0800)
libtest/cmdline.cc
libtest/error.h
libtest/strerror.cc
libtest/test.cc
tests/cli.am
tests/include.am
tests/libmemcached_world.h
tests/libmemcached_world_socket.h
tests/memexist.cc
tests/memstat.cc
tests/memtouch.cc

index aae91110b6e7c562de79c6efdf5cc01aff06ef21..5b4b64c8ff3692937913f76a7ea2e9be7cf25515 100644 (file)
@@ -425,9 +425,8 @@ int exec_cmdline(const std::string& command, const char *args[], bool use_libtoo
   {
     return int(ret);
   }
-  ret= app.wait();
 
-  return int(ret);
+  return int(app.wait());
 }
 
 const char *gearmand_binary() 
index 3fa5bfa21faab584b5df0eed8b4bfe7228e00480..7e34227620552cf291799b873dfc0195699948cd 100644 (file)
@@ -25,9 +25,7 @@
 enum test_return_t {
   TEST_SUCCESS,
   TEST_FAILURE,
-  TEST_MEMORY_ALLOCATION_FAILURE,
-  TEST_SKIPPED,
-  TEST_FATAL // Collection should not be continued
+  TEST_SKIPPED
 };
 
 
index e4f0cf5089bc6e6af3f860b1dd5a14586c61a002..d081bafcd2d433af39afedb4d1ee399e5d16df32 100644 (file)
@@ -32,17 +32,11 @@ const char *test_strerror(test_return_t code)
   case TEST_FAILURE:
     return "failed";
 
-  case TEST_MEMORY_ALLOCATION_FAILURE:
-    return "memory allocation";
-
   case TEST_SKIPPED:
     return "skipped";
-
-  case TEST_FATAL:
-    break;
   }
 
-  return "failed";
+  throw fatal_message("No port could be found");
 }
 
 } // namespace libtest
index 92c1226b24ffca5e7b686926b99753c20051200c..66d258a0b009094430793e268598203ee8a836b9 100644 (file)
@@ -226,9 +226,7 @@ int main(int argc, char *argv[])
         delete world;
         return EXIT_SUCCESS;
 
-      case TEST_FATAL:
       case TEST_FAILURE:
-      case TEST_MEMORY_ALLOCATION_FAILURE:
         delete world;
         return EXIT_FAILURE;
       }
@@ -276,7 +274,6 @@ int main(int argc, char *argv[])
         case TEST_SUCCESS:
           break;
 
-        case TEST_FATAL:
         case TEST_FAILURE:
           Out << next->name << " [ failed ]";
           failed= true;
@@ -288,8 +285,8 @@ int main(int argc, char *argv[])
           skipped= true;
           goto cleanup;
 
-        case TEST_MEMORY_ALLOCATION_FAILURE:
-          test_assert(0, "Allocation failure, or unknown return");
+        default:
+          throw fatal_message("invalid return code");
         }
 
         Out << "Collection: " << next->name;
@@ -381,7 +378,6 @@ int main(int argc, char *argv[])
             stats.success++;
             break;
 
-          case TEST_FATAL:
           case TEST_FAILURE:
             stats.failed++;
             failed= true;
@@ -394,8 +390,8 @@ int main(int argc, char *argv[])
             Out << "\tTesting " << run->name <<  "\t\t\t\t\t" << "[ " << test_strerror(return_code) << " ]";
             break;
 
-          case TEST_MEMORY_ALLOCATION_FAILURE:
-            test_assert(0, "Memory Allocation Error");
+          default:
+            throw fatal_message("invalid return code");
           }
 
           if (test_failed(world->on_error(return_code, creators_ptr)))
@@ -464,6 +460,10 @@ cleanup:
   {
     std::cerr << e.what() << std::endl;
   }
+  catch (std::bad_alloc& e)
+  {
+    std::cerr << e.what() << std::endl;
+  }
   catch (...)
   {
     std::cerr << "Unknown exception halted execution" << std::endl;
index 689c5c52f08f0d9d83237413491f02c489b2beeb..ecc66dda7be1e855294da3c32fe267e4ac29d689 100644 (file)
@@ -86,67 +86,11 @@ tests_memdump_LDADD=  libtest/libtest.la $(TESTS_LDADDS)
 check_PROGRAMS+= tests/memdump
 noinst_PROGRAMS+= tests/memdump
 
-test-memerror: clients/memerror
+test-memstat: tests/memstat
+       tests/memstat
+
+test-memerror: tests/memerror
        tests/memerror
 
 valgrind-memerror: clients/memerror
         @$(VALGRIND_COMMAND) tests/memerror
-
-test-memcp: clients/memcp
-       @echo "Testing memcp"
-       @@MEMC_BINARY@ -d -u root -P `pwd`/tests/Xumemc.pid -p 12555
-       @clients/memcp --servers="localhost:12555" clients/memcp clients/memcat clients/memstat
-       @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server"
-       @rm tests/Xumemc.pid
-
-valgrind-memcp: clients/memcat clients/memcp
-       @echo "Testing memcp"
-       @@MEMC_BINARY@ -d -u root -P `pwd`/tests/Xumemc.pid -p 12555
-       @$(VALGRIND_COMMAND) clients/memcp --servers="localhost:12555" clients/memcp clients/memcat clients/memstat
-       @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server"
-       @rm tests/Xumemc.pid
-
-test-memflush: clients/memflush
-       @echo "Testing memflush"
-       @$(MEMC_BINARY) -d -u root -P `pwd`/tests/Xumemc.pid -p 12555
-       @clients/memflush --servers="localhost:12555"
-       @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server"
-       @rm tests/Xumemc.pid
-
-valgrind-memflush: clients/memflush
-       @echo "Testing memflush"
-       @$(MEMC_BINARY) -d -u root -P `pwd`/tests/Xumemc.pid -p 12555
-       @$(VALGRIND_COMMAND) clients/memflush --servers="localhost:12555"
-       @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server"
-       @rm tests/Xumemc.pid
-
-test-memdump: clients/memdump clients/memcp
-       @echo "Testing memdump"
-       @$(MEMC_BINARY) -d -u root -P `pwd`/tests/Xumemc.pid -p 12555
-       @clients/memcp --servers="localhost:12555" clients/memcat
-       @clients/memdump --servers="localhost:12555" > /dev/null
-       @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server"
-       @rm tests/Xumemc.pid
-
-valgrind-memdump: clients/memcat clients/memcp
-       @echo "Testing memdump"
-       @$(MEMC_BINARY) -d -u root -P `pwd`/tests/Xumemc.pid -p 12555
-       @clients/memcp --servers="localhost:12555" clients/memcat
-       @$(VALGRIND_COMMAND) clients/memdump --servers="localhost:12555" > /dev/null
-       @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server"
-       @rm tests/Xumemc.pid
-
-test-memstat: clients/memstat
-       @echo "Testing memstat"
-       @$(MEMC_BINARY) -d -u root -P `pwd`/tests/Xumemc.pid -p 12555
-       @clients/memstat --servers="localhost:12555" > /dev/null
-       @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server"
-       @rm tests/Xumemc.pid
-
-valgrind-memstat: clients/memstat
-       @echo "Testing memstat"
-       @$(MEMC_BINARY) -d -u root -P `pwd`/tests/Xumemc.pid -p 12555
-       @$(VALGRIND_COMMAND) clients/memstat --servers="localhost:12555" > /dev/null
-       @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server"
-       @rm tests/Xumemc.pid
-
index 41ea2ec33332f7cdcb6abf67a1f40e46316f6e55..7bc9e60b99dcddf2f338ada4accedcb3759239f4 100644 (file)
@@ -67,9 +67,6 @@ test: check
 check-local: $(TEST_DOCS)
        @echo "Tests completed"
 
-test-x: test-plus test-memcp test-memdump test-memflush test-memstat
-       @echo "Tests completed"
-
 test-mem: tests/var tests/libmemcached-1.0/testapp
        @tests/libmemcached-1.0/testapp
 
index 0d3b57dff1a24b1a5006ebe5fe33c59dd013aece..cedb8c2fa6e6b8da44428b12a6ae029ea1d4d881 100644 (file)
@@ -78,47 +78,26 @@ static void *world_create(libtest::server_startup_st& servers, test_return_t& er
 
   for (uint32_t x= 0; x < servers.count(); x++)
   {
-    char variable_buffer[1024];
-    snprintf(variable_buffer, sizeof(variable_buffer), "LIBMEMCACHED_PORT_%u", x);
-
-    in_port_t port;
-    char *var;
-    if ((var= getenv(variable_buffer)))
-    {
-      port= in_port_t(atoi(var));
-    }
-    else
-    {
-      port= in_port_t(libtest::get_free_port());
-    }
+    in_port_t port= libtest::get_free_port();
 
     const char *argv[1]= { "memcached" };
     if (servers.sasl())
     {
-      if (not server_startup(servers, "memcached-sasl", port, 1, argv))
+      if (server_startup(servers, "memcached-sasl", port, 1, argv) == false)
       {
-        error= TEST_FATAL;
-        return NULL;
+        fatal_message("Could not start memcached-sasl");
       }
     }
     else
     {
-      if (not server_startup(servers, "memcached", port, 1, argv))
+      if (server_startup(servers, "memcached", port, 1, argv) == false)
       {
-        error= TEST_FATAL;
-        return NULL;
+        fatal_message("Could not start memcached");
       }
     }
   }
 
   libmemcached_test_container_st *global_container= new libmemcached_test_container_st(servers);
-  if (global_container == NULL)
-  {
-    error= TEST_MEMORY_ALLOCATION_FAILURE;
-    return NULL;
-  }
-
-  error= TEST_SUCCESS;
 
   return global_container;
 }
index 3e410084de3844340bcdc3eafe20490d79aa158e..d867ef88ef9c6a3f553890cd63442ba120627764 100644 (file)
@@ -68,18 +68,12 @@ static void *world_create(libtest::server_startup_st& servers, test_return_t& er
     const char *argv[1]= { "memcached" };
     if (not servers.start_socket_server("memcached", libtest::get_free_port(), 1, argv))
     {
-      error= TEST_FATAL;
-      return NULL;
+      fatal_message("Could not launch memcached");
     }
   }
 
 
   libmemcached_test_container_st *global_container= new libmemcached_test_container_st(servers);
-  if (global_container == NULL)
-  {
-    error= TEST_MEMORY_ALLOCATION_FAILURE;
-    return NULL;
-  }
 
   error= TEST_SUCCESS;
 
index ed2546d31f21c8adbfe3b7c11bb8482b6b6e3dc9..6cc1f0514448335c287a51933dadfd36926bcd09 100644 (file)
@@ -50,21 +50,13 @@ using namespace libtest;
 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
 #endif
 
-static std::string executable;
-
-static test_return_t quiet_test(void *)
-{
-  const char *args[]= { "--quiet", 0 };
-
-  test_true(exec_cmdline(executable, args));
-  return TEST_SUCCESS;
-}
+static std::string executable("./clients/memexist");
 
 static test_return_t help_test(void *)
 {
-  const char *args[]= { "--quiet", "--help", 0 };
+  const char *args[]= { "--help", 0 };
 
-  test_true(exec_cmdline(executable, args));
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
   return TEST_SUCCESS;
 }
 
@@ -72,7 +64,7 @@ static test_return_t exist_test(void *)
 {
   char buffer[1024];
   snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port()));
-  const char *args[]= { "--quiet", buffer, "foo", 0 };
+  const char *args[]= { buffer, "foo", 0 };
 
   memcached_st *memc= memcached(buffer, strlen(buffer));
   test_true(memc);
@@ -84,7 +76,7 @@ static test_return_t exist_test(void *)
   test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc));
   test_compare(MEMCACHED_SUCCESS, rc);
 
-  test_true(exec_cmdline(executable, args));
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
 
   test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc));
   test_compare(MEMCACHED_SUCCESS, rc);
@@ -98,7 +90,7 @@ static test_return_t NOT_FOUND_test(void *)
 {
   char buffer[1024];
   snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port()));
-  const char *args[]= { "--quiet", buffer, "foo", 0 };
+  const char *args[]= { buffer, "foo", 0 };
 
   memcached_st *memc= memcached(buffer, strlen(buffer));
   test_true(memc);
@@ -109,7 +101,7 @@ static test_return_t NOT_FOUND_test(void *)
   test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc));
   test_compare(MEMCACHED_NOTFOUND, rc);
 
-  test_true(exec_cmdline(executable, args));
+  test_compare(EXIT_FAILURE, exec_cmdline(executable, args, true));
 
   test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc));
   test_compare(MEMCACHED_NOTFOUND, rc);
@@ -120,7 +112,6 @@ static test_return_t NOT_FOUND_test(void *)
 }
 
 test_st memexist_tests[] ={
-  {"--quiet", true, quiet_test },
   {"--help", true, help_test },
   {"exist(FOUND)", true, exist_test },
   {"exist(NOT_FOUND)", true, NOT_FOUND_test },
@@ -152,7 +143,6 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
 
 void get_world(Framework *world)
 {
-  executable= "./clients/memexist";
   world->collections= collection;
   world->_create= world_create;
 }
index 2ffb26bded821fbb126baa4f0bdbf0cba5ed01ca..6bb8c053bd5f685f64446f7b99a4993c63314312 100644 (file)
@@ -50,22 +50,13 @@ using namespace libtest;
 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
 #endif
 
-static std::string executable;
-
-static test_return_t quiet_test(void *)
-{
-  const char *args[]= { "--quiet", 0 };
-
-  test_true(exec_cmdline(executable, args));
-  return TEST_SUCCESS;
-}
-
+static std::string executable("./clients/memstat");
 
 static test_return_t help_test(void *)
 {
-  const char *args[]= { "--help", "--quiet", 0 };
+  const char *args[]= { "--help", 0 };
 
-  test_true(exec_cmdline(executable, args));
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
 
   return TEST_SUCCESS;
 }
@@ -74,9 +65,9 @@ static test_return_t binary_TEST(void *)
 {
   char buffer[1024];
   snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(libtest::default_port()));
-  const char *args[]= { "--quiet", buffer, " --binary ", 0 };
+  const char *args[]= { buffer, " --binary ", 0 };
 
-  test_true(exec_cmdline(executable, args));
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
   return TEST_SUCCESS;
 }
 
@@ -84,9 +75,9 @@ static test_return_t server_version_TEST(void *)
 {
   char buffer[1024];
   snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(libtest::default_port()));
-  const char *args[]= { "--quiet", buffer, " --server-version", 0 };
+  const char *args[]= { buffer, " --server-version", 0 };
 
-  test_true(exec_cmdline(executable, args));
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
   return TEST_SUCCESS;
 }
 
@@ -94,14 +85,14 @@ static test_return_t binary_server_version_TEST(void *)
 {
   char buffer[1024];
   snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(libtest::default_port()));
-  const char *args[]= { "--quiet", buffer, " --binary --server-version", 0 };
+  const char *args[]= { buffer, " --binary --server-version", 0 };
+
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
 
-  test_true(exec_cmdline(executable, args));
   return TEST_SUCCESS;
 }
 
 test_st memstat_tests[] ={
-  {"--quiet", 0, quiet_test},
   {"--help", 0, help_test},
   {"--binary", 0, binary_TEST},
   {"--server-version", 0, server_version_TEST},
@@ -134,7 +125,6 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
 
 void get_world(Framework *world)
 {
-  executable= "./clients/memstat";
   world->collections= collection;
   world->_create= world_create;
 }
index 6813eb8deefdce3554eec47c509398222c9cc7ea..426e3c981d88c0ae650539f6f71aec0ed08f34bb 100644 (file)
@@ -52,19 +52,12 @@ using namespace libtest;
 
 static std::string executable;
 
-static test_return_t quiet_test(void *)
-{
-  const char *args[]= { "--quiet", 0 };
-
-  test_true(exec_cmdline(executable, args));
-  return TEST_SUCCESS;
-}
-
 static test_return_t help_test(void *)
 {
-  const char *args[]= { "--quiet", "--help", 0 };
+  const char *args[]= { "--help", 0 };
+
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
 
-  test_true(exec_cmdline(executable, args));
   return TEST_SUCCESS;
 }
 
@@ -72,7 +65,7 @@ static test_return_t touch_test(void *)
 {
   char buffer[1024];
   snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port()));
-  const char *args[]= { "--quiet", "--expire=30", buffer, "foo", 0 };
+  const char *args[]= { "--expire=30", buffer, "foo", 0 };
 
   memcached_st *memc= memcached(buffer, strlen(buffer));
   test_true(memc);
@@ -82,7 +75,7 @@ static test_return_t touch_test(void *)
 
   test_compare(MEMCACHED_SUCCESS, memcached_exist(memc, test_literal_param("foo")));
 
-  test_true(exec_cmdline(executable, args));
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
 
   test_compare(MEMCACHED_SUCCESS, memcached_exist(memc, test_literal_param("foo")));
 
@@ -95,7 +88,7 @@ static test_return_t NOT_FOUND_test(void *)
 {
   char buffer[1024];
   snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port()));
-  const char *args[]= { "--quiet", "--expire=30", buffer, "foo", 0 };
+  const char *args[]= { "--expire=30", buffer, "foo", 0 };
 
   memcached_st *memc= memcached(buffer, strlen(buffer));
   test_true(memc);
@@ -104,7 +97,7 @@ static test_return_t NOT_FOUND_test(void *)
 
   test_compare(MEMCACHED_NOTFOUND, memcached_exist(memc, test_literal_param("foo")));
 
-  test_true(exec_cmdline(executable, args));
+  test_compare(EXIT_FAILURE, exec_cmdline(executable, args, true));
 
   test_compare(MEMCACHED_NOTFOUND, memcached_exist(memc, test_literal_param("foo")));
 
@@ -114,7 +107,6 @@ static test_return_t NOT_FOUND_test(void *)
 }
 
 test_st memtouch_tests[] ={
-  {"--quiet", true, quiet_test },
   {"--help", true, help_test },
   {"touch(FOUND)", true, touch_test },
   {"touch(NOT_FOUND)", true, NOT_FOUND_test },