Skip to content

Conversation

@kamalesh-babulal
Copy link
Contributor

Add support for installing testcases, so that the users can run it later
after installation too. The installcheck hook is part of GNU automake
and under the hook, gtest binary gets build and copied over to
$(libdir)/libcgroup/tests/, along with its dependent library
googletest/libgtest.so.

Currently, the gtest is built/run with make check. While building it
uses -rpath to link with /googletest/../libgtest.so.
Just copying over the binary/library might fail to run, if the libcgroup
sources are removed, to address this issue an extra -rpath of install
the destination is pre-pended during linking.

Fixes: libcgroup/libcgroup#60

Suggested-by: Ross Burton ross.burton@arm.com
Signed-off-by: Kamalesh Babulal kamalesh.babulal@oracle.com

Add support for installing testcases, so that the users can run it later
after installation too.  The installcheck hook is part of GNU automake
and under the hook, gtest binary gets build and copied over to
$(libdir)/libcgroup/tests/, along with its dependent library
googletest/libgtest.so.

Currently, the gtest is built/run with make check. While building it
uses -rpath to link with <libcgroup source>/googletest/../libgtest.so.
Just copying over the binary/library might fail to run, if the libcgroup
sources are removed, to address this issue an extra -rpath of install
the destination is pre-pended during linking.

Fixes: libcgroup/libcgroup#60

Suggested-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
@rossburton
Copy link

That appears to be abusing installcheck, which is designed to run a test suite against the installed binaries.

In cross-compiled environments, you can't run the test suite, so make installcheck will just fail.

@kamalesh-babulal
Copy link
Contributor Author

@rossburton Thanks for the review. Agree, I missed that cross-compiling environment, the reason for this feature, while getting it to work. Sorry for the noise.

@kamalesh-babulal
Copy link
Contributor Author

We could make it a part of install-exec-hook, so it gets installed on the target system.

@kamalesh-babulal
Copy link
Contributor Author

The idea is to have a configure flag --enable-tests-install, which is disabled by default, and once enabled it will build the test sources and install them using the make install via install-exec-hook. Please let me know your thought on it.

@rossburton where does the libgtest.so gets generated in your cross-compilation,
in googletest or googlemock/gtest/? If it gets generated in the latter then that path
also needs to be included in the Library path and -rpath.

diff --git a/configure.ac b/configure.ac
index b68c655..9413283 100644
--- a/configure.ac
+++ b/configure.ac
@@ -146,6 +146,18 @@ AC_ARG_ENABLE([tests],
        [with_tests=true])
 AM_CONDITIONAL([WITH_TESTS], [test x$with_tests = xtrue])
 
+AC_ARG_ENABLE([tests-install],
+      [AS_HELP_STRING([--enable-tests-install],[install libcgroup tests [default=no]])],
+      [
+               if test "x$enableval" == xno; then
+                       with_tests_install=false
+               else
+                       with_tests_install=true
+               fi
+       ],
+       [with_tests_install=false])
+AM_CONDITIONAL([WITH_TESTS_INSTALL], [test x$with_tests_install = xtrue])

diff --git a/gunit/Makefile.am b/gunit/Makefile.am
index ba91039..5ba5c28 100644
--- a/gunit/Makefile.am
+++ b/gunit/Makefile.am
@@ -46,5 +46,16 @@ gtest_SOURCES = gtest.cpp \
 gtest_LDFLAGS = -L$(top_srcdir)/googletest/googletest -l:libgtest.so \
                -rpath $(abs_top_srcdir)/googletest/googletest
 
+if WITH_TESTS_INSTALL
+noinst_PROGRAMS = gtest
+TESTS_INSTALL_DIR=$(DESTDIR)/$(libdir)/libcgroup/tests
+gtest_LDFLAGS += -rpath $(TESTS_INSTALL_DIR)
+
+install-exec-hook:
+       mkdir -p $(TESTS_INSTALL_DIR)
+       cp -f .libs/gtests $(TESTS_INSTALL_DIR)
+       cp -f $(top_srcdir)/googletest/googletest/libgtest.so $(TESTS_INSTALL_DIR)
+endif
+
 clean-local:
        ${RM} test-procpidcgroup

@rossburton
Copy link

rossburton commented Aug 2, 2022 via email

@kamalesh-babulal
Copy link
Contributor Author

@rossburton Thanks for taking a look. Have a nice vacation.

@drakenclimber
Copy link
Member

@rossburton, thoughts on this pull request?

@rossburton
Copy link

Very late reply, sorry.

automake's installcheck is designed to run the local test suite on the installed binaries, not install the test suite. As such I don't really see much value in supporting installcheck in libcgroup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RFE: Add option to install tests

3 participants