On 11/15/19 2:23 PM, Dhaval Giani wrote:
On Wed, Nov 6, 2019 at 3:43 PM Tom Hromatka <tom.hroma...@oracle.com> wrote:
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 <tom.hroma...@oracle.com>
So if I read this riht, we need to replace static with STATIC in the code?
Yes, but it can be done on a case-by-case basis as we add tests for those
functions with unit tests.
Tom
Thanks!
Dhaval
---
src/Makefile.am | 4 ++--
src/libcgroup-internal.h | 9 +++++++++
tests/gunit/Makefile.am | 4 +++-
3 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index 4a7b974d0a1b..9fc965ba5ed7 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 9875dd9a7396..37c1f4592865 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 1f54ad9377f5..79f9f7ee08b9 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
--
1.8.3.1
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel