From: Brian Aker Date: Sun, 8 Apr 2012 01:12:29 +0000 (-0700) Subject: Merge in libtest. X-Git-Tag: 1.0.6~2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=96702d0bcb4bd8f45ede2830660e4ccb072675ab;hp=45c6b15d970aca4fa5619b2ba501c1b0f1d89006;p=m6w6%2Flibmemcached Merge in libtest. --- diff --git a/libtest/cmdline.cc b/libtest/cmdline.cc index cbc9d0a6..6fc34031 100644 --- a/libtest/cmdline.cc +++ b/libtest/cmdline.cc @@ -107,6 +107,7 @@ Application::Application(const std::string& arg, const bool _use_libtool_arg) : _use_libtool(_use_libtool_arg), _use_valgrind(false), _use_gdb(false), + _use_ptrcheck(false), _argc(0), _exectuble(arg), stdin_fd(STDIN_FILENO), @@ -209,7 +210,7 @@ Application::error_t Application::run(const char *args[]) const_cast(_exectuble_with_path.c_str()), 0}; - spawn_ret= posix_spawnp(&_pid, libtool(), &file_actions, &spawnattr, argv, NULL); + spawn_ret= posix_spawnp(&_pid, libtool(), &file_actions, &spawnattr, argv, environ); } else { @@ -222,7 +223,7 @@ Application::error_t Application::run(const char *args[]) const_cast(gdb_run_file.c_str()), const_cast(_exectuble_with_path.c_str()), 0}; - spawn_ret= posix_spawnp(&_pid, "gdb", &file_actions, &spawnattr, argv, NULL); + spawn_ret= posix_spawnp(&_pid, "gdb", &file_actions, &spawnattr, argv, environ); } } else @@ -619,11 +620,18 @@ void Application::create_argv(const char *args[]) _argc+= 1; // For the command /* - valgrind --error-exitcode=1 --leak-check=yes --show-reachable=yes --track-fds=yes --malloc-fill=A5 --free-fill=DE + valgrind --error-exitcode=1 --leak-check=yes --show-reachable=yes --track-fds=yes --track-origin=yes --malloc-fill=A5 --free-fill=DE --log-file= */ if (_use_valgrind) { - _argc+= 7; + _argc+= 8; + } + else if (_use_ptrcheck) + { + /* + valgrind --error-exitcode=1 --tool=exp-ptrcheck --log-file= + */ + _argc+= 4; } else if (_use_gdb) // gdb { @@ -669,8 +677,32 @@ void Application::create_argv(const char *args[]) built_argv[x++]= strdup("--leak-check=yes"); built_argv[x++]= strdup("--show-reachable=yes"); built_argv[x++]= strdup("--track-fds=yes"); +#if 0 + built_argv[x++]= strdup("--track-origin=yes"); +#endif built_argv[x++]= strdup("--malloc-fill=A5"); built_argv[x++]= strdup("--free-fill=DE"); + + std::string log_file= create_tmpfile("valgrind"); + char buffer[1024]; + int length= snprintf(buffer, sizeof(buffer), "--log-file=%s", log_file.c_str()); + fatal_assert(length > 0 and length < sizeof(buffer)); + built_argv[x++]= strdup(buffer); + } + else if (_use_ptrcheck) + { + /* + valgrind --error-exitcode=1 --tool=exp-ptrcheck --log-file= + */ + built_argv[x++]= strdup("valgrind"); + built_argv[x++]= strdup("--error-exitcode=1"); + built_argv[x++]= strdup("--tool=exp-ptrcheck"); + _argc+= 4; + std::string log_file= create_tmpfile("ptrcheck"); + char buffer[1024]; + int length= snprintf(buffer, sizeof(buffer), "--log-file=%s", log_file.c_str()); + fatal_assert(length > 0 and length < sizeof(buffer)); + built_argv[x++]= strdup(buffer); } else if (_use_gdb) { diff --git a/libtest/cmdline.h b/libtest/cmdline.h index 12086b0f..44fd17f9 100644 --- a/libtest/cmdline.h +++ b/libtest/cmdline.h @@ -117,6 +117,11 @@ public: _use_gdb= arg; } + void use_ptrcheck(bool arg= true) + { + _use_ptrcheck= arg; + } + std::string arguments(); std::string gdb_filename() @@ -137,6 +142,7 @@ private: const bool _use_libtool; bool _use_valgrind; bool _use_gdb; + bool _use_ptrcheck; size_t _argc; std::string _exectuble_name; std::string _exectuble; diff --git a/libtest/gearmand.cc b/libtest/gearmand.cc index 177de120..325582f6 100644 --- a/libtest/gearmand.cc +++ b/libtest/gearmand.cc @@ -49,40 +49,6 @@ using namespace libtest; #pragma GCC diagnostic ignored "-Wold-style-cast" #endif -class GetPid : public util::Instance::Finish -{ -private: - pid_t _pid; - -public: - GetPid() : - _pid(-1) - { } - - pid_t pid() - { - return _pid; - } - - - bool call(const bool success, const std::string &response) - { - _pid= -1; - if (success and response.size()) - { - _pid= atoi(response.c_str()); - } - - if (is_pid_valid(_pid) == false) - { - _pid= -1; - return false; - } - - return true; - } -}; - using namespace libtest; class Gearmand : public libtest::Server @@ -169,8 +135,6 @@ public: bool Gearmand::build(size_t argc, const char *argv[]) { - std::stringstream arg_buffer; - if (getuid() == 0 or geteuid() == 0) { add_option("-u", "root"); diff --git a/libtest/include.am b/libtest/include.am index c5f0b5cc..59706ad8 100644 --- a/libtest/include.am +++ b/libtest/include.am @@ -26,6 +26,7 @@ VALGRIND_COMMAND= TESTS_ENVIRONMENT="valgrind" $(VALGRIND_EXEC_COMMAND) HELGRIND_COMMAND= $(LIBTOOL_COMMAND) valgrind --tool=helgrind --read-var-info=yes --error-exitcode=1 --read-var-info=yes DRD_COMMAND= $(LIBTOOL_COMMAND) valgrind --tool=drd GDB_COMMAND= $(LIBTOOL_COMMAND) gdb -f -x libtest/run.gdb +PTRCHECK_COMMAND= $(LIBTOOL_COMMAND) valgrind --tool=exp-ptrcheck --error-exitcode=1 export LIBTOOL_COMMAND export VALGRIND_COMMAND diff --git a/libtest/memcached.cc b/libtest/memcached.cc index e634df63..17884a17 100644 --- a/libtest/memcached.cc +++ b/libtest/memcached.cc @@ -356,8 +356,6 @@ public: bool Memcached::build(size_t argc, const char *argv[]) { - std::stringstream arg_buffer; - if (getuid() == 0 or geteuid() == 0) { add_option("-u", "root"); diff --git a/libtest/server.cc b/libtest/server.cc index c1d01c74..a57b44d5 100644 --- a/libtest/server.cc +++ b/libtest/server.cc @@ -25,12 +25,14 @@ #include #include +#include #include #include #include #include #include +#include // trim from end static inline std::string &rtrim(std::string &s) @@ -159,11 +161,16 @@ bool Server::start() } #endif - if (getenv("YATL_VALGRIND_SERVER")) + if (getenv("YATL_PTRCHECK_SERVER")) + { + _app.use_ptrcheck(); + } + else if (getenv("YATL_VALGRIND_SERVER")) { _app.use_valgrind(); } - else if (args(_app) == false) + + if (args(_app) == false) { Error << "Could not build command()"; return false; @@ -199,6 +206,12 @@ bool Server::start() throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Unable to open pidfile for: %s", _running.c_str()); + char buf[PATH_MAX]; + getcwd(buf, sizeof(buf)); + throw libtest::fatal(LIBYATL_DEFAULT_PARAM, + "Unable to open pidfile in %s for: %s", + buf, + _running.c_str()); } } } @@ -319,8 +332,7 @@ bool Server::set_pid_file() int fd; if ((fd= mkstemp(file_buffer)) == -1) { - perror(file_buffer); - return false; + throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "mkstemp() failed on %s with %s", file_buffer, strerror(errno)); } close(fd); unlink(file_buffer); diff --git a/libtest/server_container.cc b/libtest/server_container.cc index 8203de9d..b63cfbb4 100644 --- a/libtest/server_container.cc +++ b/libtest/server_container.cc @@ -240,7 +240,7 @@ bool server_startup(server_startup_st& construct, const std::string& server_type server->build(argc, argv); - if (gdb_is_caller() and false) + if (false) { Out << "Pausing for startup, hit return when ready."; std::string gdb_command= server->base_command(); @@ -341,7 +341,7 @@ bool server_startup_st::start_socket_server(const std::string& server_type, cons server->build(argc, argv); - if (gdb_is_caller() and false) + if (false) { Out << "Pausing for startup, hit return when ready."; std::string gdb_command= server->base_command(); diff --git a/libtest/unittest.cc b/libtest/unittest.cc index 87f69acb..c5b392dc 100644 --- a/libtest/unittest.cc +++ b/libtest/unittest.cc @@ -586,6 +586,7 @@ static test_return_t wait_services_appliction_TEST(void *) static test_return_t gdb_wait_services_appliction_TEST(void *) { + test_skip(true, false); #if defined(TARGET_OS_OSX) && TARGET_OS_OSX test_skip(0, TARGET_OS_OSX); #endif @@ -605,6 +606,7 @@ static test_return_t gdb_wait_services_appliction_TEST(void *) static test_return_t gdb_abort_services_appliction_TEST(void *) { + test_skip(true, false); test_skip(0, access("/usr/bin/gdb", X_OK )); #if defined(TARGET_OS_OSX) && TARGET_OS_OSX