From 10782d6bbac98487896cb211119c6927244f0efd Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Wed, 11 Dec 2024 13:43:13 +0100 Subject: [PATCH 1/3] Removed files from libutils & libpromises in libtest sources The `libtest` library should not really have any sources from CFEngine libraries, as it can cause duplicate definitions of symbols when a test binary links against any of these libraries. Furthermore, `libtest` did not really need any of these sources, other than `alloc.c`. Additionally I removed the `alloc.c` dependency of libtest. And I made `file_read_string()` into static function, as it is not used other places than `test.c`. Ticket: CFE-4471 Changelog: None Signed-off-by: Lars Erik Wik --- tests/unit/Makefile.am | 15 +++++---------- tests/unit/test.c | 10 +++++++--- tests/unit/test.h | 2 -- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index 26c3b4c28c..00a20b97c7 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -52,15 +52,7 @@ AM_CFLAGS = $(PTHREAD_CFLAGS) check_LTLIBRARIES = libtest.la -libtest_la_SOURCES = cmockery.c cmockery.h schema.h test.c test.h \ - ../../libntech/libutils/alloc.c \ - ../../libpromises/patches.c \ - ../../libpromises/constants.c \ - ../../libntech/libutils/known_dirs.c \ - ../../libntech/libutils/map.c \ - ../../libntech/libutils/array_map.c \ - ../../libntech/libutils/hash.c \ - ../../libntech/libutils/hash_map.c +libtest_la_SOURCES = cmockery.c cmockery.h schema.h test.c test.h libtest_la_LIBADD = ../../libntech/libcompat/libcompat.la @@ -303,7 +295,10 @@ files_copy_test_LDADD = libtest.la ../../libpromises/libpromises.la sort_test_SOURCES = sort_test.c sort_test_LDADD = libtest.la ../../libpromises/libpromises.la -logging_test_SOURCES = logging_test.c ../../libpromises/syslog_client.c +logging_test_SOURCES = logging_test.c \ + ../../libpromises/syslog_client.c \ + ../../libpromises/patches.c \ + ../../libpromises/constants.c logging_test_LDADD = libtest.la ../../libntech/libutils/libutils.la connection_management_test_SOURCES = connection_management_test.c \ diff --git a/tests/unit/test.c b/tests/unit/test.c index abea779971..ab41a05b7e 100644 --- a/tests/unit/test.c +++ b/tests/unit/test.c @@ -3,9 +3,8 @@ #include #include #include -#include -char *file_read_string(FILE *in) +static char *file_read_string(FILE *in) { fpos_t pos; long size; @@ -19,7 +18,12 @@ char *file_read_string(FILE *in) assert_int_equal(fseek(in, 0, SEEK_SET), 0); - buffer = xcalloc(size + 1L, sizeof(char)); + buffer = calloc(size + 1L, sizeof(char)); + if (buffer == NULL) + { + fputs("CRITICAL: Unable to allocate memory\n", stderr); + exit(255); + } assert_int_equal(fread(buffer, 1, size, in), size); assert_int_equal(fsetpos(in, &pos), 0); diff --git a/tests/unit/test.h b/tests/unit/test.h index 7533cedb95..a98e77b409 100644 --- a/tests/unit/test.h +++ b/tests/unit/test.h @@ -24,8 +24,6 @@ printf("==================================================\n") -char *file_read_string(FILE *in); - void assert_file_equal(FILE *a, FILE *b); #define assert_double_close(a, b) _assert_double_close(a, b, __FILE__, __LINE__) From f852c14b494165f84d3eeed54deeaed919a54847 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Wed, 11 Dec 2024 14:22:02 +0100 Subject: [PATCH 2/3] Removed libstr from tests/unit/Makefile.am The library was probably made as a convenience library. However, when linking with `libstr` and other CFEngine libraries, or when including sources from these libraries, we can quickly run into many problems. Problems like, objects 'created with both libtool and without'. Or duplicate symbol definitions. It's better to either include with just the sources we need, or to only link with the CFEngine libraries when creating test binaries. Ticket: CFE-4471 Changelog: None Signed-off-by: Lars Erik Wik --- tests/unit/Makefile.am | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index 00a20b97c7..c65dbf610c 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -56,18 +56,6 @@ libtest_la_SOURCES = cmockery.c cmockery.h schema.h test.c test.h libtest_la_LIBADD = ../../libntech/libcompat/libcompat.la -check_LTLIBRARIES += libstr.la -libstr_la_SOURCES = \ - ../../libntech/libutils/buffer.c \ - ../../libntech/libutils/encode.c \ - ../../libntech/libutils/logging.c \ - ../../libntech/libutils/misc_lib.c \ - ../../libntech/libutils/regex.c \ - ../../libntech/libutils/sequence.c \ - ../../libntech/libutils/string_lib.c \ - ../../libntech/libutils/writer.c -libstr_la_LIBADD = libtest.la - check_LTLIBRARIES += libdb.la libdb_la_SOURCES = db_stubs.c \ @@ -91,7 +79,7 @@ libdb_la_SOURCES = db_stubs.c \ if HPUX libdb_la_SOURCES += ../../libpromises/cf3globals.c endif -libdb_la_LIBADD = libstr.la ../../libntech/libutils/libutils.la +libdb_la_LIBADD = ../../libntech/libutils/libutils.la #libdb_la_CPPFLAGS = $(LMDB_CPPFLAGS) $(TOKYOCABINET_CPPFLAGS) $(QDBM_CPPFLAGS) # Make sure that source files are compiled to separate object files # libdb_la-file.o @@ -214,10 +202,9 @@ EXTRA_enterprise_extension_test_DEPENDENCIES = cfengine-enterprise.la endif set_domainname_test_SOURCES = set_domainname_test.c -set_domainname_test_LDADD = libstr.la ../../libpromises/libpromises.la +set_domainname_test_LDADD = libtest.la ../../libpromises/libpromises.la str_test_SOURCES = str_test.c -str_test_LDADD = libstr.la regex_test_SOURCES = regex_test.c ../../libpromises/match_scope.c @@ -258,14 +245,14 @@ db_test_LDADD = libtest.la ../../libpromises/libpromises.la db_concurrent_test_SOURCES = db_concurrent_test.c #db_concurrent_test_CPPFLAGS = $(libdb_la_CPPFLAGS) -db_concurrent_test_LDADD = libdb.la +db_concurrent_test_LDADD = libtest.la libdb.la lastseen_test_SOURCES = lastseen_test.c \ ../../libpromises/item_lib.c \ ../../libpromises/lastseen.c \ ../../libntech/libutils/statistics.c #lastseen_test_CPPFLAGS = $(libdb_la_CPPFLAGS) -lastseen_test_LDADD = libdb.la ../../libpromises/libpromises.la +lastseen_test_LDADD = libtest.la libdb.la ../../libpromises/libpromises.la lastseen_migration_test_SOURCES = lastseen_migration_test.c \ ../../libpromises/lastseen.c \ From 18e8ce4e3ec1f557fd9624e2b8258932f4321d8d Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Wed, 11 Dec 2024 16:45:48 +0100 Subject: [PATCH 3/3] Removed unit test str_test Guess what... str_test.c does not exist. Ticket: CFE-4471 Changelog: None Signed-off-by: Lars Erik Wik --- tests/unit/Makefile.am | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index c65dbf610c..7bad06eca2 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -204,8 +204,6 @@ endif set_domainname_test_SOURCES = set_domainname_test.c set_domainname_test_LDADD = libtest.la ../../libpromises/libpromises.la -str_test_SOURCES = str_test.c - regex_test_SOURCES = regex_test.c ../../libpromises/match_scope.c protocol_test_SOURCES = protocol_test.c \