Closed Nayana-ibm closed 1 year ago
Hi @Nayana-ibm. gtest
is now a system dependency and is used for unit tests in libscap and libsinsp. It seems like you either have not it installed in your system, or you don't have a version compatible with the one required by libscap. My suggestion is to make sure the dependency is installed, and if it doesn't work you can attempt compiling with -DUSE_BUNDLED_DEPS=ON
which should compile all dependencies from source and avoid the problem.
@jasondellaluce I tried suggested options but it didn't resolve the issue.
cmake -DUSE_BUNDLED_GTEST=ON -DCREATE_TEST_TARGETS=ON -DSYSDIG_VERSION=0.30.1 ..
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
USE_BUNDLED_GTEST
-- Build files have been written to: /root/sysdig/sysdig/build
cmake -DUSE_BUNDLED_DEPS=ON -DCREATE_TEST_TARGETS=ON -DSYSDIG_VERSION=0.30.1 .. make
[ 45%] Building CXX object libscap/test/CMakeFiles/unit-test-libscap.dir/scap_event.ut.cpp.o
/root/sysdig/sysdig/build/falcosecurity-libs-repo/falcosecurity-libs-prefix/src/falcosecurity-libs/userspace/libscap/test/scap_event.ut.cpp:19:10: fatal error: gtest/gtest.h: No such file or directory
#include <gtest/gtest.h>
^~~~~~~~~~~~~~~
compilation terminated.
Installing libgtest-dev,
[ 45%] Completed 'protobuf'
[ 45%] Built target protobuf
[ 45%] Building CXX object libscap/test/CMakeFiles/unit-test-libscap.dir/scap_event.ut.cpp.o
[ 45%] Linking CXX executable unit-test-libscap
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
CMakeFiles/unit-test-libscap.dir/scap_event.ut.cpp.o: In function `scap_event_empty_clone_Test::TestBody()':
/usr/include/gtest/internal/gtest-port.h:1134: undefined reference to `testing::internal::IsTrue(bool)'
CMakeFiles/unit-test-libscap.dir/scap_event.ut.cpp.o: In function `scap_event_empty_clone_Test::TestBody()':
/usr/include/gtest/gtest.h:1522: undefined reference to `testing::AssertionSuccess()'
CMakeFiles/unit-test-libscap.dir/scap_event.ut.cpp.o: In function `scap_event_empty_clone_Test::TestBody()':
/usr/include/gtest/internal/gtest-port.h:1134: undefined reference to `testing::internal::IsTrue(bool)'
/usr/include/gtest/internal/gtest-port.h:1134: undefined reference to `testing::internal::IsTrue(bool)'
/usr/include/gtest/internal/gtest-port.h:1134: undefined reference to `testing::internal::IsTrue(bool)'
CMakeFiles/unit-test-libscap.dir/scap_event.ut.cpp.o: In function `scap_event_empty_clone_Test::TestBody()':
/root/sysdig/sysdig/build/falcosecurity-libs-repo/falcosecurity-libs-prefix/src/falcosecurity-libs/userspace/libscap/test/scap_event.ut.cpp:94: undefined reference to `testing::Message::Message()'
/root/sysdig/sysdig/build/falcosecurity-libs-repo/falcosecurity-libs-prefix/src/falcosecurity-libs/userspace/libscap/test/scap_event.ut.cpp:94: undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
/root/sysdig/sysdig/build/falcosecurity-libs-repo/falcosecurity-libs-prefix/src/falcosecurity-libs/userspace/libscap/test/scap_event.ut.cpp:94: undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
/root/sysdig/sysdig/build/falcosecurity-libs-repo/falcosecurity-libs-prefix/src/falcosecurity-libs/userspace/libscap/test/scap_event.ut.cpp:94: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
@LucaGuerra do you have any insight on this by any chance?
@luca-sd Do you have any info on this.
Looks like test target had moved to falcosecurity/libs and Sysdig actually don't run the tests. https://github.com/draios/sysdig/blob/0.30.2/cmake/modules/falcosecurity-libs.cmake#L67 Below patch allows the tests to run in Sysdig for our verification purpose only.
diff --git a/CMakeListsGtestInclude.cmake b/CMakeListsGtestInclude.cmake
index 76c0f1b1..f7a5f9e4 100644
--- a/CMakeListsGtestInclude.cmake
+++ b/CMakeListsGtestInclude.cmake
@@ -23,7 +23,7 @@ project(googletest-download NONE)
include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
- GIT_TAG main
+ GIT_TAG "release-1.12.1"
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
diff --git a/cmake/modules/falcosecurity-libs.cmake b/cmake/modules/falcosecurity-libs.cmake
index 806573bf..a1e7caf6 100644
--- a/cmake/modules/falcosecurity-libs.cmake
+++ b/cmake/modules/falcosecurity-libs.cmake
@@ -78,6 +78,10 @@ set(USE_BUNDLED_RE2 ON CACHE BOOL "")
list(APPEND CMAKE_MODULE_PATH "${FALCOSECURITY_LIBS_SOURCE_DIR}/cmake/modules")
+if(CREATE_TEST_TARGETS AND NOT WIN32)
+ include(gtest)
+endif()
+
include(driver)
include(libscap)
include(libsinsp)
Closing the issue as we found workaround.
cc @therealbobo
I am building sysdig v0.30.1 from source on Ubuntu 20.04/10.04 x86_64. Tried to enable Tests through cmake as
cmake -DCREATE_TEST_TARGETS=ON -DSYSDIG_VERSION=0.30.0 ..
However build fails (make) with below error.Installed libgtest-dev however later it failed with undefined references error.
/usr/bin/ld: /root/sysdig/build/falcosecurity-libs-repo/falcosecurity-libs-prefix/src/falcosecurity-libs/userspace/libscap/test/scap_event.ut.cpp:97: undefined reference to testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
Any inputs?