summaryrefslogtreecommitdiff
path: root/libtest
diff options
context:
space:
mode:
authorContinuous Integration <ci@tangent.org>2013-04-20 02:58:06 -0700
committerContinuous Integration <ci@tangent.org>2013-04-20 02:58:06 -0700
commit979aeab103387877cb5687ec79d2c7ed26041ca7 (patch)
treea7f4939ec82a4770f9352036dfbe7a7edca1f3e3 /libtest
parentc638593177a29eace04b193715e7f70eefbfdc96 (diff)
parent4ec400319b67d93c1f6a103f58196018f52dafd2 (diff)
downloadlibmemcached-979aeab103387877cb5687ec79d2c7ed26041ca7.tar.gz
Merge lp:~brianaker/libmemcached/merge-1.0-april-2013 Build: jenkins-Libmemcached-270
Diffstat (limited to 'libtest')
-rw-r--r--libtest/cmdline.cc49
-rw-r--r--libtest/cmdline.h3
-rw-r--r--libtest/common.h2
-rw-r--r--libtest/dream.cc2
-rw-r--r--libtest/drizzled.cc10
-rw-r--r--libtest/framework.cc2
-rw-r--r--libtest/framework.h2
-rw-r--r--libtest/has.cc54
-rw-r--r--libtest/has.hpp10
-rw-r--r--libtest/include.am15
-rw-r--r--libtest/lite.h12
-rw-r--r--libtest/main.cc5
-rw-r--r--libtest/memcached.cc10
-rw-r--r--libtest/memcached.hpp2
-rw-r--r--libtest/result.cc1
-rw-r--r--libtest/run-ci.gdb1
-rw-r--r--libtest/run.gdb1
-rw-r--r--libtest/server_container.cc12
-rw-r--r--libtest/signal.cc10
-rw-r--r--libtest/unittest.cc9
-rw-r--r--libtest/valgrind.h55
-rw-r--r--libtest/vchar.cc5
-rw-r--r--libtest/vchar.hpp3
23 files changed, 202 insertions, 73 deletions
diff --git a/libtest/cmdline.cc b/libtest/cmdline.cc
index 741d18d7..fd9e510d 100644
--- a/libtest/cmdline.cc
+++ b/libtest/cmdline.cc
@@ -2,7 +2,7 @@
*
* Data Differential YATL (i.e. libtest) library
*
- * Copyright (C) 2012 Data Differential, http://datadifferential.com/
+ * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -412,7 +412,6 @@ Application::error_t Application::join()
slurp();
if (waited_pid == _pid and WIFEXITED(_status) == false)
{
-
/*
What we are looking for here is how the exit status happened.
- 127 means that posix_spawn() itself had an error.
@@ -437,15 +436,18 @@ Application::error_t Application::join()
{
if (WTERMSIG(_status) != SIGTERM and WTERMSIG(_status) != SIGHUP)
{
+ slurp();
_app_exit_state= Application::INVALID_POSIX_SPAWN;
std::string error_string(print_argv(built_argv));
error_string+= " was killed by signal ";
error_string+= strsignal(WTERMSIG(_status));
+
if (stdout_result_length())
{
error_string+= " stdout: ";
error_string+= stdout_c_str();
}
+
if (stderr_result_length())
{
error_string+= " stderr: ";
@@ -479,8 +481,20 @@ Application::error_t Application::join()
}
else if (waited_pid == -1)
{
+ std::string error_string;
+ if (stdout_result_length())
+ {
+ error_string+= " stdout: ";
+ error_string+= stdout_c_str();
+ }
+
+ if (stderr_result_length())
+ {
+ error_string+= " stderr: ";
+ error_string+= stderr_c_str();
+ }
+ Error << "waitpid() returned errno:" << strerror(errno) << " " << error_string;
_app_exit_state= Application::UNKNOWN;
- Error << "waitpid() returned errno:" << strerror(errno);
}
else
{
@@ -573,6 +587,7 @@ bool Application::Pipe::read(libtest::vchar_t& arg)
void Application::Pipe::nonblock()
{
int flags;
+ do
{
flags= fcntl(_pipe_fd[READ], F_GETFL, 0);
} while (flags == -1 and (errno == EINTR or errno == EAGAIN));
@@ -601,23 +616,21 @@ void Application::Pipe::reset()
close(READ);
close(WRITE);
-#if defined(HAVE_PIPE2) && HAVE_PIPE2
+#ifdef HAVE_PIPE2
if (pipe2(_pipe_fd, O_NONBLOCK|O_CLOEXEC) == -1)
-#else
- if (pipe(_pipe_fd) == -1)
#endif
{
- FATAL(strerror(errno));
- }
- _open[0]= true;
- _open[1]= true;
+ if (pipe(_pipe_fd) == -1)
+ {
+ FATAL(strerror(errno));
+ }
-#if defined(HAVE_PIPE2) && HAVE_PIPE2
- {
+ // Since either pipe2() was not found/called we set the pipe directly
nonblock();
cloexec();
}
-#endif
+ _open[0]= true;
+ _open[1]= true;
}
void Application::Pipe::cloexec()
@@ -817,14 +830,4 @@ int exec_cmdline(const std::string& command, const char *args[], bool use_libtoo
return int(app.join());
}
-const char *gearmand_binary()
-{
- return GEARMAND_BINARY;
-}
-
-const char *drizzled_binary()
-{
- return DRIZZLED_BINARY;
-}
-
} // namespace exec_cmdline
diff --git a/libtest/cmdline.h b/libtest/cmdline.h
index 6bf71b64..368daaec 100644
--- a/libtest/cmdline.h
+++ b/libtest/cmdline.h
@@ -245,7 +245,4 @@ static inline std::ostream& operator<<(std::ostream& output, const enum Applicat
int exec_cmdline(const std::string& executable, const char *args[], bool use_libtool= false);
-const char *gearmand_binary();
-const char *drizzled_binary();
-
}
diff --git a/libtest/common.h b/libtest/common.h
index b611e1a9..90d8b6a8 100644
--- a/libtest/common.h
+++ b/libtest/common.h
@@ -69,7 +69,7 @@
# include <arpa/inet.h>
#endif
-#if defined(_WIN32)
+#if defined(WIN32)
# include "win32/wrappers.h"
# define get_socket_errno() WSAGetLastError()
#else
diff --git a/libtest/dream.cc b/libtest/dream.cc
index cd7d6aa6..42f9222d 100644
--- a/libtest/dream.cc
+++ b/libtest/dream.cc
@@ -41,7 +41,7 @@ namespace libtest {
void dream(time_t tv_sec, long tv_nsec)
{
-#if defined(_WIN32)
+#if defined(WIN32)
if (tv_sec == 0 and tv_nsec)
{
tv_sec++;
diff --git a/libtest/drizzled.cc b/libtest/drizzled.cc
index b8068ac8..3a93b666 100644
--- a/libtest/drizzled.cc
+++ b/libtest/drizzled.cc
@@ -74,11 +74,11 @@ bool ping_drizzled(const in_port_t _port)
#if defined(HAVE_LIBDRIZZLE) && HAVE_LIBDRIZZLE
if (HAVE_LIBDRIZZLE)
{
- drizzle_st *drizzle= drizzle_create_tcp(getenv("MYSQL_SERVER"),
- getenv("MYSQL_PORT") ? atoi("MYSQL_PORT") : DRIZZLE_DEFAULT_TCP_PORT,
- getenv("MYSQL_USER"),
- getenv("MYSQL_PASSWORD"),
- getenv("MYSQL_SCHEMA"), drizzle_options_t());
+ drizzle_st *drizzle= drizzle_create(getenv("MYSQL_SERVER"),
+ getenv("MYSQL_PORT") ? atoi("MYSQL_PORT") : DRIZZLE_DEFAULT_TCP_PORT,
+ getenv("MYSQL_USER"),
+ getenv("MYSQL_PASSWORD"),
+ getenv("MYSQL_SCHEMA"), 0);
if (drizzle == NULL)
{
diff --git a/libtest/framework.cc b/libtest/framework.cc
index 30f511af..92aacfee 100644
--- a/libtest/framework.cc
+++ b/libtest/framework.cc
@@ -68,7 +68,7 @@ Framework::Framework(libtest::SignalThread& signal_,
get_world(this);
}
-void Framework::collections(collection_st* collections_)
+void Framework::collections(collection_st collections_[])
{
for (collection_st *next= collections_; next and next->name; next++)
{
diff --git a/libtest/framework.h b/libtest/framework.h
index 7a24466a..361779db 100644
--- a/libtest/framework.h
+++ b/libtest/framework.h
@@ -72,7 +72,7 @@ public:
_destroy= arg;
}
- void collections(collection_st* arg);
+ void collections(collection_st arg[]);
void set_on_error(test_callback_error_fn *arg)
{
diff --git a/libtest/has.cc b/libtest/has.cc
index 9b26b96b..a7a09cb4 100644
--- a/libtest/has.cc
+++ b/libtest/has.cc
@@ -2,7 +2,7 @@
*
* Data Differential YATL (i.e. libtest) library
*
- * Copyright (C) 2012 Data Differential, http://datadifferential.com/
+ * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -37,6 +37,7 @@
#include "libtest/yatlcon.h"
#include <libtest/common.h>
+#include <cstdio>
#include <cstdlib>
#include <unistd.h>
@@ -138,14 +139,17 @@ bool has_mysqld()
return false;
}
-bool has_memcached()
+static char memcached_binary_path[FILENAME_MAX];
+
+static void initialize_curl_startup()
{
+ memcached_binary_path[0]= NULL;
+
#if defined(HAVE_MEMCACHED_BINARY) && HAVE_MEMCACHED_BINARY
if (HAVE_MEMCACHED_BINARY)
{
std::stringstream arg_buffer;
-
char *getenv_ptr;
if (bool((getenv_ptr= getenv("PWD"))) and strcmp(MEMCACHED_BINARY, "memcached/memcached") == 0)
{
@@ -156,14 +160,46 @@ bool has_memcached()
if (access(arg_buffer.str().c_str(), X_OK) == 0)
{
- return true;
+ strncpy(memcached_binary_path, arg_buffer.str().c_str(), FILENAME_MAX);
}
}
#endif
+}
+
+static pthread_once_t memcached_binary_once= PTHREAD_ONCE_INIT;
+static void initialize_memcached_binary(void)
+{
+ int ret;
+ if ((ret= pthread_once(&memcached_binary_once, initialize_curl_startup)) != 0)
+ {
+ FATAL(strerror(ret));
+ }
+}
+
+bool has_memcached()
+{
+ initialize_memcached_binary();
+
+ if (memcached_binary_path[0])
+ {
+ return true;
+ }
return false;
}
+const char* memcached_binary()
+{
+ initialize_memcached_binary();
+
+ if (memcached_binary_path[0])
+ {
+ return memcached_binary_path;
+ }
+
+ return NULL;
+}
+
bool has_memcached_sasl()
{
#if defined(HAVE_MEMCACHED_SASL_BINARY) && HAVE_MEMCACHED_SASL_BINARY
@@ -179,4 +215,14 @@ bool has_memcached_sasl()
return false;
}
+const char *gearmand_binary()
+{
+ return GEARMAND_BINARY;
+}
+
+const char *drizzled_binary()
+{
+ return DRIZZLED_BINARY;
+}
+
} // namespace libtest
diff --git a/libtest/has.hpp b/libtest/has.hpp
index e6c9d4d5..f38306d5 100644
--- a/libtest/has.hpp
+++ b/libtest/has.hpp
@@ -2,7 +2,7 @@
*
* Data Differential YATL (i.e. libtest) library
*
- * Copyright (C) 2012 Data Differential, http://datadifferential.com/
+ * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -62,4 +62,12 @@ bool has_drizzled();
LIBTEST_API
bool has_mysqld();
+LIBTEST_API
+const char* memcached_binary();
+
+LIBTEST_API
+const char *gearmand_binary();
+
+LIBTEST_API
+const char *drizzled_binary();
} // namespace libtest
diff --git a/libtest/include.am b/libtest/include.am
index d1ede13b..c9368c4f 100644
--- a/libtest/include.am
+++ b/libtest/include.am
@@ -5,10 +5,12 @@
#
LIBTOOL_COMMAND= ${abs_top_builddir}/libtool --mode=execute
-VALGRIND_EXEC_COMMAND= $(LIBTOOL_COMMAND) valgrind --error-exitcode=1 --leak-check=yes --track-fds=yes --malloc-fill=A5 --free-fill=DE
+VALGRIND_EXEC_COMMAND= $(LIBTOOL_COMMAND) valgrind --tool=memcheck --error-exitcode=1 --leak-check=yes --track-fds=yes --malloc-fill=A5 --free-fill=DE
+SGCHECK_EXEC_COMMAND= $(LIBTOOL_COMMAND) valgrind --tool=exp-sgcheck --error-exitcode=1
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
+DRD_COMMAND= $(LIBTOOL_COMMAND) valgrind --tool=drd --error-exitcode=1
+SGCHECK_COMMAND= $(LIBTOOL_COMMAND) valgrind --tool=exp-sgcheck --error-exitcode=1
MASSIF_COMMAND= $(LIBTOOL_COMMAND) valgrind --tool=massif
GDB_COMMAND= $(LIBTOOL_COMMAND) gdb -f -x libtest/run.gdb
PTRCHECK_COMMAND= $(LIBTOOL_COMMAND) valgrind --tool=exp-ptrcheck --error-exitcode=1
@@ -19,11 +21,15 @@ export LIBTOOL_COMMAND
export VALGRIND_COMMAND
export HELGRIND_COMMAND
export DRD_COMMAND
+export SGCHECK_COMMAND
export GDB_COMMAND
valgrind:
@echo make check TESTS_ENVIRONMENT="\"$(VALGRIND_EXEC_COMMAND)\""
+sgcheck:
+ @echo make check TESTS_ENVIRONMENT="\"$(SGCHECK_EXEC_COMMAND)\""
+
valgrind-supressions:
@echo make check TESTS_ENVIRONMENT="\"$(VALGRIND_SUPRESSION)\""
@@ -96,6 +102,7 @@ noinst_HEADERS+= libtest/test.hpp
noinst_HEADERS+= libtest/thread.hpp
noinst_HEADERS+= libtest/tmpfile.hpp
noinst_HEADERS+= libtest/lite.h
+noinst_HEADERS+= libtest/valgrind.h
noinst_HEADERS+= libtest/vchar.hpp
noinst_HEADERS+= libtest/version.h
noinst_HEADERS+= libtest/visibility.h
@@ -204,6 +211,10 @@ helgrind-unittest: libtest/unittest
drd-unittest: libtest/unittest
@$(DRD_COMMAND) libtest/unittest
+sgcheck-unittest: libtest/unittest
+ echo $(SGCHECK_COMMAND)
+ @$(SGCHECK_COMMAND) libtest/unittest
+
libtest_skiptest_LDADD= libtest/libtest.la
libtest_skiptest_SOURCES= libtest/skiptest.cc
check_PROGRAMS+= libtest/skiptest
diff --git a/libtest/lite.h b/libtest/lite.h
index 70aee2b0..342be97d 100644
--- a/libtest/lite.h
+++ b/libtest/lite.h
@@ -51,7 +51,7 @@
# include <string.h>
#endif
-#if defined(_WIN32)
+#if defined(WIN32)
# include <malloc.h>
#else
# include <alloca.h>
@@ -77,15 +77,7 @@
# define SKIP(__message_format, ...)
#endif
-static inline bool valgrind_is_caller(void)
-{
- if (getenv("TESTS_ENVIRONMENT") && strstr(getenv("TESTS_ENVIRONMENT"), "valgrind"))
- {
- return true;
- }
-
- return false;
-}
+#include <libtest/valgrind.h>
static inline size_t yatl_strlen(const char *s)
{
diff --git a/libtest/main.cc b/libtest/main.cc
index 80ffa769..2ceeac92 100644
--- a/libtest/main.cc
+++ b/libtest/main.cc
@@ -165,7 +165,6 @@ int main(int argc, char *argv[])
Error << "unknown value passed to --repeat: `" << optarg << "`";
exit(EXIT_FAILURE);
}
-
break;
case OPT_LIBYATL_MATCH_COLLECTION:
@@ -383,9 +382,9 @@ int main(int argc, char *argv[])
std::cerr << "std::exception:" << e.what() << std::endl;
exit_code= EXIT_FAILURE;
}
- catch (char const*)
+ catch (char const* s)
{
- std::cerr << "Exception:" << std::endl;
+ std::cerr << "Exception:" << s << std::endl;
exit_code= EXIT_FAILURE;
}
catch (...)
diff --git a/libtest/memcached.cc b/libtest/memcached.cc
index 0d6cc92a..35040535 100644
--- a/libtest/memcached.cc
+++ b/libtest/memcached.cc
@@ -75,14 +75,14 @@ public:
const std::string& username_arg,
const std::string& password_arg) :
libtest::Server(host_arg, port_arg,
- MEMCACHED_BINARY, false, is_socket_arg),
+ memcached_binary(), false, is_socket_arg),
_username(username_arg),
_password(password_arg)
{ }
Memcached(const std::string& host_arg, const in_port_t port_arg, const bool is_socket_arg) :
libtest::Server(host_arg, port_arg,
- MEMCACHED_BINARY, false, is_socket_arg)
+ memcached_binary(), false, is_socket_arg)
{
set_pid_file();
}
@@ -134,7 +134,7 @@ public:
const char *executable()
{
- return MEMCACHED_BINARY;
+ return memcached_binary();
}
bool is_libtool()
@@ -221,7 +221,7 @@ bool Memcached::build()
libtest::Server *build_memcached(const std::string& hostname, const in_port_t try_port)
{
- if (HAVE_MEMCACHED_BINARY)
+ if (has_memcached())
{
return new Memcached(hostname, try_port, false);
}
@@ -231,7 +231,7 @@ libtest::Server *build_memcached(const std::string& hostname, const in_port_t tr
libtest::Server *build_memcached_socket(const std::string& socket_file, const in_port_t try_port)
{
- if (HAVE_MEMCACHED_BINARY)
+ if (has_memcached())
{
return new Memcached(socket_file, try_port, true);
}
diff --git a/libtest/memcached.hpp b/libtest/memcached.hpp
index 142f167c..5d010faf 100644
--- a/libtest/memcached.hpp
+++ b/libtest/memcached.hpp
@@ -39,7 +39,7 @@
#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
inline bool operator== (const memcached_st& memc, const memcached_return_t rc)
{
- if (memcached_last_error(&memc) == rc)
+ if (memcached_last_error(const_cast<memcached_st *>(&memc)) == rc)
{
return true;
}
diff --git a/libtest/result.cc b/libtest/result.cc
index 9a1c8fba..a102b4f7 100644
--- a/libtest/result.cc
+++ b/libtest/result.cc
@@ -69,6 +69,7 @@ __test_result::~__test_result() throw()
}
__test_result::__test_result(const __test_result& other) :
+ std::exception(),
_line(other._line),
_file(other._file),
_func(other._func),
diff --git a/libtest/run-ci.gdb b/libtest/run-ci.gdb
index 86b5fe07..20724b00 100644
--- a/libtest/run-ci.gdb
+++ b/libtest/run-ci.gdb
@@ -1,6 +1,7 @@
set logging on
set logging overwrite on
set environment LIBTEST_IN_GDB=1
+set ASAN_OPTIONS=abort_on_error=1
run
thread apply all bt
quit
diff --git a/libtest/run.gdb b/libtest/run.gdb
index c38beb27..25dcdd53 100644
--- a/libtest/run.gdb
+++ b/libtest/run.gdb
@@ -1,5 +1,6 @@
set logging on
set logging overwrite on
set environment LIBTEST_IN_GDB=1
+#set ASAN_OPTIONS=abort_on_error=1
run
thread apply all bt
diff --git a/libtest/server_container.cc b/libtest/server_container.cc
index 3a5a7a0e..4e73a0e9 100644
--- a/libtest/server_container.cc
+++ b/libtest/server_container.cc
@@ -215,9 +215,9 @@ libtest::Server* server_startup_st::create(const std::string& server_type, in_po
}
else if (server_type.compare("drizzled") == 0)
{
- if (DRIZZLED_BINARY)
+ if (has_drizzled())
{
- if (HAVE_LIBDRIZZLE)
+ if (has_libdrizzle())
{
server= build_drizzled("localhost", try_port);
}
@@ -225,8 +225,9 @@ libtest::Server* server_startup_st::create(const std::string& server_type, in_po
}
else if (server_type.compare("blobslap_worker") == 0)
{
- if (GEARMAND_BINARY)
+ if (has_gearmand())
{
+#ifdef GEARMAND_BLOBSLAP_WORKER
if (GEARMAND_BLOBSLAP_WORKER)
{
if (HAVE_LIBGEARMAN)
@@ -234,11 +235,12 @@ libtest::Server* server_startup_st::create(const std::string& server_type, in_po
server= build_blobslap_worker(try_port);
}
}
+#endif // GEARMAND_BLOBSLAP_WORKER
}
}
else if (server_type.compare("memcached") == 0)
{
- if (HAVE_MEMCACHED_BINARY)
+ if (has_memcached())
{
server= build_memcached("localhost", try_port);
}
@@ -327,7 +329,7 @@ bool server_startup_st::_start_server(const bool is_socket,
else
{
{
-#if defined(DEBUG)
+#ifdef DEBUG
if (DEBUG)
{
Outn();
diff --git a/libtest/signal.cc b/libtest/signal.cc
index 51f42a4e..70012f1d 100644
--- a/libtest/signal.cc
+++ b/libtest/signal.cc
@@ -153,17 +153,13 @@ static void *sig_thread(void *arg)
switch (sig)
{
case SIGALRM:
- Error << "SIGALRM";
+ case SIGVTALRM:
+ Error << strsignal(sig);
if (gdb_is_caller())
{
abort();
}
- exit(EXIT_SKIP);
-
- case SIGVTALRM:
- Error << "SIGVTALRM was called";
- context->unblock();
- raise(SIGVTALRM);
+ exit(EXIT_FAILURE);
case SIGABRT:
case SIGUSR2:
diff --git a/libtest/unittest.cc b/libtest/unittest.cc
index c7be63fa..1663e59a 100644
--- a/libtest/unittest.cc
+++ b/libtest/unittest.cc
@@ -181,6 +181,11 @@ static test_return_t test_throw_fail_TEST(void *)
}
#pragma GCC diagnostic ignored "-Wstack-protector"
+#ifdef __clang__
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wformat-security"
+#endif
+
static test_return_t ASSERT_FALSE__TEST(void *)
{
try {
@@ -199,6 +204,10 @@ static test_return_t ASSERT_FALSE__TEST(void *)
return TEST_FAILURE;
}
+#ifdef __clang__
+# pragma GCC diagnostic pop
+#endif
+
static test_return_t ASSERT_NEQ_FAIL_TEST(void *)
{
try {
diff --git a/libtest/valgrind.h b/libtest/valgrind.h
new file mode 100644
index 00000000..9d9e8bac
--- /dev/null
+++ b/libtest/valgrind.h
@@ -0,0 +1,55 @@
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Data Differential YATL (i.e. libtest) library
+ *
+ * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * The names of its contributors may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#pragma once
+
+static inline bool valgrind_is_caller(void)
+{
+ if (getenv("TESTS_ENVIRONMENT") && strstr(getenv("TESTS_ENVIRONMENT"), "valgrind"))
+ {
+ if (strstr(getenv("TESTS_ENVIRONMENT"), "--tool") == NULL)
+ {
+ return true;
+ }
+
+ if (strstr(getenv("TESTS_ENVIRONMENT"), "--tool=memcheck"))
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
diff --git a/libtest/vchar.cc b/libtest/vchar.cc
index 9d2244b3..4af110b4 100644
--- a/libtest/vchar.cc
+++ b/libtest/vchar.cc
@@ -50,6 +50,11 @@ static size_t get_alpha_num(void)
namespace libtest {
+int random_alpha_num(void)
+{
+ return ALPHANUMERICS[get_alpha_num()];
+}
+
static std::string printer(const char *str, size_t length)
{
std::ostringstream buf;
diff --git a/libtest/vchar.hpp b/libtest/vchar.hpp
index 1cc45b44..541bb92f 100644
--- a/libtest/vchar.hpp
+++ b/libtest/vchar.hpp
@@ -44,6 +44,8 @@
namespace libtest {
+int random_alpha_num(void);
+
typedef std::vector<char*> vchar_ptr_t;
typedef std::vector<char> vchar_t;
@@ -61,6 +63,7 @@ void append(libtest::vchar_t& arg, const char*);
} // namespace vchar
#define vchar_param(__arg) (&__arg[0]), (__arg.size())
+#define vchar_printf(__arg) int(__arg.size()), (&__arg[0])
std::ostream& operator<<(std::ostream& output, const libtest::vchar_t& arg);