On Mon, May 6, 2019 at 2:17 PM Tom Hromatka <tom.hroma...@oracle.com> wrote: > > This commit adds support for the googletest unit test > framework. To enable the testing of non-exported > functions, a more permissive map file was added. > > Signed-off-by: Tom Hromatka <tom.hroma...@oracle.com>
Aha, I found it. It got caught in my spam filters. Not sure why. > --- > .gitignore | 1 + > .gitmodules | 4 ++ > Makefile.am | 3 +- > configure.in | 6 ++- > googletest | 1 + > gtests/.gitignore | 6 +++ > gtests/001-path.cpp | 114 +++++++++++++++++++++++++++++++++++++++ > gtests/Makefile.am | 25 +++++++++ > gtests/gtest.cpp | 14 +++++ > src/Makefile.am | 6 ++- > src/libcgroup_unittest.map | 130 > +++++++++++++++++++++++++++++++++++++++++++++ > 11 files changed, 307 insertions(+), 3 deletions(-) > create mode 100644 .gitmodules > create mode 160000 googletest > create mode 100644 gtests/.gitignore > create mode 100644 gtests/001-path.cpp > create mode 100644 gtests/Makefile.am > create mode 100644 gtests/gtest.cpp > create mode 100644 src/libcgroup_unittest.map > > diff --git a/.gitignore b/.gitignore > index 31b3376..fcae10c 100644 > --- a/.gitignore > +++ b/.gitignore > @@ -19,6 +19,7 @@ configure > depcomp > libtool > ltmain.sh > +m4 > missing > install-sh > aclocal.m4 > diff --git a/.gitmodules b/.gitmodules > new file mode 100644 > index 0000000..eddc93c > --- /dev/null > +++ b/.gitmodules > @@ -0,0 +1,4 @@ > +[submodule "googletest"] > + path = googletest > + url = g...@github.com:google/googletest.git > + fetchRecurseSubmodules = true > diff --git a/Makefile.am b/Makefile.am > index 7b107cc..802535e 100644 > --- a/Makefile.am > +++ b/Makefile.am > @@ -1,5 +1,6 @@ > AUTOMAKE_OPTIONS = foreign > -SUBDIRS = dist doc include samples scripts src tests > +ACLOCAL_AMFLAGS= -I m4 > +SUBDIRS = dist doc include samples scripts src gtests tests > > EXTRA_DIST = README_daemon libcgroup.doxyfile README_systemd > > diff --git a/configure.in b/configure.in > index 75f4a51..4a4cab1 100644 > --- a/configure.in > +++ b/configure.in > @@ -16,7 +16,7 @@ AC_PREREQ(2.61) > > # In following section update all occurences of version, including soname > AC_INIT([libcgroup], 0.41) > -AM_INIT_AUTOMAKE([foreign dist-bzip2]) > +AM_INIT_AUTOMAKE([foreign dist-bzip2 subdir-objects]) > > m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) > > @@ -28,6 +28,9 @@ AC_SUBST(LIBRARY_VERSION_RELEASE, 41) > # we do not want static libraries > AC_DISABLE_STATIC > > +AM_PROG_AR > +LT_INIT > + > AC_CONFIG_SRCDIR([src]) > AC_CONFIG_HEADER([config.h]) > > @@ -194,6 +197,7 @@ if test x$with_pam = xtrue; then > fi > > AC_CONFIG_FILES([Makefile > + gtests/Makefile > tests/Makefile > tests/tools/testenv.sh > tests/tools/Makefile > diff --git a/googletest b/googletest > new file mode 160000 > index 0000000..2fe3bd9 > --- /dev/null > +++ b/googletest > @@ -0,0 +1 @@ > +Subproject commit 2fe3bd994b3189899d93f1d5a881e725e046fdc2 > diff --git a/gtests/.gitignore b/gtests/.gitignore > new file mode 100644 > index 0000000..3308721 > --- /dev/null > +++ b/gtests/.gitignore > @@ -0,0 +1,6 @@ > +*.log > +*.o > +*.trs > + > +gtest > +libgtest.la > diff --git a/gtests/001-path.cpp b/gtests/001-path.cpp > new file mode 100644 > index 0000000..8fd0c00 > --- /dev/null > +++ b/gtests/001-path.cpp > @@ -0,0 +1,114 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * libcgroup googletest for cg_build_path() > + * > + * Author: Tom Hromatka <tom.hroma...@oracle.com> > + */ > +#include "gtest/gtest.h" > + > +#include "libcgroup-internal.h" > + > +class BuildPathV1Test : public ::testing::Test { > + protected: > + > + /** > + * Setup this test suite > + * > + * This test suite calls cg_build_path() to generate various > + * cgroup paths. The SetUp() routine creates a simple mount > + * table that can be used to verify cg_build_path() behavior. > + * > + * cg_mount_table for this test is as follows: > + * name mount_point index > + * ----------------------------------------------------- > + * controller0 /sys/fs/cgroup/controller0 0 > + * controller1 /sys/fs/cgroup/controller1 1 > + * controller2 /sys/fs/cgroup/controller2 2 > + * controller3 /sys/fs/cgroup/controller3 3 > + * controller4 /sys/fs/cgroup/controller4 4 > + * controller5 /sys/fs/cgroup/controller5 5 > + * > + * Note that controllers 1 and 5 are also given namespaces > + */ > + void SetUp() override { > + char NAMESPACE1[] = "ns1"; > + char NAMESPACE5[] = "ns5"; > + const int ENTRY_CNT = 6; > + int i; > + > + memset(&cg_mount_table, 0, sizeof(cg_mount_table)); > + memset(cg_namespace_table, 0, > + CG_CONTROLLER_MAX * sizeof(cg_namespace_table[0])); > + > + // Populate the mount table > + for (i = 0; i < ENTRY_CNT; i++) { > + snprintf(cg_mount_table[i].name, FILENAME_MAX, > + "controller%d", i); > + cg_mount_table[i].index = i; > + > + snprintf(cg_mount_table[i].mount.path, FILENAME_MAX, > + "/sys/fs/cgroup/%s", cg_mount_table[i].name); > + cg_mount_table[i].mount.next = NULL; > + } > + > + // Give a couple of the entries a namespace as well > + cg_namespace_table[1] = NAMESPACE1; > + cg_namespace_table[5] = NAMESPACE5; > + } > +}; > + > +TEST_F(BuildPathV1Test, BuildPathV1_ControllerMismatch) > +{ > + char *name = NULL; > + char path[FILENAME_MAX]; > + /* type intentionally _does not_ match any controllers */ > + char type[] = "FOO"; > + char *out; > + > + out = cg_build_path(name, path, type); > + ASSERT_STREQ(out, NULL); > +} > + > +TEST_F(BuildPathV1Test, BuildPathV1_ControllerMatch) > +{ > + char *name = NULL; > + char path[FILENAME_MAX]; > + char type[] = "controller0"; > + char *out; > + > + out = cg_build_path(name, path, type); > + ASSERT_STREQ(out, "/sys/fs/cgroup/controller0/"); > +} > + > +TEST_F(BuildPathV1Test, BuildPathV1_ControllerMatchWithName) > +{ > + char name[] = "TomsCgroup1"; > + char path[FILENAME_MAX]; > + char type[] = "controller3"; > + char *out; > + > + out = cg_build_path(name, path, type); > + ASSERT_STREQ(out, "/sys/fs/cgroup/controller3/TomsCgroup1/"); > +} > + > +TEST_F(BuildPathV1Test, BuildPathV1_ControllerMatchWithNs) > +{ > + char *name = NULL; > + char path[FILENAME_MAX]; > + char type[] = "controller1"; > + char *out; > + > + out = cg_build_path(name, path, type); > + ASSERT_STREQ(out, "/sys/fs/cgroup/controller1/ns1/"); > +} > + > +TEST_F(BuildPathV1Test, BuildPathV1_ControllerMatchWithNameAndNs) > +{ > + char name[] = "TomsCgroup2"; > + char path[FILENAME_MAX]; > + char type[] = "controller5"; > + char *out; > + > + out = cg_build_path(name, path, type); > + ASSERT_STREQ(out, "/sys/fs/cgroup/controller5/ns5/TomsCgroup2/"); > +} > diff --git a/gtests/Makefile.am b/gtests/Makefile.am > new file mode 100644 > index 0000000..d9cf680 > --- /dev/null > +++ b/gtests/Makefile.am > @@ -0,0 +1,25 @@ > +# SPDX-License-Identifier: GPL-2.0 > +# > +# libcgroup googletests Makefile.am > +# > +# Author: Tom Hromatka <tom.hroma...@oracle.com> > +# > + > +AM_CPPFLAGS = -I$(top_srcdir)/include \ > + -I$(top_srcdir)/src \ > + -I$(top_srcdir)/googletest/googletest/include \ > + -I$(top_srcdir)/googletest/googletest \ > + -std=c++11 > +LDADD = $(top_builddir)/src/.libs/libcgroupfortesting.la \ > + libgtest.la > + > +libgtest_la_SOURCES = ../googletest/googletest/src/gtest-all.cc > +libgtest_la_CPPFLAGS = -I$(top_srcdir)/googletest/googletest/include \ > + -I$(top_srcdir)/googletest/googletest > + > +check_LTLIBRARIES = libgtest.la > +check_PROGRAMS = gtest > +TESTS = gtest > + > +gtest_SOURCES = gtest.cpp \ > + 001-path.cpp > diff --git a/gtests/gtest.cpp b/gtests/gtest.cpp > new file mode 100644 > index 0000000..3b5b2b9 > --- /dev/null > +++ b/gtests/gtest.cpp > @@ -0,0 +1,14 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * libcgroup googletest main entry point > + * > + * Author: Tom Hromatka <tom.hroma...@oracle.com> > + */ > +#include "gtest/gtest.h" > + > +int main(int argc, char **argv) > +{ > + ::testing::InitGoogleTest(&argc, argv); > + > + return RUN_ALL_TESTS(); > +} > diff --git a/src/Makefile.am b/src/Makefile.am > index 3a92d59..af21c51 100644 > --- a/src/Makefile.am > +++ b/src/Makefile.am > @@ -10,9 +10,13 @@ AM_YFLAGS = -d > CLEANFILES = lex.c parse.c parse.h > > INCLUDES = -I$(top_srcdir)/include > -lib_LTLIBRARIES = libcgroup.la > +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 > libcgroup_la_LDFLAGS = -Wl,--version-script,$(srcdir)/libcgroup.map \ > -version-number > $(LIBRARY_VERSION_MAJOR):$(LIBRARY_VERSION_MINOR):$(LIBRARY_VERSION_RELEASE) > > +libcgroupfortesting_la_SOURCES = parse.h parse.y lex.l api.c config.c > libcgroup-internal.h libcgroup_unittest.map wrapper.c log.c > +libcgroupfortesting_la_LIBADD = -lpthread > +libcgroupfortesting_la_LDFLAGS = > -Wl,--version-script,$(srcdir)/libcgroup_unittest.map \ > + -version-number > $(LIBRARY_VERSION_MAJOR):$(LIBRARY_VERSION_MINOR):$(LIBRARY_VERSION_RELEASE) > diff --git a/src/libcgroup_unittest.map b/src/libcgroup_unittest.map > new file mode 100644 > index 0000000..d2af56c > --- /dev/null > +++ b/src/libcgroup_unittest.map > @@ -0,0 +1,130 @@ > +CGROUP_0.32 { > +global: > + cgroup_init; > + cgroup_attach_task; > + cgroup_modify_cgroup; > + cgroup_create_cgroup; > + cgroup_delete_cgroup; > + cgroup_attach_task_pid; > + cgroup_get_cgroup; > + cgroup_create_cgroup_from_parent; > + cgroup_copy_cgroup; > + cgroup_change_cgroup_uid_gid; > + cgroup_change_cgroup_path; > + cgroup_new_cgroup; > + cgroup_add_controller; > + cgroup_free; > + cgroup_free_controllers; > + cgroup_add_value_string; > + cgroup_add_value_int64; > + cgroup_add_value_uint64; > + cgroup_add_value_bool; > + cgroup_compare_cgroup; > + cgroup_compare_controllers; > + cgroup_set_uid_gid; > + cgroup_get_uid_gid; > + cgroup_get_value_string; > + cgroup_set_value_string; > + cgroup_get_value_int64; > + cgroup_set_value_int64; > + cgroup_get_value_uint64; > + cgroup_set_value_uint64; > + cgroup_get_value_bool; > + cgroup_set_value_bool; > + cgroup_change_cgroup_uid_gid_flags; > + cgroup_print_rules_config; > + cgroup_reload_cached_rules; > + cgroup_init_rules_cache; > + cgroup_get_current_controller_path; > + cgroup_config_load_config; > + *; > +}; > + > +CGROUP_0.32.1 { > +global: > + cgroup_strerror; > +} CGROUP_0.32; > + > +CGROUP_0.33 { > +global: > + cgroup_get_last_errno; > + cgroup_walk_tree_begin; > + cgroup_walk_tree_next; > + cgroup_walk_tree_end; > +} CGROUP_0.32.1; > + > +CGROUP_0.34 { > +global: > + cgroup_get_task_begin; > + cgroup_get_task_end; > + cgroup_get_task_next; > + cgroup_read_stats_begin; > + cgroup_read_stats_next; > + cgroup_read_stats_end; > + cgroup_walk_tree_set_flags; > + cgroup_get_controller_end; > + cgroup_get_controller_next; > + cgroup_get_controller_begin; > + cgroup_unload_cgroups; > + cgroup_get_controller; > + cgroup_get_uid_gid_from_procfs; > + cgroup_get_subsys_mount_point; > + cgroup_get_procname_from_procfs; > + cgroup_register_unchanged_process; > + cgroup_change_cgroup_flags; > +} CGROUP_0.33; > + > +CGROUP_0.35 { > +global: > + create_cgroup_from_name_value_pairs; > + cgroup_delete_cgroup_ext; > + cgroup_get_all_controller_begin; > + cgroup_get_all_controller_next; > + cgroup_get_all_controller_end; > + cgroup_get_value_name_count; > + cgroup_get_value_name; > +} CGROUP_0.34; > + > +CGROUP_0.36 { > +} CGROUP_0.35; > + > +CGROUP_0.37 { > + cgroup_get_procs; > + cgroup_read_value_begin; > + cgroup_read_value_next; > + cgroup_read_value_end; > + cg_chmod_recursive; > +} CGROUP_0.36; > + > +CGROUP_0.38 { > + cgroup_get_subsys_mount_point_begin; > + cgroup_get_subsys_mount_point_next; > + cgroup_get_subsys_mount_point_end; > + cgroup_set_permissions; > + cgroup_config_unload_config; > + cgroup_config_set_default; > +} CGROUP_0.37; > + > +CGROUP_0.39 { > + cgroup_reload_cached_templates; > + cgroup_init_templates_cache; > + cgroup_config_create_template_group; > + cgroup_change_all_cgroups; > + cgroup_set_logger; > + cgroup_set_default_logger; > + cgroup_set_loglevel; > + cgroup_log; > + cgroup_parse_log_level_str; > +} CGROUP_0.38; > + > +CGROUP_0.40 { > + cgroup_templates_cache_set_source_files; > + cgroup_load_templates_cache_from_files; > +} CGROUP_0.39; > + > +CGROUP_0.41 { > +} CGROUP_0.40; > + > +CGROUP_0.42 { > + cgroup_add_all_controllers; > +} CGROUP_0.41; > -- > 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