2008-07-15, Version 4.4.2
* build system: Use pkg-config to detect the upsclient library.
- * collectd: Try even harder to determine the endianess of the
+ * collectd: Try even harder to determine the endianness of the
architecture collectd is being built on.
* disk plugin: Fix for Linux 2.4: A wrong field was used as the name
of disks.
2008-08-30, Version 4.3.4
* Build system: Improved detection of and linking with the statgrab
library.
- * collectd: Portability fixes, especially to determine endianess more
+ * collectd: Portability fixes, especially to determine endianness more
reliable.
* Various plugins: Fix format strings.
* disk plugin: A fix for giving disks under Linux 2.4 the right names
=item B<gc_read_config> (I<$file>)
Reads the configuration from the file located at I<$file>. Returns B<true> when
-successfull and B<false> otherwise.
+successful and B<false> otherwise.
=cut
=item B<gc_read_config> (I<$file>)
Reads the configuration from the file located at I<$file>. Returns B<true> when
-successfull and B<false> otherwise.
+successful and B<false> otherwise.
=cut
my $module = shift;
my $obj;
- # Surpress warnings and error messages caused by the eval.
+ # Suppress warnings and error messages caused by the eval.
local $SIG{__WARN__} = sub { return (1); print STDERR "WARNING: " . join (', ', @_) . "\n"; };
local $SIG{__DIE__} = sub { return (1); print STDERR "FATAL: " . join (', ', @_) . "\n"; };
imagestring($png, 4, ceil(($w-strlen($title)*imagefontwidth(4)) / 2), 10, $title, $c_txt);
imagestring($png, 5, 60, 35, sprintf('%s [%d]', $code_msg, $code), $c_etxt);
if (function_exists('imagettfbbox') && is_file($config['error_font'])) {
- // Detailled error message
+ // Detailed error message
$fmt_msg = makeTextBlock($msg, $errorfont, 10, $w-86);
$fmtbox = imagettfbbox(12, 0, $errorfont, $fmt_msg);
imagettftext($png, 10, 0, 55, 35+3+imagefontwidth(5)-$fmtbox[7]+$fmtbox[1], $c_txt, $errorfont, $fmt_msg);
-- and 'values' to store the value-list identifier and the actual values
-- respectively.
--
--- The 'values' table is partitioned to improve performance and maintainance.
--- Please note that additional maintainance scripts are required in order to
+-- The 'values' table is partitioned to improve performance and maintenance.
+-- Please note that additional maintenance scripts are required in order to
-- keep the setup running -- see the comments below for details.
--
-- The function 'collectd_insert' may be used to actually insert values
* Sat Nov 17 2012 Ruben Kerkhof <ruben@tilaa.nl> 5.1.0-2
- Move perl stuff to perl_vendorlib
- Replace hardcoded paths with macros
-- Remove unneccesary Requires
+- Remove unnecessary Requires
- Removed .a and .la files
- Some other small cleanups
- New upstream version
- Changes to support 5.1.0
- Enabled all buildable plugins based on libraries available on EL6 + EPEL
-- All plugins requiring external libraries are now shipped in seperate
+- All plugins requiring external libraries are now shipped in separate
packages.
- No longer treat Java plugin as an exception, correctly set $JAVA_HOME during
the build process + ensure build deps are installed.
rm -f $(DESTDIR)$(sysconfdir)/collectd.conf
rm -f $(DESTDIR)$(pkgdatadir)/postgresql_default.conf;
-if BUILD_FEATURE_DEBUG
-bin_PROGRAMS += utils_vl_lookup_test
-utils_vl_lookup_test_SOURCES = utils_vl_lookup_test.c \
+check_PROGRAMS = test_common test_utils_avltree test_utils_heap test_utils_mount test_utils_vl_lookup
+
+test_common_SOURCES = tests/test_common.c \
+ common.h common.c \
+ tests/mock/plugin.c \
+ tests/mock/utils_cache.c \
+ tests/mock/utils_time.c
+test_common_CPPFLAGS = $(AM_CPPFLAGS) $(LTDLINCL)
+test_common_LDFLAGS = -export-dynamic
+test_common_LDADD =
+
+test_utils_avltree_SOURCES = tests/test_utils_avltree.c \
+ utils_avltree.c utils_avltree.h
+test_utils_avltree_CPPFLAGS = $(AM_CPPFLAGS) $(LTDLINCL)
+test_utils_avltree_LDFLAGS = -export-dynamic
+test_utils_avltree_LDADD =
+
+test_utils_heap_SOURCES = tests/test_utils_heap.c \
+ utils_heap.c utils_heap.h
+test_utils_heap_CPPFLAGS = $(AM_CPPFLAGS) $(LTDLINCL)
+test_utils_heap_LDFLAGS = -export-dynamic
+test_utils_heap_LDADD =
+
+test_utils_mount_SOURCES = tests/test_utils_mount.c \
+ utils_mount.c utils_mount.h \
+ common.c common.h \
+ tests/mock/plugin.c \
+ tests/mock/utils_cache.c \
+ tests/mock/utils_time.c
+test_utils_mount_CPPFLAGS = $(AM_CPPFLAGS) $(LTDLINCL)
+test_utils_mount_LDFLAGS = -export-dynamic
+test_utils_mount_LDADD =
+
+test_utils_vl_lookup_SOURCES = tests/test_utils_vl_lookup.c \
utils_vl_lookup.h utils_vl_lookup.c \
utils_avltree.c utils_avltree.h \
- common.h
-
-utils_vl_lookup_test_CPPFLAGS = $(AM_CPPFLAGS) $(LTDLINCL) -DBUILD_TEST=1
-utils_vl_lookup_test_CFLAGS = $(AM_CFLAGS)
-utils_vl_lookup_test_LDFLAGS = -export-dynamic
-utils_vl_lookup_test_LDADD =
-endif
+ common.c common.h \
+ tests/mock/plugin.c \
+ tests/mock/utils_cache.c \
+ tests/mock/utils_time.c
+test_utils_vl_lookup_CPPFLAGS = $(AM_CPPFLAGS) $(LTDLINCL)
+test_utils_vl_lookup_LDFLAGS = -export-dynamic
+test_utils_vl_lookup_LDADD =
+
+TESTS = test_common test_utils_avltree test_utils_heap test_utils_mount test_utils_vl_lookup
static int battery_init (void)
{
#if HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H
- /* No init neccessary */
+ /* No init necessary */
/* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */
#elif KERNEL_LINUX
/*
* Gets called for every file/folder in /sys/fs/cgroup/cpu,cpuacct (or
- * whereever cpuacct is mounted on the system). Calls walk_directory with the
+ * wherever cpuacct is mounted on the system). Calls walk_directory with the
* read_cpuacct_procs callback on every folder it finds, such as "system".
*/
static int read_cpuacct_root (const char *dirname, const char *filename,
=item B<Scale> I<Value>
The gauge-values returned by the SNMP-agent are multiplied by I<Value>. This
-is useful when values are transfered as a fixed point real number. For example,
+is useful when values are transferred as a fixed point real number. For example,
thermometers may transfer B<243> but actually mean B<24.3>, so you can specify
a scale value of B<0.1> to correct this. The default value is, of course,
B<1.0>.
=item B<ShowCPU> B<true>|B<false>
-If enabled (the default) a sum of the CPU usage accross all cores is reported.
+If enabled (the default) a sum of the CPU usage across all cores is reported.
=item B<ShowCPUCores> B<true>|B<false>
=head2 Plugin C<write_riemann>
-The I<write_riemann plugin> will send values to I<Riemann>, a powerfull stream
+The I<write_riemann plugin> will send values to I<Riemann>, a powerful stream
aggregation and monitoring system. The plugin sends I<Protobuf> encoded data to
I<Riemann> using UDP packets.
if (buf[i] != '\\')
continue;
- if ((i >= buf_len) || (buf[i + 1] == '\0')) {
+ if (((i + 1) >= buf_len) || (buf[i + 1] == 0)) {
ERROR ("string unescape: backslash found at end of string.");
+ /* Ensure null-byte at the end of the buffer. */
+ buf[i] = 0;
return (-1);
}
break;
}
+ /* Move everything after the position one position to the left.
+ * Add a null-byte as last character in the buffer. */
memmove (buf + i + 1, buf + i + 2, buf_len - i - 2);
+ buf[buf_len - 1] = 0;
}
return (0);
} /* int strunescape */
#include <longintrepr.h>
-/* These two macros are basicly Py_BEGIN_ALLOW_THREADS and Py_BEGIN_ALLOW_THREADS
+/* These two macros are basically Py_BEGIN_ALLOW_THREADS and Py_BEGIN_ALLOW_THREADS
* from the other direction. If a Python thread calls a C function
* Py_BEGIN_ALLOW_THREADS is used to allow other python threads to run because
* we don't intend to call any Python functions.
* These two macros are used whenever a C thread intends to call some Python
* function, usually because some registered callback was triggered.
* Just like Py_BEGIN_ALLOW_THREADS it opens a block so these macros have to be
- * used in pairs. They aquire the GIL, create a new Python thread state and swap
+ * used in pairs. They acquire the GIL, create a new Python thread state and swap
* the current thread state with the new one. This means this thread is now allowed
* to execute Python code. */
cbi = (cjni_callback_info_t *) arg;
- /* This condition can occurr when shutting down. */
+ /* This condition can occur when shutting down. */
if (jvm == NULL)
{
sfree (cbi);
status = tss2_receive_line (read_fh, buffer, sizeof (buffer));
if (status != 0)
{
- /* Set to NULL just to make sure noone uses these FHs anymore. */
+ /* Set to NULL just to make sure no one uses these FHs anymore. */
read_fh = NULL;
write_fh = NULL;
ERROR ("teamspeak2 plugin: tss2_receive_line failed.");
status = tss2_receive_line (read_fh, buffer, sizeof (buffer));
if (status != 0)
{
- /* Set to NULL just to make sure noone uses these FHs anymore. */
+ /* Set to NULL just to make sure no one uses these FHs anymore. */
read_fh = NULL;
write_fh = NULL;
ERROR ("teamspeak2 plugin: tss2_receive_line failed.");
--- /dev/null
+/**
+ * collectd - src/common_test.c
+ *
+ * Copyright (C) 2013 Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Florian octo Forster <octo at collectd.org>
+ */
+
+#include "tests/macros.h"
+#include "common.h"
+
+DEF_TEST(sstrncpy)
+{
+ char buffer[16] = "";
+ char *ptr = &buffer[4];
+ char *ret;
+
+ buffer[0] = buffer[1] = buffer[2] = buffer[3] = 0xff;
+ buffer[12] = buffer[13] = buffer[14] = buffer[15] = 0xff;
+
+ ret = sstrncpy (ptr, "foobar", 8);
+ OK(ret == ptr);
+ STREQ ("foobar", ptr);
+ OK(buffer[3] == buffer[12]);
+
+ ret = sstrncpy (ptr, "abc", 8);
+ OK(ret == ptr);
+ STREQ ("abc", ptr);
+ OK(buffer[3] == buffer[12]);
+
+ ret = sstrncpy (ptr, "collectd", 8);
+ OK(ret == ptr);
+ OK(ptr[7] == 0);
+ STREQ ("collect", ptr);
+ OK(buffer[3] == buffer[12]);
+
+ return (0);
+}
+
+DEF_TEST(ssnprintf)
+{
+ char buffer[16] = "";
+ char *ptr = &buffer[4];
+ int status;
+
+ buffer[0] = buffer[1] = buffer[2] = buffer[3] = 0xff;
+ buffer[12] = buffer[13] = buffer[14] = buffer[15] = 0xff;
+
+ status = ssnprintf (ptr, 8, "%i", 1337);
+ OK(status == 4);
+ STREQ ("1337", ptr);
+
+ status = ssnprintf (ptr, 8, "%s", "collectd");
+ OK(status == 8);
+ OK(ptr[7] == 0);
+ STREQ ("collect", ptr);
+ OK(buffer[3] == buffer[12]);
+
+ return (0);
+}
+
+DEF_TEST(sstrdup)
+{
+ char *ptr;
+
+ ptr = sstrdup ("collectd");
+ OK(ptr != NULL);
+ STREQ ("collectd", ptr);
+
+ sfree(ptr);
+ OK(ptr == NULL);
+
+ ptr = sstrdup (NULL);
+ OK(ptr == NULL);
+
+ return (0);
+}
+
+DEF_TEST(strsplit)
+{
+ char buffer[32];
+ char *fields[8];
+ int status;
+
+ strncpy (buffer, "foo bar", sizeof (buffer));
+ status = strsplit (buffer, fields, 8);
+ OK(status == 2);
+ STREQ ("foo", fields[0]);
+ STREQ ("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]);
+
+ 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]);
+
+ strncpy (buffer, "\twith trailing\n", sizeof (buffer));
+ status = strsplit (buffer, fields, 8);
+ OK(status == 2);
+ STREQ ("with", fields[0]);
+ STREQ ("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]);
+
+ strncpy (buffer, "single", sizeof (buffer));
+ status = strsplit (buffer, fields, 8);
+ OK(status == 1);
+ STREQ ("single", fields[0]);
+
+ strncpy (buffer, "", sizeof (buffer));
+ status = strsplit (buffer, fields, 8);
+ OK(status == 0);
+
+ return (0);
+}
+
+DEF_TEST(strjoin)
+{
+ char buffer[16];
+ char *fields[4];
+ int status;
+
+ fields[0] = "foo";
+ fields[1] = "bar";
+ fields[2] = "baz";
+ fields[3] = "qux";
+
+ status = strjoin (buffer, sizeof (buffer), fields, 2, "!");
+ OK(status == 7);
+ STREQ ("foo!bar", buffer);
+
+ status = strjoin (buffer, sizeof (buffer), fields, 1, "!");
+ OK(status == 3);
+ STREQ ("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);
+
+ status = strjoin (buffer, sizeof (buffer), fields, 4, "");
+ OK(status == 12);
+ STREQ ("foobarbazqux", buffer);
+
+ status = strjoin (buffer, sizeof (buffer), fields, 4, "!");
+ OK(status == 15);
+ STREQ ("foo!bar!baz!qux", buffer);
+
+ fields[0] = "0123";
+ fields[1] = "4567";
+ fields[2] = "8901";
+ fields[3] = "2345";
+ status = strjoin (buffer, sizeof (buffer), fields, 4, "-");
+ OK(status < 0);
+
+ return (0);
+}
+
+DEF_TEST(strunescape)
+{
+ char buffer[16];
+ int status;
+
+ strncpy (buffer, "foo\\tbar", sizeof (buffer));
+ status = strunescape (buffer, sizeof (buffer));
+ OK(status == 0);
+ STREQ ("foo\tbar", buffer);
+
+ strncpy (buffer, "\\tfoo\\r\\n", sizeof (buffer));
+ status = strunescape (buffer, sizeof (buffer));
+ OK(status == 0);
+ STREQ ("\tfoo\r\n", buffer);
+
+ strncpy (buffer, "With \\\"quotes\\\"", sizeof (buffer));
+ status = strunescape (buffer, sizeof (buffer));
+ OK(status == 0);
+ STREQ ("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);
+ return (0);
+
+ /* Backslash at buffer end */
+ strncpy (buffer, "\\t3\\56", sizeof (buffer));
+ status = strunescape (buffer, 4);
+ OK(status != 0);
+ OK(buffer[0] == '\t');
+ OK(buffer[1] == '3');
+ OK(buffer[2] == 0);
+ OK(buffer[3] == 0);
+ OK(buffer[4] == '5');
+ OK(buffer[5] == '6');
+ OK(buffer[6] == '7');
+
+ return (0);
+}
+
+int main (void)
+{
+ RUN_TEST(sstrncpy);
+ RUN_TEST(ssnprintf);
+ RUN_TEST(sstrdup);
+ RUN_TEST(strsplit);
+ RUN_TEST(strjoin);
+ RUN_TEST(strunescape);
+
+ END_TEST;
+}
+
+/* vim: set sw=2 sts=2 et : */
--- /dev/null
+/**
+ * collectd - src/tests/macros.h
+ *
+ * Copyright (C) 2013 Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Florian octo Forster <octo at collectd.org>
+ */
+
+static int fail_count__ = 0;
+static int check_count__ = 0;
+
+#define DEF_TEST(func) static int test_##func ()
+
+#define RUN_TEST(func) do { \
+ int status; \
+ printf ("Testing %s ...\n", #func); \
+ status = test_ ## func (); \
+ printf ("%s.\n", (status == 0) ? "Success" : "FAILURE"); \
+ if (status != 0) { fail_count__++; } \
+} while (0)
+
+#define END_TEST exit ((fail_count__ == 0) ? 0 : 1);
+
+#define OK1(cond, text) do { \
+ _Bool result = (cond); \
+ printf ("%s %i - %s\n", result ? "ok" : "not ok", ++check_count__, text); \
+} while (0)
+#define OK(cond) OK1(cond, #cond)
+
+#define STREQ(expect, actual) do { \
+ if (strcmp (expect, actual) != 0) { \
+ printf ("not ok %i - %s incorrect: expected \"%s\", got \"%s\"\n", \
+ ++check_count__, #actual, expect, actual); \
+ return (-1); \
+ } \
+ printf ("ok %i - %s evaluates to \"%s\"\n", ++check_count__, #actual, expect); \
+} while (0)
+
+#define CHECK_NOT_NULL(expr) do { \
+ void *ptr_; \
+ ptr_ = (expr); \
+ OK1(ptr_ != NULL, #expr); \
+} while (0)
+
+#define CHECK_ZERO(expr) do { \
+ long status_; \
+ status_ = (long) (expr); \
+ OK1(status_ == 0L, #expr); \
+} while (0)
--- /dev/null
+/**
+ * collectd - src/mock/plugin.c
+ *
+ * Copyright (C) 2013 Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Florian octo Forster <octo at collectd.org>
+ */
+
+#include "plugin.h"
+
+void plugin_log (int level, char const *format, ...)
+{
+ char buffer[1024];
+ va_list ap;
+
+ va_start (ap, format);
+ vsnprintf (buffer, sizeof (buffer), format, ap);
+ va_end (ap);
+
+ printf ("plugin_log (%i, \"%s\");\n", level, buffer);
+}
+
+/* vim: set sw=2 sts=2 et : */
--- /dev/null
+/**
+ * collectd - src/mock/utils_cache.c
+ *
+ * Copyright (C) 2013 Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Florian octo Forster <octo at collectd.org>
+ */
+
+#include "utils_cache.h"
+
+gauge_t *uc_get_rate (const data_set_t *ds, const value_list_t *vl)
+{
+ return (NULL);
+}
--- /dev/null
+/**
+ * collectd - src/mock/utils_time.c
+ *
+ * Copyright (C) 2013 Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Florian octo Forster <octo at collectd.org>
+ */
+
+#include "utils_time.h"
+
+cdtime_t cdtime (void)
+{
+ return (0);
+}
+
--- /dev/null
+/**
+ * collectd - src/common_test.c
+ *
+ * Copyright (C) 2013 Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Florian octo Forster <octo at collectd.org>
+ */
+
+#include "tests/macros.h"
+#include "common.h"
+
+DEF_TEST(sstrncpy)
+{
+ char buffer[16] = "";
+ char *ptr = &buffer[4];
+ char *ret;
+
+ buffer[0] = buffer[1] = buffer[2] = buffer[3] = 0xff;
+ buffer[12] = buffer[13] = buffer[14] = buffer[15] = 0xff;
+
+ ret = sstrncpy (ptr, "foobar", 8);
+ OK(ret == ptr);
+ STREQ ("foobar", ptr);
+ OK(buffer[3] == buffer[12]);
+
+ ret = sstrncpy (ptr, "abc", 8);
+ OK(ret == ptr);
+ STREQ ("abc", ptr);
+ OK(buffer[3] == buffer[12]);
+
+ ret = sstrncpy (ptr, "collectd", 8);
+ OK(ret == ptr);
+ OK(ptr[7] == 0);
+ STREQ ("collect", ptr);
+ OK(buffer[3] == buffer[12]);
+
+ return (0);
+}
+
+DEF_TEST(ssnprintf)
+{
+ char buffer[16] = "";
+ char *ptr = &buffer[4];
+ int status;
+
+ buffer[0] = buffer[1] = buffer[2] = buffer[3] = 0xff;
+ buffer[12] = buffer[13] = buffer[14] = buffer[15] = 0xff;
+
+ status = ssnprintf (ptr, 8, "%i", 1337);
+ OK(status == 4);
+ STREQ ("1337", ptr);
+
+ status = ssnprintf (ptr, 8, "%s", "collectd");
+ OK(status == 8);
+ OK(ptr[7] == 0);
+ STREQ ("collect", ptr);
+ OK(buffer[3] == buffer[12]);
+
+ return (0);
+}
+
+DEF_TEST(sstrdup)
+{
+ char *ptr;
+
+ ptr = sstrdup ("collectd");
+ OK(ptr != NULL);
+ STREQ ("collectd", ptr);
+
+ sfree(ptr);
+ OK(ptr == NULL);
+
+ ptr = sstrdup (NULL);
+ OK(ptr == NULL);
+
+ return (0);
+}
+
+DEF_TEST(strsplit)
+{
+ char buffer[32];
+ char *fields[8];
+ int status;
+
+ strncpy (buffer, "foo bar", sizeof (buffer));
+ status = strsplit (buffer, fields, 8);
+ OK(status == 2);
+ STREQ ("foo", fields[0]);
+ STREQ ("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]);
+
+ 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]);
+
+ strncpy (buffer, "\twith trailing\n", sizeof (buffer));
+ status = strsplit (buffer, fields, 8);
+ OK(status == 2);
+ STREQ ("with", fields[0]);
+ STREQ ("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]);
+
+ strncpy (buffer, "single", sizeof (buffer));
+ status = strsplit (buffer, fields, 8);
+ OK(status == 1);
+ STREQ ("single", fields[0]);
+
+ strncpy (buffer, "", sizeof (buffer));
+ status = strsplit (buffer, fields, 8);
+ OK(status == 0);
+
+ return (0);
+}
+
+DEF_TEST(strjoin)
+{
+ char buffer[16];
+ char *fields[4];
+ int status;
+
+ fields[0] = "foo";
+ fields[1] = "bar";
+ fields[2] = "baz";
+ fields[3] = "qux";
+
+ status = strjoin (buffer, sizeof (buffer), fields, 2, "!");
+ OK(status == 7);
+ STREQ ("foo!bar", buffer);
+
+ status = strjoin (buffer, sizeof (buffer), fields, 1, "!");
+ OK(status == 3);
+ STREQ ("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);
+
+ status = strjoin (buffer, sizeof (buffer), fields, 4, "");
+ OK(status == 12);
+ STREQ ("foobarbazqux", buffer);
+
+ status = strjoin (buffer, sizeof (buffer), fields, 4, "!");
+ OK(status == 15);
+ STREQ ("foo!bar!baz!qux", buffer);
+
+ fields[0] = "0123";
+ fields[1] = "4567";
+ fields[2] = "8901";
+ fields[3] = "2345";
+ status = strjoin (buffer, sizeof (buffer), fields, 4, "-");
+ OK(status < 0);
+
+ return (0);
+}
+
+DEF_TEST(strunescape)
+{
+ char buffer[16];
+ int status;
+
+ strncpy (buffer, "foo\\tbar", sizeof (buffer));
+ status = strunescape (buffer, sizeof (buffer));
+ OK(status == 0);
+ STREQ ("foo\tbar", buffer);
+
+ strncpy (buffer, "\\tfoo\\r\\n", sizeof (buffer));
+ status = strunescape (buffer, sizeof (buffer));
+ OK(status == 0);
+ STREQ ("\tfoo\r\n", buffer);
+
+ strncpy (buffer, "With \\\"quotes\\\"", sizeof (buffer));
+ status = strunescape (buffer, sizeof (buffer));
+ OK(status == 0);
+ STREQ ("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);
+ return (0);
+
+ /* Backslash at buffer end */
+ strncpy (buffer, "\\t3\\56", sizeof (buffer));
+ status = strunescape (buffer, 4);
+ OK(status != 0);
+ OK(buffer[0] == '\t');
+ OK(buffer[1] == '3');
+ OK(buffer[2] == 0);
+ OK(buffer[3] == 0);
+ OK(buffer[4] == '5');
+ OK(buffer[5] == '6');
+ OK(buffer[6] == '7');
+
+ return (0);
+}
+
+int main (void)
+{
+ RUN_TEST(sstrncpy);
+ RUN_TEST(ssnprintf);
+ RUN_TEST(sstrdup);
+ RUN_TEST(strsplit);
+ RUN_TEST(strjoin);
+ RUN_TEST(strunescape);
+
+ END_TEST;
+}
+
+/* vim: set sw=2 sts=2 et : */
--- /dev/null
+/**
+ * collectd - src/utils_avltree_test.c
+ *
+ * Copyright (C) 2013 Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Florian octo Forster <octo at collectd.org>
+ */
+
+#include "tests/macros.h"
+#include "collectd.h"
+#include "utils_avltree.h"
+
+static int compare_total_count = 0;
+#define RESET_COUNTS() do { compare_total_count = 0; } while (0)
+
+static int compare_callback (void const *v0, void const *v1)
+{
+ assert (v0 != NULL);
+ assert (v1 != NULL);
+
+ compare_total_count++;
+ return (strcmp (v0, v1));
+}
+
+DEF_TEST(success)
+{
+ c_avl_tree_t *t;
+ char key_orig[] = "foo";
+ char value_orig[] = "bar";
+ char *key_ret = NULL;
+ char *value_ret = NULL;
+
+ RESET_COUNTS ();
+ t = c_avl_create (compare_callback);
+ OK (t != NULL);
+
+ OK (c_avl_insert (t, key_orig, value_orig) == 0);
+ OK (c_avl_size (t) == 1);
+
+ /* Key already exists. */
+ OK (c_avl_insert (t, "foo", "qux") > 0);
+
+ OK (c_avl_get (t, "foo", (void *) &value_ret) == 0);
+ OK (value_ret == &value_orig[0]);
+
+ key_ret = value_ret = NULL;
+ OK (c_avl_remove (t, "foo", (void *) &key_ret, (void *) &value_ret) == 0);
+ OK (key_ret == &key_orig[0]);
+ OK (value_ret == &value_orig[0]);
+ OK (c_avl_size (t) == 0);
+
+ c_avl_destroy (t);
+
+ return (0);
+}
+
+int main (void)
+{
+ RUN_TEST(success);
+
+ END_TEST;
+}
+
+/* vim: set sw=2 sts=2 et : */
--- /dev/null
+/**
+ * collectd - src/tests/utils_heap_test.c
+ *
+ * Copyright (C) 2013 Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Florian octo Forster <octo at collectd.org>
+ */
+
+#include "collectd.h"
+#include "tests/macros.h"
+#include "utils_heap.h"
+
+static int compare (void const *v0, void const *v1)
+{
+ int const *i0 = v0;
+ int const *i1 = v1;
+
+ if ((*i0) < (*i1))
+ return -1;
+ else if ((*i0) > (*i1))
+ return 1;
+ else
+ return 0;
+}
+
+DEF_TEST(simple)
+{
+ int values[] = { 9, 5, 6, 1, 3, 4, 0, 8, 2, 7 };
+ int i;
+ c_heap_t *h;
+
+ CHECK_NOT_NULL(h = c_heap_create (compare));
+ for (i = 0; i < 10; i++)
+ CHECK_ZERO(c_heap_insert (h, &values[i]));
+
+ for (i = 0; i < 5; i++)
+ {
+ int *ret = NULL;
+ CHECK_NOT_NULL(ret = c_heap_get_root(h));
+ OK(*ret == i);
+ }
+
+ CHECK_ZERO(c_heap_insert (h, &values[6] /* = 0 */));
+ CHECK_ZERO(c_heap_insert (h, &values[3] /* = 1 */));
+ CHECK_ZERO(c_heap_insert (h, &values[8] /* = 2 */));
+ CHECK_ZERO(c_heap_insert (h, &values[4] /* = 3 */));
+ CHECK_ZERO(c_heap_insert (h, &values[5] /* = 4 */));
+
+ for (i = 0; i < 10; i++)
+ {
+ int *ret = NULL;
+ CHECK_NOT_NULL(ret = c_heap_get_root(h));
+ OK(*ret == i);
+ }
+
+ c_heap_destroy(h);
+ return (0);
+}
+
+int main (void)
+{
+ RUN_TEST(simple);
+
+ END_TEST;
+}
+
+/* vim: set sw=2 sts=2 et : */
--- /dev/null
+/**
+ * collectd - src/utils_mount_test.c
+ *
+ * Copyright (C) 2013 Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Florian octo Forster <octo at collectd.org>
+ */
+
+#include "tests/macros.h"
+#include "collectd.h"
+#include "utils_mount.h"
+
+DEF_TEST(cu_mount_checkoption)
+{
+ char line_opts[] = "foo=one,bar=two,qux=three";
+ char *foo = strstr (line_opts, "foo");
+ char *bar = strstr (line_opts, "bar");
+ char *qux = strstr (line_opts, "qux");
+
+ char line_bool[] = "one,two,three";
+ char *one = strstr (line_bool, "one");
+ char *two = strstr (line_bool, "two");
+ char *three = strstr (line_bool, "three");
+
+ /* Normal operation */
+ OK (foo == cu_mount_checkoption (line_opts, "foo", 0));
+ OK (bar == cu_mount_checkoption (line_opts, "bar", 0));
+ OK (qux == cu_mount_checkoption (line_opts, "qux", 0));
+ OK (NULL == cu_mount_checkoption (line_opts, "unknown", 0));
+
+ OK (one == cu_mount_checkoption (line_bool, "one", 0));
+ OK (two == cu_mount_checkoption (line_bool, "two", 0));
+ OK (three == cu_mount_checkoption (line_bool, "three", 0));
+ OK (NULL == cu_mount_checkoption (line_bool, "four", 0));
+
+ /* Shorter and longer parts */
+ OK (foo == cu_mount_checkoption (line_opts, "fo", 0));
+ OK (bar == cu_mount_checkoption (line_opts, "bar=", 0));
+ OK (qux == cu_mount_checkoption (line_opts, "qux=thr", 0));
+
+ OK (one == cu_mount_checkoption (line_bool, "o", 0));
+ OK (two == cu_mount_checkoption (line_bool, "tw", 0));
+ OK (three == cu_mount_checkoption (line_bool, "thr", 0));
+
+ /* "full" flag */
+ OK (one == cu_mount_checkoption (line_bool, "one", 1));
+ OK (two == cu_mount_checkoption (line_bool, "two", 1));
+ OK (three == cu_mount_checkoption (line_bool, "three", 1));
+ OK (NULL == cu_mount_checkoption (line_bool, "four", 1));
+
+ OK (NULL == cu_mount_checkoption (line_bool, "o", 1));
+ OK (NULL == cu_mount_checkoption (line_bool, "tw", 1));
+ OK (NULL == cu_mount_checkoption (line_bool, "thr", 1));
+
+ return (0);
+}
+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="));
+ 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"));
+ OK (NULL == cu_mount_getoptionvalue (line_bool, "four"));
+
+ return (0);
+}
+
+int main (void)
+{
+ RUN_TEST(cu_mount_checkoption);
+ RUN_TEST(cu_mount_getoptionvalue);
+
+ END_TEST;
+}
+
+/* vim: set sw=2 sts=2 et : */
--- /dev/null
+/**
+ * collectd - src/utils_vl_lookup_test.c
+ * Copyright (C) 2012 Florian Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Florian Forster <octo at collectd.org>
+ **/
+
+#include "tests/macros.h"
+#include "collectd.h"
+#include "utils_vl_lookup.h"
+
+static _Bool expect_new_obj = 0;
+static _Bool have_new_obj = 0;
+
+static identifier_t last_class_ident;
+static identifier_t last_obj_ident;
+
+static data_source_t dsrc_test = { "value", DS_TYPE_DERIVE, 0.0, NAN };
+static data_set_t const ds_test = { "test", 1, &dsrc_test };
+
+static data_source_t dsrc_unknown = { "value", DS_TYPE_DERIVE, 0.0, NAN };
+static data_set_t const ds_unknown = { "unknown", 1, &dsrc_unknown };
+
+static int lookup_obj_callback (data_set_t const *ds,
+ value_list_t const *vl,
+ void *user_class, void *user_obj)
+{
+ identifier_t *class = user_class;
+ identifier_t *obj = user_obj;
+
+ OK1(expect_new_obj == have_new_obj,
+ (expect_new_obj ? "New obj is created." : "Updating existing obj."));
+
+ memcpy (&last_class_ident, class, sizeof (last_class_ident));
+ memcpy (&last_obj_ident, obj, sizeof (last_obj_ident));
+
+ if (strcmp (obj->plugin_instance, "failure") == 0)
+ return (-1);
+
+ return (0);
+}
+
+static void *lookup_class_callback (data_set_t const *ds,
+ value_list_t const *vl, void *user_class)
+{
+ identifier_t *class = user_class;
+ identifier_t *obj;
+
+ OK(expect_new_obj);
+
+ memcpy (&last_class_ident, class, sizeof (last_class_ident));
+
+ obj = malloc (sizeof (*obj));
+ strncpy (obj->host, vl->host, sizeof (obj->host));
+ strncpy (obj->plugin, vl->plugin, sizeof (obj->plugin));
+ strncpy (obj->plugin_instance, vl->plugin_instance, sizeof (obj->plugin_instance));
+ strncpy (obj->type, vl->type, sizeof (obj->type));
+ strncpy (obj->type_instance, vl->type_instance, sizeof (obj->type_instance));
+
+ have_new_obj = 1;
+
+ return ((void *) obj);
+}
+
+static void checked_lookup_add (lookup_t *obj, /* {{{ */
+ char const *host,
+ char const *plugin, char const *plugin_instance,
+ char const *type, char const *type_instance,
+ unsigned int group_by)
+{
+ identifier_t ident;
+ void *user_class;
+
+ memset (&ident, 0, sizeof (ident));
+ strncpy (ident.host, host, sizeof (ident.host));
+ strncpy (ident.plugin, plugin, sizeof (ident.plugin));
+ strncpy (ident.plugin_instance, plugin_instance, sizeof (ident.plugin_instance));
+ strncpy (ident.type, type, sizeof (ident.type));
+ strncpy (ident.type_instance, type_instance, sizeof (ident.type_instance));
+
+ user_class = malloc (sizeof (ident));
+ memmove (user_class, &ident, sizeof (ident));
+
+ OK(lookup_add (obj, &ident, group_by, user_class) == 0);
+} /* }}} void test_add */
+
+static int checked_lookup_search (lookup_t *obj,
+ char const *host,
+ char const *plugin, char const *plugin_instance,
+ char const *type, char const *type_instance,
+ _Bool expect_new)
+{
+ int status;
+ value_list_t vl = VALUE_LIST_STATIC;
+ data_set_t const *ds = &ds_unknown;
+
+ strncpy (vl.host, host, sizeof (vl.host));
+ strncpy (vl.plugin, plugin, sizeof (vl.plugin));
+ strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
+ strncpy (vl.type, type, sizeof (vl.type));
+ strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+
+ if (strcmp (vl.type, "test") == 0)
+ ds = &ds_test;
+
+ expect_new_obj = expect_new;
+ have_new_obj = 0;
+
+ status = lookup_search (obj, ds, &vl);
+ return (status);
+}
+
+static lookup_t *checked_lookup_create (void)
+{
+ lookup_t *obj = lookup_create (
+ lookup_class_callback,
+ lookup_obj_callback,
+ (void *) free,
+ (void *) free);
+ OK(obj != NULL);
+ return (obj);
+}
+
+DEF_TEST(group_by_specific_host)
+{
+ lookup_t *obj = checked_lookup_create ();
+
+ checked_lookup_add (obj, "/.*/", "test", "", "test", "/.*/", LU_GROUP_BY_HOST);
+ checked_lookup_search (obj, "host0", "test", "", "test", "0",
+ /* expect new = */ 1);
+ checked_lookup_search (obj, "host0", "test", "", "test", "1",
+ /* expect new = */ 0);
+ checked_lookup_search (obj, "host1", "test", "", "test", "0",
+ /* expect new = */ 1);
+ checked_lookup_search (obj, "host1", "test", "", "test", "1",
+ /* expect new = */ 0);
+
+ lookup_destroy (obj);
+ return (0);
+}
+
+DEF_TEST(group_by_any_host)
+{
+ lookup_t *obj = checked_lookup_create ();
+
+ checked_lookup_add (obj, "/.*/", "/.*/", "/.*/", "test", "/.*/", LU_GROUP_BY_HOST);
+ checked_lookup_search (obj, "host0", "plugin0", "", "test", "0",
+ /* expect new = */ 1);
+ checked_lookup_search (obj, "host0", "plugin0", "", "test", "1",
+ /* expect new = */ 0);
+ checked_lookup_search (obj, "host0", "plugin1", "", "test", "0",
+ /* expect new = */ 0);
+ checked_lookup_search (obj, "host0", "plugin1", "", "test", "1",
+ /* expect new = */ 0);
+ checked_lookup_search (obj, "host1", "plugin0", "", "test", "0",
+ /* expect new = */ 1);
+ checked_lookup_search (obj, "host1", "plugin0", "", "test", "1",
+ /* expect new = */ 0);
+ checked_lookup_search (obj, "host1", "plugin1", "", "test", "0",
+ /* expect new = */ 0);
+ checked_lookup_search (obj, "host1", "plugin1", "", "test", "1",
+ /* expect new = */ 0);
+
+ lookup_destroy (obj);
+ return (0);
+}
+
+DEF_TEST(multiple_lookups)
+{
+ lookup_t *obj = checked_lookup_create ();
+ int status;
+
+ checked_lookup_add (obj, "/.*/", "plugin0", "", "test", "/.*/", LU_GROUP_BY_HOST);
+ checked_lookup_add (obj, "/.*/", "/.*/", "", "test", "ti0", LU_GROUP_BY_HOST);
+
+ status = checked_lookup_search (obj, "host0", "plugin1", "", "test", "",
+ /* expect new = */ 0);
+ assert (status == 0);
+ status = checked_lookup_search (obj, "host0", "plugin0", "", "test", "",
+ /* expect new = */ 1);
+ assert (status == 1);
+ status = checked_lookup_search (obj, "host0", "plugin1", "", "test", "ti0",
+ /* expect new = */ 1);
+ assert (status == 1);
+ status = checked_lookup_search (obj, "host0", "plugin0", "", "test", "ti0",
+ /* expect new = */ 0);
+ assert (status == 2);
+
+ lookup_destroy (obj);
+ return (0);
+}
+
+DEF_TEST(regex)
+{
+ lookup_t *obj = checked_lookup_create ();
+
+ checked_lookup_add (obj, "/^db[0-9]\\./", "cpu", "/.*/", "cpu", "/.*/",
+ LU_GROUP_BY_TYPE_INSTANCE);
+ checked_lookup_search (obj, "db0.example.com", "cpu", "0", "cpu", "user",
+ /* expect new = */ 1);
+ checked_lookup_search (obj, "db0.example.com", "cpu", "0", "cpu", "idle",
+ /* expect new = */ 1);
+ checked_lookup_search (obj, "db0.example.com", "cpu", "1", "cpu", "user",
+ /* expect new = */ 0);
+ checked_lookup_search (obj, "db0.example.com", "cpu", "1", "cpu", "idle",
+ /* expect new = */ 0);
+ checked_lookup_search (obj, "app0.example.com", "cpu", "0", "cpu", "user",
+ /* expect new = */ 0);
+ checked_lookup_search (obj, "app0.example.com", "cpu", "0", "cpu", "idle",
+ /* expect new = */ 0);
+ checked_lookup_search (obj, "db1.example.com", "cpu", "0", "cpu", "user",
+ /* expect new = */ 0);
+ checked_lookup_search (obj, "db1.example.com", "cpu", "0", "cpu", "idle",
+ /* expect new = */ 0);
+ checked_lookup_search (obj, "db1.example.com", "cpu", "0", "cpu", "system",
+ /* expect new = */ 1);
+
+ lookup_destroy (obj);
+ return (0);
+}
+
+int main (int argc, char **argv) /* {{{ */
+{
+ RUN_TEST(group_by_specific_host);
+ RUN_TEST(group_by_any_host);
+ RUN_TEST(multiple_lookups);
+ RUN_TEST(regex);
+
+ END_TEST;
+} /* }}} int main */
": Value is no longer missing.");
else
status = ssnprintf (buf, bufsize,
- ": All data sources are within range again.");
+ ": All data sources are within range again. "
+ "Current value of \"%s\" is %f.",
+ ds->ds[ds_index].name, values[ds_index]);
buf += status;
bufsize -= status;
}
/* XXX: This is an experimental code, not optimized, not fast, not reliable,
* and probably, do not work as you expect. Enjoy! :D */
- if ( (th->hysteresis > 0) && ((prev_state = uc_get_state(ds,vl)) != STATE_OKAY) )
- {
- switch(prev_state)
+ if (th->hysteresis > 0)
+ {
+ prev_state = uc_get_state(ds,vl);
+ /* The purpose of hysteresis is elliminating flapping state when the value
+ * oscilates around the thresholds. In other words, what is important is
+ * the previous state; if the new value would trigger a transition, make
+ * sure that we artificially widen the range which is considered to apply
+ * for the previous state, and only trigger the notification if the value
+ * is outside of this expanded range.
+ *
+ * There is no hysteresis for the OKAY state.
+ * */
+ gauge_t hysteresis_for_warning = 0, hysteresis_for_failure = 0;
+ switch (prev_state)
{
case STATE_ERROR:
- if ( (!isnan (th->failure_min) && ((th->failure_min + th->hysteresis) < values[ds_index])) ||
- (!isnan (th->failure_max) && ((th->failure_max - th->hysteresis) > values[ds_index])) )
- return (STATE_OKAY);
- else
- is_failure++;
+ hysteresis_for_failure = th->hysteresis;
+ break;
case STATE_WARNING:
- if ( (!isnan (th->warning_min) && ((th->warning_min + th->hysteresis) < values[ds_index])) ||
- (!isnan (th->warning_max) && ((th->warning_max - th->hysteresis) > values[ds_index])) )
- return (STATE_OKAY);
- else
- is_warning++;
- }
+ hysteresis_for_warning = th->hysteresis;
+ break;
+ case STATE_OKAY:
+ /* do nothing -- the hysteresis only applies to the non-normal states */
+ break;
+ }
+
+ if ((!isnan (th->failure_min) && (th->failure_min + hysteresis_for_failure > values[ds_index]))
+ || (!isnan (th->failure_max) && (th->failure_max - hysteresis_for_failure < values[ds_index])))
+ is_failure++;
+
+ if ((!isnan (th->warning_min) && (th->warning_min + hysteresis_for_warning > values[ds_index]))
+ || (!isnan (th->warning_max) && (th->warning_max - hysteresis_for_warning < values[ds_index])))
+ is_warning++;
+
}
else { /* no hysteresis */
if ((!isnan (th->failure_min) && (th->failure_min > values[ds_index]))
if ((!isnan (th->warning_min) && (th->warning_min > values[ds_index]))
|| (!isnan (th->warning_max) && (th->warning_max < values[ds_index])))
is_warning++;
- }
+ }
if (is_failure != 0)
return (STATE_ERROR);
gauge_t uptime;
time_t elapsed;
- /* calculate the ammount of time elapsed since boot, AKA uptime */
+ /* calculate the amount of time elapsed since boot, AKA uptime */
elapsed = time (NULL) - boottime;
uptime = (gauge_t) elapsed;
pthread_mutex_lock (&h->lock);
- /* TODO: Checking this everytime may be a bit much..? */
+ /* TODO: Checking this every time may be a bit much..? */
fbh_check_file (h);
status = c_avl_get (h->tree, key, (void *) &value);
DESCRIPTION
The cu_mount_checkoption() function is a replacement of
char *hasmntopt(const struct mntent *mnt, const char *opt).
- In fact hasmntopt() just looks for the first occurence of the
+ In fact hasmntopt() just looks for the first occurrence of the
characters at opt in mnt->mnt_opts. cu_mount_checkoption()
checks for the *option* keyword in line, starting at the
first character of line or after a ','.
+++ /dev/null
-/**
- * collectd - src/utils_vl_lookup_test.c
- * Copyright (C) 2012 Florian Forster
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- * Florian Forster <octo at collectd.org>
- **/
-
-#include "collectd.h"
-#include "utils_vl_lookup.h"
-
-static _Bool expect_new_obj = 0;
-static _Bool have_new_obj = 0;
-
-static identifier_t last_class_ident;
-static identifier_t last_obj_ident;
-
-static data_source_t dsrc_test = { "value", DS_TYPE_DERIVE, 0.0, NAN };
-static data_set_t const ds_test = { "test", 1, &dsrc_test };
-
-static data_source_t dsrc_unknown = { "value", DS_TYPE_DERIVE, 0.0, NAN };
-static data_set_t const ds_unknown = { "unknown", 1, &dsrc_unknown };
-
-static int lookup_obj_callback (data_set_t const *ds,
- value_list_t const *vl,
- void *user_class, void *user_obj)
-{
- identifier_t *class = user_class;
- identifier_t *obj = user_obj;
-
- assert (expect_new_obj == have_new_obj);
-
- memcpy (&last_class_ident, class, sizeof (last_class_ident));
- memcpy (&last_obj_ident, obj, sizeof (last_obj_ident));
-
- if (strcmp (obj->plugin_instance, "failure") == 0)
- return (-1);
-
- return (0);
-}
-
-static void *lookup_class_callback (data_set_t const *ds,
- value_list_t const *vl, void *user_class)
-{
- identifier_t *class = user_class;
- identifier_t *obj;
-
- assert (expect_new_obj);
-
- memcpy (&last_class_ident, class, sizeof (last_class_ident));
-
- obj = malloc (sizeof (*obj));
- strncpy (obj->host, vl->host, sizeof (obj->host));
- strncpy (obj->plugin, vl->plugin, sizeof (obj->plugin));
- strncpy (obj->plugin_instance, vl->plugin_instance, sizeof (obj->plugin_instance));
- strncpy (obj->type, vl->type, sizeof (obj->type));
- strncpy (obj->type_instance, vl->type_instance, sizeof (obj->type_instance));
-
- have_new_obj = 1;
-
- return ((void *) obj);
-}
-
-static void checked_lookup_add (lookup_t *obj, /* {{{ */
- char const *host,
- char const *plugin, char const *plugin_instance,
- char const *type, char const *type_instance,
- unsigned int group_by)
-{
- identifier_t ident;
- void *user_class;
- int status;
-
- memset (&ident, 0, sizeof (ident));
- strncpy (ident.host, host, sizeof (ident.host));
- strncpy (ident.plugin, plugin, sizeof (ident.plugin));
- strncpy (ident.plugin_instance, plugin_instance, sizeof (ident.plugin_instance));
- strncpy (ident.type, type, sizeof (ident.type));
- strncpy (ident.type_instance, type_instance, sizeof (ident.type_instance));
-
- user_class = malloc (sizeof (ident));
- memmove (user_class, &ident, sizeof (ident));
-
- status = lookup_add (obj, &ident, group_by, user_class);
- assert (status == 0);
-} /* }}} void test_add */
-
-static int checked_lookup_search (lookup_t *obj,
- char const *host,
- char const *plugin, char const *plugin_instance,
- char const *type, char const *type_instance,
- _Bool expect_new)
-{
- int status;
- value_list_t vl = VALUE_LIST_STATIC;
- data_set_t const *ds = &ds_unknown;
-
- strncpy (vl.host, host, sizeof (vl.host));
- strncpy (vl.plugin, plugin, sizeof (vl.plugin));
- strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
- strncpy (vl.type, type, sizeof (vl.type));
- strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
-
- if (strcmp (vl.type, "test") == 0)
- ds = &ds_test;
-
- expect_new_obj = expect_new;
- have_new_obj = 0;
-
- status = lookup_search (obj, ds, &vl);
- return (status);
-}
-
-static lookup_t *checked_lookup_create (void)
-{
- lookup_t *obj = lookup_create (
- lookup_class_callback,
- lookup_obj_callback,
- (void *) free,
- (void *) free);
- assert (obj != NULL);
- return (obj);
-}
-
-static void testcase0 (void)
-{
- lookup_t *obj = checked_lookup_create ();
-
- checked_lookup_add (obj, "/.*/", "test", "", "test", "/.*/", LU_GROUP_BY_HOST);
- checked_lookup_search (obj, "host0", "test", "", "test", "0",
- /* expect new = */ 1);
- checked_lookup_search (obj, "host0", "test", "", "test", "1",
- /* expect new = */ 0);
- checked_lookup_search (obj, "host1", "test", "", "test", "0",
- /* expect new = */ 1);
- checked_lookup_search (obj, "host1", "test", "", "test", "1",
- /* expect new = */ 0);
-
- lookup_destroy (obj);
-}
-
-static void testcase1 (void)
-{
- lookup_t *obj = checked_lookup_create ();
-
- checked_lookup_add (obj, "/.*/", "/.*/", "/.*/", "test", "/.*/", LU_GROUP_BY_HOST);
- checked_lookup_search (obj, "host0", "plugin0", "", "test", "0",
- /* expect new = */ 1);
- checked_lookup_search (obj, "host0", "plugin0", "", "test", "1",
- /* expect new = */ 0);
- checked_lookup_search (obj, "host0", "plugin1", "", "test", "0",
- /* expect new = */ 0);
- checked_lookup_search (obj, "host0", "plugin1", "", "test", "1",
- /* expect new = */ 0);
- checked_lookup_search (obj, "host1", "plugin0", "", "test", "0",
- /* expect new = */ 1);
- checked_lookup_search (obj, "host1", "plugin0", "", "test", "1",
- /* expect new = */ 0);
- checked_lookup_search (obj, "host1", "plugin1", "", "test", "0",
- /* expect new = */ 0);
- checked_lookup_search (obj, "host1", "plugin1", "", "test", "1",
- /* expect new = */ 0);
-
- lookup_destroy (obj);
-}
-
-static void testcase2 (void)
-{
- lookup_t *obj = checked_lookup_create ();
- int status;
-
- checked_lookup_add (obj, "/.*/", "plugin0", "", "test", "/.*/", LU_GROUP_BY_HOST);
- checked_lookup_add (obj, "/.*/", "/.*/", "", "test", "ti0", LU_GROUP_BY_HOST);
-
- status = checked_lookup_search (obj, "host0", "plugin1", "", "test", "",
- /* expect new = */ 0);
- assert (status == 0);
- status = checked_lookup_search (obj, "host0", "plugin0", "", "test", "",
- /* expect new = */ 1);
- assert (status == 1);
- status = checked_lookup_search (obj, "host0", "plugin1", "", "test", "ti0",
- /* expect new = */ 1);
- assert (status == 1);
- status = checked_lookup_search (obj, "host0", "plugin0", "", "test", "ti0",
- /* expect new = */ 0);
- assert (status == 2);
-
- lookup_destroy (obj);
-}
-
-static void testcase3 (void)
-{
- lookup_t *obj = checked_lookup_create ();
-
- checked_lookup_add (obj, "/^db[0-9]\\./", "cpu", "/.*/", "cpu", "/.*/",
- LU_GROUP_BY_TYPE_INSTANCE);
- checked_lookup_search (obj, "db0.example.com", "cpu", "0", "cpu", "user",
- /* expect new = */ 1);
- checked_lookup_search (obj, "db0.example.com", "cpu", "0", "cpu", "idle",
- /* expect new = */ 1);
- checked_lookup_search (obj, "db0.example.com", "cpu", "1", "cpu", "user",
- /* expect new = */ 0);
- checked_lookup_search (obj, "db0.example.com", "cpu", "1", "cpu", "idle",
- /* expect new = */ 0);
- checked_lookup_search (obj, "app0.example.com", "cpu", "0", "cpu", "user",
- /* expect new = */ 0);
- checked_lookup_search (obj, "app0.example.com", "cpu", "0", "cpu", "idle",
- /* expect new = */ 0);
- checked_lookup_search (obj, "db1.example.com", "cpu", "0", "cpu", "user",
- /* expect new = */ 0);
- checked_lookup_search (obj, "db1.example.com", "cpu", "0", "cpu", "idle",
- /* expect new = */ 0);
- checked_lookup_search (obj, "db1.example.com", "cpu", "0", "cpu", "system",
- /* expect new = */ 1);
-
- lookup_destroy (obj);
-}
-
-int main (int argc, char **argv) /* {{{ */
-{
- testcase0 ();
- testcase1 ();
- testcase2 ();
- testcase3 ();
- return (EXIT_SUCCESS);
-} /* }}} int main */
}
host->flags |= F_CONNECT;
- DEBUG("write_riemann plugin: got a succesful connection for: %s:%s",
+ DEBUG("write_riemann plugin: got a successful connection for: %s:%s",
node, service);
break;
}