mirror of
https://github.com/pine64/blisp.git
synced 2026-09-18 17:31:30 +00:00
Fixup test building in cmake and path injection
This commit is contained in:
@@ -105,6 +105,21 @@ endif()
|
|||||||
|
|
||||||
|
|
||||||
if(COMPILE_TESTS)
|
if(COMPILE_TESTS)
|
||||||
|
# Bring in googletest & C++
|
||||||
|
enable_language(CXX)
|
||||||
|
enable_testing()
|
||||||
|
include(FetchContent)
|
||||||
|
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
googletest
|
||||||
|
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||||
|
GIT_TAG v1.17.0
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(googletest)
|
||||||
|
add_library(GTest::GTest INTERFACE IMPORTED)
|
||||||
|
target_link_libraries(GTest::GTest INTERFACE gtest_main)
|
||||||
|
|
||||||
add_subdirectory(tools/blisp/src/file_parsers/dfu/tests)
|
add_subdirectory(tools/blisp/src/file_parsers/dfu/tests)
|
||||||
add_subdirectory(tools/blisp/src/file_parsers/hex/tests)
|
add_subdirectory(tools/blisp/src/file_parsers/hex/tests)
|
||||||
endif(COMPILE_TESTS)
|
endif(COMPILE_TESTS)
|
||||||
|
|||||||
@@ -1,29 +1,10 @@
|
|||||||
enable_language(CXX)
|
|
||||||
|
|
||||||
enable_testing()
|
|
||||||
include(FetchContent)
|
|
||||||
|
|
||||||
|
|
||||||
FetchContent_Declare(
|
|
||||||
googletest
|
|
||||||
GIT_REPOSITORY https://github.com/google/googletest.git
|
|
||||||
GIT_TAG v1.17.0
|
|
||||||
)
|
|
||||||
FetchContent_MakeAvailable(googletest)
|
|
||||||
add_library(GTest::GTest INTERFACE IMPORTED)
|
|
||||||
target_link_libraries(GTest::GTest INTERFACE gtest_main)
|
|
||||||
|
|
||||||
|
|
||||||
add_executable(dfu_file_test test_dfu_file.cpp ../dfu_file.c ../dfu_crc.c ../../get_file_contents.c)
|
add_executable(dfu_file_test test_dfu_file.cpp ../dfu_file.c ../dfu_crc.c ../../get_file_contents.c)
|
||||||
|
|
||||||
target_link_libraries(dfu_file_test
|
target_link_libraries(dfu_file_test
|
||||||
PRIVATE
|
PRIVATE
|
||||||
GTest::GTest
|
GTest::GTest
|
||||||
)
|
)
|
||||||
|
include(GoogleTest)
|
||||||
include_directories(dfu_file_test PRIVATE ../ ../../)
|
include_directories(dfu_file_test PRIVATE ../ ../../)
|
||||||
add_test(dfu_file_test_gtests dfu_file_test)
|
target_compile_definitions(dfu_file_test PUBLIC "SOURCE_DIR=\"${CMAKE_SOURCE_DIR}\"")
|
||||||
|
gtest_discover_tests(dfu_file_test)
|
||||||
configure_file(Config.h.in ${CMAKE_BINARY_DIR}/Config.h)
|
|
||||||
include_directories(${CMAKE_BINARY_DIR})
|
|
||||||
|
|
||||||
set(TEST_APP_NAME dfu_file_tests)
|
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by ralim on 26/09/22.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef BLISP_CONFIG_H_IN_H
|
|
||||||
#define BLISP_CONFIG_H_IN_H
|
|
||||||
|
|
||||||
#define SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
|
|
||||||
|
|
||||||
#endif // BLISP_CONFIG_H_IN_H
|
|
||||||
@@ -2,16 +2,16 @@
|
|||||||
// Created by ralim on 26/09/22.
|
// Created by ralim on 26/09/22.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "Config.h"
|
|
||||||
#include "dfu_file.h"
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include "dfu_file.h"
|
||||||
TEST(DFU_FILE_PARSER, ParseTestFile) {
|
TEST(DFU_FILE_PARSER, ParseTestFile) {
|
||||||
uint8_t* payload = nullptr;
|
uint8_t* payload = nullptr;
|
||||||
size_t payload_size = 0;
|
size_t payload_size = 0;
|
||||||
size_t payload_address = 0;
|
size_t payload_address = 0;
|
||||||
int res = dfu_file_parse(SOURCE_DIR "/test.dfu", &payload, &payload_size,
|
int res = dfu_file_parse(SOURCE_DIR
|
||||||
&payload_address);
|
"/tools/blisp/src/file_parsers/dfu/tests/test.dfu",
|
||||||
ASSERT_EQ(res, 1);
|
&payload, &payload_size, &payload_address);
|
||||||
ASSERT_EQ(payload_size, 1337);
|
ASSERT_EQ(res, 1);
|
||||||
ASSERT_EQ(payload_address, 0x11223344);
|
ASSERT_EQ(payload_size, 1337);
|
||||||
}
|
ASSERT_EQ(payload_address, 0x11223344);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,29 +1,10 @@
|
|||||||
enable_language(CXX)
|
add_executable(hex_file_test test_hex_file.cpp ../hex_file.c )
|
||||||
|
|
||||||
enable_testing()
|
|
||||||
include(FetchContent)
|
|
||||||
|
|
||||||
|
|
||||||
FetchContent_Declare(
|
|
||||||
googletest
|
|
||||||
GIT_REPOSITORY https://github.com/google/googletest.git
|
|
||||||
GIT_TAG v1.17.0
|
|
||||||
)
|
|
||||||
FetchContent_MakeAvailable(googletest)
|
|
||||||
add_library(GTest::GTest INTERFACE IMPORTED)
|
|
||||||
target_link_libraries(GTest::GTest INTERFACE gtest_main)
|
|
||||||
|
|
||||||
|
|
||||||
add_executable(hex_file_test test_hex_file.cpp ../hex_file.c)
|
|
||||||
|
|
||||||
target_link_libraries(hex_file_test
|
target_link_libraries(hex_file_test
|
||||||
PRIVATE
|
PRIVATE
|
||||||
GTest::GTest
|
GTest::GTest
|
||||||
)
|
)
|
||||||
|
include(GoogleTest)
|
||||||
include_directories(hex_file_test PRIVATE ../ ../../)
|
include_directories(hex_file_test PRIVATE ../ ../../)
|
||||||
add_test(hex_file_test_gtests hex_file_test)
|
target_compile_definitions(hex_file_test PUBLIC "SOURCE_DIR=\"${CMAKE_SOURCE_DIR}\"")
|
||||||
|
gtest_discover_tests(hex_file_test)
|
||||||
configure_file(Config.h.in ${CMAKE_BINARY_DIR}/Config.h)
|
|
||||||
include_directories(${CMAKE_BINARY_DIR})
|
|
||||||
|
|
||||||
set(TEST_APP_NAME hex_file_tests)
|
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
//
|
|
||||||
// Created for Intel HEX file tests
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef HEX_FILE_TESTS_CONFIG_H
|
|
||||||
#define HEX_FILE_TESTS_CONFIG_H
|
|
||||||
|
|
||||||
#define SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
|
|
||||||
|
|
||||||
#endif // HEX_FILE_TESTS_CONFIG_H
|
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
//
|
// Intel hex file parser test
|
||||||
// Created for Intel HEX file tests
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include "Config.h"
|
|
||||||
#include "hex_file.h"
|
#include "hex_file.h"
|
||||||
#include "parse_file.h"
|
#include "parse_file.h"
|
||||||
|
|
||||||
@@ -11,10 +8,11 @@ TEST(HEX_FILE_PARSER, ParseTestFile) {
|
|||||||
uint8_t* payload = nullptr;
|
uint8_t* payload = nullptr;
|
||||||
size_t payload_size = 0;
|
size_t payload_size = 0;
|
||||||
size_t payload_address = 0;
|
size_t payload_address = 0;
|
||||||
int res = hex_file_parse(SOURCE_DIR "/test.hex", &payload, &payload_size,
|
int res = hex_file_parse(SOURCE_DIR
|
||||||
&payload_address);
|
"/tools/blisp/src/file_parsers/hex/tests/test.hex",
|
||||||
|
&payload, &payload_size, &payload_address);
|
||||||
ASSERT_EQ(res, 1);
|
// Shall return 0 on success
|
||||||
|
ASSERT_EQ(res, 0);
|
||||||
// The expected base address is 0x230F0000 + 0xFC00 = 0x230FFC00
|
// The expected base address is 0x230F0000 + 0xFC00 = 0x230FFC00
|
||||||
ASSERT_EQ(payload_address, 0x230FFC00);
|
ASSERT_EQ(payload_address, 0x230FFC00);
|
||||||
// There are 7 data records of 16 bytes each, so payload size should be 0x70
|
// There are 7 data records of 16 bytes each, so payload size should be 0x70
|
||||||
|
|||||||
Reference in New Issue
Block a user