Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update warning fix from upstream #21

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ __pycache__
.pydevproject
.gdbinit

# vsstudio code
.vscode

# vagrant
.vagrant

# libuavcan DSDL compiler default output directory
dsdlc_generated

Expand Down
16 changes: 5 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: cpp
compiler: gcc
dist: xenial
env:
global:
# The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
Expand All @@ -19,16 +20,9 @@ addons:
build_command: "make --ignore-errors"
branch_pattern: coverity_scan
before_install:
- git submodule update --init --recursive
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
- sudo add-apt-repository ppa:terry.guo/gcc-arm-embedded -y
- sudo apt-get update -qq
- if [ "$CXX" = "g++" ]; then sudo apt-get install --force-yes -qq g++-4.8; fi
- if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi
- sudo apt-get install --force-yes libgtest-dev gcc-arm-none-eabi
- "cd /usr/src/gtest && sudo cmake . && sudo cmake --build . && sudo mv libg* /usr/local/lib/ ; cd -"
- ./bootstrap.sh
before_script: "mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Debug -DCONTINUOUS_INTEGRATION_BUILD=1"
script:
- if [ "${COVERITY_SCAN_BRANCH}" != 1 ] && [ "${TARGET}" == "native" ]; then make ; fi
- if [ "${COVERITY_SCAN_BRANCH}" != 1 ] && [ "${TARGET}" == "lpc11c24" ]; then cd "$TRAVIS_BUILD_DIR/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24" && make all ; fi
- if [ "${COVERITY_SCAN_BRANCH}" != 1 ] && [ "${TARGET}" == "stm32" ]; then cd "$TRAVIS_BUILD_DIR/libuavcan_drivers/stm32/test_stm32f107" && git clone "https://github.com/Zubax/zubax_chibios" && cd zubax_chibios && git checkout stable_v1 && git submodule update --init --recursive && cd .. && make ; fi
- if [ "${COVERITY_SCAN_BRANCH}" != 1 ] && [ "${TARGET}" == "native" ]; then make && make ARGS=-VV test; fi
- if [ "${COVERITY_SCAN_BRANCH}" != 1 ] && [ "${TARGET}" == "lpc11c24" ]; then cd "$TRAVIS_BUILD_DIR/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24" && make all; fi
- if [ "${COVERITY_SCAN_BRANCH}" != 1 ] && [ "${TARGET}" == "stm32" ]; then echo "TODO STM32 test environment is not configured"; fi
42 changes: 40 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (C) 2014 Pavel Kirienko <[email protected]>
#

cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 2.8.11)

project(uavcan C CXX)

Expand All @@ -19,10 +19,10 @@ set(opts
"CMAKE_BUILD_TYPE:STRING:RelWithDebInfo:Debug Release RelWithDebInfo MinSizeRel:Build type."
"CMAKE_CXX_FLAGS:STRING:::C++ flags."
"CMAKE_C_FLAGS:STRING:::C flags."
"UAVCAN_USE_CPP03:BOOL:OFF::Use C++03 standard."
"UAVCAN_PLATFORM:STRING:generic:generic linux stm32:Platform."
"CONTINUOUS_INTEGRATION_BUILD:BOOL:OFF::Disable error redirection and timing tests"
"UAVCAN_CMAKE_VERBOSE:BOOL:OFF::Verbose CMake configure output"
"UAVCAN_CPP_VERSION:STRING:2011:2011 2014 2017:CPP version to force."
)
foreach(_opt ${opts})
# arguments are : delimited
Expand Down Expand Up @@ -67,6 +67,44 @@ include_directories(
# DSDL definitions
install(DIRECTORY dsdl DESTINATION share/uavcan)

#
# Googletest
#
if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
# (Taken from googletest/README.md documentation)
# GTest executables
# Download and unpack googletest at configure time
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
if(result)
message(WARNING "CMake step for googletest failed: ${result}")
else()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
if(result)
message(WARNING "Build step for googletest failed: ${result}")
else()

# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
${CMAKE_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)

set(GTEST_FOUND ON)
set(BUILD_TESTING ON)
enable_testing()
endif()
endif()
endif()

#
# Subdirectories
#
Expand Down
15 changes: 15 additions & 0 deletions CMakeLists.txt.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 2.8.2)

project(googletest-download NONE)

include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG ba96d0b1161f540656efdaed035b3c062b60e006
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ The installed DSDL compiler will not function unless pyuavcan is installed.
## Library development

Despite the fact that the library itself can be used on virtually any platform that has a standard-compliant
C++03 or C++11 compiler, the library development process assumes that the host OS is Linux.
C++11 compiler, the library development process assumes that the host OS is Linux.

Prerequisites:

* Google test library for C++ - gtest (see [how to install on Debian/Ubuntu](http://stackoverflow.com/questions/13513905/how-to-properly-setup-googletest-on-linux))
* C++03 *and* C++11 capable compiler with GCC-like interface (e.g. GCC, Clang)
* Google test library for C++ - gtest (dowloaded as part of the build from [github](https://github.com/google/googletest))
* C++11 capable compiler with GCC-like interface (e.g. GCC, Clang)
* CMake 2.8+
* Optional: static analysis tool for C++ - cppcheck (on Debian/Ubuntu use package `cppcheck`)

Expand All @@ -89,15 +89,42 @@ Building the debug version and running the unit tests:
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
make
make -j8
make ARGS=-VV test
```

Test outputs can be found in the build directory under `libuavcan`.
Note that unit tests must be executed in real time, otherwise they may produce false warnings;

> Note that unit tests suffixed with "_RealTime" must be executed in real time, otherwise they may produce false warnings;
this implies that they will likely fail if ran on a virtual machine or on a highly loaded system.

Contributors, please follow the [Zubax Style Guide](https://github.com/Zubax/zubax_style_guide).

### Vagrant
Vagrant can be used to setup a compatible Ubuntu virtual image. Follow the instructions on [Vagrantup](https://www.vagrantup.com/) to install virtualbox and vagrant then do:

```bash
vagrant up
vagrant ssh
mkdir build
cd build
mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Debug -DCONTINUOUS_INTEGRATION_BUILD=1
```

> Note that -DCONTINUOUS_INTEGRATION_BUILD=1 is required for this build as the realtime unit tests will not work on a virt.

You can build using commands like:

```bash
vagrant ssh -c "cd /vagrant/build && make -j4 && make test"
```

or to run a single test:

```bash
vagrant ssh -c "cd /vagrant/build && make libuavcan_test && ./libuavcan/libuavcan_test --gtest_filter=Node.Basic"
```

### Developing with Eclipse

An Eclipse project can be generated like that:
Expand Down
22 changes: 22 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

config.vm.box = "ubuntu/trusty64"

# use shell and other provisioners as usual
config.vm.provision :shell, path: "bootstrap.sh"
config.vm.provider :virtualbox do |v|
v.memory = 10000
v.cpus = 4
v.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000 ]
end
config.vm.provision "shell" do |s|
s.inline = <<-SCRIPT
# Change directory automatically on ssh login
echo "export CXX=\"g++-5\" CC=\"gcc-5\"" >> /home/vagrant/.bashrc
echo "cd /vagrant" >> /home/vagrant/.bashrc
SCRIPT
end
end
35 changes: 35 additions & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

# +----------------------------------------------------------+
# | BASH : Modifying Shell Behaviour
# | (https://www.gnu.org/software/bash/manual)
# +----------------------------------------------------------+
# Treat unset variables and parameters other than the special
# parameters ‘@’ or ‘*’ as an error when performing parameter
# expansion. An error message will be written to the standard
# error, and a non-interactive shell will exit.
set -o nounset

# Exit immediately if a pipeline returns a non-zero status.
set -o errexit

# If set, the return value of a pipeline is the value of the
# last (rightmost) command to exit with a non-zero status, or
# zero if all commands in the pipeline exit successfully.
set -o pipefail

# +----------------------------------------------------------+

sudo apt-get update
sudo apt-get -y install software-properties-common
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa -y
sudo apt-get update
sudo apt-get -y install cmake
sudo apt-get -y install python3
sudo apt-get -y install git
sudo apt-get -y install g++-5;
sudo apt-get -y install gcc-arm-embedded

# Export to tell cmake which native compilers to use.
export CXX="g++-5" CC="gcc-5";
48 changes: 25 additions & 23 deletions libuavcan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,22 @@ include_directories(${DSDLC_OUTPUT})
#
if (COMPILER_IS_GCC_COMPATIBLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wundef")
if (UAVCAN_USE_CPP03)
message(STATUS "Using C++03")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++03 -Wno-variadic-macros -Wno-long-long")
else ()
message(STATUS "Using C++11 (pass UAVCAN_USE_CPP03=1 to override)")
endif ()

if (DEFINED UAVCAN_CPP_VERSION)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUAVCAN_CPP_VERSION=${UAVCAN_CPP_VERSION}")
if (UAVCAN_CPP_VERSION STREQUAL 2011)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif (UAVCAN_CPP_VERSION STREQUAL 2014)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
elseif (UAVCAN_CPP_VERSION STREQUAL 2017)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
else ()
message(WARNING "UAVCAN_CPP_VERSION value \"${UAVCAN_CPP_VERSION}\" is unknown. -std flag will not be set by the build script.")
endif ()
else ()
message(STATUS "Using C++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif ()

if (DEBUG_BUILD)
Expand All @@ -89,7 +98,6 @@ install(CODE "execute_process(COMMAND ${PYTHON} setup.py install --record instal
#
function(add_libuavcan_test name library flags) # Adds GTest executable and creates target to execute it every build
find_package(Threads REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})

file(GLOB_RECURSE TEST_CXX_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "test/*.cpp")
add_executable(${name} ${TEST_CXX_FILES})
Expand All @@ -99,21 +107,23 @@ function(add_libuavcan_test name library flags) # Adds GTest executable and crea
set_target_properties(${name} PROPERTIES COMPILE_FLAGS ${flags})
endif ()

target_link_libraries(${name} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(${name} gmock_main)
target_link_libraries(${name} ${library})
target_link_libraries(${name} rt)
if (${UAVCAN_PLATFORM} STREQUAL "linux")
target_link_libraries(${name} rt)
endif()

# Tests run automatically upon successful build
# If failing tests need to be investigated with debugger, use 'make --ignore-errors'
if (CONTINUOUS_INTEGRATION_BUILD)
# Don't redirect test output, and don't run tests suffixed with "RealTime"
add_custom_command(TARGET ${name} POST_BUILD
COMMAND ./${name} --gtest_filter=-*RealTime
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_test(NAME ${name}
COMMAND ${name} --gtest_filter=-*RealTime
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
else ()
add_custom_command(TARGET ${name} POST_BUILD
COMMAND ./${name} 1>"${name}.log" 2>&1
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_test(NAME ${name}
COMMAND ${name} 1>"${name}.log" 2>&1
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif()
endfunction()

Expand All @@ -128,29 +138,21 @@ if (DEBUG_BUILD)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wzero-as-null-pointer-constant -Wnon-virtual-dtor")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual -Wsign-promo -Wold-style-cast")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=deprecated-declarations")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weffc++ -Wno-error=effc++") # Produces heaps of useless warnings
set(cpp03_flags "-std=c++03 -Wno-variadic-macros -Wno-long-long -Wno-zero-as-null-pointer-constant")
set(optim_flags "-O3 -DNDEBUG -g0")
else ()
message(STATUS "Compiler ID: ${CMAKE_CXX_COMPILER_ID}")
message(FATAL_ERROR "This compiler cannot be used to build tests; use release build instead.")
endif ()

# Additional flavours of the library
add_library(uavcan_cpp03 STATIC ${LIBUAVCAN_CXX_FILES})
set_target_properties(uavcan_cpp03 PROPERTIES COMPILE_FLAGS ${cpp03_flags})
add_dependencies(uavcan_cpp03 libuavcan_dsdlc)

add_library(uavcan_optim STATIC ${LIBUAVCAN_CXX_FILES})
set_target_properties(uavcan_optim PROPERTIES COMPILE_FLAGS ${optim_flags})
add_dependencies(uavcan_optim libuavcan_dsdlc)

# GTest executables
find_package(GTest)
if (GTEST_FOUND)
message(STATUS "GTest found, tests will be built and run [${GTEST_INCLUDE_DIRS}] [${GTEST_BOTH_LIBRARIES}]")
message(STATUS "GTest found, tests will be built and run.")
add_libuavcan_test(libuavcan_test uavcan "") # Default
add_libuavcan_test(libuavcan_test_cpp03 uavcan_cpp03 "${cpp03_flags}") # C++03
add_libuavcan_test(libuavcan_test_optim uavcan_optim "${optim_flags}") # Max optimization
else (GTEST_FOUND)
message(STATUS "GTest was not found, tests will not be built")
Expand Down
2 changes: 2 additions & 0 deletions libuavcan/include/uavcan/build_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
* standard than used by the compiler, in which case this symbol can be overridden manually via
* compiler flags.
*/
#define UAVCAN_CPP17 2017
#define UAVCAN_CPP14 2014
#define UAVCAN_CPP11 2011
#define UAVCAN_CPP03 2003

Expand Down
4 changes: 4 additions & 0 deletions libuavcan/include/uavcan/dynamic_memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ class LimitedPoolAllocator : public IPoolAllocator
template <std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer>
const uint16_t PoolAllocator<PoolSize, BlockSize, RaiiSynchronizer>::NumBlocks;

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"

template <std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer>
PoolAllocator<PoolSize, BlockSize, RaiiSynchronizer>::PoolAllocator() :
free_list_(reinterpret_cast<Node*>(pool_.bytes)),
Expand All @@ -155,6 +158,7 @@ PoolAllocator<PoolSize, BlockSize, RaiiSynchronizer>::PoolAllocator() :
}
free_list_[NumBlocks - 1].next = UAVCAN_NULLPTR;
}
#pragma pop

template <std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer>
void* PoolAllocator<PoolSize, BlockSize, RaiiSynchronizer>::allocate(std::size_t size)
Expand Down
Loading