Fixup test building in cmake and path injection

This commit is contained in:
Ben Brown
2025-07-08 22:17:09 +10:00
parent e598bdb002
commit 027b7d8c51
7 changed files with 39 additions and 84 deletions
+15
View File
@@ -105,6 +105,21 @@ endif()
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/hex/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)
target_link_libraries(dfu_file_test
PRIVATE
GTest::GTest
)
include(GoogleTest)
include_directories(dfu_file_test PRIVATE ../ ../../)
add_test(dfu_file_test_gtests 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)
target_compile_definitions(dfu_file_test PUBLIC "SOURCE_DIR=\"${CMAKE_SOURCE_DIR}\"")
gtest_discover_tests(dfu_file_test)
@@ -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.
//
#include "Config.h"
#include "dfu_file.h"
#include <gtest/gtest.h>
#include "dfu_file.h"
TEST(DFU_FILE_PARSER, ParseTestFile) {
uint8_t* payload = nullptr;
size_t payload_size = 0;
size_t payload_address = 0;
int res = dfu_file_parse(SOURCE_DIR "/test.dfu", &payload, &payload_size,
&payload_address);
ASSERT_EQ(res, 1);
ASSERT_EQ(payload_size, 1337);
ASSERT_EQ(payload_address, 0x11223344);
}
uint8_t* payload = nullptr;
size_t payload_size = 0;
size_t payload_address = 0;
int res = dfu_file_parse(SOURCE_DIR
"/tools/blisp/src/file_parsers/dfu/tests/test.dfu",
&payload, &payload_size, &payload_address);
ASSERT_EQ(res, 1);
ASSERT_EQ(payload_size, 1337);
ASSERT_EQ(payload_address, 0x11223344);
}
@@ -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(hex_file_test test_hex_file.cpp ../hex_file.c)
add_executable(hex_file_test test_hex_file.cpp ../hex_file.c )
target_link_libraries(hex_file_test
PRIVATE
GTest::GTest
)
include(GoogleTest)
include_directories(hex_file_test PRIVATE ../ ../../)
add_test(hex_file_test_gtests 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)
target_compile_definitions(hex_file_test PUBLIC "SOURCE_DIR=\"${CMAKE_SOURCE_DIR}\"")
gtest_discover_tests(hex_file_test)
@@ -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 @@
//
// Created for Intel HEX file tests
//
// Intel hex file parser test
#include <gtest/gtest.h>
#include "Config.h"
#include "hex_file.h"
#include "parse_file.h"
@@ -11,10 +8,11 @@ TEST(HEX_FILE_PARSER, ParseTestFile) {
uint8_t* payload = nullptr;
size_t payload_size = 0;
size_t payload_address = 0;
int res = hex_file_parse(SOURCE_DIR "/test.hex", &payload, &payload_size,
&payload_address);
ASSERT_EQ(res, 1);
int res = hex_file_parse(SOURCE_DIR
"/tools/blisp/src/file_parsers/hex/tests/test.hex",
&payload, &payload_size, &payload_address);
// Shall return 0 on success
ASSERT_EQ(res, 0);
// The expected base address is 0x230F0000 + 0xFC00 = 0x230FFC00
ASSERT_EQ(payload_address, 0x230FFC00);
// There are 7 data records of 16 bytes each, so payload size should be 0x70