Build system updates, including -Werror on TravisCI (#4202)
* [TravisCI] Build using avr-gcc 4.9.2 (up from 4.8.2). Relies on https://github.com/opentx/opentx/pull/4169 . Fixes all linker warnings, makes clean build. * [build] Add ARM/AVR compiler version check/display and a workaround for avr-gcc linker warnings when using WARNINGS_AS_ERRORS=true. * [TravisCI] Enable -Werror on all build targets (WARNINGS_AS_ERRORS=true). * [build] CMake script updates: Enable WARNINGS_AS_ERRORS option for all targets (not just firmware); Consolidate some C/CXX flag settings for firmware target, avoid duplication/redundancy; All warning flags are now passed to linker (GCC only); Add a "build report" for each main target showing compiler, flags, and defines, with verbosity controlled by new VERBOSE_CMAKELISTS option; Added properties to PCB, TRANSLATIONS, and a few other options (makes option selector lists in cmake-gui); Add macro for conditionally adding C++11 flag; Silence CMake >3.0 warnings about CMP0054 policy not being set; Reverts AVR linker -Werror workaround; Misc. cleanup/consolidation. * [build] More CMakeLists updates: Silence superfluous "CRT_SECURE" series MSVC warnings; Formalize finding pthread lib/dll on MSVC builds and fix some issues with install target script; Add property string lists to more options; Quotes some paths with possible spaces, & other minor cosmetics. * [build] firmware/bootloader: Remove remaining CMake default compiler flags and add FIRMWARE_C[XX}_FLAGS[_DEBUG] options for user to specify additional flags. Also move ASM language call to silence CMake warning w/MSVC. * [build] Workaround bogus "uninitialized" warnings from AVR linker. * [tests] Add custom printer for less verbose gtest output (use --verbose option to revert to gtest default). * [build] Use less verbose CMake output for TravisCI builds. Formalize search for gtest code and enable gtests target on WIN32-GCC. Minor language fix.
This commit is contained in:
committed by
Bertrand Songis
parent
54742fcad9
commit
1f788723f9
@@ -1,38 +1,46 @@
|
||||
set(GTEST_INCDIR /usr/include/gtest CACHE string "Location of Google Test includes")
|
||||
set(GTEST_SRCDIR /usr/src/gtest CACHE string "Location of Google Test directory")
|
||||
set(GTEST_ROOT /usr CACHE string "Base path to Google Test headers and source.")
|
||||
|
||||
if(EXISTS "${GTEST_SRCDIR}/src/gtest-all.cc")
|
||||
if(Qt5Widgets_FOUND)
|
||||
add_library(gtests-lib STATIC EXCLUDE_FROM_ALL ${GTEST_SRCDIR}/src/gtest-all.cc )
|
||||
target_include_directories(gtests-lib PUBLIC ${GTEST_INCDIR} PUBLIC ${GTEST_SRCDIR})
|
||||
add_definitions(-DSIMU)
|
||||
set(TESTS_PATH ${RADIO_SRC_DIRECTORY})
|
||||
configure_file(${RADIO_SRC_DIRECTORY}/tests/location.h.in ${CMAKE_CURRENT_BINARY_DIR}/location.h @ONLY)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
find_path(GTEST_INCDIR gtest/gtest.h HINTS "${GTEST_ROOT}/include" DOC "Path to Google Test header files folder ('gtest/gtest.h').")
|
||||
find_path(GTEST_SRCDIR src/gtest-all.cc HINTS "${GTEST_ROOT}" "${GTEST_ROOT}/src/gtest" DOC "Path of Google Test 'src' folder.")
|
||||
|
||||
foreach(FILE ${SRC})
|
||||
set(RADIO_SRC ${RADIO_SRC} ../${FILE})
|
||||
endforeach()
|
||||
|
||||
file(GLOB TEST_SRC_FILES ${RADIO_SRC_DIRECTORY}/tests/*.cpp)
|
||||
|
||||
if (${CMAKE_VERSION} VERSION_LESS 3.1.0})
|
||||
set(COMMON_CPP_FLAGS "${COMMON_FLAGS} -std=gnu++11")
|
||||
message("USING -std=gnu++11")
|
||||
else()
|
||||
set(COMMON_CPP_FLAGS ${COMMON_FLAGS})
|
||||
endif()
|
||||
set(CMAKE_C_FLAGS_DEBUG "${COMMON_FLAGS} -g -O0")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${COMMON_CPP_FLAGS} -g -O0")
|
||||
|
||||
add_executable(gtests EXCLUDE_FROM_ALL ${TEST_SRC_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/location.h ${RADIO_SRC} ../targets/simu/simpgmspace.cpp ../targets/simu/simueeprom.cpp)
|
||||
qt5_use_modules(gtests Core Widgets)
|
||||
add_dependencies(gtests ${FIRMWARE_DEPENDENCIES} gtests-lib)
|
||||
target_link_libraries(gtests gtests-lib pthread)
|
||||
message("Added optional gtests target")
|
||||
else()
|
||||
message("WARNING: Qt5 widgets not found, gtest target will not be available!")
|
||||
if(GTEST_INCDIR AND GTEST_SRCDIR AND Qt5Widgets_FOUND)
|
||||
add_library(gtests-lib STATIC EXCLUDE_FROM_ALL ${GTEST_SRCDIR}/src/gtest-all.cc )
|
||||
target_include_directories(gtests-lib PUBLIC ${GTEST_INCDIR} ${GTEST_INCDIR}/gtest ${GTEST_SRCDIR})
|
||||
add_definitions(-DSIMU)
|
||||
set(TESTS_PATH ${RADIO_SRC_DIRECTORY})
|
||||
configure_file(${RADIO_SRC_DIRECTORY}/tests/location.h.in ${CMAKE_CURRENT_BINARY_DIR}/location.h @ONLY)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
if(WIN32)
|
||||
target_include_directories(gtests-lib PUBLIC ${WIN_INCLUDE_DIRS})
|
||||
target_link_libraries(gtests-lib PRIVATE ${WIN_LINK_LIBRARIES})
|
||||
endif(WIN32)
|
||||
|
||||
if(SDL_FOUND AND SIMU_AUDIO)
|
||||
target_include_directories(gtests-lib PUBLIC ${SDL_INCLUDE_DIR})
|
||||
target_link_libraries(gtests-lib PRIVATE ${SDL_LIBRARY})
|
||||
endif()
|
||||
|
||||
foreach(FILE ${SRC})
|
||||
set(RADIO_SRC ${RADIO_SRC} ../${FILE})
|
||||
endforeach()
|
||||
|
||||
file(GLOB TEST_SRC_FILES ${RADIO_SRC_DIRECTORY}/tests/*.cpp)
|
||||
|
||||
if(MINGW)
|
||||
# struct packing breaks on MinGW w/out -mno-ms-bitfields: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991 & http://stackoverflow.com/questions/24015852/struct-packing-and-alignment-with-mingw
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mno-ms-bitfields")
|
||||
endif()
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
|
||||
|
||||
use_cxx11() # ensure gnu++11 in CXX_FLAGS with CMake < 3.1
|
||||
|
||||
add_executable(gtests EXCLUDE_FROM_ALL ${TEST_SRC_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/location.h ${RADIO_SRC} ../targets/simu/simpgmspace.cpp ../targets/simu/simueeprom.cpp)
|
||||
qt5_use_modules(gtests Core Widgets)
|
||||
add_dependencies(gtests ${FIRMWARE_DEPENDENCIES} gtests-lib)
|
||||
target_link_libraries(gtests gtests-lib pthread)
|
||||
message(STATUS "Added optional gtests target")
|
||||
else()
|
||||
message("WARNING: can't find gtests source, gtest target will not be available!")
|
||||
message(WARNING "WARNING: gtests target will not be available (check that GTEST_INCDIR, GTEST_SRCDIR, and Qt5Widgets are configured).")
|
||||
endif()
|
||||
|
||||
+111
-1
@@ -19,8 +19,106 @@
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <memory>
|
||||
#include "gtests.h"
|
||||
|
||||
using ::testing::TestEventListener;
|
||||
using ::testing::EmptyTestEventListener;
|
||||
using ::testing::Test;
|
||||
using ::testing::TestCase;
|
||||
using ::testing::TestEventListeners;
|
||||
using ::testing::TestInfo;
|
||||
using ::testing::TestPartResult;
|
||||
using ::testing::UnitTest;
|
||||
using ::testing::InitGoogleTest;
|
||||
|
||||
namespace {
|
||||
|
||||
void printColorCode(int color)
|
||||
{
|
||||
#if !GTEST_OS_WINDOWS
|
||||
if (isatty(fileno(stdout)))
|
||||
fprintf(stdout, "\033[0;%dm", color);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces gtest's PrettyUnitTestResultPrinter with something less verbose.
|
||||
* Uses the default printer if/when the messages might be interesting,
|
||||
* e.g. for full error info or tests summary.
|
||||
*/
|
||||
class TersePrinter : public EmptyTestEventListener {
|
||||
public:
|
||||
explicit TersePrinter(TestEventListener * prettyPrinter)
|
||||
: prettyPrinter(prettyPrinter), currentTestInfo(NULL)
|
||||
{
|
||||
}
|
||||
void OnTestProgramStart(const UnitTest & unit_test)
|
||||
{
|
||||
prettyPrinter->OnTestProgramStart(unit_test);
|
||||
}
|
||||
void OnTestIterationStart(const UnitTest & unit_test, int iteration)
|
||||
{
|
||||
printColorCode(36);
|
||||
fprintf(stdout, "############ ");
|
||||
fprintf(stdout, "Running %d test(s) from %d test case(s), iteration: %d.\n", unit_test.test_to_run_count(), unit_test.test_case_to_run_count(), iteration + 1);
|
||||
printColorCode(0);
|
||||
fflush(stdout);
|
||||
}
|
||||
void OnTestCaseStart(const TestCase & test_case)
|
||||
{
|
||||
prettyPrinter->OnTestCaseStart(test_case);
|
||||
}
|
||||
void OnTestStart(const TestInfo & test_info)
|
||||
{
|
||||
currentTestInfo = &test_info;
|
||||
}
|
||||
void OnTestPartResult(const TestPartResult & test_part_result)
|
||||
{
|
||||
if (test_part_result.failed()) {
|
||||
prettyPrinter->OnTestStart(*currentTestInfo);
|
||||
prettyPrinter->OnTestPartResult(test_part_result);
|
||||
}
|
||||
}
|
||||
void OnTestEnd(const TestInfo & test_info)
|
||||
{
|
||||
currentTestInfo = NULL;
|
||||
if (test_info.result()->Failed()) {
|
||||
prettyPrinter->OnTestEnd(test_info);
|
||||
}
|
||||
else {
|
||||
printColorCode(32);
|
||||
fprintf(stdout, "+");
|
||||
printColorCode(0);
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
void OnTestCaseEnd(const TestCase & test_case)
|
||||
{
|
||||
fprintf(stdout, "\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
void OnTestIterationEnd(const UnitTest & unit_test, int iteration)
|
||||
{
|
||||
prettyPrinter->OnTestIterationEnd(unit_test, iteration);
|
||||
}
|
||||
void OnTestProgramEnd(const UnitTest & unit_test)
|
||||
{
|
||||
prettyPrinter->OnTestProgramEnd(unit_test);
|
||||
}
|
||||
|
||||
private:
|
||||
// gtest's default unit test result printer.
|
||||
std::unique_ptr<TestEventListener> prettyPrinter;
|
||||
// The currently running TestInfo, if any.
|
||||
const TestInfo * currentTestInfo;
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int32_t lastAct = 0;
|
||||
uint16_t anaInValues[NUM_STICKS+NUM_POTS+NUM_SLIDERS] = { 0 };
|
||||
uint16_t anaIn(uint8_t chan)
|
||||
@@ -53,6 +151,18 @@ int main(int argc, char **argv)
|
||||
StartEepromThread(NULL);
|
||||
menuLevel = 0;
|
||||
menuHandlers[0] = menuMainView;
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
InitGoogleTest(&argc, argv);
|
||||
|
||||
// use --verbose option to revert to gtest's default output format
|
||||
bool verbose = false;
|
||||
if (argc > 1 && !strcmp(argv[1], "--verbose"))
|
||||
verbose = true;
|
||||
|
||||
if (!verbose) {
|
||||
TestEventListeners & listeners = UnitTest::GetInstance()->listeners();
|
||||
TestEventListener * defaultPrinter = listeners.Release(listeners.default_result_printer());
|
||||
listeners.Append(new TersePrinter(defaultPrinter));
|
||||
}
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user