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> --- .gitignore | 1 + .gitmodules | 4 + Makefile.am | 1 + configure.in | 6 +- src/Makefile.am | 6 +- tests/Makefile.am | 2 +- tests/gunit/.gitignore | 6 ++ tests/gunit/Makefile.am | 38 +++++++++ tests/gunit/gtest.cpp | 29 +++++++ tests/gunit/libcgroup_unittest.map | 130 +++++++++++++++++++++++++++++ 10 files changed, 220 insertions(+), 3 deletions(-) create mode 100644 .gitmodules create mode 100644 tests/gunit/.gitignore create mode 100644 tests/gunit/Makefile.am create mode 100644 tests/gunit/gtest.cpp create mode 100644 tests/gunit/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..e87ec8a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,5 @@ AUTOMAKE_OPTIONS = foreign +ACLOCAL_AMFLAGS= -I m4 SUBDIRS = dist doc include samples scripts src tests EXTRA_DIST = README_daemon libcgroup.doxyfile README_systemd diff --git a/configure.in b/configure.in index 75f4a51..81949b1 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]) @@ -195,6 +198,7 @@ fi AC_CONFIG_FILES([Makefile tests/Makefile + tests/gunit/Makefile tests/tools/testenv.sh tests/tools/Makefile tests/tools/cgconfigparser/Makefile diff --git a/src/Makefile.am b/src/Makefile.am index 3a92d59..52d0e00 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 = $(libcgroup_la_SOURCES) +libcgroupfortesting_la_LIBADD = -lpthread +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/tests/Makefile.am b/tests/Makefile.am index 4d556aa..7f1a071 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = tools +SUBDIRS = gunit tools INCLUDES = -I$(top_srcdir)/include LDADD = $(top_builddir)/src/.libs/libcgroup.la diff --git a/tests/gunit/.gitignore b/tests/gunit/.gitignore new file mode 100644 index 0000000..3308721 --- /dev/null +++ b/tests/gunit/.gitignore @@ -0,0 +1,6 @@ +*.log +*.o +*.trs + +gtest +libgtest.la diff --git a/tests/gunit/Makefile.am b/tests/gunit/Makefile.am new file mode 100644 index 0000000..3ffeac3 --- /dev/null +++ b/tests/gunit/Makefile.am @@ -0,0 +1,38 @@ +# +# libcgroup googletests Makefile.am +# +# Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. +# Author: Tom Hromatka <tom.hroma...@oracle.com> +# + +# +# This library is free software; you can redistribute it and/or modify it +# under the terms of version 2.1 of the GNU Lesser General Public License as +# published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License +# for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this library; if not, see <http://www.gnu.org/licenses>. +# + +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 = $(top_srcdir)/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 diff --git a/tests/gunit/gtest.cpp b/tests/gunit/gtest.cpp new file mode 100644 index 0000000..1ff88c2 --- /dev/null +++ b/tests/gunit/gtest.cpp @@ -0,0 +1,29 @@ +/** + * libcgroup googletest main entry point + * + * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. + * Author: Tom Hromatka <tom.hroma...@oracle.com> + */ + +/* + * This library is free software; you can redistribute it and/or modify it + * under the terms of version 2.1 of the GNU Lesser General Public License as + * published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, see <http://www.gnu.org/licenses>. + */ + +#include "gtest/gtest.h" + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} diff --git a/tests/gunit/libcgroup_unittest.map b/tests/gunit/libcgroup_unittest.map new file mode 100644 index 0000000..d2af56c --- /dev/null +++ b/tests/gunit/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; -- 2.21.0 _______________________________________________ Libcg-devel mailing list Libcg-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libcg-devel