1TEST_PROGRAM=test_nvs
2all: $(TEST_PROGRAM)
3
4SOURCE_FILES = \
5	esp_error_check_stub.cpp \
6	$(addprefix ../src/, \
7		nvs_types.cpp \
8		nvs_api.cpp \
9		nvs_page.cpp \
10		nvs_pagemanager.cpp \
11		nvs_storage.cpp \
12		nvs_item_hash_list.cpp \
13		nvs_handle_simple.cpp \
14		nvs_handle_locked.cpp \
15		nvs_partition_manager.cpp \
16		nvs_partition.cpp \
17		nvs_encrypted_partition.cpp \
18		nvs_cxx_api.cpp \
19	) \
20	spi_flash_emulation.cpp \
21	test_compressed_enum_table.cpp \
22	test_spi_flash_emulation.cpp \
23	test_intrusive_list.cpp \
24	test_nvs.cpp \
25	test_partition_manager.cpp \
26	test_nvs_handle.cpp \
27	test_nvs_storage.cpp \
28	test_nvs_partition.cpp \
29	test_nvs_cxx_api.cpp \
30	test_nvs_initialization.cpp \
31	main.cpp
32
33SOURCE_FILES_C = ../../esp_rom/linux/esp_rom_crc.c
34
35ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1)
36COMPILER := clang
37else
38COMPILER := gcc
39endif
40
41CPPFLAGS += -I../include -I../src -I../../esp_rom/include -I../../esp_rom/include/linux -I../../log/include -I./ -I../../esp_common/include -I../../esp32/include -I ../../mbedtls/mbedtls/include -I ../../spi_flash/include -I ../../hal/include -I ../../xtensa/include -I ../../../tools/catch -fprofile-arcs -ftest-coverage -g2 -ggdb
42CFLAGS += -fprofile-arcs -ftest-coverage -DLINUX_TARGET
43CXXFLAGS += -std=c++11 -Wall -Werror -DLINUX_TARGET
44LDFLAGS += -lstdc++ -Wall -fprofile-arcs -ftest-coverage
45
46ifeq ($(COMPILER),clang)
47CFLAGS += -fsanitize=address
48CXXFLAGS += -fsanitize=address
49LDFLAGS += -fsanitize=address
50endif
51
52OBJ_FILES = $(SOURCE_FILES:.cpp=.o)
53OBJ_FILES_C = $(SOURCE_FILES_C:.c=.o)
54
55COVERAGE_FILES = $(OBJ_FILES:.o=.gc*)
56
57$(OBJ_FILES): %.o: %.cpp
58$(OBJ_FILES_C): %.c: %.c
59
60$(TEST_PROGRAM): clean-coverage $(OBJ_FILES) $(OBJ_FILES_C)
61	$(MAKE) -C ../../mbedtls/mbedtls/ lib
62	g++ $(LDFLAGS) -o $(TEST_PROGRAM) $(OBJ_FILES) $(OBJ_FILES_C) ../../mbedtls/mbedtls/library/libmbedcrypto.a
63
64$(OUTPUT_DIR):
65	mkdir -p $(OUTPUT_DIR)
66
67test: $(TEST_PROGRAM)
68	./$(TEST_PROGRAM) -d yes exclude:[long]
69
70long-test: $(TEST_PROGRAM)
71	./$(TEST_PROGRAM) -d yes
72
73$(COVERAGE_FILES): $(TEST_PROGRAM) long-test
74
75coverage.info: $(COVERAGE_FILES)
76	find ../src/ -name "*.gcno" -exec gcov -r -pb {} +
77	lcov --capture --directory ../src --no-external --output-file coverage.info
78
79coverage_report: coverage.info
80	genhtml coverage.info --output-directory coverage_report
81	@echo "Coverage report is in coverage_report/index.html"
82
83clean-coverage:
84	rm -f $(COVERAGE_FILES) *.gcov
85	rm -rf coverage_report/
86	rm -f coverage.info
87
88clean: clean-coverage
89	$(MAKE) -C ../../mbedtls/mbedtls/ clean
90	rm -f $(OBJ_FILES) $(OBJ_FILES_C) $(TEST_PROGRAM)
91	rm -f ../nvs_partition_generator/partition_single_page.bin
92	rm -f ../nvs_partition_generator/partition_multipage_blob.bin
93	rm -f ../nvs_partition_generator/partition_encrypted.bin
94	rm -f ../nvs_partition_generator/partition_encrypted_using_keygen.bin
95	rm -f ../nvs_partition_generator/partition_encrypted_using_keyfile.bin
96	rm -f ../nvs_partition_generator/partition_decrypted.bin
97	rm -f ../nvs_partition_generator/partition_encoded.bin
98	rm -f ../nvs_partition_generator/Test-1-partition-encrypted.bin
99	rm -f ../nvs_partition_generator/Test-1-partition.bin
100	rm -f ../../../tools/mass_mfg/samples/sample_values_multipage_blob_created.csv
101	rm -f ../../../tools/mass_mfg/samples/sample_values_singlepage_blob_created.csv
102
103
104
105.PHONY: clean clean-coverage all test long-test
106