From: Brian Aker Date: Mon, 27 Feb 2012 14:39:54 +0000 (-0800) Subject: cleanup from merge of updates from libgearman's libtest. X-Git-Tag: 1.0.5~24 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=64e9fa38f42f0d30463da5ddc3a573619941d93a;p=awesomized%2Flibmemcached cleanup from merge of updates from libgearman's libtest. --- diff --git a/libtest/cmdline.cc b/libtest/cmdline.cc index aae91110..5b4b64c8 100644 --- a/libtest/cmdline.cc +++ b/libtest/cmdline.cc @@ -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() diff --git a/libtest/error.h b/libtest/error.h index 3fa5bfa2..7e342276 100644 --- a/libtest/error.h +++ b/libtest/error.h @@ -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 }; diff --git a/libtest/strerror.cc b/libtest/strerror.cc index e4f0cf50..d081bafc 100644 --- a/libtest/strerror.cc +++ b/libtest/strerror.cc @@ -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 diff --git a/libtest/test.cc b/libtest/test.cc index 92c1226b..66d258a0 100644 --- a/libtest/test.cc +++ b/libtest/test.cc @@ -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; diff --git a/tests/cli.am b/tests/cli.am index 689c5c52..ecc66dda 100644 --- a/tests/cli.am +++ b/tests/cli.am @@ -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 - diff --git a/tests/include.am b/tests/include.am index 41ea2ec3..7bc9e60b 100644 --- a/tests/include.am +++ b/tests/include.am @@ -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 diff --git a/tests/libmemcached_world.h b/tests/libmemcached_world.h index 0d3b57df..cedb8c2f 100644 --- a/tests/libmemcached_world.h +++ b/tests/libmemcached_world.h @@ -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; } diff --git a/tests/libmemcached_world_socket.h b/tests/libmemcached_world_socket.h index 3e410084..d867ef88 100644 --- a/tests/libmemcached_world_socket.h +++ b/tests/libmemcached_world_socket.h @@ -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; diff --git a/tests/memexist.cc b/tests/memexist.cc index ed2546d3..6cc1f051 100644 --- a/tests/memexist.cc +++ b/tests/memexist.cc @@ -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; } diff --git a/tests/memstat.cc b/tests/memstat.cc index 2ffb26bd..6bb8c053 100644 --- a/tests/memstat.cc +++ b/tests/memstat.cc @@ -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; } diff --git a/tests/memtouch.cc b/tests/memtouch.cc index 6813eb8d..426e3c98 100644 --- a/tests/memtouch.cc +++ b/tests/memtouch.cc @@ -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 },