mirror of
https://github.com/meekrosoft/fff
synced 2026-01-29 03:04:27 +01:00
Migrate build to CMake and standard github workflows
Replace makefiles with CMakeLists.txt. This will allow for IDE and platform agnostic builds of FFF. Update the CI for FFF to use github workflows which don't depend on MS VC. The workflow added will verify the pull requests sent to master buy running 'buildandtest' which mirrors the developer workflow. Signed-off-by: Yuval Peress <peress@google.com>
This commit is contained in:
6
examples/CMakeLists.txt
Normal file
6
examples/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
# Copyright 2022 Google LLC
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
add_subdirectory(driver_testing)
|
||||
add_subdirectory(embedded_ui)
|
||||
add_subdirectory(weak_linking)
|
||||
@@ -1,9 +0,0 @@
|
||||
all:
|
||||
cd embedded_ui; $(MAKE) all
|
||||
cd driver_testing; $(MAKE) all
|
||||
cd weak_linking; $(MAKE) all
|
||||
clean:
|
||||
cd embedded_ui; $(MAKE) clean
|
||||
cd driver_testing; $(MAKE) clean
|
||||
cd weak_linking; $(MAKE) clean
|
||||
|
||||
31
examples/driver_testing/CMakeLists.txt
Normal file
31
examples/driver_testing/CMakeLists.txt
Normal file
@@ -0,0 +1,31 @@
|
||||
# Copyright 2022 Google LLC
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# Create the driver test binary
|
||||
add_executable(driver_test
|
||||
src/driver.c
|
||||
src/driver.test.cpp
|
||||
)
|
||||
target_include_directories(driver_test PRIVATE include)
|
||||
target_link_libraries(driver_test PRIVATE gtest fff)
|
||||
target_compile_definitions(driver_test PUBLIC TEST_USER_OWN_TR1_TUPLE=1 TESTING)
|
||||
|
||||
# Create the driver fff test binary
|
||||
add_executable(driver_fff_test
|
||||
src/driver.c
|
||||
src/driver.test.fff.cpp
|
||||
)
|
||||
target_include_directories(driver_fff_test PRIVATE include)
|
||||
target_link_libraries(driver_fff_test PRIVATE gtest fff)
|
||||
target_compile_definitions(driver_fff_test PUBLIC TEST_USER_OWN_TR1_TUPLE=1 TESTING)
|
||||
|
||||
# Add tests to ctest
|
||||
add_test(
|
||||
NAME driver_test
|
||||
COMMAND $<TARGET_FILE:driver_test>
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME driver_fff_test
|
||||
COMMAND $<TARGET_FILE:driver_fff_test>
|
||||
)
|
||||
@@ -1,64 +0,0 @@
|
||||
$(VERBOSE).SILENT:
|
||||
|
||||
BUILD_DIR = ../../build
|
||||
TEMPLATE_PROGNAME = $(BUILD_DIR)/template
|
||||
CPP_PROGNAME_NOFFF = $(BUILD_DIR)/driver_testing
|
||||
CPP_PROGNAME_FFF = $(BUILD_DIR)/driver_testing_fff
|
||||
CC = gcc
|
||||
CC += -c
|
||||
CPP = g++
|
||||
CPP += -c
|
||||
LD = g++
|
||||
|
||||
GTEST_OBJS = $(BUILD_DIR)/gtest-all.o $(BUILD_DIR)/gtest-main.o
|
||||
C_OBJFILES = $(BUILD_DIR)/driver.o
|
||||
TEMPLATE_OBJFILES = $(BUILD_DIR)/test_suite_template.o
|
||||
FFF_OBJFILES = $(BUILD_DIR)/driver.test.fff.o $(GTEST_OBJS)
|
||||
NOFFF_OBJFILES = $(BUILD_DIR)/driver.test.o $(GTEST_OBJS)
|
||||
CPP_LIBS = -lpthread
|
||||
|
||||
|
||||
all: $(CPP_PROGNAME_NOFFF) $(CPP_PROGNAME_FFF) $(TEMPLATE_PROGNAME)
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
clean:
|
||||
@echo "Cleaning object files"
|
||||
@echo " rm -f $(BUILD_DIR)/*.o"
|
||||
rm -f $(BUILD_DIR)/*.o
|
||||
@echo "Cleaning backups"
|
||||
@echo " rm -f *~"
|
||||
rm -f *~
|
||||
@echo "Removing programs"
|
||||
@echo " rm -f $(CPP_PROGNAME_NOFFF) $(CPP_PROGNAME_FFF) $(TEMPLATE_PROGNAME)"
|
||||
rm -f $(CPP_PROGNAME_NOFFF) $(CPP_PROGNAME_FFF) $(TEMPLATE_PROGNAME)
|
||||
|
||||
|
||||
$(BUILD_DIR)/%.o: %.c
|
||||
@echo "Compiling "$@
|
||||
@echo " CC "$<
|
||||
$(CC) -o $@ $< -DTESTING
|
||||
|
||||
$(BUILD_DIR)/%.o: %.cpp
|
||||
@echo "Compiling "$@
|
||||
@echo " CPP "$<
|
||||
$(CPP) -DGTEST_USE_OWN_TR1_TUPLE=1 -I../.. -o $@ $< -DTESTING
|
||||
|
||||
$(TEMPLATE_PROGNAME): $(TEMPLATE_OBJFILES)
|
||||
@echo "Linking "$@
|
||||
@echo " LD -o "ctemplate" "$(TEMPLATE_OBJFILES)
|
||||
$(LD) -o $(TEMPLATE_PROGNAME) $(TEMPLATE_OBJFILES)
|
||||
|
||||
$(CPP_PROGNAME_FFF): $(FFF_OBJFILES) $(C_OBJFILES)
|
||||
@echo "Linking "$@
|
||||
@echo " LD -o "$(CPP_PROGNAME_FFF)" "$(FFF_OBJFILES)
|
||||
$(LD) -o $(CPP_PROGNAME_FFF) $(FFF_OBJFILES) $(C_OBJFILES) $(CPP_LIBS)
|
||||
|
||||
$(CPP_PROGNAME_NOFFF): $(NOFFF_OBJFILES) $(C_OBJFILES)
|
||||
@echo "Linking "$@
|
||||
@echo " LD -o "$(CPP_PROGNAME_NOFFF)" "$(NOFFF_OBJFILES)
|
||||
$(LD) -o $(CPP_PROGNAME_NOFFF) $(NOFFF_OBJFILES) $(C_OBJFILES) $(CPP_LIBS)
|
||||
|
||||
nothing:
|
||||
@echo "Nothing to do; quitting :("
|
||||
@echo "HINT: Try make all"
|
||||
@@ -3,7 +3,7 @@ extern "C"
|
||||
#include "driver.h"
|
||||
#include "registers.h"
|
||||
}
|
||||
#include "../../fff.h"
|
||||
#include "../../../fff.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ extern "C"{
|
||||
#include "registers.h"
|
||||
#include "hardware_abstraction.h"
|
||||
}
|
||||
#include "../../fff.h"
|
||||
#include "fff.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
DEFINE_FFF_GLOBALS;
|
||||
23
examples/embedded_ui/CMakeLists.txt
Normal file
23
examples/embedded_ui/CMakeLists.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
# Copyright 2022 Google LLC
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# Create the ui_test_ansic test binary
|
||||
add_executable(ui_test_ansic src/UI_test_ansic.c src/UI.c)
|
||||
target_include_directories(ui_test_ansic PRIVATE include)
|
||||
target_link_libraries(ui_test_ansic PRIVATE fff)
|
||||
|
||||
# Create the ui_test_cpp test binary
|
||||
add_executable(ui_test_cpp src/UI_test_cpp.cpp src/UI.c)
|
||||
target_include_directories(ui_test_cpp PRIVATE include)
|
||||
target_link_libraries(ui_test_cpp PRIVATE gtest fff)
|
||||
|
||||
# Add tests to ctest
|
||||
add_test(
|
||||
NAME ui_test_ansic
|
||||
COMMAND $<TARGET_FILE:ui_test_ansic>
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME ui_test_cpp
|
||||
COMMAND $<TARGET_FILE:ui_test_cpp>
|
||||
)
|
||||
@@ -1,67 +0,0 @@
|
||||
$(VERBOSE).SILENT:
|
||||
|
||||
BUILD_DIR = ../../build
|
||||
TEMPLATE_PROGNAME = $(BUILD_DIR)/template
|
||||
C_PROGNAME = $(BUILD_DIR)/ui_test_ansic
|
||||
CPP_PROGNAME = $(BUILD_DIR)/ui_test_cpp
|
||||
CC = gcc
|
||||
CC += -c
|
||||
CPP = g++
|
||||
CPP += -c
|
||||
LD = g++
|
||||
|
||||
GTEST_OBJS = $(BUILD_DIR)/gtest-all.o $(BUILD_DIR)/gtest-main.o
|
||||
C_OBJFILES = $(BUILD_DIR)/UI_test_ansic.o $(BUILD_DIR)/UI.o
|
||||
TEMPLATE_OBJFILES = $(BUILD_DIR)/test_suite_template.o
|
||||
CPP_OBJFILES = $(BUILD_DIR)/UI_test_cpp.o $(BUILD_DIR)/UI.o $(GTEST_OBJS)
|
||||
CPP_LIBS = -lpthread
|
||||
|
||||
|
||||
all: $(C_PROGNAME) $(CPP_PROGNAME) $(TEMPLATE_PROGNAME)
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
clean:
|
||||
@echo "Cleaning object files"
|
||||
@echo " rm -f $(BUILD_DIR)/*.o"
|
||||
rm -f $(BUILD_DIR)/*.o
|
||||
@echo "Cleaning backups"
|
||||
@echo " rm -f *~"
|
||||
rm -f *~
|
||||
@echo "Removing programs"
|
||||
@echo " rm -f "$(C_PROGNAME)
|
||||
rm -f $(C_PROGNAME)
|
||||
@echo " rm -f "$(CPP_PROGNAME) $(TEMPLATE_PROGNAME)
|
||||
rm -f $(CPP_PROGNAME) $(TEMPLATE_PROGNAME)
|
||||
|
||||
|
||||
$(BUILD_DIR)/%.o: %.c
|
||||
@echo "Compiling "$@
|
||||
@echo " CC "$<
|
||||
$(CC) -o $@ $<
|
||||
|
||||
$(BUILD_DIR)/%.o: %.cpp
|
||||
@echo "Compiling "$@
|
||||
@echo " CPP "$<
|
||||
$(CPP) -DGTEST_USE_OWN_TR1_TUPLE=1 -I../.. -o $@ $<
|
||||
|
||||
$(TEMPLATE_PROGNAME): $(TEMPLATE_OBJFILES)
|
||||
@echo "Linking "$@
|
||||
@echo " LD -o "ctemplate" "$(TEMPLATE_OBJFILES)
|
||||
$(LD) -o $(TEMPLATE_PROGNAME) $(TEMPLATE_OBJFILES)
|
||||
|
||||
$(C_PROGNAME): $(C_OBJFILES)
|
||||
@echo "Linking "$@
|
||||
@echo " LD -o "$(C_PROGNAME)" "$(C_OBJFILES)
|
||||
$(LD) -o $(C_PROGNAME) $(C_OBJFILES)
|
||||
|
||||
$(CPP_PROGNAME): $(CPP_OBJFILES) $(C_OBJFILES)
|
||||
@echo "Linking "$@
|
||||
@echo " LD -o "$(CPP_PROGNAME)" "$(CPP_OBJFILES)
|
||||
$(LD) -o $(CPP_PROGNAME) $(CPP_OBJFILES) $(CPP_LIBS)
|
||||
|
||||
|
||||
|
||||
nothing:
|
||||
@echo "Nothing to do; quitting :("
|
||||
@echo "HINT: Try make all"
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "UI.h"
|
||||
#include "../../fff.h"
|
||||
#include "fff.h"
|
||||
#include "SYSTEM.h"
|
||||
#include "DISPLAY.h"
|
||||
|
||||
@@ -6,7 +6,7 @@ extern "C"{
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
||||
#include "../../fff.h"
|
||||
#include "fff.h"
|
||||
DEFINE_FFF_GLOBALS;
|
||||
|
||||
/* SYSTEM.h */
|
||||
@@ -1,34 +0,0 @@
|
||||
#include "../../test/c_test_framework.h"
|
||||
|
||||
/* Initialializers called for every test */
|
||||
void setup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/* Tests go here */
|
||||
TEST_F(GreeterTests, hello_world)
|
||||
{
|
||||
assert(1 == 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
setbuf(stderr, NULL);
|
||||
fprintf(stdout, "-------------\n");
|
||||
fprintf(stdout, "Running Tests\n");
|
||||
fprintf(stdout, "-------------\n\n");
|
||||
fflush(0);
|
||||
|
||||
/* Run tests */
|
||||
RUN_TEST(GreeterTests, hello_world);
|
||||
|
||||
|
||||
printf("\n-------------\n");
|
||||
printf("Complete\n");
|
||||
printf("-------------\n\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
54
examples/weak_linking/CMakeLists.txt
Normal file
54
examples/weak_linking/CMakeLists.txt
Normal file
@@ -0,0 +1,54 @@
|
||||
# Copyright 2022 Google LLC
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# Skip these tests for Windows
|
||||
if(WIN32)
|
||||
message(STATUS "Weak linking requires __attribute__((weak)) which isn't supported on MS VS, skipping tests")
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Set the global FFF_GCC_FUNCTION_ATTRIBUTES for config.h
|
||||
set(FFF_GCC_FUNCTION_ATTRIBUTES "__attribute__((weak))")
|
||||
configure_file(config/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
||||
|
||||
# Create a libfakes static library that will be used in the executables below.
|
||||
# This library will depend on the above generated config.h which will add the
|
||||
# FFF 'weak' function attributes.
|
||||
add_library(libfakes STATIC
|
||||
test/src/bus.fake.c
|
||||
test/src/display.fake.c
|
||||
test/src/error.fake.c
|
||||
test/src/sensor.fake.c
|
||||
test/src/test_common.c
|
||||
)
|
||||
target_precompile_headers(libfakes PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
||||
target_include_directories(libfakes PUBLIC include test/include)
|
||||
target_link_libraries(libfakes PUBLIC fff)
|
||||
|
||||
# Create the main test binary
|
||||
add_executable(test_main src/main.c test/src/main.test.c)
|
||||
target_link_libraries(test_main PRIVATE libfakes)
|
||||
|
||||
# Create the sensor test binary
|
||||
add_executable(test_sensor src/sensor.c test/src/sensor.test.c)
|
||||
target_link_libraries(test_sensor PRIVATE libfakes)
|
||||
|
||||
# Create the display test binary
|
||||
add_executable(test_display src/display.c test/src/display.test.c ${LIBFAKES_SRCS})
|
||||
target_link_libraries(test_display PRIVATE libfakes)
|
||||
|
||||
# Add tests to ctest
|
||||
add_test(
|
||||
NAME test_main
|
||||
COMMAND $<TARGET_FILE:test_main>
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME test_sensor
|
||||
COMMAND $<TARGET_FILE:test_sensor>
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME test_display
|
||||
COMMAND $<TARGET_FILE:test_display>
|
||||
)
|
||||
@@ -1,39 +0,0 @@
|
||||
BUILD_DIR = ../../build
|
||||
INCLUDE_DIRS = -I "../../" -I "./src/"
|
||||
|
||||
BUILD_DIR_FAKE = $(BUILD_DIR)/weak_linking
|
||||
CC = gcc
|
||||
WEAK_FLAGS=-Wall -DFFF_GCC_FUNCTION_ATTRIBUTES="__attribute__((weak))"
|
||||
|
||||
$(BUILD_DIR_FAKE)/%.o: test/%.c
|
||||
@echo "Compiling "$@
|
||||
$(CC) $(WEAK_FLAGS) $(INCLUDE_DIRS) -g -O0 -c $< -o $@
|
||||
|
||||
FAKE_OBJECTS = $(BUILD_DIR_FAKE)/display.fake.o $(BUILD_DIR_FAKE)/sensor.fake.o $(BUILD_DIR_FAKE)/sensor.fake.o $(BUILD_DIR_FAKE)/error.fake.o $(BUILD_DIR_FAKE)/bus.fake.o $(BUILD_DIR_FAKE)/test_common.o
|
||||
|
||||
TEST_BINARIES = $(BUILD_DIR_FAKE)/test_main $(BUILD_DIR_FAKE)/test_display $(BUILD_DIR_FAKE)/test_sensor
|
||||
mkdir:
|
||||
mkdir -p $(BUILD_DIR_FAKE)/
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR_FAKE)/
|
||||
|
||||
$(BUILD_DIR_FAKE)/libfakes.a: $(FAKE_OBJECTS)
|
||||
ar r $@ $^
|
||||
|
||||
# First case where we need __weak__ linking:
|
||||
# - If we have the build objects (for some reason) in order where the fake object comes first.
|
||||
$(BUILD_DIR_FAKE)/test_display: ./test/display.test.c $(BUILD_DIR_FAKE)/libfakes.a ./src/display.c
|
||||
$(CC) $(WEAK_FLAGS) $(INCLUDE_DIRS) -o $@ $^
|
||||
|
||||
# Second case where we need weak linking:
|
||||
# - If we use an object from the fake object -> gcc linker will include it.
|
||||
$(BUILD_DIR_FAKE)/test_sensor: ./test/sensor.test.c ./src/sensor.c $(BUILD_DIR_FAKE)/libfakes.a
|
||||
$(CC) $(WEAK_FLAGS) $(INCLUDE_DIRS) -o $@ $^
|
||||
|
||||
# Third case where we need weak linking:
|
||||
# - We want to fake one function but not all.
|
||||
$(BUILD_DIR_FAKE)/test_main: ./test/main.test.c ./src/main.c $(BUILD_DIR_FAKE)/libfakes.a
|
||||
$(CC) $(WEAK_FLAGS) $(INCLUDE_DIRS) -o $@ $^
|
||||
|
||||
all: mkdir $(TEST_BINARIES)
|
||||
5
examples/weak_linking/config/config.h.in
Normal file
5
examples/weak_linking/config/config.h.in
Normal file
@@ -0,0 +1,5 @@
|
||||
/* Copyright 2022 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#cmakedefine FFF_GCC_FUNCTION_ATTRIBUTES @FFF_GCC_FUNCTION_ATTRIBUTES@
|
||||
@@ -22,12 +22,12 @@ void init_tests()
|
||||
{
|
||||
memset( GLOBAL_TEST_bus_read_ret, 0x00, sizeof(GLOBAL_TEST_bus_read_ret));
|
||||
FFF_RESET_HISTORY();
|
||||
|
||||
|
||||
RESET_FAKE(bus_read_write);
|
||||
RESET_FAKE(bus_write);
|
||||
RESET_FAKE(runtime_error);
|
||||
|
||||
|
||||
runtime_error_fake.custom_fake = spoof_runtime_error;
|
||||
bus_read_write_fake.custom_fake = spoof_bus_read_write;
|
||||
bus_write_fake.return_val = true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user