1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

Add valgrind and string tests to host_tests (#4939)

* Add valgrind and string tests to host_tests

Valgrind identified an error that was causing intermittent failures in
the host tests, and can check for subtle memory access and allocation bugs.
Add it to the standard host_test suite, and any errors will cause test
failure.

Also start adding string tests, since two undefined behaviors have been
found so far just by inspection.

* Add additional String tests

Looks like a possible bug in the concatenation operator, need to verify
expected behavior.

* Remove verbose from valgrind run

No need to be so chatty on the test.  Errors were a little hard to spot.
Go to normal verbosity.

* Add lcov and more string tests

LCOV and genhtml can generate nice HTML coverage charts hilighting test
coverage issues in a much simpler way than gcov text format.  Generate these
automatically from gcov output.

Add additional string creation and comparison tests.

* Move String coverage to >50%

Additional string tests and checks

* 66% test coverage in String

* Add allocation-unit-sized strings test

Ensure that strings that are right on the edge of the allocation
size are handled properly and account for trailing 0.
This commit is contained in:
Earle F. Philhower, III
2018-07-27 10:10:55 -07:00
committed by Develo
parent 3cc12b1e08
commit 03ea61a32a
5 changed files with 282 additions and 6 deletions

View File

@ -1,4 +1,5 @@
BINARY_DIRECTORY := bin
LCOV_DIRECTORY := lcov
OUTPUT_BINARY := $(BINARY_DIRECTORY)/host_tests
CORE_PATH := ../../cores/esp8266
@ -8,6 +9,9 @@ CC ?= gcc
CXX ?= g++
endif
GCOV ?= gcov
VALGRIND ?= valgrind
LCOV ?= lcov
GENHTML ?= genhtml
CORE_CPP_FILES := $(addprefix $(CORE_PATH)/,\
StreamString.cpp \
@ -49,11 +53,12 @@ TEST_CPP_FILES := \
fs/test_fs.cpp \
core/test_pgmspace.cpp \
core/test_md5builder.cpp \
core/test_string.cpp
CXXFLAGS += -std=c++11 -Wall -coverage -O0 -fno-common
CFLAGS += -std=c99 -Wall -coverage -O0 -fno-common
CXXFLAGS += -std=c++11 -Wall -Werror -coverage -O0 -fno-common -g
CFLAGS += -std=c99 -Wall -Werror -coverage -O0 -fno-common -g
LDFLAGS += -coverage -O0
VALGRINDFLAGS += --leak-check=full --track-origins=yes --error-limit=no --show-leak-kinds=all --error-exitcode=999
remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))
@ -69,7 +74,7 @@ CPP_OBJECTS = $(CPP_OBJECTS_CORE) $(CPP_OBJECTS_TESTS)
OBJECTS = $(C_OBJECTS) $(CPP_OBJECTS)
COVERAGE_FILES = $(OBJECTS:.o=.gc*)
all: build-info $(OUTPUT_BINARY) test gcov
all: build-info $(OUTPUT_BINARY) valgrind test gcov
test: $(OUTPUT_BINARY)
$(OUTPUT_BINARY)
@ -81,11 +86,18 @@ clean-objects:
rm -rf $(OBJECTS)
clean-coverage:
rm -rf $(COVERAGE_FILES) *.gcov
rm -rf $(COVERAGE_FILES) $(LCOV_DIRECTORY) *.gcov
gcov: test
find $(CORE_PATH) -name "*.gcno" -exec $(GCOV) -r -pb {} +
valgrind: $(OUTPUT_BINARY)
mkdir -p $(LCOV_DIRECTORY)
$(LCOV) --directory ../../cores/esp8266/ --zerocounters
$(VALGRIND) $(VALGRINDFLAGS) $(OUTPUT_BINARY)
$(LCOV) --directory $(CORE_PATH) --capture --output-file $(LCOV_DIRECTORY)/app.info
$(GENHTML) $(LCOV_DIRECTORY)/app.info -o $(LCOV_DIRECTORY)
build-info:
@echo "-------- build tools info --------"
@echo "CC: " $(CC)