From: Tom Hromatka Date: Mon, 4 Nov 2019 23:14:16 +0000 (+0000) Subject: tests: Add STATIC and UNIT_TEST definitions to automake files X-Git-Tag: v0.42.rc1~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1c0eea36fe93c9b9144bfacf2b045d247fec29f;p=thirdparty%2Flibcgroup.git tests: Add STATIC and UNIT_TEST definitions to automake files This commit adds two new definitions to the automake Makefile.am files. This change has no effect on the deliverable binaries. STATIC - For a standard libcgroup library build, STATIC is equal to the "static" keyword and behaves exactly the same. For a unit test build, STATIC is mapped to an empty string. This allows the unit tests to invoke static functions that would otherwise be unavailable to the test suite. UNIT_TEST - This define is used in libcgroup-internal.h to wrap the function prototypes of STATIC functions. In a standard libcgroup library build, UNIT_TEST is _not_ defined, and thus the prototypes are not available. In a unit test build, UNIT_TEST is defined and the function prototypes are available for the unit tests to use. Signed-off-by: Tom Hromatka --- diff --git a/src/Makefile.am b/src/Makefile.am index 4a7b974d..9fc965ba 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,12 +15,12 @@ INCLUDES = -I$(top_srcdir)/include lib_LTLIBRARIES = libcgroup.la libcgroupfortesting.la libcgroup_la_SOURCES = parse.h parse.y lex.l api.c config.c libcgroup-internal.h libcgroup.map wrapper.c log.c libcgroup_la_LIBADD = -lpthread $(CODE_COVERAGE_LIBS) -libcgroup_la_CFLAGS = $(CODE_COVERAGE_CFLAGS) +libcgroup_la_CFLAGS = $(CODE_COVERAGE_CFLAGS) -DSTATIC=static libcgroup_la_LDFLAGS = -Wl,--version-script,$(srcdir)/libcgroup.map \ -version-number $(LIBRARY_VERSION_MAJOR):$(LIBRARY_VERSION_MINOR):$(LIBRARY_VERSION_RELEASE) libcgroupfortesting_la_SOURCES = $(libcgroup_la_SOURCES) libcgroupfortesting_la_LIBADD = -lpthread $(CODE_COVERAGE_LIBS) -libcgroupfortesting_la_CFLAGS = $(CODE_COVERAGE_CFLAGS) +libcgroupfortesting_la_CFLAGS = $(CODE_COVERAGE_CFLAGS) -DSTATIC= -DUNIT_TEST libcgroupfortesting_la_LDFLAGS = -Wl,--version-script,$(top_srcdir)/tests/gunit/libcgroup_unittest.map \ -version-number $(LIBRARY_VERSION_MAJOR):$(LIBRARY_VERSION_MINOR):$(LIBRARY_VERSION_RELEASE) diff --git a/src/libcgroup-internal.h b/src/libcgroup-internal.h index 9875dd9a..37c1f459 100644 --- a/src/libcgroup-internal.h +++ b/src/libcgroup-internal.h @@ -283,6 +283,15 @@ extern void cgroup_dictionary_iterator_end(void **handle); */ int cg_chmod_path(const char *path, mode_t mode, int owner_is_umask); +/** + * Functions that are defined as STATIC can be placed within the UNIT_TEST + * ifdef. This will allow them to be included in the unit tests while + * remaining static in a normal libcgroup library build. + */ +#ifdef UNIT_TEST + +#endif /* UNIT_TEST */ + __END_DECLS #endif diff --git a/tests/gunit/Makefile.am b/tests/gunit/Makefile.am index 1f54ad93..79f9f7ee 100644 --- a/tests/gunit/Makefile.am +++ b/tests/gunit/Makefile.am @@ -23,7 +23,9 @@ AM_CPPFLAGS = -I$(top_srcdir)/include \ -I$(top_srcdir)/src \ -I$(top_builddir)/googletest/googletest/include \ -I$(top_builddir)/googletest/googletest \ - -std=c++11 + -std=c++11 \ + -DSTATIC= \ + -DUNIT_TEST LDADD = ../../src/.libs/libcgroupfortesting.la \ libgtest.la