Skip to content

Commit

Permalink
Merge branch 'master' into bracz-f7-spiffs-flash
Browse files Browse the repository at this point in the history
* master:
  Unaligned read/write support in TivaEEPROM storage (#741)
  Adds support for producer/consumer identified message in the CallbackEventHandler. (#743)
  Improve error handling in BroadcastTimeDefs::string_to_date() (#745)
  Fix test makefiles and test target (#736)
  Moves the bootloader hook so that the hook implementation gets a chance to look at incoming frames.
  Fixes missing includes.
  Fixes missing symbol error.
  Adds stm32f072 HAL drivers to bare.armv6m compilation target.
  Update HASSERT and DIE to use ets_printf() on ESP32 (#744)
  Adds a useful command to generate release notes.
  • Loading branch information
balazsracz committed Nov 12, 2023
2 parents 276e824 + 4b16fc1 commit 6a74c9b
Show file tree
Hide file tree
Showing 46 changed files with 256 additions and 155 deletions.
1 change: 1 addition & 0 deletions arduino/RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Arduino ecosystem (whichever incarnation) are used.
1. Edit library.properties and library.json to increment the version number.
1. Run `arduino/libify.sh "/path/to/OpenMRNLite" . -f`
1. Go to OpenMRNLite, commit the results to git, then push it to master.
To generate the commit note and later the release notes, use this command: `git log --oneline OpenMRNLite-v1.0.3..OpenMRNLite-v2.0.0 | sed -e 's/[(]#/(https:\/\/github.com\/bakerstu\/openmrn\/pull\//' | sed 's/^/bakerstu\/openmrn@/'`
1. go to http://github.com/openmrn/OpenMRNLite, click the releases tab, then
create a release called v1.2.3 if your library.properties said 1.2.3 as
version.
Expand Down
13 changes: 10 additions & 3 deletions etc/core_target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ include $(OPENMRNPATH)/etc/config.mk
include $(OPENMRNPATH)/etc/path.mk
include $(OPENMRNPATH)/etc/$(TARGET).mk

# lib here is only needed for clean to work properly. Libraries are copied
# there by the original build rules.
SUBDIRS = $(CORELIBS) $(SYSLIB_SUBDIRS) lib
SUBDIRS = $(CORELIBS) $(SYSLIB_SUBDIRS)

# This defines how to create nonexistant directories.
MKSUBDIR_OPENMRNINCLUDE=lib.mk

include $(OPENMRNPATH)/etc/recurse.mk

# lib/timestamp is a dependency to all test binaries. This rule has to have a
# body to execute, or else make will take the mtime of this file too early in
# the execution process. The body shall not actually touch the file, as the
# touches happen in the BUILDDIRS recursions. This workaround ensures that when
# a source file changes in openmrn, the tests are all re-linked and
# re-run. Otherwise you need to run tests twice to actually execute them.
lib/timestamp: $(BUILDDIRS)
true
26 changes: 24 additions & 2 deletions etc/core_test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

ifneq ($(HOST_TARGET)$(EMU),0)

include $(OPENMRNPATH)/etc/make_utils.mk

FULLPATHCXXTESTSRCS := $(foreach DIR,$(SUBDIRS) tests,$(wildcard $(SRCDIR)/$(DIR)/*.cxxtest))

TESTOBJSEXTRA += gtest-all.o gmock-all.o
Expand All @@ -33,16 +35,36 @@ CXXFLAGS += $(INCLUDES)
ifdef LIBDIR
# we are under prog.mk
TESTLIBDEPS += $(foreach lib,$(SUBDIRS),lib/lib$(lib).a)

# This ensures that link targets that depend on lib/libfoo.a will recurse into
# the directory foo and rebuild stuff that's there. However, the dependency is
# phrased in a way that if recursing does not change the library (when it's
# up-to-date) then the .elf linking is not re-done.
$(foreach lib,$(SUBDIRS),$(eval $(call SUBDIR_helper_template,$(lib))))

# Ensures that when the core target is clean (missing lib/libfoo.a), make knows
# how to build its libraries. This also ensures that the text.executable files
# are remade when something changes in the openmrn codebase.
$(foreach lib,$(CORELIBS),$(LIBDIR)/lib$(lib).a): $(LIBDIR)/timestamp

else
LIBDIR = lib

# This ensures that link targets that depend on lib/libfoo.a will recurse into
# the directory foo and rebuild stuff that's there. However, the dependency is
# phrased in a way that if recursing does not change the library (when it's
# up-to-date) then the .elf linking is not re-done.
$(foreach lib,$(CORELIBS),$(eval $(call SUBDIR_helper_template,$(lib))))

endif
TESTLIBDEPS += $(foreach lib,$(CORELIBS),$(LIBDIR)/lib$(lib).a)

LDFLAGS += -L$(LIBDIR)

$(LIBDIR)/timestamp: $(BUILDDIRS)

$(info test deps $(TESTOBJSEXTRA) $(LIBDIR)/timestamp )

$(info test deps $(TESTOBJSEXTRA) $(LIBDIR)/timestamp | $(BUILDDIRS) )
$(TESTBINS): %.test$(EXTENTION) : %.test.o $(TESTOBJSEXTRA) $(LIBDIR)/timestamp lib/timestamp $(TESTLIBDEPS) $(TESTEXTRADEPS) | $(BUILDDIRS)
$(LD) -o $@ $(LDFLAGS) -los $< $(TESTOBJSEXTRA) $(LIBS) $(STARTGROUP) $(LINKCORELIBS) $(ENDGROUP) $(SYSLIBRARIES)

Expand All @@ -53,7 +75,7 @@ $(TESTOBJS): %.test.o : $(SRCDIR)/%.cxxtest
$(CXX) $(CXXFLAGS) -MMD -MF $*.dtest -MT $@ -x c++ $< -o $@

gtest-all.o : %.o : $(GTESTSRCPATH)/src/%.cc
$(CXX) $(CXXFLAGS) -Wno-uninitialized -I$(GTESTPATH) -I$(GTESTSRCPATH) -MMD -MF $*.d $< -o $@
$(CXX) $(CXXFLAGS) -Wno-uninitialized -Wno-maybe-uninitialized -I$(GTESTPATH) -I$(GTESTSRCPATH) -MMD -MF $*.d $< -o $@

gmock-all.o : %.o : $(GMOCKSRCPATH)/src/%.cc
$(CXX) $(CXXFLAGS) -I$(GMOCKPATH) -I$(GMOCKSRCPATH) -MMD -MF $*.d $< -o $@
Expand Down
8 changes: 5 additions & 3 deletions etc/cov.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ else
ARCHOPTIMIZATION = -g $(TESTOPTIMIZATION) -fprofile-arcs -ftest-coverage
endif

CSHAREDFLAGS = -c -frandom-seed=$(shell echo $(abspath $<) | md5sum | sed 's/\(.*\) .*/\1/') $(ARCHOPTIMIZATION) $(INCLUDES) -Wall -Werror -Wno-unknown-pragmas -MD -MP -fno-stack-protector -D_GNU_SOURCE -DGTEST
CSHAREDFLAGS = -c -frandom-seed=$(shell echo $(abspath $<) | md5sum | sed 's/\(.*\) .*/\1/') \
$(ARCHOPTIMIZATION) $(INCLUDES) -Wall -Werror -Wno-unknown-pragmas -MD -MP \
-fno-stack-protector -D_GNU_SOURCE -DGTEST

CFLAGS = $(CSHAREDFLAGS) -std=gnu99 $(CFLAGSEXTRA)
CFLAGS = $(CSHAREDFLAGS) -std=gnu99 $(CFLAGSENV) $(CFLAGSEXTRA)

CXXFLAGS = $(CSHAREDFLAGS) -std=c++14 -D__STDC_FORMAT_MACROS \
-D__STDC_LIMIT_MACROS $(CXXFLAGSEXTRA) #-D__LINEAR_MAP__
-D__STDC_LIMIT_MACROS $(CXXFLAGSENV) $(CXXFLAGSEXTRA) \


LDFLAGS = $(ARCHOPTIMIZATION) -Wl,-Map="$(@:%=%.map)"
Expand Down
8 changes: 4 additions & 4 deletions etc/make_utils.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ $(foreach tgt,$(1),$(eval $(call REDIRECT_helper_template,$(tgt),$(2))))
endef


### Helper template to declare a dependency.
### Arguments: target_file dependency_file
### Helper template to declare a library subdirectory dependency.
### Arguments: library_basename
### Example on how to call: Put the following on a standalone line in the Makefile
### $(foreach lib,$(LIBDIRS),$(eval $(call SUBDIR_helper_template,lib/lib$(lib).a,build-$(lib))))
### $(foreach lib,$(LIBDIRS),$(eval $(call SUBDIR_helper_template,$(lib))))
define SUBDIR_helper_template

$(1)/lib$(1).a: | build-$(1)
$(1)/lib$(1).a: build-$(1)

lib/lib$(1).a: $(1)/lib$(1).a

Expand Down
126 changes: 26 additions & 100 deletions etc/test.mk
Original file line number Diff line number Diff line change
@@ -1,116 +1,42 @@
ifeq ($(BASENAME),)
# if the basename is so far undefined
BASENAME := $(notdir $(CURDIR))
endif
TOOLPATH ?= /usr/bin

include $(OPENMRNPATH)/etc/config.mk
# Get the $(CFLAGSENV), $(CXXFLAGSENV), $(LDFLAGSENV)
include $(OPENMRNPATH)/etc/env.mk

include $(OPENMRNPATH)/etc/linux.x86.mk
# Define this variable if you want to use a specific (suffixed) GCC version
# instead of the system default.
#GCCVERSION=-8

include $(OPENMRNPATH)/etc/path.mk
CC = $(shell $(OPENMRNPATH)/bin/find_distcc.sh gcc$(GCCVERSION))
CXX = $(shell $(OPENMRNPATH)/bin/find_distcc.sh g++$(GCCVERSION))
AR = ar
LD = g++$(GCCVERSION)
OBJDUMP = objdump

SRCDIR = $(OPENMRNPATH)/src/$(BASENAME)/
VPATH = $(SRCDIR):$(GMOCKPATH)/src:$(GMOCKSRCPATH)
AROPTS=D

exist := $(wildcard $(SRCDIR)/sources)
ifneq ($(strip $(exist)),)
include $(SRCDIR)/sources
else
exist := $(wildcard sources)
ifneq ($(strip $(exist)),)
include sources
else
FULLPATHCSRCS = $(wildcard $(VPATH)*.c)
FULLPATHCXXSRCS = $(wildcard $(VPATH)*.cxx)
FULLPATHCXXTESTSRCS = $(wildcard $(VPATH)*.cxxtest)
HOST_TARGET := 1

CSRCS = $(notdir $(FULLPATHCSRCS)) $(wildcard *.c)
CXXSRCS = $(notdir $(FULLPATHCXXSRCS)) $(wildcard *.cxx)
CXXTESTSRCS = $(notdir $(FULLPATHCXXTESTSRCS)) $(wildcard *.cxxtest)
endif
endif

OBJS = $(CXXSRCS:.cxx=.o) $(CSRCS:.c=.o)
TESTOBJS = $(CXXTESTSRCS:.cxxtest=.otest)
TESTOBJSEXTRA = gtest-all.o gmock-all.o

TESTBINS = $(CXXTESTSRCS:.cxxtest=.test)
TESTOUTPUTS = $(CXXTESTSRCS:.cxxtest=.testout)

LIBDIR = $(OPENMRNPATH)/targets/linux.x86/lib
FULLPATHLIBS = $(wildcard $(LIBDIR)/*.a) $(wildcard lib/*.a)
LIBDIRS := $(SUBDIRS)
LIBS = $(STARTGROUP) \
$(foreach lib,$(LIBDIRS),-l$(lib)) \
$(ENDGROUP) \
$(LINKCORELIBS)
STARTGROUP := -Wl,--start-group
ENDGROUP := -Wl,--end-group

TESTOPTIMIZATION=-O0

INCLUDES += -I$(GTESTPATH)/include -I$(GMOCKPATH)/include -I$(GMOCKPATH) \
-I$(OPENMRNPATH)/src -I$(OPENMRNPATH)/include
CFLAGS += -DGTEST $(INCLUDES) -Wno-unused-but-set-variable -fprofile-arcs -ftest-coverage $(TESTOPTIMIZATION)
CXXFLAGS += -DGTEST $(INCLUDES) -Wno-unused-but-set-variable -fprofile-arcs -ftest-coverage $(TESTOPTIMIZATION)
SYSLIBRARIES += -lgcov -fprofile-arcs -ftest-coverage $(TESTOPTIMIZATION)
LDFLAGS += -L$(LIBDIR)

.SUFFIXES:
.SUFFIXES: .o .otest .c .cxx .cxxtest .test

all: $(TESTBINS)

-include $(OBJS:.o=.d) $(TESTOBJS:.otest=.dtest)

$(TESTBINS): $(OBJS) $(TESTOBJS) $(FULLPATHLIBS) $(TESTOBJSEXTRA)
$(LD) -o $@ $*.otest $(TESTOBJSEXTRA) \
$(filter $(@:.test=.o),$(OBJS)) $(OBJSEXTRA) \
$(LDFLAGS) $(LIBS) $(SYSLIBRARIES)

$(TESTOUTPUTS): %.testout : %.test
(cd lcovdir; ../$< $(TESTARGS) --gtest_death_test_style=threadsafe && touch $@)

gtest-all.o : %.o : $(GTESTSRCPATH)/src/%.cc
$(CXX) $(CXXFLAGS) -I$(GTESTPATH) -I$(GTESTSRCPATH) $< -o $@
$(CXX) -MM $(CXXFLAGS) -I$(GTESTPATH) -I$(GTESTSRCPATH) $< > $*.d

gmock-all.o : %.o : $(GMOCKSRCPATH)/src/%.cc
$(CXX) $(CXXFLAGS) -I$(GMOCKPATH) -I$(GMOCKSRCPATH) $< -o $@
$(CXX) -MM $(CXXFLAGS) -I$(GMOCKPATH) -I$(GMOCKSRCPATH) $< > $*.d

.cxx.o:
$(CXX) $(CXXFLAGS) $< -o $@

.c.o:
$(CC) $(CFLAGS) $< -o $@

.cxxtest.otest:
$(CXX) $(CXXFLAGS) -MF $*.dtest -x c++ $< -o $@
# ln -s [email protected] $*.gcno
ARCHOPTIMIZATION = -g $(TESTOPTIMIZATION) -fdata-sections -ffunction-sections -fPIC -O0

#.otest.test:
# $(LD) -o $@ $< $(GTESTPATH)/src/gtest-all.o \
# $(GTESTPATH)/src/gtest_main.o $(filter $(<:.otest=.o),$(OBJS)) \
# $(LDFLAGS) $(SYSLIBRARIES)
CSHAREDFLAGS = -c -frandom-seed=$(shell echo $(abspath $<) | md5sum | sed 's/\(.*\) .*/\1/') \
$(ARCHOPTIMIZATION) $(INCLUDES) -Wall -Werror -Wno-unknown-pragmas -MD -MP \
-fno-stack-protector -D_GNU_SOURCE -DGTEST

tests: all
echo $(foreach TESTBINS,$(TESTBINS),gcov $(VPATH)$(TESTBINS:.test=.cxxtest))
[ -z "$(TESTBINS)" ] || (mkdir -p lcovdir; cd lcovdir; \
lcov --directory ../ --no-recursion -z; cd .. ; \
$(MAKE) run-tests ; cd lcovdir ; \
lcov --directory ../ --no-recursion --capture --output-file app.info; \
lcov -r app.info "/usr/include/*" -o app.info; \
lcov -r app.info "*.cxxtest" -o app.info; \
lcov -r app.info "*gtest*" -o app.info; \
genhtml -o . app.info )
CFLAGS = $(CSHAREDFLAGS) -std=gnu99 $(CFLAGSENV) $(CFLAGSEXTRA)

run-tests: $(TESTOUTPUTS)
CXXFLAGS = $(CSHAREDFLAGS) -std=c++14 -D__STDC_FORMAT_MACROS \
-D__STDC_LIMIT_MACROS $(CXXFLAGSENV) $(CXXFLAGSEXTRA) \

clean: clean-local
LDFLAGS = $(ARCHOPTIMIZATION) -pg -Wl,-Map="$(@:%=%.map)" -Wl,--undefined=ignore_fn

clean-local:
rm -rf *.o *.otest *.d *.dtest *.test *.gcda *.gcno *.png *.info bits ext home i686-linux-gnu opt usr *.html *.css lcovdir *.map
SYSLIB_SUBDIRS +=
SYSLIBRARIES = -lrt -lpthread -lavahi-client -lavahi-common $(SYSLIBRARIESEXTRA)

veryclean: clean-local
EXTENTION =

#nothing to do
mksubdirs:
2 changes: 1 addition & 1 deletion src/freertos_drivers/sources
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ endif
endif

ifeq ($(TARGET),bare.armv6m)
SUBDIRS += stm32cubef091xc
SUBDIRS += stm32cubef091xc stm32cubef071xb_2xb
CXXSRCS += c++_operators.cxx
endif

Expand Down
7 changes: 3 additions & 4 deletions src/openlcb/Bootloader.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -1048,10 +1048,6 @@ bool bootloader_init() {
/// should keep running (i.e., to call again).
bool bootloader_loop()
{
#ifdef BOOTLOADER_LOOP_HOOK
BOOTLOADER_LOOP_HOOK();
#endif

{
#ifdef __linux__
AtomicHolder h(&g_bootloader_lock);
Expand All @@ -1073,6 +1069,9 @@ bool bootloader_loop()
g_bootloader_busy = new_busy;
}
}
#ifdef BOOTLOADER_LOOP_HOOK
BOOTLOADER_LOOP_HOOK();
#endif
if (state_.output_frame_full && try_send_can_frame(state_.output_frame))
{
state_.output_frame_full = 0;
Expand Down
23 changes: 22 additions & 1 deletion src/openlcb/BroadcastTimeDefs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,32 @@ int16_t BroadcastTimeDefs::string_to_rate_quarters(const std::string &srate)
bool BroadcastTimeDefs::string_to_date(
const std::string &sdate, int *year, int *month, int *day)
{
struct tm tm = {};
struct tm tm;
memset(&tm, 0, sizeof(tm));
if (strptime(sdate.c_str(), "%b %e, %Y", &tm) == nullptr)
{
return false;
}

// newlib does not have the proper boundary checking for strptime().
// Therefore we use mktime() to determine if the time we have is really
// valid or not. In newlib, mktime() can actually correct some invalid
// struct tm values by making some educated guesses.
//
// While glibc does have proper boundary checking for strptime(), it
// can still use mktime() to correct some invalid struct tm values by
// making some educated guesses.
time_t t = mktime(&tm);

// newlib does not correctly set the errno value when mktime()
// encounters an error. Instead it "only" returns -1, which is technically
// a valid time. We are counting on the fact that we zeroed out the struct
// tm above, and subsequently -1 cannot be an expected result.
if (t == (time_t)-1)
{
return false;
}

if (tm.tm_year < (0 - 1900) || tm.tm_year > (4095 - 1900))
{
// Out of range for openlcb.
Expand Down
13 changes: 7 additions & 6 deletions src/openlcb/BroadcastTimeDefs.cxxtest
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,10 @@ TEST_F(BroadcastTimeDefsTest, string_to_date)
parse_date("Feb 29, 2024", 2024, 2, 29);

// Not leap year
parse_date("Feb 29, 2023", 2023, 2, 29);
// No canonicalization in glibc
parse_date("Feb 31, 2023", 2023, 2, 31);
parse_date("Feb 29, 2023", 2023, 3, 1);

// canonize
parse_date("Feb 31, 2023", 2023, 3, 3);
}

TEST_F(BroadcastTimeDefsTest, string_to_date_fail)
Expand Down Expand Up @@ -202,9 +203,9 @@ TEST_F(BroadcastTimeDefsTest, date_canonicalize)

EXPECT_FALSE(canon_date("Aug 12, 2023"));
EXPECT_TRUE(canon_date("Aug 12, \n\t 2023", "Aug 12, 2023"));
EXPECT_FALSE(canon_date("Feb 31, 2023"));
EXPECT_FALSE(canon_date("Feb 31, 23"));
EXPECT_FALSE(canon_date("Feb 31, 3023"));
EXPECT_TRUE(canon_date("Feb 31, 2023", "Mar 3, 2023"));
EXPECT_TRUE(canon_date("Feb 31, 23", "Mar 3, 23"));
EXPECT_TRUE(canon_date("Feb 31, 3023", "Mar 3, 3023"));

EXPECT_TRUE(canon_date("Aug 9, 2023", "Aug 9, 2023"));

Expand Down
Loading

0 comments on commit 6a74c9b

Please sign in to comment.