From a65e0194511a30024aa7cb9dc65d7a4cfe546fc1 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 22 Aug 2016 14:16:21 +0800 Subject: [PATCH] components/nvs: fix host build with GCC 4.9, add coverage report generation --- components/nvs_flash/.gitignore | 6 +++++ components/nvs_flash/test/Makefile | 24 +++++++++++++++---- .../nvs_flash/test/spi_flash_emulation.h | 6 ++--- components/nvs_flash/test/test_nvs.cpp | 5 ---- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/components/nvs_flash/.gitignore b/components/nvs_flash/.gitignore index ba6fca0386..f07085166b 100644 --- a/components/nvs_flash/.gitignore +++ b/components/nvs_flash/.gitignore @@ -1 +1,7 @@ test/test_nvs +test/coverage +test/coverage.info +*.gcno +*.gcda +*.gcov +*.o diff --git a/components/nvs_flash/test/Makefile b/components/nvs_flash/test/Makefile index ded1235d70..8fa7b3efe3 100644 --- a/components/nvs_flash/test/Makefile +++ b/components/nvs_flash/test/Makefile @@ -1,5 +1,5 @@ TEST_PROGRAM=test_nvs -all: test +all: $(TEST_PROGRAM) SOURCE_FILES = \ $(addprefix ../src/, \ @@ -14,15 +14,18 @@ SOURCE_FILES = \ test_spi_flash_emulation.cpp \ test_intrusive_list.cpp \ test_nvs.cpp \ - crc.cpp \ + crc.cpp \ main.cpp -CPPFLAGS += -I../include -I../src -I./ -I../../esp32/include -I ../../spi_flash/include +CPPFLAGS += -I../include -I../src -I./ -I../../esp32/include -I ../../spi_flash/include -fprofile-arcs -ftest-coverage +CFLAGS += -fprofile-arcs -ftest-coverage CXXFLAGS += -std=c++11 -Wall -Werror -LDFLAGS += -lstdc++ +LDFLAGS += -lstdc++ -Wall -fprofile-arcs -ftest-coverage OBJ_FILES = $(SOURCE_FILES:.cpp=.o) +COVERAGE_FILES = $(OBJ_FILES:.o=.gc*) + $(OBJ_FILES): %.o: %.cpp $(TEST_PROGRAM): $(OBJ_FILES) @@ -34,7 +37,20 @@ $(OUTPUT_DIR): test: $(TEST_PROGRAM) ./$(TEST_PROGRAM) +$(COVERAGE_FILES): $(TEST_PROGRAM) test + +coverage.info: $(COVERAGE_FILES) + find ../src/ -name "*.gcno" -exec gcov -r -pb {} + + lcov --capture --directory ../src --no-external --output-file coverage.info + +coverage_report: coverage.info + genhtml coverage.info --output-directory coverage_report + @echo "Coverage report is in coverage_report/index.html" + clean: rm -f $(OBJ_FILES) $(TEST_PROGRAM) + rm -f $(COVERAGE_FILES) *.gcov + rm -rf coverage_report/ + rm -f coverage.info .PHONY: clean all test diff --git a/components/nvs_flash/test/spi_flash_emulation.h b/components/nvs_flash/test/spi_flash_emulation.h index ca1f9e27f5..d5a242b240 100644 --- a/components/nvs_flash/test/spi_flash_emulation.h +++ b/components/nvs_flash/test/spi_flash_emulation.h @@ -74,7 +74,7 @@ public: return false; } - if (mFailCountdown != SIZE_T_MAX && mFailCountdown-- == 0) { + if (mFailCountdown != SIZE_MAX && mFailCountdown-- == 0) { return false; } @@ -108,7 +108,7 @@ public: return false; } - if (mFailCountdown != SIZE_T_MAX && mFailCountdown-- == 0) { + if (mFailCountdown != SIZE_MAX && mFailCountdown-- == 0) { return false; } @@ -203,7 +203,7 @@ protected: size_t mLowerSectorBound = 0; size_t mUpperSectorBound = 0; - size_t mFailCountdown = SIZE_T_MAX; + size_t mFailCountdown = SIZE_MAX; }; diff --git a/components/nvs_flash/test/test_nvs.cpp b/components/nvs_flash/test/test_nvs.cpp index 6e8f4124fc..beaa79e816 100644 --- a/components/nvs_flash/test/test_nvs.cpp +++ b/components/nvs_flash/test/test_nvs.cpp @@ -554,11 +554,6 @@ public: static_assert(nKeys == sizeof(types) / sizeof(types[0]), ""); static_assert(nKeys == sizeof(values) / sizeof(values[0]), ""); - - auto generateRandomString = [](char* dst, size_t size) { - size_t len = 0; - }; - auto randomRead = [&](size_t index) -> esp_err_t { switch (types[index]) { case ItemType::I32: -- 2.40.0