Skip to content

Commit

Permalink
Removed files from libutils & libpromises in libtest sources
Browse files Browse the repository at this point in the history
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 <lars.erik.wik@northern.tech>
  • Loading branch information
larsewi committed Dec 11, 2024
1 parent 871e87e commit 10782d6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
15 changes: 5 additions & 10 deletions tests/unit/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 \
Expand Down
10 changes: 7 additions & 3 deletions tests/unit/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <alloc.h>

char *file_read_string(FILE *in)
static char *file_read_string(FILE *in)
{
fpos_t pos;
long size;
Expand All @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down

0 comments on commit 10782d6

Please sign in to comment.