test

Committer:
peyo
Date:
Wed Apr 12 14:09:46 2017 +0200
Revision:
1:3f75eb8d46f4
Parent:
0:cd5404401c2f
add main

Who changed what in which revision?

UserRevisionLine numberNew contents of line
peyo 0:cd5404401c2f 1 #This target is to ensure accidental execution of Makefile as a bash script will not execute commands like rm in unexpected directories and exit gracefully.
peyo 0:cd5404401c2f 2 .prevent_execution:
peyo 0:cd5404401c2f 3 exit 0
peyo 0:cd5404401c2f 4
peyo 0:cd5404401c2f 5 #Set this to @ to keep the makefile quiet
peyo 0:cd5404401c2f 6 ifndef SILENCE
peyo 0:cd5404401c2f 7 SILENCE = @
peyo 0:cd5404401c2f 8 endif
peyo 0:cd5404401c2f 9
peyo 0:cd5404401c2f 10 CC = gcc
peyo 0:cd5404401c2f 11 RM = rm
peyo 0:cd5404401c2f 12
peyo 0:cd5404401c2f 13 DEBUG =
peyo 0:cd5404401c2f 14
peyo 0:cd5404401c2f 15 #--- Inputs ----#
peyo 0:cd5404401c2f 16 COMPONENT_NAME = IotSdkC
peyo 0:cd5404401c2f 17
peyo 0:cd5404401c2f 18 ALL_TARGETS := build-cpputest
peyo 0:cd5404401c2f 19 ALL_TARGETS_CLEAN :=
peyo 0:cd5404401c2f 20
peyo 0:cd5404401c2f 21 CPPUTEST_USE_EXTENSIONS = Y
peyo 0:cd5404401c2f 22 CPP_PLATFORM = Gcc
peyo 0:cd5404401c2f 23 CPPUTEST_CFLAGS += -std=gnu99
peyo 0:cd5404401c2f 24 CPPUTEST_LDFLAGS += -lpthread
peyo 0:cd5404401c2f 25 CPPUTEST_CFLAGS += -D__USE_BSD
peyo 0:cd5404401c2f 26 CPPUTEST_USE_GCOV = Y
peyo 0:cd5404401c2f 27
peyo 0:cd5404401c2f 28 #IoT client directory
peyo 0:cd5404401c2f 29 IOT_CLIENT_DIR = .
peyo 0:cd5404401c2f 30
peyo 0:cd5404401c2f 31 APP_DIR = $(IOT_CLIENT_DIR)/tests/unit
peyo 0:cd5404401c2f 32 APP_NAME = aws_iot_sdk_unit_tests
peyo 0:cd5404401c2f 33 APP_SRC_FILES = $(shell find $(APP_DIR)/src -name '*.cpp')
peyo 0:cd5404401c2f 34 APP_SRC_FILES = $(shell find $(APP_DIR)/src -name '*.c')
peyo 0:cd5404401c2f 35 APP_INCLUDE_DIRS = -I $(APP_DIR)/include
peyo 0:cd5404401c2f 36
peyo 0:cd5404401c2f 37 CPPUTEST_DIR = $(IOT_CLIENT_DIR)/external_libs/CppUTest
peyo 0:cd5404401c2f 38
peyo 0:cd5404401c2f 39 # Provide paths for CppUTest to run Unit Tests otherwise build will fail
peyo 0:cd5404401c2f 40 ifndef CPPUTEST_INCLUDE
peyo 0:cd5404401c2f 41 CPPUTEST_INCLUDE = $(CPPUTEST_DIR)/include
peyo 0:cd5404401c2f 42 endif
peyo 0:cd5404401c2f 43
peyo 0:cd5404401c2f 44 ifndef CPPUTEST_BUILD_LIB
peyo 0:cd5404401c2f 45 CPPUTEST_BUILD_LIB = $(CPPUTEST_DIR)
peyo 0:cd5404401c2f 46 endif
peyo 0:cd5404401c2f 47
peyo 0:cd5404401c2f 48 CPPUTEST_LDFLAGS += -ldl $(CPPUTEST_BUILD_LIB)/libCppUTest.a
peyo 0:cd5404401c2f 49
peyo 0:cd5404401c2f 50 PLATFORM_DIR = $(IOT_CLIENT_DIR)/platform/linux
peyo 0:cd5404401c2f 51
peyo 0:cd5404401c2f 52 #MbedTLS directory
peyo 0:cd5404401c2f 53 TEMP_MBEDTLS_SRC_DIR = $(APP_DIR)/tls_mock
peyo 0:cd5404401c2f 54 TLS_LIB_DIR = $(TEMP_MBEDTLS_SRC_DIR)
peyo 0:cd5404401c2f 55 TLS_INCLUDE_DIR = -I $(TEMP_MBEDTLS_SRC_DIR)
peyo 0:cd5404401c2f 56
peyo 0:cd5404401c2f 57 # Logging level control
peyo 0:cd5404401c2f 58 LOG_FLAGS += -DENABLE_IOT_DEBUG
peyo 0:cd5404401c2f 59 #LOG_FLAGS += -DENABLE_IOT_TRACE
peyo 0:cd5404401c2f 60 LOG_FLAGS += -DENABLE_IOT_INFO
peyo 0:cd5404401c2f 61 LOG_FLAGS += -DENABLE_IOT_WARN
peyo 0:cd5404401c2f 62 LOG_FLAGS += -DENABLE_IOT_ERROR
peyo 0:cd5404401c2f 63 COMPILER_FLAGS += $(LOG_FLAGS)
peyo 0:cd5404401c2f 64
peyo 0:cd5404401c2f 65 EXTERNAL_LIBS += -L$(CPPUTEST_BUILD_LIB)
peyo 0:cd5404401c2f 66
peyo 0:cd5404401c2f 67 #IoT client directory
peyo 0:cd5404401c2f 68 PLATFORM_COMMON_DIR = $(PLATFORM_DIR)/common
peyo 0:cd5404401c2f 69
peyo 0:cd5404401c2f 70 IOT_INCLUDE_DIRS = -I $(PLATFORM_COMMON_DIR)
peyo 0:cd5404401c2f 71 IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/include
peyo 0:cd5404401c2f 72 IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/external_libs/jsmn
peyo 0:cd5404401c2f 73
peyo 0:cd5404401c2f 74 IOT_SRC_FILES += $(shell find $(PLATFORM_COMMON_DIR)/ -name '*.c')
peyo 0:cd5404401c2f 75 IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/src/ -name '*.c')
peyo 0:cd5404401c2f 76 IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/external_libs/jsmn/ -name '*.c')
peyo 0:cd5404401c2f 77
peyo 0:cd5404401c2f 78 #Aggregate all include and src directories
peyo 0:cd5404401c2f 79 INCLUDE_DIRS += $(IOT_INCLUDE_DIRS)
peyo 0:cd5404401c2f 80 INCLUDE_DIRS += $(APP_INCLUDE_DIRS)
peyo 0:cd5404401c2f 81 INCLUDE_DIRS += $(TLS_INCLUDE_DIR)
peyo 0:cd5404401c2f 82 INCLUDE_DIRS += $(CPPUTEST_INCLUDE)
peyo 0:cd5404401c2f 83
peyo 0:cd5404401c2f 84 TEST_SRC_DIRS = $(APP_DIR)/src
peyo 0:cd5404401c2f 85
peyo 0:cd5404401c2f 86 SRC_FILES += $(APP_SRC_FILES)
peyo 0:cd5404401c2f 87 SRC_FILES += $(IOT_SRC_FILES)
peyo 0:cd5404401c2f 88
peyo 0:cd5404401c2f 89 COMPILER_FLAGS += -g
peyo 0:cd5404401c2f 90 COMPILER_FLAGS += $(LOG_FLAGS)
peyo 0:cd5404401c2f 91 PRE_MAKE_CMDS = cd $(CPPUTEST_DIR) &&
peyo 0:cd5404401c2f 92 PRE_MAKE_CMDS += cmake CMakeLists.txt &&
peyo 0:cd5404401c2f 93 PRE_MAKE_CMDS += make &&
peyo 0:cd5404401c2f 94 PRE_MAKE_CMDS += cd - &&
peyo 0:cd5404401c2f 95 PRE_MAKE_CMDS += pwd &&
peyo 0:cd5404401c2f 96 PRE_MAKE_CMDS += cp -f $(CPPUTEST_DIR)/src/CppUTest/libCppUTest.a $(CPPUTEST_DIR)/libCppUTest.a &&
peyo 0:cd5404401c2f 97 PRE_MAKE_CMDS += cp -f $(CPPUTEST_DIR)/src/CppUTestExt/libCppUTestExt.a $(CPPUTEST_DIR)/libCppUTestExt.a
peyo 0:cd5404401c2f 98
peyo 0:cd5404401c2f 99 # Using TLS Mock for running Unit Tests
peyo 0:cd5404401c2f 100 MOCKS_SRC += $(APP_DIR)/tls_mock/aws_iot_tests_unit_mock_tls_params.c
peyo 0:cd5404401c2f 101 MOCKS_SRC += $(APP_DIR)/tls_mock/aws_iot_tests_unit_mock_tls.c
peyo 0:cd5404401c2f 102
peyo 0:cd5404401c2f 103 ISYSTEM_HEADERS += $(IOT_ISYSTEM_HEADERS)
peyo 0:cd5404401c2f 104 CPPUTEST_CPPFLAGS += $(ISYSTEM_HEADERS)
peyo 0:cd5404401c2f 105 CPPUTEST_CPPFLAGS += $(LOG_FLAGS)
peyo 0:cd5404401c2f 106
peyo 0:cd5404401c2f 107 LCOV_EXCLUDE_PATTERN = "tests/unit/*"
peyo 0:cd5404401c2f 108 LCOV_EXCLUDE_PATTERN += "tests/integration/*"
peyo 0:cd5404401c2f 109 LCOV_EXCLUDE_PATTERN += "external_libs/*"
peyo 0:cd5404401c2f 110
peyo 0:cd5404401c2f 111 #use this section for running a specific group of tests, comment this to run all
peyo 0:cd5404401c2f 112 #ONLY FOR TESTING PURPOSE
peyo 0:cd5404401c2f 113 #COMMAND_LINE_ARGUMENTS += -g CommonTests
peyo 0:cd5404401c2f 114 #COMMAND_LINE_ARGUMENTS += -v
peyo 0:cd5404401c2f 115
peyo 0:cd5404401c2f 116 build-cpputest:
peyo 0:cd5404401c2f 117 $(PRE_MAKE_CMDS)
peyo 0:cd5404401c2f 118
peyo 0:cd5404401c2f 119 include CppUTestMakefileWorker.mk
peyo 0:cd5404401c2f 120
peyo 0:cd5404401c2f 121 .PHONY: run-unit-tests
peyo 0:cd5404401c2f 122 run-unit-tests: $(ALL_TARGETS)
peyo 0:cd5404401c2f 123 @echo $(ALL_TARGETS)
peyo 0:cd5404401c2f 124
peyo 0:cd5404401c2f 125 .PHONY: clean
peyo 0:cd5404401c2f 126 clean:
peyo 0:cd5404401c2f 127 $(MAKE) -C $(CPPUTEST_DIR) clean
peyo 0:cd5404401c2f 128 $(RM) -rf build_output
peyo 0:cd5404401c2f 129 $(RM) -rf gcov
peyo 0:cd5404401c2f 130 $(RM) -rf objs
peyo 0:cd5404401c2f 131 $(RM) -rf testLibs