This commit is contained in:
rusefillc 2024-02-22 09:00:10 -05:00
commit 9ec9c0ba0e
15 changed files with 43960 additions and 0 deletions

17
.editorconfig Normal file
View File

@ -0,0 +1,17 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
root = true
[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 2
# 4 space indentation
[*.java]
indent_size = 4

37
.gitattributes vendored Normal file
View File

@ -0,0 +1,37 @@
#
# see https://help.github.com/articles/dealing-with-line-endings/
#
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto
# Explicitly declare text files you want to always be normalized and converted
# to Unix line endings on checkout.
*.c text eol=lf
*.cpp text eol=lf
*.h text eol=lf
*.xml text eol=lf
*.mk text eol=lf
*.java text eol=lf
*.bat text eol=lf
*.sh text eol=lf
*.inc text eol=lf
*.env text eol=lf
*.iml text eol=lf
*.txt text eol=lf
*.yaml text eol=lf
*.ini text eol=lf
*.input text eol=lf
*.rules text eol=lf
# KiCad files
*.dsn text eol=lf
*.kicad_pcb text eol=lf
*.net text eol=lf
*.pro text eol=lf
*.sch text eol=lf
# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
build/
.dep/
.idea

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "ext/googletest"]
path = ext/googletest
url = https://github.com/google/googletest.git

1
ext/googletest Submodule

@ -0,0 +1 @@
Subproject commit db38b59fa0194e4b701793ee50d28a9ee319d20c

198
unit_tests/Makefile Normal file
View File

@ -0,0 +1,198 @@
##############################################################################
# Build global options
# NOTE: Can be overridden externally.
#
PROJECT_DIR = .
# Imported source files and paths
RUSEFI_LIB = .
include $(RUSEFI_LIB)/util/util.mk
include $(RUSEFI_LIB)/pt2001/pt2001.mk
# C sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
CSRC += \
$(RUSEFI_LIB_C) \
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
CPPSRC += \
$(RUSEFI_LIB_CPP) \
$(RUSEFI_LIB_CPP_TEST) \
util/src/timer.cpp \
mock/lib-time-mocks.cpp \
gtest-all.cpp \
gmock-all.cpp \
gtest_main.cpp \
INCDIR += \
$(PROJECT_DIR)/ext/googletest/googlemock/ \
$(PROJECT_DIR)/ext/googletest/googlemock/include \
$(PROJECT_DIR)/ext/googletest/googletest \
$(PROJECT_DIR)/ext/googletest/googletest/include \
$(PROJECT_DIR)/mock \
$(RUSEFI_LIB_INC) \
# User may want to pass in a forced value for SANITIZE
ifeq ($(SANITIZE),)
ifneq ($(OS),Windows_NT)
SANITIZE = yes
else
SANITIZE = no
endif
endif
IS_MAC = no
ifneq ($(OS),Windows_NT)
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
IS_MAC = yes
endif
endif
# Compiler options here.
ifeq ($(USE_OPT),)
# -O2 is needed for mingw, without it there is a linking issue to isnanf?!?!
#USE_OPT = $(RFLAGS) -O2 -fgnu89-inline -ggdb -fomit-frame-pointer -falign-functions=16 -std=gnu99 -Werror-implicit-function-declaration -Werror -Wno-error=pointer-sign -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=sign-compare -Wno-error=unused-parameter -Wno-error=missing-field-initializers
USE_OPT = -c -Wall -O0 -ggdb -g
USE_OPT += -Werror=missing-field-initializers -Werror=shadow
endif
# C specific options here (added to USE_OPT).
ifeq ($(USE_COPT),)
USE_COPT = -std=gnu99 -fgnu89-inline
endif
# C++ specific options here (added to USE_OPT).
ifeq ($(USE_CPPOPT),)
USE_CPPOPT = -std=gnu++2a -fno-rtti -fno-use-cxa-atexit
endif
# Enable address sanitizer for C++ files, but not on Windows since x86_64-w64-mingw32-g++ doesn't support it.
# only c++ because lua does some things asan doesn't like, but don't actually cause overruns.
ifeq ($(SANITIZE),yes)
ifeq ($(IS_MAC),yes)
USE_CPPOPT += -fsanitize=address
else
USE_CPPOPT += -fsanitize=address -fsanitize=bounds-strict -fno-sanitize-recover=all
endif
endif
# Enable this if you want the linker to remove unused code and data
ifeq ($(USE_LINK_GC),)
USE_LINK_GC = yes
endif
# Enable this if you want to see the full log while compiling.
ifeq ($(USE_VERBOSE_COMPILE),)
USE_VERBOSE_COMPILE = no
endif
# C sources to be compiled in ARM mode regardless of the global setting.
ACSRC =
# C++ sources to be compiled in ARM mode regardless of the global setting.
ACPPSRC =
# List ASM source files here
ASMSRC =
##############################################################################
# Compiler settings
#
# It looks like cygwin build of mingwg-w64 has issues with gcov runtime :(
# mingw-w64 is a project which forked from mingw in 2007 - be careful not to confuse these two.
# In order to have coverage generated please download from https://mingw-w64.org/doku.php/download/mingw-builds
# Install using mingw-w64-install.exe instead of similar thing packaged with cygwin
# Both 32 bit and 64 bit versions of mingw-w64 are generating coverage data.
ifeq ($(OS),Windows_NT)
ifeq ($(USE_MINGW32_I686),)
#this one is 64 bit
TRGT = x86_64-w64-mingw32-
else
#this one was 32 bit
TRGT = i686-w64-mingw32-
endif
else
TRGT =
endif
CC = $(TRGT)gcc
CPPC = $(TRGT)g++
LD = $(TRGT)g++
CP = $(TRGT)objcopy
AS = $(TRGT)gcc -x assembler-with-cpp
OD = $(TRGT)objdump
HEX = $(CP) -O ihex
BIN = $(CP) -O binary
# Define C warning options here
CWARN = -Wall -Wextra -Wstrict-prototypes -pedantic -Wmissing-prototypes -Wold-style-definition
# Define C++ warning options here
CPPWARN = -Wall -Wextra -Werror -pedantic -Wno-error=sign-compare
#
# Compiler settings
##############################################################################
##############################################################################
# Start of default section
#
# List all default ASM defines here, like -D_DEBUG=1
DADEFS =
# List all default directories to look for include files here
DINCDIR =
# List the default directory to look for the libraries here
DLIBDIR =
# List all default libraries here
ifeq ($(OS),Windows_NT)
# Windows
DLIBS = -static-libgcc -static -static-libstdc++
else
# Linux
DLIBS = -pthread
endif
#
# End of default section
##############################################################################
##############################################################################
# Start of user section
#
# List all user C define here, like -D_DEBUG=1
UDEFS =
# Define ASM defines here
UADEFS =
# List all user directories here
UINCDIR =
# List the user directory to look for the libraries here
ULIBDIR =
# List all user libraries here
ULIBS = -lm
ifeq ($(SANITIZE),yes)
ULIBS += -fsanitize=address -fsanitize=undefined
endif
#
# End of user defines
##############################################################################
# Define project name here
PROJECT = mpx_logic_test
include rules.mk

13
unit_tests/gmock-all.cpp Normal file
View File

@ -0,0 +1,13 @@
// this is a work-around since our Makefile does not recognise .cc format
// todo: adjust the makefile so that we can remove this
// This line ensures that gmock.h can be compiled on its own, even
// when it's fused.
#include "gmock/gmock.h"
// The following lines pull in the real gmock *.cc files.
#include "src/gmock-cardinalities.cc"
#include "src/gmock-internal-utils.cc"
#include "src/gmock-matchers.cc"
#include "src/gmock-spec-builders.cc"
#include "src/gmock.cc"

17
unit_tests/gtest-all.cpp Normal file
View File

@ -0,0 +1,17 @@
// this is a work-around since our Makefile does not recognise .cc format
// todo: adjust the makefile so that we can remove this
// This line ensures that gtest.h can be compiled on its own, even
// when it's fused.
#include "gtest/gtest.h"
// The following lines pull in the real gtest *.cc files.
#include "src/gtest-assertion-result.cc"
#include "src/gtest-death-test.cc"
#include "src/gtest-filepath.cc"
#include "src/gtest-matchers.cc"
#include "src/gtest-port.cc"
#include "src/gtest-printers.cc"
#include "src/gtest-test-part.cc"
#include "src/gtest-typed-test.cc"
#include "src/gtest.cc"

38
unit_tests/gtest_main.cpp Normal file
View File

@ -0,0 +1,38 @@
// Copyright 2006, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <cstdio>
#include "gtest/gtest.h"
GTEST_API_ int main(int argc, char **argv) {
printf("Running main() from %s\n", __FILE__);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
saleae Logic 1.x files .logicdata files at https://github.com/rusefi/rusefi_documentation/tree/master/OEM-Docs/Toyota/1998-GS300

155
unit_tests/rules.mk Normal file
View File

@ -0,0 +1,155 @@
# ARM Cortex-Mx common makefile scripts and rules.
ifeq ($(BUILDDIR),)
# Define if not specified
BUILDDIR = build
endif
ifeq ($(BUILDDIR),.)
# Redefine if pointing at current folder
BUILDDIR = build
endif
BINARY_OUTPUT = $(BUILDDIR)/$(PROJECT)
# Automatic compiler options
OPT = $(USE_OPT)
COPT = $(USE_COPT)
CPPOPT = $(USE_CPPOPT)
ifeq ($(USE_LINK_GC),yes)
OPT += -ffunction-sections -fdata-sections -fno-common
endif
ACSRC += $(CSRC)
ACPPSRC += $(CPPSRC)
ASRC = $(ACSRC)$(ACPPSRC)
SRCPATHS = $(sort $(dir $(ASMXSRC)) $(dir $(ASMSRC)) $(dir $(ASRC)))
# Various directories
OBJDIR = $(BUILDDIR)/obj
LSTDIR = $(BUILDDIR)/lst
# Object files groups
ACOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ACSRC:.c=.o)))
ACPPOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ACPPSRC:.cpp=.o)))
ASMOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ASMSRC:.s=.o)))
ASMXOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ASMXSRC:.S=.o)))
OBJS = $(ASMXOBJS) $(ASMOBJS) $(ACOBJS) $(ACPPOBJS)
# Paths
IINCDIR = $(patsubst %,-I%,$(INCDIR) $(DINCDIR) $(UINCDIR))
LLIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))
# Macros
DEFS = $(DDEFS) $(UDEFS)
ADEFS = $(DADEFS) $(UADEFS)
# Libs
LIBS = $(DLIBS) $(ULIBS)
# Various settings
ifeq ($(IS_MAC),yes)
ODFLAGS = -x --syms
ASFLAGS = $(MCFLAGS) -Wa $(ADEFS)
ASXFLAGS = $(MCFLAGS) -Wa $(ADEFS)
CFLAGS = $(MCFLAGS) $(OPT) $(COPT) $(CWARN) $(DEFS)
CPPFLAGS = $(MCFLAGS) $(OPT) $(CPPOPT) $(CPPWARN) $(DEFS)
LDFLAGS = $(MCFLAGS) $(LLIBDIR)
else
# not mac
ODFLAGS = -x --syms
ASFLAGS = $(MCFLAGS) $(ADEFS)
ASXFLAGS = $(MCFLAGS) $(ADEFS)
CFLAGS = $(MCFLAGS) $(OPT) $(COPT) $(CWARN) $(DEFS)
CPPFLAGS = $(MCFLAGS) $(OPT) $(CPPOPT) $(CPPWARN) $(DEFS)
ifeq ($(USE_LINK_GC),yes)
LDFLAGS = $(MCFLAGS) -Wl,-Map=$(BINARY_OUTPUT).map,--cref,--no-warn-mismatch,--gc-sections $(LLIBDIR)
else
LDFLAGS = $(MCFLAGS) -Wl,-Map=$(BINARY_OUTPUT).map,--cref,--no-warn-mismatch $(LLIBDIR)
endif
endif
# Generate dependency information
CFLAGS += -MD -MP -MF .dep/$(@F).d
CPPFLAGS += -MD -MP -MF .dep/$(@F).d
# Paths where to search for sources
VPATH = $(SRCPATHS)
#
# Makefile rules
#
all: $(OBJS) $(BINARY_OUTPUT) MAKE_ALL_RULE_HOOK
MAKE_ALL_RULE_HOOK:
$(OBJS): | $(BUILDDIR)
$(BUILDDIR) $(OBJDIR) $(LSTDIR):
ifneq ($(USE_VERBOSE_COMPILE),yes)
@echo Compiler Options
@echo $(CPPC) -c $(CPPFLAGS) -I. $(IINCDIR) main.cpp -o main.o
@echo
endif
mkdir -p $(OBJDIR)
mkdir -p $(LSTDIR)
$(ACPPOBJS) : $(OBJDIR)/%.o : %.cpp Makefile
ifeq ($(USE_VERBOSE_COMPILE),yes)
@echo
$(CPPC) -c $(CPPFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@
else
@echo Compiling $(<F)
@$(CPPC) -c $(CPPFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@
endif
$(ACOBJS) : $(OBJDIR)/%.o : %.c Makefile
ifeq ($(USE_VERBOSE_COMPILE),yes)
@echo
$(CC) -c $(CFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@
else
@echo Compiling $(<F)
@$(CC) -c $(CFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@
endif
$(ASMOBJS) : $(OBJDIR)/%.o : %.s Makefile
ifeq ($(USE_VERBOSE_COMPILE),yes)
@echo
$(AS) -c $(ASFLAGS) -I. $(IINCDIR) $< -o $@
else
@echo Compiling $(<F)
@$(AS) -c $(ASFLAGS) -I. $(IINCDIR) $< -o $@
endif
$(ASMXOBJS) : $(OBJDIR)/%.o : %.S Makefile
ifeq ($(USE_VERBOSE_COMPILE),yes)
@echo
$(CC) -c $(ASXFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
else
@echo Compiling $(<F)
@$(CC) -c $(ASXFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
endif
$(BINARY_OUTPUT): $(OBJS)
rm -rf $(BUILDDIR)/obj/*gcda
ifeq ($(USE_VERBOSE_COMPILE),yes)
@echo
$(LD) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
else
@echo Linking $@
@$(LD) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
endif
clean: CLEAN_RULE_HOOK
@echo Cleaning
-rm -fR .dep $(BUILDDIR)
@echo Done
CLEAN_RULE_HOOK:
#
# Include the dependency files, should be the last of the makefile
#
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
# *** EOF ***

10
unit_tests/test.cpp Normal file
View File

@ -0,0 +1,10 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
using testing::ElementsAre;
TEST(Util_Arrays, CopyArray) {
}