summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 349d153)
raw | patch | inline | side by side (parent: 349d153)
author | Florian Forster <octo@collectd.org> | |
Thu, 26 Nov 2015 09:33:07 +0000 (10:33 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Wed, 2 Dec 2015 09:21:52 +0000 (10:21 +0100) |
This allows us to test rfc3339() while mocking out cdtime().
src/Makefile.am | patch | blob | history | |
src/daemon/Makefile.am | patch | blob | history | |
src/daemon/utils_time.c | patch | blob | history | |
src/daemon/utils_time.h | patch | blob | history | |
src/daemon/utils_time_mock.c | [deleted file] | patch | blob | history |
src/testing.h | patch | blob | history |
diff --git a/src/Makefile.am b/src/Makefile.am
index d3b1acd35f8fca375d850b19e299a181e93aea14..6267a3108975765f52992fb194e9818acc1735c5 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
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
+test_utils_latency_LDADD = liblatency.la daemon/libplugin_mock.la -lm
noinst_LTLIBRARIES += liblookup.la
liblookup_la_SOURCES = utils_vl_lookup.c utils_vl_lookup.h
check_PROGRAMS += test_utils_vl_lookup
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
+test_utils_vl_lookup_LDADD = liblookup.la daemon/libplugin_mock.la
if BUILD_WITH_LIBKSTAT
test_utils_vl_lookup_LDADD += -lkstat
endif
check_PROGRAMS += test_utils_mount
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
+test_utils_mount_LDADD = libmount.la daemon/libplugin_mock.la
if BUILD_WITH_LIBKSTAT
test_utils_mount_LDADD += -lkstat
endif
diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am
index 3d50029bac73d6ea41a9124c9063e70cfca9f29d..cdd927bc7b859e037aeb5e1abf2c9596e4a5fae4 100644 (file)
--- a/src/daemon/Makefile.am
+++ b/src/daemon/Makefile.am
libmetadata_la_SOURCES = meta_data.c meta_data.h
-libplugin_mock_la_SOURCES = plugin_mock.c utils_cache_mock.c utils_time_mock.c
-libplugin_mock_la_LIBADD = $(COMMON_LIBS)
+libplugin_mock_la_SOURCES = plugin_mock.c utils_cache_mock.c \
+ utils_time.c utils_time.h
+libplugin_mock_la_CPPFLAGS = $(AM_CPPFLAGS) -DMOCK_TIME
+libplugin_mock_la_LIBADD = $(COMMON_LIBS) libcommon.la
collectd_SOURCES = collectd.c collectd.h \
configfile.c configfile.h \
TESTS = test_common test_meta_data test_utils_avltree test_utils_heap test_utils_time test_utils_subst
test_common_SOURCES = common_test.c ../testing.h
-test_common_LDADD = libcommon.la libplugin_mock.la
+test_common_LDADD = libplugin_mock.la
test_meta_data_SOURCES = meta_data_test.c ../testing.h
test_meta_data_LDADD = libmetadata.la libplugin_mock.la
test_utils_subst_SOURCES = utils_subst_test.c ../testing.h \
utils_subst.c utils_subst.h
-test_utils_subst_LDADD = libcommon.la libplugin_mock.la
+test_utils_subst_LDADD = libplugin_mock.la
index f500e138b0a0226144c7e5311ae9ae1c7c324c32..7f482da7fdcb5944e086723a6c0b17c83d7f429a 100644 (file)
--- a/src/daemon/utils_time.c
+++ b/src/daemon/utils_time.c
/**
* collectd - src/utils_time.c
- * Copyright (C) 2010 Florian octo Forster
+ * Copyright (C) 2010-2015 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"),
* DEALINGS IN THE SOFTWARE.
*
* Authors:
- * Florian octo Forster <ff at octo.it>
+ * Florian octo Forster <octo at collectd.org>
**/
#include "collectd.h"
#include "plugin.h"
#include "common.h"
-#if HAVE_CLOCK_GETTIME
+#ifndef DEFAULT_MOCK_TIME
+# define DEFAULT_MOCK_TIME 1542455354518929408ULL
+#endif
+
+#ifdef MOCK_TIME
+cdtime_t cdtime_mock = (cdtime_t) MOCK_TIME;
+
+cdtime_t cdtime (void)
+{
+ return cdtime_mock;
+}
+#else /* !MOCK_TIME */
+# if HAVE_CLOCK_GETTIME
cdtime_t cdtime (void) /* {{{ */
{
int status;
return (TIMESPEC_TO_CDTIME_T (&ts));
} /* }}} cdtime_t cdtime */
-#else
+# else /* !HAVE_CLOCK_GETTIME */
/* Work around for Mac OS X which doesn't have clock_gettime(2). *sigh* */
cdtime_t cdtime (void) /* {{{ */
{
return (TIMEVAL_TO_CDTIME_T (&tv));
} /* }}} cdtime_t cdtime */
+# endif
#endif
/* format_zone reads time zone information from "extern long timezone", exported
index 07e560afd373a8978c56b2691313c308d394355d..9e98040694eb8b57822653e6fc1df5296646a314 100644 (file)
--- a/src/daemon/utils_time.h
+++ b/src/daemon/utils_time.h
#include "collectd.h"
+#ifdef TESTING_H
+/* cdtime_mock is the time returned by cdtime() when build with
+ * -DMOCK_TIME */
+extern cdtime_t cdtime_mock;
+#endif
+
/*
* "cdtime_t" is a 64bit unsigned integer. The time is stored at a 2^-30 second
* resolution, i.e. the most significant 34 bit are used to store the time in
diff --git a/src/daemon/utils_time_mock.c b/src/daemon/utils_time_mock.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * collectd - src/tests/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 ((cdtime_t) 1542455354518929408ULL);
-}
-
diff --git a/src/testing.h b/src/testing.h
index 0c415e48909f96db0d8844e3f422cdd7325d86a1..c0a9e88ac09cd6c50f7631d281e5afd98a061670 100644 (file)
--- a/src/testing.h
+++ b/src/testing.h
* Florian octo Forster <octo at collectd.org>
*/
+#ifndef TESTING_H
+#define TESTING_H 1
+
#include <inttypes.h>
static int fail_count__ = 0;
status_ = (long) (expr); \
OK1(status_ == 0L, #expr); \
} while (0)
+
+#endif /* TESTING_H */