googletest with a baremetal cortex m4 cmake project

588 views
Skip to first unread message

Mohammed Talha

unread,
Jan 28, 2019, 9:38:42 AM1/28/19
to Google C++ Testing Framework
I'm trying to enable testing in a cmake cortex m4 arm-none-eabi-g++(7.3.1) project. Following is the tree structure of the project

.
├── build
├── CMakeLists.txt   -----------> Top Level Cmake (includes the stm32_arm.cmake file which sets cmake_c_compiler and cmake_cxx_compiler to /usr/bin/arm-none-eabi-gcc and arm-none-eabi-g++ respectively.)
├── src
│   ├── CMakeLists.txt
│   ├── Drivers
│   ├── libuavcan
│   ├── stm32-cmake
│   ├── stm32_uavcan
│   ├── sys
│   └── util
├── tests
│   ├── arm_gtest.patch  ---> a simple patch that changes -std=c++11 to -std=gnu++11 in the gtest top cmake
│   ├── CMakeLists.txt   --> gtest added via Eternal_Project_Add
│   ├── src
│   └── Tests
├── thirdparty
│   ├── ChibiOS_17.6.0
│   ├── sml
│   ├── STM32F429I-Discovery_FW_V1.0.1
│   └── stm32plus
└── TODO.txt


The following flags are being passed to the gtest via cmake_cxx_flags "-DGTEST_HAS_PTHREAD=0 -DGTEST_HAS_POSIX_RE=0 -DGTEST_HAS_CLONE=0 -DGTEST_HAS_EXCEPTIONS=0 -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_HAS_STREAM_REDIRECTION=0 -DGTEST_HAS_RTTI=0". 

I get the following errors when building the project.

In file included from /home/talha/Seven_LLS_experimental/build/tests/gtest/src/gtest/googlemock/include/gmock/internal/gmock-port.h:55:0,
                 
from /home/talha/Seven_LLS_experimental/build/tests/gtest/src/gtest/googlemock/include/gmock/internal/gmock-internal-utils.h:46,
                 
from /home/talha/Seven_LLS_experimental/build/tests/gtest/src/gtest/googlemock/include/gmock/gmock-actions.h:51,
                 
from /home/talha/Seven_LLS_experimental/build/tests/gtest/src/gtest/googlemock/include/gmock/gmock.h:59,
                 
from /home/talha/Seven_LLS_experimental/tests/Tests/ringbuffer/testRingbuffer.cpp:2:
/home/talha/Seven_LLS_experimental/build/tests/gtest/src/gtest/googletest/include/gtest/internal/gtest-port.h: In function 'int testing::internal::posix::FileNo(FILE*)':
/home/talha/Seven_LLS_experimental/build/tests/gtest/src/gtest/googletest/include/gtest/internal/gtest-port.h:2088:40: error: 'fileno' was not declared in this scope
 
inline int FileNo(FILE* file) { return fileno(file); }
                                       
^~~~~~
/home/talha/Seven_LLS_experimental/build/tests/gtest/src/gtest/googletest/include/gtest/internal/gtest-port.h:2088:40: note: suggested alternative: 'file'
 
inline int FileNo(FILE* file) { return fileno(file); }
                                       
^~~~~~
                                        file
/home/talha/Seven_LLS_experimental/build/tests/gtest/src/gtest/googletest/include/gtest/internal/gtest-port.h: In function 'char* testing::internal::posix::StrDup(const char*)':
/home/talha/Seven_LLS_experimental/build/tests/gtest/src/gtest/googletest/include/gtest/internal/gtest-port.h:2094:47: error: 'strdup' was not declared in this scope
 
inline char* StrDup(const char* src) { return strdup(src); }
                                               
^~~~~~
/home/talha/Seven_LLS_experimental/build/tests/gtest/src/gtest/googletest/include/gtest/internal/gtest-port.h:2094:47: note: suggested alternative: 'StrDup'
 
inline char* StrDup(const char* src) { return strdup(src); }
                                               
^~~~~~
                                               
StrDup
/home/talha/Seven_LLS_experimental/build/tests/gtest/src/gtest/googletest/include/gtest/internal/gtest-port.h: In function 'FILE* testing::internal::posix::FDOpen(int, const char*)':
/home/talha/Seven_LLS_experimental/build/tests/gtest/src/gtest/googletest/include/gtest/internal/gtest-port.h:2122:56: error: 'fdopen' was not declared in this scope
 
inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
                                                       
^~~~~~
/home/talha/Seven_LLS_experimental/build/tests/gtest/src/gtest/googletest/include/gtest/internal/gtest-port.h:2122:56: note: suggested alternative: 'fopen'
 
inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
                                                       
^~~~~~
                                                        fopen
In file included from /home/talha/Seven_LLS_experimental/build/tests/gtest/src/gtest/googlemock/include/gmock/internal/gmock-internal-utils.h:47:0,
                 
from /home/talha/Seven_LLS_experimental/build/tests/gtest/src/gtest/googlemock/include/gmock/gmock-actions.h:51,
                 
from /home/talha/Seven_LLS_experimental/build/tests/gtest/src/gtest/googlemock/include/gmock/gmock.h:59,
                 
from /home/talha/Seven_LLS_experimental/tests/Tests/ringbuffer/testRingbuffer.cpp:2:
/home/talha/Seven_LLS_experimental/build/tests/gtest/src/gtest/googletest/include/gtest/gtest.h: In instantiation of 'testing::AssertionResult testing::internal::CmpHelperEQ(const char*, const char*, const T1&, const T2&) [with T1 = int; T2 = unsigned int]':
/home/talha//Seven_LLS_experimental/build/tests/gtest/src/gtest/googletest/include/gtest/gtest.h:1548:23:   required from 'static testing::AssertionResult testing::internal::EqHelper<lhs_is_null_literal>::Compare(const char*, const char*, const T1&, const T2&) [with T1 = int; T2 = unsigned int; bool lhs_is_null_literal = false]'
/home/talha/Seven_LLS_experimental/tests/Tests/ringbuffer/testRingbuffer.cpp:13:2:   required from here
/home/talha/Seven_LLS_experimental/build/tests/gtest/src/gtest/googletest/include/gtest/gtest.h:1520:11: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
   
if (lhs == rhs) {
       
~~~~^~~~~~
cc1plus
: all warnings being treated as errors
tests
/Tests/ringbuffer/CMakeFiles/testringbuffer.dir/build.make:62: recipe for target 'tests/Tests/ringbuffer/CMakeFiles/testringbuffer.dir/testRingbuffer.cpp.obj' failed
make
[2]: *** [tests/Tests/ringbuffer/CMakeFiles/testringbuffer.dir/testRingbuffer.cpp.obj] Error 1
CMakeFiles/Makefile2:177: recipe for target 'tests/Tests/ringbuffer/CMakeFiles/testringbuffer.dir/all' failed
make
[1]: *** [tests/Tests/ringbuffer/CMakeFiles/testringbuffer.dir/all] Error 2

I have attached the tests cmake file here for reference.

CMakeLists.txt
Reply all
Reply to author
Forward
0 new messages