From 57fe2af8bc419922cc1501d966d5e7036aae5025 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Sun, 17 May 2015 18:07:24 +0200 Subject: [PATCH] get all tests to comile and use VPATH, common Makefile for all --- test/Makefile | 33 ++++++++++++++++++++++++++++++++ test/ble_client/Makefile | 3 +++ test/des_iterator/Makefile | 15 +++++++++++---- test/gatt_client/Makefile | 19 +++++++++++------- test/gatt_client/mock.c | 5 ++++- test/linked_list/Makefile | 13 ++++++++++--- test/remote_device_db/Makefile | 25 ++++++++++++++++-------- test/sdp_client/Makefile | 23 ++++++++++++++++------ test/security_manager/Makefile | 35 +++++++++++++++++++++------------- test/security_manager/mock.c | 20 +++++++++++++++++++ 10 files changed, 149 insertions(+), 42 deletions(-) create mode 100644 test/Makefile diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 000000000..89b12a9a9 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,33 @@ + +# Makefile to build and run all tests + +SUBDIRS = \ + ble_client \ + des_iterator \ + gatt_client \ + linked_list \ + remote_device_db \ + sdp_client \ + security_manager \ + +EXCLUDED = ios + +subdirs: + echo Building all tests + for dir in $(SUBDIRS); do \ + $(MAKE) -C $$dir; \ + done + +clean: + echo Clean all test + for dir in $(SUBDIRS); do \ + $(MAKE) -C $$dir clean; \ + done + +test: + echo Run all test + for dir in $(SUBDIRS); do \ + $(MAKE) -C $$dir test; \ + done + + diff --git a/test/ble_client/Makefile b/test/ble_client/Makefile index 82ad3b502..c8172e056 100644 --- a/test/ble_client/Makefile +++ b/test/ble_client/Makefile @@ -33,6 +33,9 @@ all: ad_parser ad_parser: ${CORE_OBJ} ${COMMON_OBJ} advertising_data_parser.c ${CC} ${CORE_OBJ} ${COMMON_OBJ} advertising_data_parser.c ${CFLAGS} ${LDFLAGS} -o $@ +test: + ./ad_parser + clean: rm -f ad_parser le_central rm -f *.o diff --git a/test/des_iterator/Makefile b/test/des_iterator/Makefile index f73b4814d..34ff05635 100644 --- a/test/des_iterator/Makefile +++ b/test/des_iterator/Makefile @@ -6,11 +6,16 @@ BTSTACK_ROOT = ../.. CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest CFLAGS = -g -Wall -I. -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include -I$(CPPUTEST_HOME)/include -LDFLAGS += -L$(CPPUTEST_HOME) -lCppUTest -lCppUTestExt +LDFLAGS += -lCppUTest -lCppUTestExt +# -L$(CPPUTEST_HOME) + +VPATH += ${BTSTACK_ROOT}/ble +VPATH += ${BTSTACK_ROOT}/src +VPATH += ${BTSTACK_ROOT}/platforms/posix/src COMMON = \ - ${BTSTACK_ROOT}/src/sdp_util.c \ - ${BTSTACK_ROOT}/src/utils.c + sdp_util.c \ + utils.c COMMON_OBJ = $(COMMON:.c=.o) @@ -19,8 +24,10 @@ all: des_iterator_test des_iterator_test: ${COMMON_OBJ} des_iterator_test.c ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ +test: + ./des_iterator_test clean: - rm -f des_iterator_test *.o ${BTSTACK_ROOT}/src/*.o + rm -f des_iterator_test *.o rm -rf *.dSYM \ No newline at end of file diff --git a/test/gatt_client/Makefile b/test/gatt_client/Makefile index 00efc1f0f..e2e6784f4 100644 --- a/test/gatt_client/Makefile +++ b/test/gatt_client/Makefile @@ -6,7 +6,8 @@ BTSTACK_ROOT = ../.. CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest CFLAGS = -DUNIT_TEST -x c++ -g -Wall -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/ble -I${BTSTACK_ROOT}/include -I$(CPPUTEST_HOME)/include -LDFLAGS += -L$(CPPUTEST_HOME) -lCppUTest -lCppUTestExt +LDFLAGS += -lCppUTest -lCppUTestExt +# -L$(CPPUTEST_HOME) VPATH += ${BTSTACK_ROOT}/ble VPATH += ${BTSTACK_ROOT}/src @@ -26,26 +27,30 @@ COMMON = \ att.c \ ad_parser.c \ gatt_client.c \ - gatt_client_test.c \ + le_device_db_memory.c \ mock.c COMMON_OBJ = $(COMMON:.c=.o) -all: gatt_client le_central +all: gatt_client_test le_central # compile .ble description profile.h: profile.gatt python ${BTSTACK_ROOT}/ble/compile-gatt.py $< $@ -gatt_client: ${CORE_OBJ} ${COMMON_OBJ} gatt_client.o profile.h expected_results.h - ${CC} ${CORE_OBJ} ${COMMON_OBJ} gatt_client.o ${CFLAGS} ${LDFLAGS} -o $@ +gatt_client_test: profile.h ${CORE_OBJ} ${COMMON_OBJ} gatt_client_test.o expected_results.h + ${CC} ${CORE_OBJ} ${COMMON_OBJ} gatt_client_test.o ${CFLAGS} ${LDFLAGS} -o $@ le_central: ${CORE_OBJ} ${COMMON_OBJ} le_central.o ${CC} ${CORE_OBJ} ${COMMON_OBJ} le_central.o ${CFLAGS} ${LDFLAGS} -o $@ +test: + ./gatt_client_test + ./le_central + clean: - rm -f gatt_client le_central - rm -f *.o *.o ${BTSTACK_ROOT}/ble/*.o + rm -f gatt_client_test le_central + rm -f *.o rm -rf *.dSYM \ No newline at end of file diff --git a/test/gatt_client/mock.c b/test/gatt_client/mock.c index 15dd5315a..3f3865575 100644 --- a/test/gatt_client/mock.c +++ b/test/gatt_client/mock.c @@ -101,9 +101,12 @@ int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t l int sm_cmac_ready(void){ return 1; } -void sm_cmac_start(sm_key_t k, uint16_t message_len, uint8_t * message, void (*done_handler)(uint8_t hash[8])){ +void sm_cmac_start(sm_key_t k, uint16_t message_len, uint8_t * message, uint32_t sign_counter, void (*done_handler)(uint8_t hash[8])){ //sm_notify_client(SM_IDENTITY_RESOLVING_SUCCEEDED, sm_central_device_addr_type, sm_central_device_address, 0, sm_central_device_matched); } +int sm_le_device_index(uint16_t handle ){ + return -1; +} void run_loop_set_timer(timer_source_t *a, uint32_t timeout_in_ms){ } diff --git a/test/linked_list/Makefile b/test/linked_list/Makefile index caa629eb3..0e08d07d4 100644 --- a/test/linked_list/Makefile +++ b/test/linked_list/Makefile @@ -6,11 +6,15 @@ BTSTACK_ROOT = ../.. CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest CFLAGS = -g -Wall -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include -I$(CPPUTEST_HOME)/include -LDFLAGS += -L$(CPPUTEST_HOME)/lib -lCppUTest -lCppUTestExt +LDFLAGS += -lCppUTest -lCppUTestExt +# -L$(CPPUTEST_HOME)/lib + +VPATH += ${BTSTACK_ROOT}/ble +VPATH += ${BTSTACK_ROOT}/src +VPATH += ${BTSTACK_ROOT}/platforms/posix/src COMMON = \ - ${BTSTACK_ROOT}/src/linked_list.c \ - + linked_list.c \ COMMON_OBJ = $(COMMON:.c=.o) @@ -19,6 +23,9 @@ all: linked_list_test linked_list_test: ${COMMON_OBJ} linked_list_test.c ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ +test: + ./linked_list_test + clean: rm -fr linked_list_test *.dSYM *.o ../src/*.o diff --git a/test/remote_device_db/Makefile b/test/remote_device_db/Makefile index a9e89c85c..347113c77 100644 --- a/test/remote_device_db/Makefile +++ b/test/remote_device_db/Makefile @@ -6,19 +6,24 @@ BTSTACK_ROOT = ../.. CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest CFLAGS = -g -Wall -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include -I${BTSTACK_ROOT}/ble -I$(CPPUTEST_HOME)/include -LDFLAGS += -L$(CPPUTEST_HOME) -lCppUTest -lCppUTestExt +LDFLAGS += -lCppUTest -lCppUTestExt +# -L$(CPPUTEST_HOME) + +VPATH += ${BTSTACK_ROOT}/ble +VPATH += ${BTSTACK_ROOT}/src +VPATH += ${BTSTACK_ROOT}/platforms/posix/src FS = \ - ${BTSTACK_ROOT}/src/utils.c \ - ${BTSTACK_ROOT}/platforms/posix/src/remote_device_db_fs.c + utils.c \ + remote_device_db_fs.c MEMORY = \ - ${BTSTACK_ROOT}/src/utils.c \ - ${BTSTACK_ROOT}/src/memory_pool.c \ - ${BTSTACK_ROOT}/src/btstack_memory.c \ - ${BTSTACK_ROOT}/src/remote_device_db_memory.c \ - ${BTSTACK_ROOT}/src/linked_list.c + utils.c \ + memory_pool.c \ + btstack_memory.c \ + remote_device_db_memory.c \ + linked_list.c FS_OBJ = $(FS:.c=.o) MEMORY_OBJ = $(MEMORY:.c=.o) @@ -31,6 +36,10 @@ remote_device_db_memory_test: ${MEMORY_OBJ} remote_device_db_memory_test.c remote_device_db_fs_test: ${FS_OBJ} remote_device_db_fs_test.c ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ +test: + ./remote_device_db_memory_test + ./remote_device_db_fs_test + clean: rm -f remote_device_db_memory_test remote_device_db_fs_test *.o ../src/*.o rm -rf *.dSYM diff --git a/test/sdp_client/Makefile b/test/sdp_client/Makefile index 2ad6f60ab..2d14ce98d 100644 --- a/test/sdp_client/Makefile +++ b/test/sdp_client/Makefile @@ -6,18 +6,23 @@ BTSTACK_ROOT = ../.. CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest CFLAGS = -g -Wall -I. -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include -I$(CPPUTEST_HOME)/include -LDFLAGS += -L$(CPPUTEST_HOME) -lCppUTest -lCppUTestExt +LDFLAGS += -lCppUTest -lCppUTestExt +# -L$(CPPUTEST_HOME) + +VPATH += ${BTSTACK_ROOT}/ble +VPATH += ${BTSTACK_ROOT}/src +VPATH += ${BTSTACK_ROOT}/platforms/posix/src COMMON = \ - ${BTSTACK_ROOT}/src/sdp_util.c \ - ${BTSTACK_ROOT}/src/sdp_parser.c \ - ${BTSTACK_ROOT}/src/utils.c \ + sdp_util.c \ + sdp_parser.c \ + utils.c \ COMMON_OBJ = $(COMMON:.c=.o) all: sdp_rfcomm_query general_sdp_query service_attribute_search_query service_search_query -sdp_rfcomm_query: ${COMMON_OBJ} ${BTSTACK_ROOT}/src/sdp_query_rfcomm.c sdp_rfcomm_query.c +sdp_rfcomm_query: ${COMMON_OBJ} sdp_query_rfcomm.c sdp_rfcomm_query.c ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ general_sdp_query: ${COMMON_OBJ} general_sdp_query.c @@ -29,7 +34,13 @@ service_attribute_search_query: ${COMMON_OBJ} service_attribute_search_query.c service_search_query: ${COMMON_OBJ} service_search_query.c ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ +test: + ./sdp_rfcomm_query + ./general_sdp_query + ./service_attribute_search_query + ./service_search_query + clean: - rm -f sdp_rfcomm_query general_sdp_query service_attribute_search_query service_search_query *.o ${BTSTACK_ROOT}/src/*.o + rm -f sdp_rfcomm_query general_sdp_query service_attribute_search_query service_search_query *.o *.o rm -rf *.dSYM \ No newline at end of file diff --git a/test/security_manager/Makefile b/test/security_manager/Makefile index e326269b4..e1b49b680 100644 --- a/test/security_manager/Makefile +++ b/test/security_manager/Makefile @@ -6,21 +6,26 @@ BTSTACK_ROOT = ../.. CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wno-unused -I. -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/ble -I${BTSTACK_ROOT}/include -I$(CPPUTEST_HOME)/include -LDFLAGS += -L$(CPPUTEST_HOME)/lib -lCppUTest -lCppUTestExt +LDFLAGS += -lCppUTest -lCppUTestExt +# -L$(CPPUTEST_HOME)/lib + +VPATH += ${BTSTACK_ROOT}/ble +VPATH += ${BTSTACK_ROOT}/src +VPATH += ${BTSTACK_ROOT}/platforms/posix/src COMMON = \ - ${BTSTACK_ROOT}/src/utils.c \ - ${BTSTACK_ROOT}/src/btstack_memory.c \ - ${BTSTACK_ROOT}/src/memory_pool.c \ - ${BTSTACK_ROOT}/src/linked_list.c \ - ${BTSTACK_ROOT}/src/sdp_util.c \ - ${BTSTACK_ROOT}/src/remote_device_db_memory.c \ - ${BTSTACK_ROOT}/src/run_loop.c \ - ${BTSTACK_ROOT}/platforms/posix/src/run_loop_posix.c \ - ${BTSTACK_ROOT}/src/hci_cmds.c \ - ${BTSTACK_ROOT}/src/hci_dump.c \ - ${BTSTACK_ROOT}/ble/sm.c \ - ${BTSTACK_ROOT}/ble/le_device_db_memory.c \ + utils.c \ + btstack_memory.c \ + memory_pool.c \ + linked_list.c \ + sdp_util.c \ + remote_device_db_memory.c \ + run_loop.c \ + run_loop_posix.c \ + hci_cmds.c \ + hci_dump.c \ + sm.c \ + le_device_db_memory.c \ rijndael.c \ mock.c @@ -34,6 +39,10 @@ security_manager: ${CORE_OBJ} ${COMMON_OBJ} security_manager.c aestest: aestest.c rijndael.c ${CC} ${CFLAGS} -m32 rijndael.c aestest.c -o $@ +test: + ./security_manager + ./aestest + clean: rm -f security_manager rm -f *.o diff --git a/test/security_manager/mock.c b/test/security_manager/mock.c index 8b7c9423d..697db2b32 100644 --- a/test/security_manager/mock.c +++ b/test/security_manager/mock.c @@ -111,10 +111,26 @@ void att_init_connection(att_connection_t * att_connection){ att_connection->authorized = 0; } +int hci_can_send_command_packet_now(void){ + return 1; +} int hci_can_send_packet_now_using_packet_buffer(uint8_t packet_type){ return 1; } +// todo: +hci_connection_t * hci_connection_for_bd_addr_and_type(bd_addr_t addr, bd_addr_type_t addr_type){ + printf("hci_connection_for_bd_addr_and_type not implemented in mock backend\n"); + return NULL; +} +hci_connection_t * hci_connection_for_handle(hci_con_handle_t con_handle){ + printf("hci_connection_for_handle not implemented in mock backend\n"); + return NULL; +} +void hci_connections_get_iterator(linked_list_iterator_t *it){ + printf("hci_connections_get_iterator not implemented in mock backend\n"); +} + // get addr type and address used in advertisement packets void hci_le_advertisement_address(uint8_t * addr_type, bd_addr_t addr){ *addr_type = 0; @@ -126,6 +142,10 @@ int l2cap_can_send_connectionless_packet_now(void){ return packet_buffer_len == 0; } +int l2cap_can_send_fixed_channel_packet_now(uint16_t handle){ + return packet_buffer_len == 0; +} + int hci_send_cmd(const hci_cmd_t *cmd, ...){ va_list argptr; va_start(argptr, cmd);