Skip to content

Commit

Permalink
Fixed ODR violations in ASAN Unit Tests
Browse files Browse the repository at this point in the history
Ticket: CFE-4454
Changelog: None
Signed-off-by: Lars Erik Wik <[email protected]>
  • Loading branch information
larsewi committed Dec 9, 2024
1 parent 1589aa3 commit 5831a46
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 28 deletions.
7 changes: 7 additions & 0 deletions libpromises/evalfunction.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
included file COSL.txt.
*/

#define CFENGINE_EVALFUNCTION_C /* To avoid one definition rule violations */

#include <platform.h>
#include <evalfunction.h>

Expand Down Expand Up @@ -10311,6 +10313,10 @@ static const FnCallArg DATATYPE_ARGS[] =

/* see fncall.h enum FnCallType */

/* The evalfunction_test.c unit test both includes this .c file and links with
* libpromises which causes the "one definition rule" to be violated when
* running ASAN Unit Tests unless we add this guard. */
#ifndef CFENGINE_EVALFUNCTION_TEST_C
const FnCallType CF_FNCALL_TYPES[] =
{
FnCallTypeNew("accessedbefore", CF_DATA_TYPE_CONTEXT, ACCESSEDBEFORE_ARGS, &FnCallIsAccessedBefore, "True if arg1 was accessed before arg2 (atime)",
Expand Down Expand Up @@ -10715,3 +10721,4 @@ const FnCallType CF_FNCALL_TYPES[] =

FnCallTypeNewNull()
};
#endif /* CFENGINE_EVALFUNCTION_TEST_C */
4 changes: 4 additions & 0 deletions libpromises/fncall.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ typedef struct
SyntaxStatus status;
} FnCallType;

/* Avoid one definition rule violations, because this file is included in
* evalfunction.c where this variable is defined. */
#ifndef CFENGINE_EVALFUNCTION_C
extern const FnCallType CF_FNCALL_TYPES[];
#endif /* CFENGINE_EVALFUNCTION_C */

bool FnCallIsBuiltIn(Rval rval);

Expand Down
19 changes: 2 additions & 17 deletions tests/unit/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,17 @@ libstr_la_LIBADD = libtest.la

check_LTLIBRARIES += libdb.la
libdb_la_SOURCES = db_stubs.c \
../../libpromises/dbm_api.c \
../../libpromises/dbm_quick.c \
../../libpromises/dbm_tokyocab.c \
../../libpromises/dbm_lmdb.c \
../../libpromises/dbm_migration.c \
../../libpromises/dbm_migration_lastseen.c \
../../libpromises/global_mutex.c \
../../cf-check/backup.c \
../../cf-check/diagnose.c \
../../cf-check/lmdump.c \
../../cf-check/repair.c \
../../cf-check/replicate_lmdb.c \
../../cf-check/utilities.c \
../../cf-check/validate.c \
../../libntech/libutils/logging.c \
../../libntech/libutils/mutex.c \
../../libntech/libutils/cleanup.c
if HPUX
libdb_la_SOURCES += ../../libpromises/cf3globals.c
endif
libdb_la_LIBADD = libstr.la ../../libntech/libutils/libutils.la
libdb_la_LIBADD = libstr.la ../../libntech/libutils/libutils.la ../../libpromises/libpromises.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
Expand Down Expand Up @@ -269,16 +259,12 @@ db_concurrent_test_SOURCES = db_concurrent_test.c
db_concurrent_test_LDADD = 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_migration_test_SOURCES = lastseen_migration_test.c \
../../libpromises/lastseen.c \
../../libntech/libutils/statistics.c \
../../libpromises/item_lib.c
../../libntech/libutils/statistics.c
#lastseen_migration_test_CPPFLAGS = $(libdb_la_CPPFLAGS)
lastseen_migration_test_LDADD = libdb.la ../../libpromises/libpromises.la

Expand Down Expand Up @@ -370,7 +356,6 @@ exec_config_test_SOURCES = exec-config-test.c \
exec_config_test_LDADD = libtest.la ../../libpromises/libpromises.la

sysinfo_test_LDADD = libtest.la \
../../libenv/libenv.la \
../../libpromises/libpromises.la

mon_cpu_test_SOURCES = mon_cpu_test.c \
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/evalfunction_test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <test.h>

#define CFENGINE_EVALFUNCTION_TEST_C

#include <eval_context.h>
#include <evalfunction.c>

Expand Down
4 changes: 0 additions & 4 deletions tests/unit/lastseen_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,7 @@ void FatalError(ARG_UNUSED char *s, ...)
exit(42);
}

HashMethod CF_DEFAULT_DIGEST;
pthread_mutex_t *cft_output;
char VIPADDRESS[CF_MAX_IP_LEN];
RSA *PUBKEY;
bool MINUSF;

char *HashPrintSafe(ARG_UNUSED char *dst, ARG_UNUSED size_t dst_size,
ARG_UNUSED const unsigned char *digest,
Expand Down
1 change: 0 additions & 1 deletion tests/unit/rlist_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,6 @@ const void *EvalContextVariableGet(const EvalContext *ctx, const VarRef *lval, D
fail();
}

pthread_mutex_t *cft_lock;
int __ThreadLock(pthread_mutex_t *name)
{
return true;
Expand Down
5 changes: 0 additions & 5 deletions tests/unit/set_domainname_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
#include <rlist.h>
#include <enterprise_extension.h>

/* Global variables we care about */

char VFQNAME[CF_MAXVARSIZE];
char VUQNAME[CF_MAXVARSIZE / 2];
char VDOMAIN[CF_MAXVARSIZE / 2];

static struct hostent h = {
.h_name = "laptop.intra.cfengine.com"
Expand Down
1 change: 0 additions & 1 deletion tests/unit/sysinfo_test.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <test.h>

#include <sysinfo.h>
#include <sysinfo.c>

static void test_uptime(void)
Expand Down

0 comments on commit 5831a46

Please sign in to comment.