Skip to content

Commit e1d9983

Browse files
committed
Adding Makefiles for samples and test
1 parent 8aa5c18 commit e1d9983

File tree

6 files changed

+356
-0
lines changed

6 files changed

+356
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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.
2+
.prevent_execution:
3+
exit 0
4+
5+
CC = gcc
6+
7+
#remove @ for no make command prints
8+
DEBUG = @
9+
10+
APP_DIR = .
11+
APP_INCLUDE_DIRS += -I $(APP_DIR)
12+
APP_NAME = shadow_sample
13+
APP_SRC_FILES = $(APP_NAME).c
14+
15+
#IoT client directory
16+
IOT_CLIENT_DIR = ../../..
17+
18+
PLATFORM_DIR = $(IOT_CLIENT_DIR)/platform/linux/mbedtls
19+
PLATFORM_COMMON_DIR = $(IOT_CLIENT_DIR)/platform/linux/common
20+
21+
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/include
22+
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/external_libs/jsmn
23+
IOT_INCLUDE_DIRS += -I $(PLATFORM_COMMON_DIR)
24+
IOT_INCLUDE_DIRS += -I $(PLATFORM_DIR)
25+
26+
IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/src/ -name '*.c')
27+
IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/external_libs/jsmn -name '*.c')
28+
IOT_SRC_FILES += $(shell find $(PLATFORM_DIR)/ -name '*.c')
29+
IOT_SRC_FILES += $(shell find $(PLATFORM_COMMON_DIR)/ -name '*.c')
30+
31+
#TLS - mbedtls
32+
MBEDTLS_DIR = $(IOT_CLIENT_DIR)/external_libs/mbedTLS
33+
TLS_LIB_DIR = $(MBEDTLS_DIR)/library
34+
TLS_INCLUDE_DIR = -I $(MBEDTLS_DIR)/include
35+
EXTERNAL_LIBS += -L$(TLS_LIB_DIR)
36+
LD_FLAG += -Wl,-rpath,$(TLS_LIB_DIR)
37+
LD_FLAG += -ldl $(TLS_LIB_DIR)/libmbedtls.a $(TLS_LIB_DIR)/libmbedcrypto.a $(TLS_LIB_DIR)/libmbedx509.a
38+
39+
40+
#Aggregate all include and src directories
41+
INCLUDE_ALL_DIRS += $(IOT_INCLUDE_DIRS)
42+
INCLUDE_ALL_DIRS += $(TLS_INCLUDE_DIR)
43+
INCLUDE_ALL_DIRS += $(APP_INCLUDE_DIRS)
44+
45+
SRC_FILES += $(APP_SRC_FILES)
46+
SRC_FILES += $(IOT_SRC_FILES)
47+
48+
# Logging level control
49+
LOG_FLAGS += -DIOT_DEBUG
50+
LOG_FLAGS += -DIOT_INFO
51+
LOG_FLAGS += -DIOT_WARN
52+
LOG_FLAGS += -DIOT_ERROR
53+
54+
COMPILER_FLAGS += -g
55+
COMPILER_FLAGS += $(LOG_FLAGS)
56+
#If the processor is big endian uncomment the compiler flag
57+
#COMPILER_FLAGS += -DREVERSED
58+
59+
MBED_TLS_MAKE_CMD = cd $(MBEDTLS_DIR) && make
60+
61+
PRE_MAKE_CMD = $(MBED_TLS_MAKE_CMD)
62+
MAKE_CMD = $(CC) $(SRC_FILES) $(COMPILER_FLAGS) -o $(APP_NAME) $(LD_FLAG) $(EXTERNAL_LIBS) $(INCLUDE_ALL_DIRS)
63+
64+
all:
65+
$(PRE_MAKE_CMD)
66+
$(DEBUG)$(MAKE_CMD)
67+
$(POST_MAKE_CMD)
68+
69+
clean:
70+
rm -f $(APP_DIR)/$(APP_NAME)
71+
$(MBED_TLS_MAKE_CMD) clean
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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.
2+
.prevent_execution:
3+
exit 0
4+
5+
CC = gcc
6+
7+
#remove @ for no make command prints
8+
DEBUG = @
9+
10+
APP_DIR = .
11+
APP_INCLUDE_DIRS += -I $(APP_DIR)
12+
APP_NAME = shadow_console_echo
13+
APP_SRC_FILES = $(APP_NAME).c
14+
15+
#IoT client directory
16+
IOT_CLIENT_DIR = ../../..
17+
18+
PLATFORM_DIR = $(IOT_CLIENT_DIR)/platform/linux/mbedtls
19+
PLATFORM_COMMON_DIR = $(IOT_CLIENT_DIR)/platform/linux/common
20+
21+
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/include
22+
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/external_libs/jsmn
23+
IOT_INCLUDE_DIRS += -I $(PLATFORM_COMMON_DIR)
24+
IOT_INCLUDE_DIRS += -I $(PLATFORM_DIR)
25+
26+
IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/src/ -name '*.c')
27+
IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/external_libs/jsmn -name '*.c')
28+
IOT_SRC_FILES += $(shell find $(PLATFORM_DIR)/ -name '*.c')
29+
IOT_SRC_FILES += $(shell find $(PLATFORM_COMMON_DIR)/ -name '*.c')
30+
31+
#TLS - mbedtls
32+
MBEDTLS_DIR = $(IOT_CLIENT_DIR)/external_libs/mbedTLS
33+
TLS_LIB_DIR = $(MBEDTLS_DIR)/library
34+
TLS_INCLUDE_DIR = -I $(MBEDTLS_DIR)/include
35+
EXTERNAL_LIBS += -L$(TLS_LIB_DIR)
36+
LD_FLAG += -Wl,-rpath,$(TLS_LIB_DIR)
37+
LD_FLAG += -ldl $(TLS_LIB_DIR)/libmbedtls.a $(TLS_LIB_DIR)/libmbedcrypto.a $(TLS_LIB_DIR)/libmbedx509.a
38+
39+
40+
#Aggregate all include and src directories
41+
INCLUDE_ALL_DIRS += $(IOT_INCLUDE_DIRS)
42+
INCLUDE_ALL_DIRS += $(MQTT_INCLUDE_DIR)
43+
INCLUDE_ALL_DIRS += $(TLS_INCLUDE_DIR)
44+
INCLUDE_ALL_DIRS += $(APP_INCLUDE_DIRS)
45+
46+
SRC_FILES += $(MQTT_SRC_FILES)
47+
SRC_FILES += $(APP_SRC_FILES)
48+
SRC_FILES += $(IOT_SRC_FILES)
49+
50+
# Logging level control
51+
LOG_FLAGS += -DIOT_DEBUG
52+
LOG_FLAGS += -DIOT_INFO
53+
LOG_FLAGS += -DIOT_WARN
54+
LOG_FLAGS += -DIOT_ERROR
55+
56+
COMPILER_FLAGS += -g
57+
COMPILER_FLAGS += $(LOG_FLAGS)
58+
59+
#If the processor is big endian uncomment the compiler flag
60+
#COMPILER_FLAGS += -DREVERSED
61+
62+
MBED_TLS_MAKE_CMD = cd $(MBEDTLS_DIR) && make
63+
64+
PRE_MAKE_CMD = $(MBED_TLS_MAKE_CMD)
65+
MAKE_CMD = $(CC) $(SRC_FILES) $(COMPILER_FLAGS) -o $(APP_NAME) $(LD_FLAG) $(EXTERNAL_LIBS) $(INCLUDE_ALL_DIRS)
66+
67+
all:
68+
$(PRE_MAKE_CMD)
69+
$(DEBUG)$(MAKE_CMD)
70+
$(POST_MAKE_CMD)
71+
72+
clean:
73+
rm -f $(APP_DIR)/$(APP_NAME)
74+
$(MBED_TLS_MAKE_CMD) clean
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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.
2+
.prevent_execution:
3+
exit 0
4+
5+
CC = gcc
6+
7+
#remove @ for no make command prints
8+
DEBUG = @
9+
10+
APP_DIR = .
11+
APP_INCLUDE_DIRS += -I $(APP_DIR)
12+
APP_NAME = subscribe_publish_sample
13+
APP_SRC_FILES = $(APP_NAME).c
14+
15+
#IoT client directory
16+
IOT_CLIENT_DIR = ../../..
17+
18+
PLATFORM_DIR = $(IOT_CLIENT_DIR)/platform/linux/mbedtls
19+
PLATFORM_COMMON_DIR = $(IOT_CLIENT_DIR)/platform/linux/common
20+
21+
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/include
22+
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/external_libs/jsmn
23+
IOT_INCLUDE_DIRS += -I $(PLATFORM_COMMON_DIR)
24+
IOT_INCLUDE_DIRS += -I $(PLATFORM_DIR)
25+
26+
IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/src/ -name '*.c')
27+
IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/external_libs/jsmn -name '*.c')
28+
IOT_SRC_FILES += $(shell find $(PLATFORM_DIR)/ -name '*.c')
29+
IOT_SRC_FILES += $(shell find $(PLATFORM_COMMON_DIR)/ -name '*.c')
30+
31+
#TLS - mbedtls
32+
MBEDTLS_DIR = $(IOT_CLIENT_DIR)/external_libs/mbedTLS
33+
TLS_LIB_DIR = $(MBEDTLS_DIR)/library
34+
TLS_INCLUDE_DIR = -I $(MBEDTLS_DIR)/include
35+
EXTERNAL_LIBS += -L$(TLS_LIB_DIR)
36+
LD_FLAG += -Wl,-rpath,$(TLS_LIB_DIR)
37+
LD_FLAG += -ldl $(TLS_LIB_DIR)/libmbedtls.a $(TLS_LIB_DIR)/libmbedcrypto.a $(TLS_LIB_DIR)/libmbedx509.a -lpthread
38+
39+
#Aggregate all include and src directories
40+
INCLUDE_ALL_DIRS += $(IOT_INCLUDE_DIRS)
41+
INCLUDE_ALL_DIRS += $(TLS_INCLUDE_DIR)
42+
INCLUDE_ALL_DIRS += $(APP_INCLUDE_DIRS)
43+
44+
SRC_FILES += $(APP_SRC_FILES)
45+
SRC_FILES += $(IOT_SRC_FILES)
46+
47+
# Logging level control
48+
LOG_FLAGS += -DIOT_DEBUG
49+
LOG_FLAGS += -DIOT_INFO
50+
LOG_FLAGS += -DIOT_WARN
51+
LOG_FLAGS += -DIOT_ERROR
52+
53+
COMPILER_FLAGS += $(LOG_FLAGS)
54+
#If the processor is big endian uncomment the compiler flag
55+
#COMPILER_FLAGS += -DREVERSED
56+
57+
MBED_TLS_MAKE_CMD = cd $(MBEDTLS_DIR) && make
58+
59+
PRE_MAKE_CMD = $(MBED_TLS_MAKE_CMD)
60+
MAKE_CMD = $(CC) $(SRC_FILES) $(COMPILER_FLAGS) -o $(APP_NAME) $(LD_FLAG) $(EXTERNAL_LIBS) $(INCLUDE_ALL_DIRS)
61+
62+
all:
63+
$(PRE_MAKE_CMD)
64+
$(DEBUG)$(MAKE_CMD)
65+
$(POST_MAKE_CMD)
66+
67+
clean:
68+
rm -f $(APP_DIR)/$(APP_NAME)
69+
$(MBED_TLS_MAKE_CMD) clean

tests/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Tests
2+
This folder contains tests to verify SDK functionality. These have been tested to work with Linux but haven't been ported to any specific platform. For additional information about porting the Device SDK for embedded C onto additional platforms please refer to the [PortingGuide](https://github.com/aws/aws-iot-device-sdk-embedded-c/blob/master/PortingGuide.md/).
3+
A description for each folder is given below
4+
5+
## integration
6+
This folder contains integration tests that run directly against the server. For further information on how to run these tests check out the [Integration Test README](https://github.com/aws/aws-iot-device-sdk-embedded-c/blob/master/tests/integration/README.md/).

tests/integration/Makefile

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
CC = gcc
2+
3+
DEBUG =
4+
5+
#IoT client directory
6+
IOT_CLIENT_DIR = ../..
7+
8+
APP_DIR = $(IOT_CLIENT_DIR)/tests/integration
9+
APP_NAME = integration_tests_mbedtls
10+
MT_APP_NAME = integration_tests_mbedtls_mt
11+
APP_SRC_FILES = $(shell find $(APP_DIR)/src/ -name '*.c')
12+
MT_APP_SRC_FILES = $(shell find $(APP_DIR)/multithreadingTest/ -name '*.c')
13+
APP_INCLUDE_DIRS = -I $(APP_DIR)/include
14+
15+
PLATFORM_DIR = $(IOT_CLIENT_DIR)/platform/linux
16+
17+
#MbedTLS directory
18+
TEMP_MBEDTLS_SRC_DIR = $(IOT_CLIENT_DIR)/external_libs/mbedTLS
19+
TLS_LIB_DIR = $(TEMP_MBEDTLS_SRC_DIR)/library
20+
TLS_INCLUDE_DIR = -I $(TEMP_MBEDTLS_SRC_DIR)/include
21+
22+
EXTERNAL_LIBS += -L$(TLS_LIB_DIR)
23+
LD_FLAG += -Wl,-rpath,$(TLS_LIB_DIR)
24+
LD_FLAG += -ldl $(TLS_LIB_DIR)/libmbedtls.a $(TLS_LIB_DIR)/libmbedcrypto.a $(TLS_LIB_DIR)/libmbedx509.a -lpthread
25+
26+
# Logging level control
27+
#LOG_FLAGS += -DIOT_DEBUG
28+
#LOG_FLAGS += -DIOT_TRACE
29+
LOG_FLAGS += -DIOT_INFO
30+
LOG_FLAGS += -DIOT_WARN
31+
LOG_FLAGS += -DIOT_ERROR
32+
COMPILER_FLAGS += $(LOG_FLAGS)
33+
34+
#IoT client directory
35+
PLATFORM_COMMON_DIR = $(PLATFORM_DIR)/common
36+
PLATFORM_THREAD_DIR = $(PLATFORM_DIR)/pthread
37+
PLATFORM_NETWORK_DIR = $(PLATFORM_DIR)/mbedtls
38+
39+
IOT_INCLUDE_DIRS = -I $(PLATFORM_COMMON_DIR)
40+
IOT_INCLUDE_DIRS += -I $(PLATFORM_THREAD_DIR)
41+
IOT_INCLUDE_DIRS += -I $(PLATFORM_NETWORK_DIR)
42+
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/include
43+
IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/external_libs/jsmn
44+
45+
IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/src/ -name '*.c')
46+
IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/external_libs/jsmn/ -name '*.c')
47+
IOT_SRC_FILES += $(shell find $(PLATFORM_NETWORK_DIR)/ -name '*.c')
48+
IOT_SRC_FILES += $(shell find $(PLATFORM_COMMON_DIR)/ -name '*.c')
49+
IOT_SRC_FILES += $(shell find $(PLATFORM_THREAD_DIR)/ -name '*.c')
50+
51+
#Aggregate all include and src directories
52+
INCLUDE_ALL_DIRS += $(IOT_INCLUDE_DIRS)
53+
INCLUDE_ALL_DIRS += $(APP_INCLUDE_DIRS)
54+
INCLUDE_ALL_DIRS += $(TLS_INCLUDE_DIR)
55+
56+
SRC_FILES += $(APP_SRC_FILES)
57+
SRC_FILES += $(IOT_SRC_FILES)
58+
59+
MT_SRC_FILES += $(MT_APP_SRC_FILES)
60+
MT_SRC_FILES += $(IOT_SRC_FILES)
61+
62+
COMPILER_FLAGS += -g
63+
COMPILER_FLAGS += $(LOG_FLAGS)
64+
PRE_MAKE_CMDS += cd $(TEMP_MBEDTLS_SRC_DIR) && make
65+
66+
MAKE_CMD = $(CC) $(SRC_FILES) $(COMPILER_FLAGS) -g3 -o $(APP_DIR)/$(APP_NAME) $(EXTERNAL_LIBS) $(LD_FLAG) $(INCLUDE_ALL_DIRS);
67+
MAKE_MT_CMD = $(CC) $(MT_SRC_FILES) $(COMPILER_FLAGS) -g3 -D_ENABLE_THREAD_SUPPORT_ -o $(APP_DIR)/$(MT_APP_NAME) $(EXTERNAL_LIBS) $(LD_FLAG) $(INCLUDE_ALL_DIRS);
68+
69+
ifeq ($(CODE_SIZE_ENABLE),Y)
70+
POST_MAKE_CMDS += $(CC) -c $(SRC_FILES) $(INCLUDE_ALL_DIRS) -fstack-usage;
71+
POST_MAKE_CMDS += (size --format=Berkeley *.o > $(APP_NAME)_size_info.txt);
72+
POST_MAKE_CMDS += (cat *.su >> $(APP_NAME)_stack_usage.txt);
73+
POST_MAKE_CMDS += (rm *.o);
74+
POST_MAKE_CMDS += (rm *.su);
75+
CLEAN_CMD += (rm -f $(APP_NAME)_size_info.txt);
76+
CLEAN_CMD += (rm -f $(APP_NAME)_stack_usage.txt);
77+
endif
78+
79+
all:
80+
$(PRE_MAKE_CMDS)
81+
$(DEBUG)$(MAKE_CMD)
82+
$(DEBUG)$(MAKE_MT_CMD)
83+
./$(APP_NAME)
84+
./$(MT_APP_NAME)
85+
$(POST_MAKE_CMDS)
86+
87+
clean:
88+
rm -f $(APP_DIR)/$(APP_NAME)
89+
rm -f $(APP_DIR)/$(MT_APP_NAME)
90+
$(CLEAN_CMD)
91+
92+
ALL_TARGETS_CLEAN += test-integration-assert-clean

tests/integration/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## Integration Tests
2+
This folder contains integration tests to verify Embedded C SDK functionality. These have been tested to work with Linux but haven't been ported to any specific platform. For additional information about porting the Device SDK for embedded C onto additional platforms please refer to the [PortingGuide](https://github.com/aws/aws-iot-device-sdk-embedded-c/blob/master/PortingGuide.md/).
3+
To run these tests, follow the below steps:
4+
5+
* Place device identity cert and private key in locations referenced in the `certs` folder
6+
* Download certificate authority CA file from [Symantec](https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem) and place in `certs` folder
7+
* Ensure the names of the cert files are the same as in the `aws_iot_config.h` file
8+
* Ensure the certificate has an attached policy which allows the proper permissions for AWS IoT
9+
* Update the Host endpoint in the `aws_iot_config.h` file
10+
* Build the example using make. (''make''). The tests will run automatically as a part of the build process
11+
* For more detailed Debug output, enable the IOT_DEBUG flag in `Logging level control` section of the Makefile. IOT_TRACE can be enabled as well for very detailed information on what functions are being executed
12+
* More information on the each test is below
13+
14+
### Integration test configuration
15+
For all the tests below, there is additional configuration in the `integ_tests_config.h`. The configuration options are explained below:
16+
17+
* PUBLISH_COUNT - Number of messages to publish in each publish thread
18+
* MAX_PUB_THREAD_COUNT - Maximum number of threads to create for the multi-threading test
19+
* RX_RECEIVE_PERCENTAGE - Minimum percentage of messages that must be received back by the yield thread. This is here ONLY because sometimes the yield thread doesn't get scheduled before the publish thread when it is created. In every other case, 100% messages should be received
20+
* CONNECT_MAX_ATTEMPT_COUNT - Max number of initial connect retries
21+
* THREAD_SLEEP_INTERVAL_USEC - Interval that each thread sleeps for
22+
* INTEGRATION_TEST_TOPIC - Test topic to publish on
23+
* INTEGRATION_TEST_CLIENT_ID - Client ID to be used for single client tests
24+
* INTEGRATION_TEST_CLIENT_ID_PUB, INTEGRATION_TEST_CLIENT_ID_SUB - Client IDs to be used for multiple client tests
25+
26+
### Test 1 - Basic Connectivity Test
27+
This test verifies basic connectivity with the server. It creates one client instance and connects to the server. It subscribes to the Integration Test topic. Then it creates two threads, one publish thread and one yield thread. The publish thread publishes `PUBLISH_COUNT` messages on the test topic and the yield thread receives them. Once all the messages are published, the program waits for 1 sec to ensure all the messages have sufficient time to be received.
28+
The test ends with the program verifying that all the messages were received and no other errors occurred.
29+
30+
### Test 2 - Multiple Client Connectivity Test
31+
This test verifies usage of multiple clients in the same application. It creates two client instances and both connect to the server. One client instance subscribes to the Integration Test topic. The other client instance publishes `PUBLISH_COUNT` messages on the test topic and the yield instance receives them. Once all the messages are published, the program waits for 1 sec to ensure all the messages have sufficient time to be received.
32+
The test ends with the program verifying that all the messages were received and no other errors occurred.
33+
34+
### Test 3 - Auto Reconnect Test
35+
This test verifies Auto-reconnect functionality. It creates one client instance. Then it performs 3 separate tests
36+
37+
* Tests the disconnect handler by causing a TLS layer disconnect.
38+
* Tests manual reconnect API by causing a TLS layer disconnect with auto-reconnect disabled
39+
* Lastly, it tests the Auto-reconnect API by enabling auto-reconnect. It renames the rootCA file to a different name to prevent immediate reconnect, verifies the error codes are returned properly and that the reconnect algorithm is running. Once that check is satisfied, it renames the rootCA file back to the original names and verifies the client was able to reconnect.
40+
41+
### Test 4 - Multi-threading Validation Test
42+
This test is used to validate thread-safe operations. This creates on client instance, one yield thread, one thread to test subscribe/unsubscribe behavior and MAX_PUB_THREAD_COUNT number of publish threads. Then it proceeds to publish PUBLISH_COUNT messages on the test topic from each publish thread. The subscribe/unsubscribe thread runs in the background constantly subscribing and unsubscribing to a second test topic. The yield threads records which messages were received.
43+
44+
The test verifies whether all the messages that were published were received or not. It also checks for errors that could occur in multi-threaded scenarios. The test has been run with 10 threads sending 500 messages each and verified to be working fine. It can be used as a reference testing application to validate whether your use case will work with multi-threading enabled.

0 commit comments

Comments
 (0)