1

I'm doing a project for ARM64 devices and am using Linux Embedded as the OS. I am trying to using Google Tests but when running bitbake, it is failing. Heres the error:

| CMake Error at /#####/tmp-glibc/work/#####-oe-linux/project_name/1.0-r0/recipe-sysroot-native/usr/share/cmake-3.16/Modules/GoogleTestAddTests.cmake:40 (message):
|   Error running test executable.
|
|     Path: '/#####/tmp-glibc/work/#####-oe-linux/project_name/1.0-r0/build/projectName/hello_test'
|     Result: 126
|     Output:
|
|
|
|
| ninja: build stopped: subcommand failed.
| WARNING: /#####/tmp-glibc/work/#####-oe-linux/project_name/1.0-r0/temp/run.do_compile.19988:1 exit 1 from 'eval ${DESTDIR:+DESTDIR=${DESTDIR} }VERBOSE=1 cmake --build '/#####/tmp-glibc/work/#####-oe-linux/project_name/1.0-r0/build' "$@" -- ${EXTRA_OECMAKE_BUILD}'

I've edited the cmake in my src folder and added these components wrt Gtests:

cmake_minimum_required(VERSION 3.5.0)
# set the project name and version
project(project_name)

#specify C++ standards
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

add_compile_options (-std=c++11 -Wall)

configure_file(common/inc/common.h.in common.h)

add_definitions(-DPACKAGE_ARCH=${PACKAGE_ARCH})
add_definitions(-DPACKAGE_DISTRO=${PACKAGE_DISTRO})

include(FetchContent)
FetchContent_Declare(
  googletest
  URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

add_subdirectory (executable_name ${PROJECT_BINARY_DIR}/srclocation)

CMake for the file containing test case:

set(S_EXECUTABLE executableName)
#specify C++ standards
add_compile_options (-std=c++11 -Wall)

# add the executable
add_executable(${S_EXECUTABLE } src/abc.cpp)
target_include_directories(${S_EXECUTABLE}
    PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc
    PUBLIC ${PROJECT_BINARY_DIR})

install(
  TARGETS ${S_EXECUTABLE}
  RUNTIME DESTINATION ${FOOBAR_INSTALL_BINDIR}
  PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
              GROUP_EXECUTE GROUP_READ
              GROUP_EXECUTE GROUP_READ
)

enable_testing()

add_executable(
  hello_test
  src/hello_test.cpp
)
target_link_libraries(
  hello_test
  gtest_main
)

include(GoogleTest)
gtest_discover_tests(hello_test)
  • Should your gtest run on the target or on the build system? – Philippos Jul 01 '21 at 11:35
  • It should ideally run on the target as some of my tests will have allocation functions specific to the target – Md. Mohsin Hussain Jul 01 '21 at 14:16
  • Then why do you have `Error running test executable` during build? As far as I understand `gtest_discover_tests()`, it runs an executable during build, so https://cmake.org/cmake/help/git-stage/module/GoogleTest.html notes, "it requires that CROSSCOMPILING_EMULATOR is properly set in order to function in a cross-compiling environment". – Philippos Jul 02 '21 at 06:20
  • It looks to me that this is not really related to yocto at all. You may have better chances to get an answer among the `gtest` and `cmake` experts at _stackoverflow_. – Philippos Jul 02 '21 at 06:25
  • I tried doing the same on a standalone ubuntu machine and found this to work properly. The tests ran when I ran the test executable and not when I built it. – Md. Mohsin Hussain Jul 02 '21 at 07:51
  • Then what about the `CROSSCOMPILING_EMULATOR` setting on both machines? – Philippos Jul 02 '21 at 10:03

0 Answers0