]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
Build system: Build tested units as libraries.
authorFlorian Forster <octo@collectd.org>
Tue, 26 May 2015 06:52:39 +0000 (08:52 +0200)
committerFlorian Forster <octo@collectd.org>
Tue, 26 May 2015 18:41:31 +0000 (20:41 +0200)
This simplifies the build rules for the tests, aka. check programs.

* test_foo.c have been renamed to foo_test.c.
* foo_test.c now reside right next to foo.c and foo.h.
* Build and refer to .la files, rather than depending on .c files from
  other directories.

Fixes: #1042
13 files changed:
src/Makefile.am
src/daemon/Makefile.am
src/daemon/common_test.c [moved from src/tests/common_test.c with 98% similarity]
src/daemon/plugin_mock.c [moved from src/tests/mock/plugin.c with 100% similarity]
src/daemon/utils_avltree_test.c [moved from src/tests/test_utils_avltree.c with 98% similarity]
src/daemon/utils_cache_mock.c [moved from src/tests/mock/utils_cache.c with 100% similarity]
src/daemon/utils_heap_test.c [moved from src/tests/test_utils_heap.c with 98% similarity]
src/daemon/utils_time_mock.c [moved from src/tests/mock/utils_time.c with 100% similarity]
src/testing.h [moved from src/tests/macros.h with 100% similarity]
src/tests/test_common.c [deleted file]
src/utils_mount.c
src/utils_mount_test.c [moved from src/tests/test_utils_mount.c with 99% similarity]
src/utils_vl_lookup_test.c [moved from src/tests/test_utils_vl_lookup.c with 99% similarity]

index 08b8d52564322b1dfdcbfe79e4949495dfbaf44d..37d9216f8a5eb2382cb49c0213f0f63489175962 100644 (file)
@@ -23,6 +23,14 @@ AM_CPPFLAGS += -DPKGDATADIR='"${pkgdatadir}"'
 
 AUTOMAKE_OPTIONS = subdir-objects
 
+noinst_LTLIBRARIES = libmount.la liblookup.la
+
+libmount_la_SOURCES = utils_mount.c utils_mount.h
+libmount_la_LIBADD = daemon/libcommon.la
+
+liblookup_la_SOURCES = utils_vl_lookup.c utils_vl_lookup.h
+liblookup_la_LIBADD = daemon/libavltree.la daemon/libcommon.la
+
 sbin_PROGRAMS = collectdmon
 bin_PROGRAMS = collectd-nagios collectdctl collectd-tg
 
@@ -55,10 +63,9 @@ endif
 collectdctl_LDADD += libcollectdclient/libcollectdclient.la
 collectdctl_DEPENDENCIES = libcollectdclient/libcollectdclient.la
 
-collectd_tg_SOURCES = collectd-tg.c \
-                     daemon/utils_heap.c daemon/utils_heap.h
+collectd_tg_SOURCES = collectd-tg.c
 collectd_tg_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/src/libcollectdclient/collectd -I$(top_builddir)/src/libcollectdclient/collectd
-collectd_tg_LDADD =
+collectd_tg_LDADD = daemon/libheap.a
 if BUILD_WITH_LIBSOCKET
 collectd_tg_LDADD += -lsocket
 endif
@@ -183,9 +190,9 @@ endif
 if BUILD_PLUGIN_CGROUPS
 pkglib_LTLIBRARIES += cgroups.la
 cgroups_la_SOURCES = cgroups.c \
-                    utils_ignorelist.c utils_ignorelist.h \
-                    utils_mount.c utils_mount.h
+                    utils_ignorelist.c utils_ignorelist.h
 cgroups_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+cgroups_la_LIBADD = libmount.la
 endif
 
 if BUILD_PLUGIN_CONNTRACK
@@ -283,9 +290,9 @@ endif
 if BUILD_PLUGIN_DF
 pkglib_LTLIBRARIES += df.la
 df_la_SOURCES = df.c \
-               utils_ignorelist.c utils_ignorelist.h \
-               utils_mount.c utils_mount.h
+               utils_ignorelist.c utils_ignorelist.h
 df_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+df_la_LIBADD = libmount.la
 endif
 
 if BUILD_PLUGIN_DISK
@@ -1373,49 +1380,12 @@ uninstall-hook:
        rm -f $(DESTDIR)$(sysconfdir)/collectd.conf
        rm -f $(DESTDIR)$(pkgdatadir)/postgresql_default.conf;
 
-check_PROGRAMS = test_common test_utils_avltree test_utils_heap test_utils_mount test_utils_vl_lookup
-
-test_common_SOURCES = tests/test_common.c \
-                      daemon/common.h daemon/common.c \
-                      tests/macros.h \
-                      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 \
-                             daemon/utils_avltree.c daemon/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 \
-                          daemon/utils_heap.c daemon/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 \
-                           daemon/common.c daemon/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 \
-                               daemon/utils_avltree.c daemon/utils_avltree.h \
-                               daemon/common.c daemon/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
+check_PROGRAMS = test_utils_mount test_utils_vl_lookup
+
+test_utils_mount_SOURCES = utils_mount_test.c
+test_utils_mount_LDADD = libmount.la daemon/libplugin_mock.la
+
+test_utils_vl_lookup_SOURCES = utils_vl_lookup_test.c
+test_utils_vl_lookup_LDADD = liblookup.la daemon/libplugin_mock.la
+
+TESTS = test_utils_mount test_utils_vl_lookup
index fc8155437807f7f34a3ba103c7dd4179300ad391..06bc150f3282a745a93313885322afec8f0bd622 100644 (file)
@@ -17,16 +17,23 @@ AUTOMAKE_OPTIONS = subdir-objects
 
 sbin_PROGRAMS = collectd
 
+noinst_LTLIBRARIES = libavltree.la libcommon.la libheap.la libplugin_mock.la
+
+libavltree_la_SOURCES = utils_avltree.c utils_avltree.h
+
+libcommon_la_SOURCES = common.c common.h
+
+libheap_la_SOURCES = utils_heap.c utils_heap.h
+
+libplugin_mock_la_SOURCES = plugin_mock.c utils_cache_mock.c utils_time_mock.c
+
 collectd_SOURCES = collectd.c collectd.h \
-                  common.c common.h \
                   configfile.c configfile.h \
                   filter_chain.c filter_chain.h \
                   meta_data.c meta_data.h \
                   plugin.c plugin.h \
-                  utils_avltree.c utils_avltree.h \
                   utils_cache.c utils_cache.h \
                   utils_complain.c utils_complain.h \
-                  utils_heap.c utils_heap.h \
                   utils_llist.c utils_llist.h \
                   utils_random.c utils_random.h \
                   utils_tail_match.c utils_tail_match.h \
@@ -41,7 +48,7 @@ collectd_SOURCES = collectd.c collectd.h \
 collectd_CPPFLAGS =  $(AM_CPPFLAGS) $(LTDLINCL)
 collectd_CFLAGS = $(AM_CFLAGS)
 collectd_LDFLAGS = -export-dynamic
-collectd_LDADD = -lm
+collectd_LDADD = libavltree.la libcommon.la libheap.la -lm
 collectd_DEPENDENCIES =
 
 # Link to these libraries..
@@ -83,3 +90,15 @@ collectd_DEPENDENCIES += $(top_builddir)/src/liboconfig/liboconfig.la
 else
 collectd_LDADD += -loconfig
 endif
+
+check_PROGRAMS = test_common test_utils_avltree test_utils_heap
+TESTS = test_common test_utils_avltree test_utils_heap
+
+test_common_SOURCES = common_test.c
+test_common_LDADD = libcommon.la libplugin_mock.la
+
+test_utils_avltree_SOURCES = utils_avltree_test.c
+test_utils_avltree_LDADD = libavltree.la
+
+test_utils_heap_SOURCES = utils_heap_test.c
+test_utils_heap_LDADD = libheap.la
similarity index 98%
rename from src/tests/common_test.c
rename to src/daemon/common_test.c
index f65fcab31e0b4fe9edaf14b5c522237736c951af..1fa8f324461293c201b30440a8bb3e857062a993 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * collectd - src/tests/common_test.c
+ * collectd - src/tests/test_common.c
  * Copyright (C) 2013       Florian octo Forster
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -24,7 +24,7 @@
  *   Florian octo Forster <octo at collectd.org>
  */
 
-#include "tests/macros.h"
+#include "testing.h"
 #include "common.h"
 
 DEF_TEST(sstrncpy)
similarity index 98%
rename from src/tests/test_utils_avltree.c
rename to src/daemon/utils_avltree_test.c
index 00d14e1615c597adedb6f9144dadf90a0eab3b9c..2a8244c9f3e6cd1008649091de98b595ebf386f6 100644 (file)
@@ -24,7 +24,7 @@
  *   Florian octo Forster <octo at collectd.org>
  */
 
-#include "tests/macros.h"
+#include "testing.h"
 #include "collectd.h"
 #include "utils_avltree.h"
 
similarity index 98%
rename from src/tests/test_utils_heap.c
rename to src/daemon/utils_heap_test.c
index 91c90e5d4f9631c220ebf569ff7399e99c352709..53d0fba863f3b7cb6a117e5224107d9dc98cfb8c 100644 (file)
@@ -24,8 +24,8 @@
  *   Florian octo Forster <octo at collectd.org>
  */
 
+#include "testing.h"
 #include "collectd.h"
-#include "tests/macros.h"
 #include "utils_heap.h"
 
 static int compare (void const *v0, void const *v1)
similarity index 100%
rename from src/tests/macros.h
rename to src/testing.h
diff --git a/src/tests/test_common.c b/src/tests/test_common.c
deleted file mode 100644 (file)
index c2eec95..0000000
+++ /dev/null
@@ -1,246 +0,0 @@
-/**
- * collectd - src/tests/test_common.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 : */
index 3cede018e243067d5f1bcfb71d5f9e76949b074e..b63a81ad29b44fe13c113ca8843a7abb701bcfbf 100644 (file)
  *   Niki W. Waibel <niki.waibel@gmx.net>
 **/
 
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "collectd.h"
+#include "utils_mount.h"
+
+#include "common.h" /* sstrncpy() et alii */
+#include "plugin.h" /* ERROR() macro */
 
-#include "common.h"
 #if HAVE_XFS_XQM_H
 # include <xfs/xqm.h>
 #define XFS_SUPER_MAGIC_STR "XFSB"
 #define XFS_SUPER_MAGIC2_STR "BSFX"
 #endif
 
-#include "plugin.h"
-#include "utils_mount.h"
-
 #if HAVE_GETVFSSTAT
 #  if HAVE_SYS_TYPES_H
 #    include <sys/types.h>
similarity index 99%
rename from src/tests/test_utils_mount.c
rename to src/utils_mount_test.c
index ba6b99bb87343ff8e5d1074b955b4c544d40e3b2..c5ffbfbcf9fb9d701db96f02aafa1cc9873b4790 100644 (file)
@@ -24,7 +24,7 @@
  *   Florian octo Forster <octo at collectd.org>
  */
 
-#include "tests/macros.h"
+#include "testing.h"
 #include "collectd.h"
 #include "utils_mount.h"
 
similarity index 99%
rename from src/tests/test_utils_vl_lookup.c
rename to src/utils_vl_lookup_test.c
index 842f3fd355202229b198fc783abe05a86d2ca218..6a2676a89e1d8ccee1cddc6735d2f5e7d9335ff7 100644 (file)
@@ -24,7 +24,7 @@
  *   Florian Forster <octo at collectd.org>
  **/
 
-#include "tests/macros.h"
+#include "testing.h"
 #include "collectd.h"
 #include "utils_vl_lookup.h"