Code

Merge remote-tracking branch 'origin/pr/1135'
authorMarc Fournier <marc.fournier@camptocamp.com>
Fri, 11 Sep 2015 20:41:55 +0000 (22:41 +0200)
committerMarc Fournier <marc.fournier@camptocamp.com>
Fri, 11 Sep 2015 20:41:55 +0000 (22:41 +0200)
1  2 
src/Makefile.am
src/daemon/common_test.c
src/daemon/utils_subst_test.c
src/utils_mount_test.c
src/utils_vl_lookup.c

diff --combined src/Makefile.am
index adadbbd27bef87c333bb8cdb7f0ca005c4aac15c,24bcbeca7d5a3664dbabf31f150783364fa3efb5..d0bf5463d125b58b83d461b347961ff25e0a3208
@@@ -6,6 -6,10 +6,6 @@@ SUBDIRS += daemo
  
  PLUGIN_LDFLAGS = -module -avoid-version -export-symbols-regex '\<module_register\>'
  
 -if COMPILER_IS_GCC
 -AM_CFLAGS = -Wall -Werror
 -endif
 -
  AM_CPPFLAGS = -I$(srcdir)/daemon
  AM_CPPFLAGS += -DPREFIX='"${prefix}"'
  AM_CPPFLAGS += -DCONFIGFILE='"${sysconfdir}/${PACKAGE_NAME}.conf"'
@@@ -23,13 -27,6 +23,13 @@@ noinst_LTLIBRARIES 
  check_PROGRAMS =
  TESTS =
  
 +noinst_LTLIBRARIES += liblatency.la
 +liblatency_la_SOURCES = utils_latency.c utils_latency.h
 +check_PROGRAMS += test_utils_latency
 +TESTS += test_utils_latency
 +test_utils_latency_SOURCES = utils_latency_test.c testing.h
 +test_utils_latency_LDADD = liblatency.la daemon/libcommon.la daemon/libplugin_mock.la -lm
 +
  noinst_LTLIBRARIES += liblookup.la
  liblookup_la_SOURCES = utils_vl_lookup.c utils_vl_lookup.h
  liblookup_la_LIBADD = daemon/libavltree.la
@@@ -37,6 -34,9 +37,9 @@@ check_PROGRAMS += test_utils_vl_looku
  TESTS += test_utils_vl_lookup
  test_utils_vl_lookup_SOURCES = utils_vl_lookup_test.c testing.h
  test_utils_vl_lookup_LDADD = liblookup.la daemon/libcommon.la daemon/libplugin_mock.la
+ if BUILD_WITH_LIBKSTAT
+ test_utils_vl_lookup_LDADD += -lkstat
+ endif
  
  noinst_LTLIBRARIES += libmount.la
  libmount_la_SOURCES = utils_mount.c utils_mount.h
@@@ -44,7 -44,9 +47,9 @@@ check_PROGRAMS += test_utils_moun
  TESTS += test_utils_mount
  test_utils_mount_SOURCES = utils_mount_test.c testing.h
  test_utils_mount_LDADD = libmount.la daemon/libcommon.la daemon/libplugin_mock.la
+ if BUILD_WITH_LIBKSTAT
+ test_utils_mount_LDADD += -lkstat
+ endif
  
  sbin_PROGRAMS = collectdmon
  bin_PROGRAMS = collectd-nagios collectdctl collectd-tg
@@@ -115,7 -117,6 +120,7 @@@ if BUILD_PLUGIN_AMQ
  pkglib_LTLIBRARIES += amqp.la
  amqp_la_SOURCES = amqp.c \
                  utils_cmd_putval.c utils_cmd_putval.h \
 +                utils_parse_option.c utils_parse_option.h \
                  utils_format_graphite.c utils_format_graphite.h \
                  utils_format_json.c utils_format_json.h
  amqp_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBRABBITMQ_LDFLAGS)
@@@ -335,9 -336,6 +340,9 @@@ endi
  if BUILD_WITH_LIBUDEV
  disk_la_LIBADD += -ludev
  endif
 +if BUILD_FREEBSD
 +disk_la_LIBADD += -ldevstat -lgeom
 +endif
  if BUILD_WITH_PERFSTAT
  disk_la_LIBADD += -lperfstat
  endif
@@@ -644,14 -642,6 +649,14 @@@ modbus_la_CFLAGS = $(AM_CFLAGS) $(BUILD
  modbus_la_LIBADD = $(BUILD_WITH_LIBMODBUS_LIBS)
  endif
  
 +if BUILD_PLUGIN_MQTT
 +pkglib_LTLIBRARIES += mqtt.la
 +mqtt_la_SOURCES = mqtt.c
 +mqtt_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 +mqtt_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBMOSQUITTO_CPPFLAGS)
 +mqtt_la_LIBADD = $(BUILD_WITH_LIBMOSQUITTO_LIBS)
 +endif
 +
  if BUILD_PLUGIN_MULTIMETER
  pkglib_LTLIBRARIES += multimeter.la
  multimeter_la_SOURCES = multimeter.c
@@@ -981,9 -971,10 +986,9 @@@ endi
  
  if BUILD_PLUGIN_STATSD
  pkglib_LTLIBRARIES += statsd.la
 -statsd_la_SOURCES = statsd.c \
 -                    utils_latency.h utils_latency.c
 +statsd_la_SOURCES = statsd.c
  statsd_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 -statsd_la_LIBADD = -lpthread -lm
 +statsd_la_LIBADD = liblatency.la -lpthread -lm
  endif
  
  if BUILD_PLUGIN_SWAP
diff --combined src/daemon/common_test.c
index 23c6f2328c01383c6c235afd42a6272d4c4a480c,d8efb1553297e92eda45b1cac073be4085f1e717..399f8b533b2bcfdce28afa6b9c3a9f7573a89a75
  #include "testing.h"
  #include "common.h"
  
+ #if HAVE_LIBKSTAT
+ kstat_ctl_t *kc;
+ #endif /* HAVE_LIBKSTAT */
  DEF_TEST(sstrncpy)
  {
    char buffer[16] = "";
  
    ret = sstrncpy (ptr, "foobar", 8);
    OK(ret == ptr);
 -  STREQ ("foobar", ptr);
 +  EXPECT_EQ_STR ("foobar", ptr);
    OK(buffer[3] == buffer[12]);
  
    ret = sstrncpy (ptr, "abc", 8);
    OK(ret == ptr);
 -  STREQ ("abc", ptr);
 +  EXPECT_EQ_STR ("abc", ptr);
    OK(buffer[3] == buffer[12]);
  
    ret = sstrncpy (ptr, "collectd", 8);
    OK(ret == ptr);
    OK(ptr[7] == 0);
 -  STREQ ("collect", ptr);
 +  EXPECT_EQ_STR ("collect", ptr);
    OK(buffer[3] == buffer[12]);
  
    return (0);
@@@ -66,12 -70,12 +70,12 @@@ DEF_TEST(ssnprintf
  
    status = ssnprintf (ptr, 8, "%i", 1337);
    OK(status == 4);
 -  STREQ ("1337", ptr);
 +  EXPECT_EQ_STR ("1337", ptr);
  
    status = ssnprintf (ptr, 8, "%s", "collectd");
    OK(status == 8);
    OK(ptr[7] == 0);
 -  STREQ ("collect", ptr);
 +  EXPECT_EQ_STR ("collect", ptr);
    OK(buffer[3] == buffer[12]);
  
    return (0);
@@@ -83,7 -87,7 +87,7 @@@ DEF_TEST(sstrdup
  
    ptr = sstrdup ("collectd");
    OK(ptr != NULL);
 -  STREQ ("collectd", ptr);
 +  EXPECT_EQ_STR ("collectd", ptr);
  
    sfree(ptr);
    OK(ptr == NULL);
@@@ -103,40 -107,40 +107,40 @@@ DEF_TEST(strsplit
    strncpy (buffer, "foo bar", sizeof (buffer));
    status = strsplit (buffer, fields, 8);
    OK(status == 2);
 -  STREQ ("foo", fields[0]);
 -  STREQ ("bar", fields[1]);
 +  EXPECT_EQ_STR ("foo", fields[0]);
 +  EXPECT_EQ_STR ("bar", fields[1]);
  
    strncpy (buffer, "foo \t bar", sizeof (buffer));
    status = strsplit (buffer, fields, 8);
    OK(status == 2);
 -  STREQ ("foo", fields[0]);
 -  STREQ ("bar", fields[1]);
 +  EXPECT_EQ_STR ("foo", fields[0]);
 +  EXPECT_EQ_STR ("bar", fields[1]);
  
    strncpy (buffer, "one two\tthree\rfour\nfive", sizeof (buffer));
    status = strsplit (buffer, fields, 8);
    OK(status == 5);
 -  STREQ ("one", fields[0]);
 -  STREQ ("two", fields[1]);
 -  STREQ ("three", fields[2]);
 -  STREQ ("four", fields[3]);
 -  STREQ ("five", fields[4]);
 +  EXPECT_EQ_STR ("one", fields[0]);
 +  EXPECT_EQ_STR ("two", fields[1]);
 +  EXPECT_EQ_STR ("three", fields[2]);
 +  EXPECT_EQ_STR ("four", fields[3]);
 +  EXPECT_EQ_STR ("five", fields[4]);
  
    strncpy (buffer, "\twith trailing\n", sizeof (buffer));
    status = strsplit (buffer, fields, 8);
    OK(status == 2);
 -  STREQ ("with", fields[0]);
 -  STREQ ("trailing", fields[1]);
 +  EXPECT_EQ_STR ("with", fields[0]);
 +  EXPECT_EQ_STR ("trailing", fields[1]);
  
    strncpy (buffer, "1 2 3 4 5 6 7 8 9 10 11 12 13", sizeof (buffer));
    status = strsplit (buffer, fields, 8);
    OK(status == 8);
 -  STREQ ("7", fields[6]);
 -  STREQ ("8", fields[7]);
 +  EXPECT_EQ_STR ("7", fields[6]);
 +  EXPECT_EQ_STR ("8", fields[7]);
  
    strncpy (buffer, "single", sizeof (buffer));
    status = strsplit (buffer, fields, 8);
    OK(status == 1);
 -  STREQ ("single", fields[0]);
 +  EXPECT_EQ_STR ("single", fields[0]);
  
    strncpy (buffer, "", sizeof (buffer));
    status = strsplit (buffer, fields, 8);
@@@ -158,26 -162,26 +162,26 @@@ DEF_TEST(strjoin
  
    status = strjoin (buffer, sizeof (buffer), fields, 2, "!");
    OK(status == 7);
 -  STREQ ("foo!bar", buffer);
 +  EXPECT_EQ_STR ("foo!bar", buffer);
  
    status = strjoin (buffer, sizeof (buffer), fields, 1, "!");
    OK(status == 3);
 -  STREQ ("foo", buffer);
 +  EXPECT_EQ_STR ("foo", buffer);
  
    status = strjoin (buffer, sizeof (buffer), fields, 0, "!");
    OK(status < 0);
  
    status = strjoin (buffer, sizeof (buffer), fields, 2, "rcht");
    OK(status == 10);
 -  STREQ ("foorchtbar", buffer);
 +  EXPECT_EQ_STR ("foorchtbar", buffer);
  
    status = strjoin (buffer, sizeof (buffer), fields, 4, "");
    OK(status == 12);
 -  STREQ ("foobarbazqux", buffer);
 +  EXPECT_EQ_STR ("foobarbazqux", buffer);
  
    status = strjoin (buffer, sizeof (buffer), fields, 4, "!");
    OK(status == 15);
 -  STREQ ("foo!bar!baz!qux", buffer);
 +  EXPECT_EQ_STR ("foo!bar!baz!qux", buffer);
  
    fields[0] = "0123";
    fields[1] = "4567";
@@@ -207,7 -211,7 +211,7 @@@ DEF_TEST(escape_slashes
  
      strncpy (buffer, cases[i].str, sizeof (buffer));
      OK(escape_slashes (buffer, sizeof (buffer)) == 0);
 -    STREQ(cases[i].want, buffer);
 +    EXPECT_EQ_STR(cases[i].want, buffer);
    }
  
    return 0;
@@@ -234,7 -238,7 +238,7 @@@ DEF_TEST(escape_string
  
      strncpy (buffer, cases[i].str, sizeof (buffer));
      OK(escape_string (buffer, sizeof (buffer)) == 0);
 -    STREQ(cases[i].want, buffer);
 +    EXPECT_EQ_STR(cases[i].want, buffer);
    }
  
    return 0;
@@@ -248,23 -252,23 +252,23 @@@ DEF_TEST(strunescape
    strncpy (buffer, "foo\\tbar", sizeof (buffer));
    status = strunescape (buffer, sizeof (buffer));
    OK(status == 0);
 -  STREQ ("foo\tbar", buffer);
 +  EXPECT_EQ_STR ("foo\tbar", buffer);
  
    strncpy (buffer, "\\tfoo\\r\\n", sizeof (buffer));
    status = strunescape (buffer, sizeof (buffer));
    OK(status == 0);
 -  STREQ ("\tfoo\r\n", buffer);
 +  EXPECT_EQ_STR ("\tfoo\r\n", buffer);
  
    strncpy (buffer, "With \\\"quotes\\\"", sizeof (buffer));
    status = strunescape (buffer, sizeof (buffer));
    OK(status == 0);
 -  STREQ ("With \"quotes\"", buffer);
 +  EXPECT_EQ_STR ("With \"quotes\"", buffer);
  
    /* Backslash before null byte */
    strncpy (buffer, "\\tbackslash end\\", sizeof (buffer));
    status = strunescape (buffer, sizeof (buffer));
    OK(status != 0);
 -  STREQ ("\tbackslash end", buffer);
 +  EXPECT_EQ_STR ("\tbackslash end", buffer);
    return (0);
  
    /* Backslash at buffer end */
@@@ -328,11 -332,11 +332,11 @@@ DEF_TEST(parse_values
      };
  
      int status = parse_values (cases[i].buffer, &vl, &ds);
 -    EXPECT_INTEQ (cases[i].status, status);
 +    EXPECT_EQ_INT (cases[i].status, status);
      if (status != 0)
        continue;
  
 -    DBLEQ (cases[i].value, vl.values[0].gauge);
 +    EXPECT_EQ_DOUBLE (cases[i].value, vl.values[0].gauge);
    }
  
    return (0);
@@@ -370,7 -374,7 +374,7 @@@ DEF_TEST(value_to_rate
      }
  
      OK(value_to_rate (&got, cases[i].v1, cases[i].ds_type, TIME_T_TO_CDTIME_T(cases[i].t1), &state) == 0);
 -    DBLEQ(cases[i].want, got);
 +    EXPECT_EQ_DOUBLE(cases[i].want, got);
    }
  
    return 0;
index 2a7080261ee366c86907cd8bc269cc4f67a96f8b,98e0b536f6142184a94a780b3e8481675b1f4478..c12aa1057fe3d91022c67983d6a4e338c3b7f6ea
  #include "common.h" /* for STATIC_ARRAY_SIZE */
  #include "utils_subst.h"
  
+ #if HAVE_LIBKSTAT
+ kstat_ctl_t *kc;
+ #endif /* HAVE_LIBKSTAT */
  DEF_TEST(subst)
  {
    struct {
@@@ -82,7 -86,7 +86,7 @@@
      }
  
      OK(subst (buffer, sizeof (buffer), cases[i].str, cases[i].off1, cases[i].off2, cases[i].rplmt) == &buffer[0]);
 -    STREQ(cases[i].want, buffer);
 +    EXPECT_EQ_STR(cases[i].want, buffer);
    }
  
    return 0;
@@@ -112,7 -116,7 +116,7 @@@ DEF_TEST(subst_string
      }
  
      OK(subst_string (buffer, sizeof (buffer), cases[i].str, cases[i].srch, cases[i].rplmt) == buffer);
 -    STREQ(cases[i].want, buffer);
 +    EXPECT_EQ_STR(cases[i].want, buffer);
    }
  
    return 0;
diff --combined src/utils_mount_test.c
index 77a4205e84de1ffed5bec5699a830d187cc71e56,a16b262c268b254581c22383d907dc6392bdf379..b4cb43219a0e63b1ff8200ee79c3e2953704ca9c
  #include "collectd.h"
  #include "utils_mount.h"
  
+ #if HAVE_LIBKSTAT
+ kstat_ctl_t *kc;
+ #endif /* HAVE_LIBKSTAT */
  DEF_TEST(cu_mount_checkoption)
  {
    char line_opts[] = "foo=one,bar=two,qux=three";
@@@ -77,14 -81,14 +81,14 @@@ DEF_TEST(cu_mount_getoptionvalue
    char line_opts[] = "foo=one,bar=two,qux=three";
    char line_bool[] = "one,two,three";
  
 -  STREQ ("one", cu_mount_getoptionvalue (line_opts, "foo="));
 -  STREQ ("two", cu_mount_getoptionvalue (line_opts, "bar="));
 -  STREQ ("three", cu_mount_getoptionvalue (line_opts, "qux="));
 +  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="));
  
 -  STREQ ("", cu_mount_getoptionvalue (line_bool, "one"));
 -  STREQ ("", cu_mount_getoptionvalue (line_bool, "two"));
 -  STREQ ("", cu_mount_getoptionvalue (line_bool, "three"));
 +  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"));
  
    return (0);
diff --combined src/utils_vl_lookup.c
index f0f0b4632ecafda01572e7d3252e25fc77c5136d,bdc77988af43152498180e4d2df16b5106096d1a..f85910e1737e7b5d1c328a6e9e15896be2d60d99
  #include "utils_vl_lookup.h"
  #include "utils_avltree.h"
  
+ #if HAVE_LIBKSTAT
+ kstat_ctl_t *kc;
+ #endif /* HAVE_LIBKSTAT */
  #if BUILD_TEST
  # define sstrncpy strncpy
  # define plugin_log(s, ...) do { \
@@@ -304,10 -308,9 +308,10 @@@ static int lu_handle_user_class (lookup
    {
      /* call lookup_class_callback_t() and insert into the list of user objects. */
      user_obj = lu_create_user_obj (obj, ds, vl, user_class);
 -    pthread_mutex_unlock (&user_class->lock);
 -    if (user_obj == NULL)
 +    if (user_obj == NULL) {
 +      pthread_mutex_unlock (&user_class->lock);
        return (-1);
 +    }
    }
    pthread_mutex_unlock (&user_class->lock);