Create libcgset.la so that functions within cgset can be
unit tested.

A functional test would be preferable in this case, but I'm
looking to test a very specific scenario - where there's an
'=' sign in the value of a setting's name/value pair.  To the
best of my knowledge, only the rdma (v1) and io (v2)
controllers have settings that utilize an '=' in such a fashion.
I can't think of an easy way to test rdma across our test fleet,
and our automated systems don't support the v2 io controller
yet.  Thus a unit test for now.

Signed-off-by: Tom Hromatka <tom.hroma...@oracle.com>
---
 src/tools/Makefile.am    |  8 +++++++-
 src/tools/tools-common.h | 11 +++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am
index fd792853a27e..9f78050f49da 100644
--- a/src/tools/Makefile.am
+++ b/src/tools/Makefile.am
@@ -10,6 +10,8 @@ bin_PROGRAMS = cgexec cgclassify cgcreate cgset cgget 
cgdelete lssubsys\
 
 sbin_PROGRAMS = cgconfigparser cgclear
 
+lib_LTLIBRARIES = libcgset.la
+
 cgexec_SOURCES = cgexec.c tools-common.c tools-common.h
 cgexec_LIBS = $(CODE_COVERAGE_LIBS)
 cgexec_CFLAGS = $(CODE_COVERAGE_CFLAGS)
@@ -22,9 +24,13 @@ cgcreate_SOURCES = cgcreate.c tools-common.c tools-common.h
 cgcreate_LIBS = $(CODE_COVERAGE_LIBS)
 cgcreate_CFLAGS = $(CODE_COVERAGE_CFLAGS)
 
+libcgset_la_SOURCES = cgset.c tools-common.c tools-common.h
+libcgset_la_LIBADD = $(CODE_COVERAGE_LIBS)
+libcgset_la_CFLAGS = $(CODE_COVERAGE_CFLAGS) -DSTATIC= -DUNIT_TEST
+
 cgset_SOURCES = cgset.c tools-common.c tools-common.h
 cgset_LIBS = $(CODE_COVERAGE_LIBS)
-cgset_CFLAGS = $(CODE_COVERAGE_CFLAGS)
+cgset_CFLAGS = $(CODE_COVERAGE_CFLAGS) -DSTATIC=static
 
 cgget_SOURCES = cgget.c tools-common.c tools-common.h
 cgget_LIBS = $(CODE_COVERAGE_LIBS)
diff --git a/src/tools/tools-common.h b/src/tools/tools-common.h
index c723eb4ceee4..7492bbbff78d 100644
--- a/src/tools/tools-common.h
+++ b/src/tools/tools-common.h
@@ -18,6 +18,7 @@
 
 #define __TOOLS_COMMON
 
+__BEGIN_DECLS
 #include "config.h"
 #include <libcgroup.h>
 #include "../libcgroup-internal.h"
@@ -122,4 +123,14 @@ int parse_mode(char *string, mode_t *pmode, const char 
*program_name);
 int parse_uid_gid(char *string, uid_t *uid, gid_t *gid,
                const char *program_name);
 
+/**
+ * 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 build.
+ */
+#ifdef UNIT_TEST
+#endif /* UNIT_TEST */
+
+__END_DECLS
+
 #endif /* TOOLS_COMMON */
-- 
2.26.2



_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to