diff --git a/platform/embedded/hal_flash_bank_memory.c b/platform/embedded/hal_flash_bank_memory.c index 2315375b1..36cbb356a 100644 --- a/platform/embedded/hal_flash_bank_memory.c +++ b/platform/embedded/hal_flash_bank_memory.c @@ -43,11 +43,6 @@ #include "stdint.h" #include "string.h" -#ifdef BTSTACK_TEST -#include "stdio.h" -#include // exit(..) -#endif - static uint32_t hal_flash_bank_memory_get_size(void * context){ hal_flash_bank_memory_t * self = (hal_flash_bank_memory_t *) context; return self->bank_size; diff --git a/test/ad_parser/Makefile b/test/ad_parser/Makefile index 6efd14ee5..efe7e1b0f 100644 --- a/test/ad_parser/Makefile +++ b/test/ad_parser/Makefile @@ -4,7 +4,10 @@ CC = g++ BTSTACK_ROOT = ../.. -CFLAGS = -g -Wall -I.. -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null +CFLAGS += -I${BTSTACK_ROOT}/src +CFLAGS += -I.. + CFLAGS_COVERAGE = ${CFLAGS} -fprofile-arcs -ftest-coverage CFLAGS_ASAN = ${CFLAGS} -fsanitize=address -DHAVE_ASSERT diff --git a/test/att_db/Makefile b/test/att_db/Makefile index 1d8031c4a..b55e858c3 100644 --- a/test/att_db/Makefile +++ b/test/att_db/Makefile @@ -4,10 +4,10 @@ CC = g++ BTSTACK_ROOT = ../.. -CFLAGS = -g -Wall \ - -I. \ - -I${BTSTACK_ROOT}/src +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null +CFLAGS += -I${BTSTACK_ROOT}/src CFLAGS += -I${BTSTACK_ROOT}/3rd-party/rijndael +CFLAGS += -I. CFLAGS_COVERAGE = ${CFLAGS} -fprofile-arcs -ftest-coverage CFLAGS_ASAN = ${CFLAGS} -fsanitize=address -DHAVE_ASSERT diff --git a/test/avdtp_util/Makefile b/test/avdtp_util/Makefile index c6388459a..040b36faf 100644 --- a/test/avdtp_util/Makefile +++ b/test/avdtp_util/Makefile @@ -4,10 +4,10 @@ CC = g++ BTSTACK_ROOT = ../.. -CFLAGS = -g -Wall \ - -I.. \ - -I${BTSTACK_ROOT}/src - +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null +CFLAGS += -I${BTSTACK_ROOT}/src +CFLAGS += -I.. + VPATH += ${BTSTACK_ROOT}/src VPATH += ${BTSTACK_ROOT}/src/classic VPATH += ${BTSTACK_ROOT}/platform/posix diff --git a/test/base64/Makefile b/test/base64/Makefile index ff1064806..6ee7c8a4c 100644 --- a/test/base64/Makefile +++ b/test/base64/Makefile @@ -5,7 +5,9 @@ CC=g++ BTSTACK_ROOT = ../.. CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest -CFLAGS = -g -Wall -I. -I../ -I${BTSTACK_ROOT}/src +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null +CFLAGS += -I${BTSTACK_ROOT}/src +CFLAGS += -I.. CFLAGS_COVERAGE = ${CFLAGS} -fprofile-arcs -ftest-coverage CFLAGS_ASAN = ${CFLAGS} -fsanitize=address -DHAVE_ASSERT diff --git a/test/ble_client/Makefile b/test/ble_client/Makefile index 90402fa38..00f828502 100644 --- a/test/ble_client/Makefile +++ b/test/ble_client/Makefile @@ -4,7 +4,10 @@ CC = g++ BTSTACK_ROOT = ../.. -CFLAGS = -g -Wall -I. -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null +CFLAGS += -I${BTSTACK_ROOT}/src +CFLAGS += -I. + CFLAGS_COVERAGE = ${CFLAGS} -fprofile-arcs -ftest-coverage CFLAGS_ASAN = ${CFLAGS} -fsanitize=address -DHAVE_ASSERT diff --git a/test/btstack_link_key_db/Makefile b/test/btstack_link_key_db/Makefile index a20625d72..750ae79b2 100644 --- a/test/btstack_link_key_db/Makefile +++ b/test/btstack_link_key_db/Makefile @@ -5,12 +5,11 @@ CC=g++ BTSTACK_ROOT = ../.. CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest -CFLAGS = -g -Wall \ - -I. \ - -I.. \ - -I${BTSTACK_ROOT}/src \ - -I${BTSTACK_ROOT}/platform/posix \ - -I${BTSTACK_ROOT}/3rd-party/tinydir +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null +CFLAGS += -I${BTSTACK_ROOT}/src +CFLAGS += -I${BTSTACK_ROOT}/platform/posix +CFLAGS += -I${BTSTACK_ROOT}/3rd-party/tinydir +CFLAGS += -I. CFLAGS_COVERAGE = ${CFLAGS} -fprofile-arcs -ftest-coverage CFLAGS_ASAN = ${CFLAGS} -fsanitize=address -DHAVE_ASSERT diff --git a/test/btstack_memory/Makefile b/test/btstack_memory/Makefile index 3847290b7..bacec78d8 100644 --- a/test/btstack_memory/Makefile +++ b/test/btstack_memory/Makefile @@ -4,7 +4,9 @@ CC = g++ BTSTACK_ROOT = ../.. -CFLAGS = -g -Wall -I${BTSTACK_ROOT}/src + +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null +CFLAGS += -I${BTSTACK_ROOT}/src CFLAGS_COVERAGE = ${CFLAGS} -fprofile-arcs -ftest-coverage CFLAGS_ASAN = ${CFLAGS} -fsanitize=address -DHAVE_ASSERT diff --git a/test/crypto/Makefile b/test/crypto/Makefile index 5bd22a7f7..0c968235d 100644 --- a/test/crypto/Makefile +++ b/test/crypto/Makefile @@ -36,10 +36,10 @@ build-coverage/%.o: %.c | build-coverage build-asan/%.o: %.c | build-asan gcc -c ${CFLAGS_ASAN} $< -o $@ -build-coverage/%.cpp.o: %.c | build-coverage +build-coverage/%.o: %.cpp | build-coverage ${CC} -c ${CFLAGS_COVERAGE} $< -o $@ -build-asan/%.cpp.o: %.c | build-asan +build-asan/%.o: %.cpp | build-asan ${CC} -c ${CFLAGS_ASAN} $< -o $@ @@ -55,7 +55,7 @@ build-coverage/ecc_micro_ecc: build-coverage/ecc_micro_ecc.o build-coverage/uECC build-coverage/aes_cmac_test: build-coverage/aes_cmac_test.o build-coverage/aes_cmac.o build-coverage/rijndael.o | build-coverage ${CC} $^ ${LDFLAGS_COVERAGE} -o $@ -build-coverage/aes_cmac_test2: build-coverage/aes_cmac_test2.cpp.o build-coverage/btstack_crypto.o build-coverage/btstack_linked_list.o build-coverage/hci_cmd.o build-coverage/btstack_util.o build-coverage/hci_dump.o build-coverage/rijndael.o | build-asan +build-coverage/aes_cmac_test2: build-coverage/aes_cmac_test2.o build-coverage/btstack_crypto.o build-coverage/btstack_linked_list.o build-coverage/hci_cmd.o build-coverage/btstack_util.o build-coverage/hci_dump.o build-coverage/rijndael.o | build-asan ${CC} $^ ${LDFLAGS_COVERAGE} -o $@ @@ -71,7 +71,7 @@ build-asan/ecc_micro_ecc: build-asan/ecc_micro_ecc.o build-asan/uECC.o | build-a build-asan/aes_cmac_test: build-asan/aes_cmac_test.o build-asan/aes_cmac.o build-asan/rijndael.o | build-asan ${CC} $^ ${LDFLAGS_ASAN} -o $@ -build-asan/aes_cmac_test2: build-asan/aes_cmac_test2.cpp.o build-asan/btstack_crypto.o build-asan/btstack_linked_list.o build-asan/hci_cmd.o build-asan/btstack_util.o build-asan/hci_dump.o build-asan/rijndael.o | build-asan +build-asan/aes_cmac_test2: build-asan/aes_cmac_test2.o build-asan/btstack_crypto.o build-asan/btstack_linked_list.o build-asan/hci_cmd.o build-asan/btstack_util.o build-asan/hci_dump.o build-asan/rijndael.o | build-asan ${CC} $^ ${LDFLAGS_ASAN} -o $@ test: all diff --git a/test/crypto/aes_cmac_test2.c b/test/crypto/aes_cmac_test2.cpp similarity index 100% rename from test/crypto/aes_cmac_test2.c rename to test/crypto/aes_cmac_test2.cpp diff --git a/test/des_iterator/Makefile b/test/des_iterator/Makefile index 811860729..da8425513 100644 --- a/test/des_iterator/Makefile +++ b/test/des_iterator/Makefile @@ -4,7 +4,10 @@ CC = g++ BTSTACK_ROOT = ../.. -CFLAGS = -g -Wall -I.. -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null +CFLAGS += -I${BTSTACK_ROOT}/src +CFLAGS += -I.. + CFLAGS_COVERAGE = ${CFLAGS} -fprofile-arcs -ftest-coverage CFLAGS_ASAN = ${CFLAGS} -fsanitize=address -DHAVE_ASSERT diff --git a/test/embedded/Makefile b/test/embedded/Makefile index 78834e39d..b2834f82f 100644 --- a/test/embedded/Makefile +++ b/test/embedded/Makefile @@ -4,10 +4,10 @@ CC = g++ BTSTACK_ROOT = ../.. -CFLAGS = -g -Wall \ - -I. \ - -I${BTSTACK_ROOT}/src \ - -I${BTSTACK_ROOT}/platform/embedded +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null +CFLAGS += -I${BTSTACK_ROOT}/src +CFLAGS += -I${BTSTACK_ROOT}/platform/embedded +CFLAGS += -I. CFLAGS += -DHAVE_HAL_AUDIO diff --git a/test/flash_tlv/Makefile b/test/flash_tlv/Makefile index b277af3ae..b2620f4cb 100644 --- a/test/flash_tlv/Makefile +++ b/test/flash_tlv/Makefile @@ -17,17 +17,11 @@ VPATH = \ ${BTSTACK_ROOT}/platform/embedded \ ${BTSTACK_ROOT}/platform/posix \ -CFLAGS = \ - -DBTSTACK_TEST \ - -g \ - -Wall \ - -Wmissing-prototypes \ - -Wnarrowing \ - -I. \ - -I.. \ - -I${BTSTACK_ROOT}/src \ - -I${BTSTACK_ROOT}/platform/embedded \ - -I${BTSTACK_ROOT}/platform/posix \ +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null +CFLAGS += -I${BTSTACK_ROOT}/src +CFLAGS += -I${BTSTACK_ROOT}/platform/embedded +CFLAGS += -I${BTSTACK_ROOT}/platform/posix +CFLAGS += -I.. CFLAGS_COVERAGE = ${CFLAGS} -fprofile-arcs -ftest-coverage CFLAGS_ASAN = ${CFLAGS} -fsanitize=address -DHAVE_ASSERT diff --git a/test/gatt_server/Makefile b/test/gatt_server/Makefile index b17df0e25..a1598fdc7 100644 --- a/test/gatt_server/Makefile +++ b/test/gatt_server/Makefile @@ -1,13 +1,14 @@ -CC = g++ - # Requirements: cpputest.github.io BTSTACK_ROOT = ../.. -CFLAGS = -DUNIT_TEST -g -Wall -Wnarrowing -Wconversion-null -I. -I../ -CFLAGS += -I${BTSTACK_ROOT}/src +CFLAGS = -DUNIT_TEST -g -Wall -Wnarrowing -Wconversion-null CFLAGS += -I${BTSTACK_ROOT}/3rd-party/rijndael CFLAGS += -I${BTSTACK_ROOT}/3rd-party/micro-ecc +CFLAGS += -I${BTSTACK_ROOT}/platform/embedded +CFLAGS += -I${BTSTACK_ROOT}/platform/posix +CFLAGS += -I${BTSTACK_ROOT}/src +CFLAGS += -I. VPATH += ${BTSTACK_ROOT}/src VPATH += ${BTSTACK_ROOT}/src/ble @@ -49,8 +50,8 @@ LDFLAGS += -lCppUTest -lCppUTestExt LDFLAGS_COVERAGE = ${LDFLAGS} -fprofile-arcs -ftest-coverage LDFLAGS_ASAN = ${LDFLAGS} -fsanitize=address -COMMON_OBJ_COVERAGE = $(addprefix build-coverage/,$(COMMON:.c=.o)) build-coverage/uECC.c.o -COMMON_OBJ_ASAN = $(addprefix build-asan/, $(COMMON:.c=.o)) build-asan/uECC.c.o +COMMON_OBJ_COVERAGE = $(addprefix build-coverage/,$(COMMON:.c=.o)) build-coverage/uECC.o +COMMON_OBJ_ASAN = $(addprefix build-asan/, $(COMMON:.c=.o)) build-asan/uECC.o all: build-coverage/gatt_server_test build-asan/gatt_server_test @@ -63,23 +64,22 @@ build-%/profile.h: profile.gatt | build-% python3 ${BTSTACK_ROOT}/tool/compile_gatt.py $< $@ build-coverage/%.o: %.c | build-coverage - ${CC} -c $(CFLAGS_COVERAGE) $< -o $@ - -build-coverage/%.c.o: %.c | build-coverage gcc -c $(CFLAGS_COVERAGE) $< -o $@ -build-asan/%.o: %.c | build-asan - ${CC} -c $(CFLAGS_ASAN) $< -o $@ +build-coverage/%.o: %.cpp | build-coverage + g++ -c $(CFLAGS_COVERAGE) $< -o $@ -build-asan/%.c.o: %.c | build-asan +build-asan/%.o: %.c | build-asan gcc -c $(CFLAGS_ASAN) $< -o $@ +build-asan/%.o: %.cpp | build-asan + g++ -c $(CFLAGS_ASAN) $< -o $@ build-coverage/gatt_server_test: ${COMMON_OBJ_COVERAGE} build-coverage/profile.h build-coverage/gatt_server_test.o | build-coverage - ${CC} $(filter-out build-coverage/profile.h,$^) ${LDFLAGS_COVERAGE} -o $@ + g++ $(filter-out build-coverage/profile.h,$^) ${LDFLAGS_COVERAGE} -o $@ build-asan/gatt_server_test: ${COMMON_OBJ_ASAN} build-asan/profile.h build-asan/gatt_server_test.o | build-asan - ${CC} $(filter-out build-asan/profile.h,$^) ${LDFLAGS_ASAN} -o $@ + g++ $(filter-out build-asan/profile.h,$^) ${LDFLAGS_ASAN} -o $@ test: all build-asan/gatt_server_test diff --git a/test/gatt_server/gatt_server_test.c b/test/gatt_server/gatt_server_test.cpp similarity index 98% rename from test/gatt_server/gatt_server_test.c rename to test/gatt_server/gatt_server_test.cpp index a2506fc79..32bbcc772 100644 --- a/test/gatt_server/gatt_server_test.c +++ b/test/gatt_server/gatt_server_test.cpp @@ -27,7 +27,7 @@ static uint8_t battery_level = 100; static const uint8_t uuid128_with_bluetooth_base[] = { 0x00, 0x00, 0xBB, 0xBB, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB}; static const uint8_t uuid128_no_bluetooth_base[] = { 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0xAA, 0xAA, 0x00, 0x00 }; -void l2cap_can_send_fixed_channel_packet_now_set_status(uint8_t status); +extern "C" void l2cap_can_send_fixed_channel_packet_now_set_status(uint8_t status); static uint16_t att_read_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size){ UNUSED(connection_handle); diff --git a/test/gatt_server/mock.c b/test/gatt_server/mock.c index 6a5de94d2..940ddd66d 100644 --- a/test/gatt_server/mock.c +++ b/test/gatt_server/mock.c @@ -4,6 +4,7 @@ #include #include "hci.h" +#include "gap.h" #include "hci_dump.h" #include "l2cap.h" @@ -50,7 +51,7 @@ void gap_start_scan(void){ } void gap_stop_scan(void){ } -uint8_t gap_connect(bd_addr_t addr, bd_addr_type_t addr_type){ +uint8_t gap_connect(const bd_addr_t addr, bd_addr_type_t addr_type){ return 0; } void gap_set_scan_parameters(uint8_t scan_type, uint16_t scan_interval, uint16_t scan_window){ @@ -191,7 +192,7 @@ void * btstack_run_loop_get_timer_context(btstack_timer_source_t *ts){ } // todo: -hci_connection_t * hci_connection_for_bd_addr_and_type(bd_addr_t addr, bd_addr_type_t addr_type){ +hci_connection_t * hci_connection_for_bd_addr_and_type(const 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; } diff --git a/test/gatt_service/Makefile b/test/gatt_service/Makefile index 18bbcfff4..5bbc7d6de 100644 --- a/test/gatt_service/Makefile +++ b/test/gatt_service/Makefile @@ -4,7 +4,9 @@ CC = g++ BTSTACK_ROOT = ../.. -CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null -Ibuild-coverage -I../ +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null +CFLAGS += -I../ + CFLAGS += -I${BTSTACK_ROOT}/src CFLAGS += -I${BTSTACK_ROOT}/test/mock CFLAGS += -I${BTSTACK_ROOT}/3rd-party/rijndael @@ -35,8 +37,8 @@ COMMON = \ ublox_spp_service_server.c \ -CFLAGS_COVERAGE = ${CFLAGS} -fprofile-arcs -ftest-coverage -CFLAGS_ASAN = ${CFLAGS} -fsanitize=address -DHAVE_ASSERT +CFLAGS_COVERAGE = ${CFLAGS} -Ibuild-coverage -fprofile-arcs -ftest-coverage +CFLAGS_ASAN = ${CFLAGS} -Ibuild-asan -fsanitize=address -DHAVE_ASSERT LDFLAGS += -lCppUTest -lCppUTestExt LDFLAGS_COVERAGE = ${LDFLAGS} -fprofile-arcs -ftest-coverage diff --git a/test/hfp/Makefile b/test/hfp/Makefile index da6689386..ee3bffb75 100644 --- a/test/hfp/Makefile +++ b/test/hfp/Makefile @@ -40,9 +40,11 @@ MOCK = \ hci_dump.c \ sdp_util.c \ -CFLAGS = -g -Wall -Wmissing-prototypes -Wnarrowing -# CFLAGS += -Werror -CFLAGS += -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/src/classic -I${POSIX_ROOT} -I${BTSTACK_ROOT}/include +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null +CFLAGS += -I. -I../ +CFLAGS += -I${BTSTACK_ROOT}/src +CFLAGS += -I${BTSTACK_ROOT}/src/classic +CFLAGS += -I${BTSTACK_ROOT}/platform/posix # CFLAGS += -D OCTAVE_OUTPUT CFLAGS_COVERAGE = ${CFLAGS} -fprofile-arcs -ftest-coverage diff --git a/test/hid_parser/Makefile b/test/hid_parser/Makefile index 406c9dabf..1aab60375 100644 --- a/test/hid_parser/Makefile +++ b/test/hid_parser/Makefile @@ -4,10 +4,12 @@ CC = g++ BTSTACK_ROOT = ../.. -CPPFLAGS = -x c++ -Wall -Wno-unused +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null + +CFLAGS += -I. +CFLAGS += -I ${BTSTACK_ROOT}/src +CFLAGS += -I ${BTSTACK_ROOT}/platform/posix -CFLAGS = -DUNIT_TEST -g -CFLAGS += -I. -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/platform/posix VPATH += ${BTSTACK_ROOT}/src ${BTSTACK_ROOT}/platform/posix COMMON = \ diff --git a/test/linked_list/Makefile b/test/linked_list/Makefile index aebe6d762..e34a28a87 100644 --- a/test/linked_list/Makefile +++ b/test/linked_list/Makefile @@ -5,7 +5,10 @@ CC=g++ BTSTACK_ROOT = ../.. CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest -CFLAGS = -g -Wall -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null +CFLAGS += -I${BTSTACK_ROOT}/src +CFLAGS += -I${BTSTACK_ROOT}/include +CFLAGS += -I.. VPATH += ${BTSTACK_ROOT}/src/ble VPATH += ${BTSTACK_ROOT}/src diff --git a/test/map_test/Makefile b/test/map_test/Makefile index 42b7571d8..3de18f7c6 100644 --- a/test/map_test/Makefile +++ b/test/map_test/Makefile @@ -5,7 +5,10 @@ CC=g++ BTSTACK_ROOT = ../.. CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest -CFLAGS = -g -Wall -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null +CFLAGS += -I${BTSTACK_ROOT}/src +CFLAGS += -I.. + LDFLAGS += -lCppUTest -lCppUTestExt VPATH += ${BTSTACK_ROOT}/src/ble diff --git a/test/obex/Makefile b/test/obex/Makefile index 081992aa3..ab15d21a6 100644 --- a/test/obex/Makefile +++ b/test/obex/Makefile @@ -5,7 +5,10 @@ CC=g++ BTSTACK_ROOT = ../.. CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest -CFLAGS = -g -Wall -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null +CFLAGS += -I${BTSTACK_ROOT}/src +CFLAGS += -I../ + LDFLAGS += -lCppUTest -lCppUTestExt VPATH += ${BTSTACK_ROOT}/src/ble diff --git a/test/ring_buffer/Makefile b/test/ring_buffer/Makefile index 102bc3ea1..9959b2f71 100644 --- a/test/ring_buffer/Makefile +++ b/test/ring_buffer/Makefile @@ -5,7 +5,9 @@ CC=g++ BTSTACK_ROOT = ../.. CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest -CFLAGS = -g -Wall -I. -I../ -I${BTSTACK_ROOT}/src +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null +CFLAGS += -I${BTSTACK_ROOT}/src +CFLAGS += -I.. LDFLAGS += -lCppUTest -lCppUTestExt VPATH += ${BTSTACK_ROOT}/src diff --git a/test/sdp/Makefile b/test/sdp/Makefile index 72b56c6b9..e584d7ae8 100644 --- a/test/sdp/Makefile +++ b/test/sdp/Makefile @@ -4,9 +4,9 @@ CC = g++ BTSTACK_ROOT = ../.. -CFLAGS = -g -Wall \ - -I.. \ - -I${BTSTACK_ROOT}/src \ +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null +CFLAGS += -I${BTSTACK_ROOT}/src +CFLAGS += -I.. LDFLAGS += -lCppUTest -lCppUTestExt diff --git a/test/sdp_client/Makefile b/test/sdp_client/Makefile index 1075d2944..f1f508ad5 100644 --- a/test/sdp_client/Makefile +++ b/test/sdp_client/Makefile @@ -5,7 +5,10 @@ CC = g++ BTSTACK_ROOT = ../.. CPPUTEST_HOME = ${BTSTACK_ROOT}/test/cpputest -CFLAGS = -g -Wall -I.. -I${BTSTACK_ROOT}/src +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null +CFLAGS += -I${BTSTACK_ROOT}/src +CFLAGS += -I.. + LDFLAGS += -lCppUTest -lCppUTestExt VPATH += ${BTSTACK_ROOT}/src/classic diff --git a/test/security_manager/Makefile b/test/security_manager/Makefile index 66b5d1dd6..1bd3defa0 100644 --- a/test/security_manager/Makefile +++ b/test/security_manager/Makefile @@ -4,8 +4,7 @@ CC = g++ BTSTACK_ROOT = ../.. -CFLAGS = -DUNIT_TEST -g -CFLAGS += -Wall -Wno-unused +CFLAGS = -DUNIT_TEST -g -Wall -Wnarrowing -Wconversion-null CFLAGS += -I. -I.. -I${BTSTACK_ROOT}/src CFLAGS += -I${BTSTACK_ROOT}/platform/embedded CFLAGS += -I${BTSTACK_ROOT}/platform/posix @@ -45,8 +44,8 @@ LDFLAGS += -lCppUTest -lCppUTestExt LDFLAGS_COVERAGE = ${LDFLAGS} -fprofile-arcs -ftest-coverage LDFLAGS_ASAN = ${LDFLAGS} -fsanitize=address -COMMON_OBJ_COVERAGE = $(addprefix build-coverage/,$(COMMON:.c=.o)) build-coverage/uECC.c.o -COMMON_OBJ_ASAN = $(addprefix build-asan/, $(COMMON:.c=.o)) build-asan/uECC.c.o +COMMON_OBJ_COVERAGE = $(addprefix build-coverage/,$(COMMON:.c=.o)) build-coverage/uECC.o +COMMON_OBJ_ASAN = $(addprefix build-asan/, $(COMMON:.c=.o)) build-asan/uECC.o all: build-coverage/security_manager build-asan/security_manager @@ -54,17 +53,17 @@ build-%: mkdir -p $@ build-coverage/%.o: %.c | build-coverage - ${CC} -c $(CFLAGS_COVERAGE) $< -o $@ - -build-coverage/%.c.o: %.c | build-coverage gcc -c $(CFLAGS_COVERAGE) $< -o $@ -build-asan/%.o: %.c | build-asan - ${CC} -c $(CFLAGS_ASAN) $< -o $@ +build-coverage/%.o: %.cpp | build-coverage + ${CC} -c $(CFLAGS_COVERAGE) $< -o $@ -build-asan/%.c.o: %.c | build-asan +build-asan/%.o: %.c | build-asan gcc -c $(CFLAGS_ASAN) $< -o $@ +build-asan/%.o: %.cpp | build-asan + ${CC} -c $(CFLAGS_ASAN) $< -o $@ + build-coverage/security_manager: ${COMMON_OBJ_COVERAGE} build-coverage/security_manager.o | build-coverage ${CC} $^ ${LDFLAGS_COVERAGE} -o $@ diff --git a/test/security_manager/mock.c b/test/security_manager/mock.c index 2e8622819..f3f55c331 100644 --- a/test/security_manager/mock.c +++ b/test/security_manager/mock.c @@ -24,7 +24,7 @@ static btstack_linked_list_t event_packet_handlers; void mock_init(void){ the_connection.item.next = NULL; - connections = (btstack_linked_item*) &the_connection; + connections = (btstack_linked_item_t*) &the_connection; } uint8_t * mock_packet_buffer(void){ @@ -142,7 +142,7 @@ int hci_can_send_packet_now_using_packet_buffer(uint8_t packet_type){ return 1; } -hci_connection_t * hci_connection_for_bd_addr_and_type(bd_addr_t addr, bd_addr_type_t addr_type){ +hci_connection_t * hci_connection_for_bd_addr_and_type(const bd_addr_t addr, bd_addr_type_t addr_type){ return &the_connection; } hci_connection_t * hci_connection_for_handle(hci_con_handle_t con_handle){ @@ -176,7 +176,7 @@ uint16_t hci_get_manufacturer(void){ void hci_le_set_own_address_type(uint8_t own_address){ } -extern "C" void l2cap_request_can_send_fix_channel_now_event(hci_con_handle_t con_handle, uint16_t cid){ +void l2cap_request_can_send_fix_channel_now_event(hci_con_handle_t con_handle, uint16_t cid){ if (packet_buffer_len) return; uint8_t event[] = { L2CAP_EVENT_CAN_SEND_NOW, 2, 0, 0}; little_endian_store_16(event, 2, cid); diff --git a/test/security_manager/security_manager.c b/test/security_manager/security_manager.cpp similarity index 97% rename from test/security_manager/security_manager.c rename to test/security_manager/security_manager.cpp index 498dc450c..a1a1f66c3 100644 --- a/test/security_manager/security_manager.c +++ b/test/security_manager/security_manager.cpp @@ -109,16 +109,18 @@ bd_addr_t test_device_addr = {0x34, 0xb1, 0xf7, 0xd1, 0x77, 0x9b}; static btstack_packet_callback_registration_t sm_event_callback_registration; -void mock_init(void); -void mock_simulate_hci_state_working(void); -void mock_simulate_hci_event(uint8_t * packet, uint16_t size); -void aes128_report_result(void); -void mock_simulate_sm_data_packet(uint8_t * packet, uint16_t size); -void mock_simulate_command_complete(const hci_cmd_t *cmd); -void mock_simulate_connected(void); -uint8_t * mock_packet_buffer(void); -uint16_t mock_packet_buffer_len(void); -void mock_clear_packet_buffer(void); +extern "C" { + void mock_init(void); + void mock_simulate_hci_state_working(void); + void mock_simulate_hci_event(uint8_t * packet, uint16_t size); + void aes128_report_result(void); + void mock_simulate_sm_data_packet(uint8_t * packet, uint16_t size); + void mock_simulate_command_complete(const hci_cmd_t *cmd); + void mock_simulate_connected(void); + uint8_t * mock_packet_buffer(void); + uint16_t mock_packet_buffer_len(void); + void mock_clear_packet_buffer(void); +} void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ uint16_t aHandle; diff --git a/test/tlv_posix/Makefile b/test/tlv_posix/Makefile index f99804f94..c57f6a5fb 100644 --- a/test/tlv_posix/Makefile +++ b/test/tlv_posix/Makefile @@ -16,15 +16,11 @@ VPATH = \ ${BTSTACK_ROOT}/src/ble \ ${BTSTACK_ROOT}/platform/posix \ -CFLAGS = \ - -DBTSTACK_TEST \ - -g \ - -Wall \ - -Wnarrowing \ - -I. \ - -I.. \ - -I${BTSTACK_ROOT}/src \ - -I${BTSTACK_ROOT}/platform/posix \ + +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null +CFLAGS += -I${BTSTACK_ROOT}/src +CFLAGS += -I${BTSTACK_ROOT}/platform/posix +CFLAGS += -I.. LDFLAGS += -lCppUTest -lCppUTestExt