Skip to content

Commit

Permalink
Unit test fixes (opentx#6706)
Browse files Browse the repository at this point in the history
* remove downloaded gtest archive after unpacking

* moved horus test files to the build directory

* cleaned up X12S test file (removed subdirectory)
  • Loading branch information
raphaelcoeffic authored and bsongis committed Sep 4, 2019
1 parent e5d5f81 commit 52fca00
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 29 deletions.
7 changes: 3 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,13 @@ if(NOT GTEST_INCDIR OR NOT GTEST_SRCDIR)
set(GTEST_URL "https://github.com/google/googletest/archive/release-${GTEST_VERSION}.tar.gz")
set(GTEST_ARCHIVE "${RADIO_SRC_DIRECTORY}/tests/gtest-${GTEST_VERSION}.tar.gz")

if (NOT EXISTS "${GTEST_ARCHIVE}")
file(DOWNLOAD "${GTEST_URL}" ${GTEST_ARCHIVE} SHOW_PROGRESS)
endif()

if (NOT EXISTS "${GTEST_SRCDIR}")
file(DOWNLOAD "${GTEST_URL}" ${GTEST_ARCHIVE} SHOW_PROGRESS)
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar -xf ${GTEST_ARCHIVE}
WORKING_DIRECTORY ${RADIO_SRC_DIRECTORY}/tests)
execute_process(
COMMAND ${CMAKE_COMMAND} -E remove -f ${GTEST_ARCHIVE})
endif()
endif()

Expand Down
34 changes: 16 additions & 18 deletions radio/src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,29 @@ if(GTEST_INCDIR AND GTEST_SRCDIR AND Qt5Widgets_FOUND)
add_definitions(-DSIMU -DGTESTS)
remove_definitions(-DCLI)
set(TESTS_PATH ${RADIO_SRC_DIRECTORY}/tests)
set(TESTS_BUILD_PATH ${CMAKE_CURRENT_BINARY_DIR})
configure_file(${RADIO_SRC_DIRECTORY}/tests/location.h.in ${CMAKE_CURRENT_BINARY_DIR}/location.h @ONLY)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS_DEBUG} -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_DEBUG} -O0 ${WARNING_FLAGS}")
use_cxx11() # ensure gnu++11 in CXX_FLAGS with CMake < 3.1

if(PCB STREQUAL X12S OR PCB STREQUAL X10)
add_custom_command(
DEPENDS ${TESTS_PATH}/model_22_x10.otx
${TESTS_PATH}/model_22_x12s.otx
OUTPUT ${TESTS_PATH}/model_22_x10/RADIO/radio.bin ${TESTS_PATH}/model_22_x10/RADIO/models.txt ${TESTS_PATH}/model_22_x10/MODELS/model1.bin
${TESTS_PATH}/model_22_x12s/RADIO/radio.bin ${TESTS_PATH}/model_22_x12s/RADIO/models.txt ${TESTS_PATH}/model_22_x12s/MODELS/model1.bin
COMMAND mkdir -p model_22_x10 && cd model_22_x10 && unzip -o -DD ../model_22_x10.otx
COMMAND mkdir -p model_22_x12s && cd model_22_x12s && unzip -o -DD ../model_22_x12s.otx
WORKING_DIRECTORY ${TESTS_PATH}
)
add_custom_target(x10-model-test-files
DEPENDS ${TESTS_PATH}/model_22_x10/RADIO/radio.bin ${TESTS_PATH}/model_22_x10/RADIO/models.txt ${TESTS_PATH}/model_22_x10/MODELS/model1.bin
)
add_custom_target(x12s-model-test-files
DEPENDS ${TESTS_PATH}/model_22_x12s/RADIO/radio.bin ${TESTS_PATH}/model_22_x12s/RADIO/models.txt ${TESTS_PATH}/model_22_x12s/MODELS/model1.bin

set(EXTRACT_MODEL_FILES model_22_x12s model_22_x10)

foreach(model_file ${EXTRACT_MODEL_FILES})
add_custom_command(
DEPENDS ${TESTS_PATH}/${model_file}.otx
OUTPUT ${TESTS_BUILD_PATH}/${model_file}/RADIO/radio.bin
COMMAND mkdir -p ${model_file} && cd ${model_file} && unzip -o -q -DD ${TESTS_PATH}/${model_file}.otx >/dev/null
WORKING_DIRECTORY ${TESTS_BUILD_PATH}
)
add_custom_target(${model_file}_files
DEPENDS ${TESTS_BUILD_PATH}/${model_file}/RADIO/radio.bin
)
set(HORUS_MODEL_FILES ${HORUS_MODEL_FILES} ${model_file}_files)
endforeach()
endif()

if(WIN32)
Expand All @@ -54,10 +55,7 @@ if(GTEST_INCDIR AND GTEST_SRCDIR AND Qt5Widgets_FOUND)
add_executable(gtests-radio EXCLUDE_FROM_ALL ${TEST_SRC_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/location.h ${RADIO_SRC} ../targets/simu/simpgmspace.cpp ../targets/simu/simueeprom.cpp ../targets/simu/simufatfs.cpp)
add_dependencies(gtests-radio ${FIRMWARE_DEPENDENCIES} gtests-radio-lib)
if(PCB STREQUAL X12S OR PCB STREQUAL X10)
add_dependencies(gtests-radio
x10-model-test-files
x12s-model-test-files
)
add_dependencies(gtests-radio ${HORUS_MODEL_FILES})
endif()
target_link_libraries(gtests-radio gtests-radio-lib pthread Qt5::Core Qt5::Widgets)
message(STATUS "Added optional gtests target")
Expand Down
12 changes: 6 additions & 6 deletions radio/src/tests/conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void loadEEPROMFile(const char * filename)
#if defined(PCBX9DP)
TEST(Conversions, ConversionX9DPFrom22)
{
loadEEPROMFile(TESTS_PATH "/eeprom_22_x9d+.bin");
loadEEPROMFile(TESTS_BUILD_PATH "/eeprom_22_x9d+.bin");

eepromOpen();
eeLoadGeneralSettingsData();
Expand Down Expand Up @@ -72,7 +72,7 @@ TEST(Conversions, ConversionX9DPFrom22)

TEST(Conversions, ConversionX9DPFrom23)
{
loadEEPROMFile(TESTS_PATH "/eeprom_23_x9d+.bin");
loadEEPROMFile(TESTS_BUILD_PATH "/eeprom_23_x9d+.bin");

eepromOpen();
eeLoadGeneralSettingsData();
Expand Down Expand Up @@ -116,7 +116,7 @@ TEST(Conversions, ConversionX9DPFrom23)
#if defined(PCBXLITE)
TEST(Conversions, ConversionXLiteFrom22)
{
loadEEPROMFile(TESTS_PATH "/eeprom_22_xlite.bin");
loadEEPROMFile(TESTS_BUILD_PATH "/eeprom_22_xlite.bin");

eepromOpen();
eeLoadGeneralSettingsData();
Expand Down Expand Up @@ -164,7 +164,7 @@ TEST(Conversions, ConversionXLiteFrom22)
#if defined(PCBX7)
TEST(Conversions, ConversionX7From22)
{
loadEEPROMFile(TESTS_PATH "/eeprom_22_x7.bin");
loadEEPROMFile(TESTS_BUILD_PATH "/eeprom_22_x7.bin");

eepromOpen();
eeLoadGeneralSettingsData();
Expand Down Expand Up @@ -217,7 +217,7 @@ TEST(Conversions, ConversionX7From22)
#if defined(PCBX10)
TEST(Conversions, ConversionX10From22)
{
simuFatfsSetPaths(TESTS_PATH "/model_22_x10/", TESTS_PATH "/model_22_x10/");
simuFatfsSetPaths(TESTS_BUILD_PATH "/model_22_x10/", TESTS_BUILD_PATH "/model_22_x10/");

loadRadioSettings("/RADIO/radio.bin");
loadModel("model1.bin");
Expand Down Expand Up @@ -293,7 +293,7 @@ TEST(Conversions, ConversionX10From22)
#if defined(PCBX12S)
TEST(Conversions, ConversionX12SFrom22)
{
simuFatfsSetPaths(TESTS_PATH "/model_22_x12s/", TESTS_PATH "/model_22_x12s/");
simuFatfsSetPaths(TESTS_BUILD_PATH "/model_22_x12s/", TESTS_BUILD_PATH "/model_22_x12s/");

loadRadioSettings("/RADIO/radio.bin");
loadModel("model1.bin");
Expand Down
3 changes: 2 additions & 1 deletion radio/src/tests/location.h.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#define TESTS_PATH "@TESTS_PATH@"
#define TESTS_PATH "@TESTS_PATH@"
#define TESTS_BUILD_PATH "@TESTS_BUILD_PATH@"
Binary file modified radio/src/tests/model_22_x12s.otx
Binary file not shown.

0 comments on commit 52fca00

Please sign in to comment.