diff --git a/.gitignore b/.gitignore index 4444ace73..a901d6407 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,12 @@ __pycache__ .pydevproject .gdbinit +# vsstudio code +.vscode + +# vagrant +.vagrant + # libuavcan DSDL compiler default output directory dsdlc_generated diff --git a/.travis.yml b/.travis.yml index 3cb219ae1..6b53f1b0f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: cpp compiler: gcc +dist: xenial env: global: # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index bbdda1e74..3826e1667 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ # Copyright (C) 2014 Pavel Kirienko # -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 2.8.11) project(uavcan C CXX) @@ -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 @@ -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 # diff --git a/CMakeLists.txt.in b/CMakeLists.txt.in new file mode 100644 index 000000000..529c8e381 --- /dev/null +++ b/CMakeLists.txt.in @@ -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 "" +) diff --git a/README.md b/README.md index 4683d50e6..41c1f9627 100644 --- a/README.md +++ b/README.md @@ -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`) @@ -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: diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 000000000..ccdefdc02 --- /dev/null +++ b/Vagrantfile @@ -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 diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 000000000..de390e259 --- /dev/null +++ b/bootstrap.sh @@ -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"; diff --git a/libuavcan/CMakeLists.txt b/libuavcan/CMakeLists.txt index cea13ce67..62eb64a4d 100644 --- a/libuavcan/CMakeLists.txt +++ b/libuavcan/CMakeLists.txt @@ -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) @@ -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}) @@ -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() @@ -128,8 +138,6 @@ 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}") @@ -137,20 +145,14 @@ if (DEBUG_BUILD) 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") diff --git a/libuavcan/include/uavcan/build_config.hpp b/libuavcan/include/uavcan/build_config.hpp index 8a886c297..1af3b6169 100644 --- a/libuavcan/include/uavcan/build_config.hpp +++ b/libuavcan/include/uavcan/build_config.hpp @@ -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 diff --git a/libuavcan/include/uavcan/dynamic_memory.hpp b/libuavcan/include/uavcan/dynamic_memory.hpp index 9ef7322a3..fa9750d1b 100644 --- a/libuavcan/include/uavcan/dynamic_memory.hpp +++ b/libuavcan/include/uavcan/dynamic_memory.hpp @@ -138,6 +138,9 @@ class LimitedPoolAllocator : public IPoolAllocator template const uint16_t PoolAllocator::NumBlocks; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-align" + template PoolAllocator::PoolAllocator() : free_list_(reinterpret_cast(pool_.bytes)), @@ -155,6 +158,7 @@ PoolAllocator::PoolAllocator() : } free_list_[NumBlocks - 1].next = UAVCAN_NULLPTR; } +#pragma pop template void* PoolAllocator::allocate(std::size_t size) diff --git a/libuavcan/include/uavcan/marshal/array.hpp b/libuavcan/include/uavcan/marshal/array.hpp index fa24086c1..b409d5d0c 100644 --- a/libuavcan/include/uavcan/marshal/array.hpp +++ b/libuavcan/include/uavcan/marshal/array.hpp @@ -809,13 +809,13 @@ class UAVCAN_EXPORT Array : public ArrayImpl * This operator can only be used with string-like arrays; otherwise it will fail to compile. * @ref c_str() */ - bool operator==(const char* ch) const + bool operator==(const char* chr) const { - if (ch == UAVCAN_NULLPTR) + if (chr == UAVCAN_NULLPTR) { return false; } - return std::strncmp(Base::c_str(), ch, MaxSize) == 0; + return std::strncmp(Base::c_str(), chr, MaxSize) == 0; } /** @@ -827,18 +827,18 @@ class UAVCAN_EXPORT Array : public ArrayImpl * This operator can only be used with string-like arrays; otherwise it will fail to compile. * @ref c_str() */ - SelfType& operator=(const char* c) + SelfType& operator=(const char* chr) { StaticAssert::check(); StaticAssert::check(); Base::clear(); - if (c == UAVCAN_NULLPTR) + if (chr == UAVCAN_NULLPTR) { handleFatalError("Array::operator=(const char*)"); } - while (*c) + while (*chr) { - push_back(ValueType(*c++)); // Value type is likely to be unsigned char, so conversion may be required. + push_back(ValueType(*chr++)); // Value type is likely to be unsigned char, so conversion may be required. } return *this; } @@ -847,17 +847,17 @@ class UAVCAN_EXPORT Array : public ArrayImpl * This operator can only be used with string-like arrays; otherwise it will fail to compile. * @ref c_str() */ - SelfType& operator+=(const char* c) + SelfType& operator+=(const char* chr) { StaticAssert::check(); StaticAssert::check(); - if (c == UAVCAN_NULLPTR) + if (chr == UAVCAN_NULLPTR) { handleFatalError("Array::operator+=(const char*)"); } - while (*c) + while (*chr) { - push_back(ValueType(*c++)); + push_back(ValueType(*chr++)); } return *this; } diff --git a/libuavcan/include/uavcan/protocol/dynamic_node_id_client.hpp b/libuavcan/include/uavcan/protocol/dynamic_node_id_client.hpp index 31e2c16a3..107f97aa1 100644 --- a/libuavcan/include/uavcan/protocol/dynamic_node_id_client.hpp +++ b/libuavcan/include/uavcan/protocol/dynamic_node_id_client.hpp @@ -69,6 +69,9 @@ class UAVCAN_EXPORT DynamicNodeIDClient : private TimerBase : TimerBase(node) , dnida_pub_(node) , dnida_sub_(node) +#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11 + , unique_id_{0} +#endif , size_of_received_unique_id_(0) { } diff --git a/libuavcan/include/uavcan/util/templates.hpp b/libuavcan/include/uavcan/util/templates.hpp index f842d4035..00abb7c67 100644 --- a/libuavcan/include/uavcan/util/templates.hpp +++ b/libuavcan/include/uavcan/util/templates.hpp @@ -202,7 +202,7 @@ struct EnumMin /** * Selects larger value */ -template +template struct EnumMax { enum { Result = (A > B) ? A : B }; diff --git a/libuavcan/src/marshal/uc_bit_stream.cpp b/libuavcan/src/marshal/uc_bit_stream.cpp index 0f4a52368..fba0153fb 100644 --- a/libuavcan/src/marshal/uc_bit_stream.cpp +++ b/libuavcan/src/marshal/uc_bit_stream.cpp @@ -84,7 +84,7 @@ std::string BitStream::toString() const for (unsigned offset = 0; true; offset++) { uint8_t byte = 0; - if (1U != buf_.read(offset, &byte, 1U)) + if (1 != buf_.read(offset, &byte, 1U)) { break; } diff --git a/libuavcan/src/transport/uc_can_acceptance_filter_configurator.cpp b/libuavcan/src/transport/uc_can_acceptance_filter_configurator.cpp index e468b3ca8..37f68e327 100644 --- a/libuavcan/src/transport/uc_can_acceptance_filter_configurator.cpp +++ b/libuavcan/src/transport/uc_can_acceptance_filter_configurator.cpp @@ -139,9 +139,9 @@ int CanAcceptanceFilterConfigurator::applyConfiguration(void) for (uint16_t i = 0; i < multiset_configs_.getSize(); i++) { UAVCAN_TRACE("CanAcceptanceFilterConfigurator::applyConfiguration()", "cfg.ID [%u] = %u", i, - multiset_configs_.getByIndex(i)->id); + static_cast(multiset_configs_.getByIndex(i)->id)); UAVCAN_TRACE("CanAcceptanceFilterConfigurator::applyConfiguration()", "cfg.MK [%u] = %u", i, - multiset_configs_.getByIndex(i)->mask); + static_cast(multiset_configs_.getByIndex(i)->mask)); } #endif diff --git a/libuavcan/test/helpers/heap_based_pool_allocator.cpp b/libuavcan/test/helpers/heap_based_pool_allocator.cpp index b1588675e..52dbb364b 100644 --- a/libuavcan/test/helpers/heap_based_pool_allocator.cpp +++ b/libuavcan/test/helpers/heap_based_pool_allocator.cpp @@ -4,13 +4,19 @@ #include #include +#ifdef __linux__ #include +#else +#include +#endif TEST(HeapBasedPoolAllocator, Basic) { +#ifdef __linux__ std::cout << ">>> HEAP BEFORE:" << std::endl; malloc_stats(); +#endif uavcan::HeapBasedPoolAllocator al(0xEEEE); @@ -61,8 +67,10 @@ TEST(HeapBasedPoolAllocator, Basic) ASSERT_EQ(0, al.getNumReservedBlocks()); ASSERT_EQ(0, al.getNumAllocatedBlocks()); +#ifdef __linux__ std::cout << ">>> HEAP AFTER:" << std::endl; malloc_stats(); +#endif } @@ -115,9 +123,11 @@ std::mutex RaiiSynchronizer::mutex; TEST(HeapBasedPoolAllocator, Concurrency) { +#ifdef __linux__ std::cout << ">>> HEAP BEFORE:" << std::endl; malloc_stats(); +#endif uavcan::HeapBasedPoolAllocator al(1000); ASSERT_EQ(1000, al.getBlockCapacity()); @@ -167,13 +177,17 @@ TEST(HeapBasedPoolAllocator, Concurrency) std::cout << "Allocated: " << al.getNumAllocatedBlocks() << std::endl; std::cout << "Reserved: " << al.getNumReservedBlocks() << std::endl; +#ifdef __linux__ std::cout << ">>> HEAP BEFORE SHRINK:" << std::endl; malloc_stats(); +#endif al.shrink(); +#ifdef __linux__ std::cout << ">>> HEAP AFTER SHRINK:" << std::endl; malloc_stats(); +#endif } #endif diff --git a/libuavcan/test/node/test_node.hpp b/libuavcan/test/node/test_node.hpp index 889b9d928..a8e6fc84f 100644 --- a/libuavcan/test/node/test_node.hpp +++ b/libuavcan/test/node/test_node.hpp @@ -5,8 +5,6 @@ #pragma once #if __GNUC__ -// We need auto_ptr for compatibility reasons -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" # pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" #endif @@ -217,7 +215,7 @@ struct TestNetwork { } }; - std::auto_ptr nodes[NumNodes]; + std::unique_ptr nodes[NumNodes]; TestNetwork(uavcan::uint8_t first_node_id = 1) { diff --git a/libuavcan/test/protocol/data_type_info_provider.cpp b/libuavcan/test/protocol/data_type_info_provider.cpp index 85141de7c..75e704b86 100644 --- a/libuavcan/test/protocol/data_type_info_provider.cpp +++ b/libuavcan/test/protocol/data_type_info_provider.cpp @@ -18,7 +18,7 @@ using uavcan::DefaultDataTypeRegistrator; using uavcan::MonotonicDuration; template -static bool validateDataTypeInfoResponse(const std::auto_ptr::Result>& resp, +static bool validateDataTypeInfoResponse(const std::unique_ptr::Result>& resp, unsigned flags) { if (!resp.get()) diff --git a/libuavcan/test/protocol/dynamic_node_id_server/distributed/server.cpp b/libuavcan/test/protocol/dynamic_node_id_server/distributed/server.cpp index 488b90551..e09fadda5 100644 --- a/libuavcan/test/protocol/dynamic_node_id_server/distributed/server.cpp +++ b/libuavcan/test/protocol/dynamic_node_id_server/distributed/server.cpp @@ -3,8 +3,6 @@ */ #if __GNUC__ -// We need auto_ptr for compatibility reasons -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" # pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" #endif @@ -57,8 +55,8 @@ TEST(dynamic_node_id_server_RaftCore, Basic) InterlinkedTestNodesWithSysClock nodes; - std::auto_ptr raft_a(new RaftCore(nodes.a, storage_a, tracer_a, commit_handler_a)); - std::auto_ptr raft_b(new RaftCore(nodes.b, storage_b, tracer_b, commit_handler_b)); + std::unique_ptr raft_a(new RaftCore(nodes.a, storage_a, tracer_a, commit_handler_a)); + std::unique_ptr raft_b(new RaftCore(nodes.b, storage_b, tracer_b, commit_handler_b)); /* * Initialization diff --git a/libuavcan/test/protocol/dynamic_node_id_server/node_discoverer.cpp b/libuavcan/test/protocol/dynamic_node_id_server/node_discoverer.cpp index 06780809b..64df33bae 100644 --- a/libuavcan/test/protocol/dynamic_node_id_server/node_discoverer.cpp +++ b/libuavcan/test/protocol/dynamic_node_id_server/node_discoverer.cpp @@ -3,8 +3,6 @@ */ #if __GNUC__ -// We need auto_ptr for compatibility reasons -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" # pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" #endif diff --git a/libuavcan/test/protocol/firmware_update_trigger.cpp b/libuavcan/test/protocol/firmware_update_trigger.cpp index cd8f112c3..a17e92c44 100644 --- a/libuavcan/test/protocol/firmware_update_trigger.cpp +++ b/libuavcan/test/protocol/firmware_update_trigger.cpp @@ -107,7 +107,7 @@ TEST(FirmwareUpdateTrigger, Basic) uavcan::FirmwareUpdateTrigger trigger(nodes.a, checker); std::cout << "sizeof(uavcan::FirmwareUpdateTrigger): " << sizeof(uavcan::FirmwareUpdateTrigger) << std::endl; - std::auto_ptr provider(new uavcan::NodeStatusProvider(nodes.b)); // Other node + std::unique_ptr provider(new uavcan::NodeStatusProvider(nodes.b)); // Other node /* * Initializing @@ -235,10 +235,10 @@ TEST(FirmwareUpdateTrigger, MultiNode) uavcan::FirmwareUpdateTrigger trigger(nodes[0], checker); // The client nodes - std::auto_ptr provider_a(new uavcan::NodeStatusProvider(nodes[1])); - std::auto_ptr provider_b(new uavcan::NodeStatusProvider(nodes[2])); - std::auto_ptr provider_c(new uavcan::NodeStatusProvider(nodes[3])); - std::auto_ptr provider_d(new uavcan::NodeStatusProvider(nodes[4])); + std::unique_ptr provider_a(new uavcan::NodeStatusProvider(nodes[1])); + std::unique_ptr provider_b(new uavcan::NodeStatusProvider(nodes[2])); + std::unique_ptr provider_c(new uavcan::NodeStatusProvider(nodes[3])); + std::unique_ptr provider_d(new uavcan::NodeStatusProvider(nodes[4])); uavcan::protocol::HardwareVersion hwver; diff --git a/libuavcan/test/protocol/helpers.hpp b/libuavcan/test/protocol/helpers.hpp index b1d2f9715..e399b483b 100644 --- a/libuavcan/test/protocol/helpers.hpp +++ b/libuavcan/test/protocol/helpers.hpp @@ -20,7 +20,7 @@ class SubscriptionCollector : uavcan::Noncopyable } public: - std::auto_ptr msg; + std::unique_ptr msg; typedef uavcan::MethodBinder Binder; @@ -85,7 +85,7 @@ class ServiceCallResultCollector : uavcan::Noncopyable } public: - std::auto_ptr result; + std::unique_ptr result; typedef uavcan::MethodBinder&)> diff --git a/libuavcan/test/protocol/node_info_retriever.cpp b/libuavcan/test/protocol/node_info_retriever.cpp index e7baa78c3..f0f1b5a9b 100644 --- a/libuavcan/test/protocol/node_info_retriever.cpp +++ b/libuavcan/test/protocol/node_info_retriever.cpp @@ -3,8 +3,6 @@ */ #if __GNUC__ -// We need auto_ptr for compatibility reasons -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" # pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" #endif @@ -27,7 +25,7 @@ static void publishNodeStatus(PairableCanDriver& can, uavcan::NodeID node_id, struct NodeInfoListener : public uavcan::INodeInfoListener { - std::auto_ptr last_node_info; + std::unique_ptr last_node_info; uavcan::NodeID last_node_id; unsigned status_message_cnt; unsigned status_change_cnt; @@ -82,7 +80,7 @@ TEST(NodeInfoRetriever, Basic) std::cout << "sizeof(uavcan::ServiceClient): " << sizeof(uavcan::ServiceClient) << std::endl; - std::auto_ptr provider(new uavcan::NodeStatusProvider(nodes.b)); + std::unique_ptr provider(new uavcan::NodeStatusProvider(nodes.b)); NodeInfoListener listener; diff --git a/libuavcan/test/test_main.cpp b/libuavcan/test/test_main.cpp index 37afc97aa..601b27b07 100644 --- a/libuavcan/test/test_main.cpp +++ b/libuavcan/test/test_main.cpp @@ -28,12 +28,16 @@ int main(int argc, char **argv) #ifndef UAVCAN_CPP_VERSION # error UAVCAN_CPP_VERSION #endif -#if UAVCAN_CPP_VERSION == UAVCAN_CPP11 +#if UAVCAN_CPP_VERSION == UAVCAN_CPP17 + std::cout << "C++17" << std::endl; +#elif UAVCAN_CPP_VERSION == UAVCAN_CPP14 + std::cout << "C++14" << std::endl; +#elif UAVCAN_CPP_VERSION == UAVCAN_CPP11 std::cout << "C++11" << std::endl; #elif UAVCAN_CPP_VERSION == UAVCAN_CPP03 std::cout << "C++03" << std::endl; #else -# error UAVCAN_CPP_VERSION + std::cout << "(unknown)" << std::endl; #endif ::testing::InitGoogleTest(&argc, argv); diff --git a/libuavcan/test/transport/dispatcher.cpp b/libuavcan/test/transport/dispatcher.cpp index 621ccf897..aa39a3128 100644 --- a/libuavcan/test/transport/dispatcher.cpp +++ b/libuavcan/test/transport/dispatcher.cpp @@ -84,7 +84,7 @@ TEST(Dispatcher, Reception) makeDataType(uavcan::DataTypeKindService, 1) }; - typedef std::auto_ptr TestListenerPtr; + typedef std::unique_ptr TestListenerPtr; static const int MaxBufSize = 512; static const int NumSubscribers = 6; TestListenerPtr subscribers[NumSubscribers] = diff --git a/libuavcan/test/transport/transfer_buffer.cpp b/libuavcan/test/transport/transfer_buffer.cpp index 9ed74bc7b..1a4ac031f 100644 --- a/libuavcan/test/transport/transfer_buffer.cpp +++ b/libuavcan/test/transport/transfer_buffer.cpp @@ -3,8 +3,6 @@ */ #if __GNUC__ -// We need auto_ptr for compatibility reasons -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" # pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" #endif @@ -238,7 +236,7 @@ TEST(TransferBufferManager, Basic) static const int POOL_BLOCKS = 100; uavcan::PoolAllocator pool; - std::auto_ptr mgr(new TransferBufferManager(MGR_MAX_BUFFER_SIZE, pool)); + std::unique_ptr mgr(new TransferBufferManager(MGR_MAX_BUFFER_SIZE, pool)); // Empty ASSERT_FALSE(mgr->access(TransferBufferManagerKey(0, uavcan::TransferTypeMessageBroadcast))); diff --git a/libuavcan/test/util/map.cpp b/libuavcan/test/util/map.cpp index 4dd2d2522..89c2faf81 100644 --- a/libuavcan/test/util/map.cpp +++ b/libuavcan/test/util/map.cpp @@ -3,8 +3,6 @@ */ #if __GNUC__ -// We need auto_ptr for compatibility reasons -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" # pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" #endif @@ -59,7 +57,7 @@ TEST(Map, Basic) uavcan::PoolAllocator pool; typedef Map MapType; - std::auto_ptr map(new MapType(pool)); + std::unique_ptr map(new MapType(pool)); // Empty ASSERT_FALSE(map->access("hi")); @@ -198,7 +196,7 @@ TEST(Map, PrimitiveKey) uavcan::PoolAllocator pool; typedef Map MapType; - std::auto_ptr map(new MapType(pool)); + std::unique_ptr map(new MapType(pool)); // Empty ASSERT_FALSE(map->access(1)); diff --git a/libuavcan/test/util/multiset.cpp b/libuavcan/test/util/multiset.cpp index 4d4212f7c..c3f227f86 100644 --- a/libuavcan/test/util/multiset.cpp +++ b/libuavcan/test/util/multiset.cpp @@ -3,8 +3,6 @@ */ #if __GNUC__ -// We need auto_ptr for compatibility reasons -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" # pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" #endif @@ -78,7 +76,7 @@ TEST(Multiset, Basic) uavcan::PoolAllocator pool; typedef Multiset MultisetType; - std::auto_ptr mset(new MultisetType(pool)); + std::unique_ptr mset(new MultisetType(pool)); typedef SummationOperator StringConcatenationOperator; @@ -199,7 +197,7 @@ TEST(Multiset, PrimitiveKey) uavcan::PoolAllocator pool; typedef Multiset MultisetType; - std::auto_ptr mset(new MultisetType(pool)); + std::unique_ptr mset(new MultisetType(pool)); // Empty mset->removeFirst(8); @@ -239,7 +237,7 @@ TEST(Multiset, NoncopyableWithCounter) uavcan::PoolAllocator pool; typedef Multiset MultisetType; - std::auto_ptr mset(new MultisetType(pool)); + std::unique_ptr mset(new MultisetType(pool)); ASSERT_EQ(0, NoncopyableWithCounter::num_objects); ASSERT_EQ(0, mset->emplace()->value); diff --git a/libuavcan_drivers/linux/CMakeLists.txt b/libuavcan_drivers/linux/CMakeLists.txt index 9577b227c..f96b41de3 100644 --- a/libuavcan_drivers/linux/CMakeLists.txt +++ b/libuavcan_drivers/linux/CMakeLists.txt @@ -43,7 +43,7 @@ endif () # Applications - tests, tools. # include_directories(include) -set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -std=c++11") # GCC or Clang +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -std=c++11") # GCC or Clang if(CMAKE_BUILD_TYPE STREQUAL "Debug") add_definitions(-DUAVCAN_DEBUG=1) diff --git a/libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp b/libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp index 978f708d3..ee0b561b4 100644 --- a/libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp +++ b/libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp @@ -369,7 +369,7 @@ void adjustUtc(uavcan::UtcDuration adjustment) { utc_locked = (std::abs(utc_rel_rate_ppm) < utc_sync_params.lock_thres_rate_ppm) && - (std::abs(utc_prev_adj) < utc_sync_params.lock_thres_offset.toUSec()); + (std::abs(utc_prev_adj) < float(utc_sync_params.lock_thres_offset.toUSec())); } } }