unit tests: Run all tests through Valgrind's memcheck, if available.
AC_PROG_LEX
AC_PROG_YACC
+AC_PATH_PROG([VALGRIND], [valgrind])
+
# Warn when pkg.m4 is missing
m4_pattern_forbid([^_?PKG_[A-Z_]+$],[*** pkg.m4 missing, please install pkg-config])
fi
AC_MSG_RESULT([$protoc3])
fi
-AC_SUBST([PROTOC])
AM_CONDITIONAL(HAVE_PROTOC3, test "x$have_protoc3" = "xyes")
AC_PATH_PROG([GRPC_CPP_PLUGIN], [grpc_cpp_plugin])
-AC_SUBST([GRPC_CPP_PLUGIN])
AM_CONDITIONAL(HAVE_GRPC_CPP, test "x$GRPC_CPP_PLUGIN" != "x")
AC_CHECK_PROG([have_protoc_c], [protoc-c], [yes], [no])
AM_CPPFLAGS += -DPLUGINDIR='"${pkglibdir}"'
AM_CPPFLAGS += -DPKGDATADIR='"${pkgdatadir}"'
+LOG_COMPILER = env VALGRIND="@VALGRIND@" $(abs_top_srcdir)/testwrapper.sh
+
V_PROTOC = $(v_protoc_@AM_V@)
v_protoc_ = $(v_protoc_@AM_DEFAULT_V@)
v_protoc_0 = @echo " PROTOC " $@;
CHECK_ZERO (yajl_parse_complete (hndl));
#endif
+ yajl_free (hndl);
return 0;
}
collectd_LDADD += -loconfig
endif
+LOG_COMPILER = env VALGRIND="@VALGRIND@" $(abs_top_srcdir)/testwrapper.sh
+
check_PROGRAMS = test_common test_meta_data test_utils_avltree test_utils_heap test_utils_time test_utils_subst
TESTS = test_common test_meta_data test_utils_avltree test_utils_heap test_utils_time test_utils_subst
#define OK(cond) OK1(cond, #cond)
#define EXPECT_EQ_STR(expect, actual) do { \
- if (strcmp (expect, actual) != 0) { \
+ /* Evaluate 'actual' only once. */ \
+ const char *got__ = actual; \
+ if (strcmp (expect, got__) != 0) { \
printf ("not ok %i - %s = \"%s\", want \"%s\"\n", \
- ++check_count__, #actual, actual, expect); \
+ ++check_count__, #actual, got__, expect); \
return (-1); \
} \
- printf ("ok %i - %s = \"%s\"\n", ++check_count__, #actual, actual); \
+ printf ("ok %i - %s = \"%s\"\n", ++check_count__, #actual, got__); \
} while (0)
#define EXPECT_EQ_INT(expect, actual) do { \
*/
#include "collectd.h"
+#include "common.h"
#include "testing.h"
#include "utils_mount.h"
{
char line_opts[] = "foo=one,bar=two,qux=three";
char line_bool[] = "one,two,three";
-
- EXPECT_EQ_STR ("one", cu_mount_getoptionvalue (line_opts, "foo="));
- EXPECT_EQ_STR ("two", cu_mount_getoptionvalue (line_opts, "bar="));
- EXPECT_EQ_STR ("three", cu_mount_getoptionvalue (line_opts, "qux="));
- OK (NULL == cu_mount_getoptionvalue (line_opts, "unknown="));
-
- EXPECT_EQ_STR ("", cu_mount_getoptionvalue (line_bool, "one"));
- EXPECT_EQ_STR ("", cu_mount_getoptionvalue (line_bool, "two"));
- EXPECT_EQ_STR ("", cu_mount_getoptionvalue (line_bool, "three"));
- OK (NULL == cu_mount_getoptionvalue (line_bool, "four"));
+ char *v;
+
+ EXPECT_EQ_STR ("one", v = cu_mount_getoptionvalue (line_opts, "foo="));
+ sfree (v);
+ EXPECT_EQ_STR ("two", v = cu_mount_getoptionvalue (line_opts, "bar="));
+ sfree (v);
+ EXPECT_EQ_STR ("three", v = cu_mount_getoptionvalue (line_opts, "qux="));
+ sfree (v);
+ OK (NULL == (v = cu_mount_getoptionvalue (line_opts, "unknown=")));
+ sfree (v);
+
+ EXPECT_EQ_STR ("", v = cu_mount_getoptionvalue (line_bool, "one"));
+ sfree (v);
+ EXPECT_EQ_STR ("", v = cu_mount_getoptionvalue (line_bool, "two"));
+ sfree (v);
+ EXPECT_EQ_STR ("", v = cu_mount_getoptionvalue (line_bool, "three"));
+ sfree (v);
+ OK (NULL == (v = cu_mount_getoptionvalue (line_bool, "four")));
+ sfree (v);
return (0);
}
obj->cb_free_class (user_class_list->entry.user_class);
user_class_list->entry.user_class = NULL;
+#define CLEAR_FIELD(field) do { \
+ if (user_class_list->entry.match.field.is_regex) { \
+ regfree (&user_class_list->entry.match.field.regex); \
+ user_class_list->entry.match.field.is_regex = 0; \
+ } \
+} while (0)
+
+ CLEAR_FIELD (host);
+ CLEAR_FIELD (plugin);
+ CLEAR_FIELD (plugin_instance);
+ CLEAR_FIELD (type);
+ CLEAR_FIELD (type_instance);
+
+#undef CLEAR_FIELD
+
lu_destroy_user_obj (obj, user_class_list->entry.user_obj_list);
user_class_list->entry.user_obj_list = NULL;
pthread_mutex_destroy (&user_class_list->entry.lock);
--- /dev/null
+#! /bin/bash
+#
+# collectd -- testwrapper.sh
+#
+# A wrapper script for running tests. If valgrind is available, memory
+# checking will be enabled for all tests.
+
+set -e
+
+MEMCHECK=""
+
+if test -n "$VALGRIND"; then
+ MEMCHECK="$VALGRIND --quiet --tool=memcheck --error-exitcode=1"
+ MEMCHECK="$MEMCHECK --trace-children=yes"
+ MEMCHECK="$MEMCHECK --leak-check=full"
+ MEMCHECK="$MEMCHECK --gen-suppressions=all"
+fi
+
+exec $MEMCHECK "$@"
+
+# vim: set tw=78 sw=4 ts=4 noexpandtab :
+