From 31437b52049f7a1b5a54d9c71f935fe16cc0e09d Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Wed, 10 Mar 2021 14:50:44 +0100 Subject: [PATCH] hci_dump: enable packet logger in tests --- test/auto-pts/main.c | 4 +--- test/flash_tlv/Makefile | 3 +++ test/flash_tlv/tlv_test.c | 8 +++++++- test/gap/Makefile | 3 ++- test/gap/test_le_scan.c | 10 +++++++--- test/hid_parser/Makefile | 7 ++++--- test/hid_parser/hid_parser_test.c | 8 +++++++- test/mesh/Makefile | 8 ++++---- test/mesh/main.c | 5 ++++- test/mesh/provisioning_device_test.cpp | 8 +++++++- test/mesh/provisioning_provisioner_test.cpp | 8 +++++++- test/pts/Makefile | 1 + test/security_manager/Makefile | 4 +++- test/security_manager/security_manager.c | 16 ++++++++++++++-- test/security_manager_sc/main.c | 5 ++++- test/tlv_posix/tlv_test.c | 7 ++++++- 16 files changed, 81 insertions(+), 24 deletions(-) diff --git a/test/auto-pts/main.c b/test/auto-pts/main.c index 50d4e6920..5bef717b0 100644 --- a/test/auto-pts/main.c +++ b/test/auto-pts/main.c @@ -208,8 +208,6 @@ int main(int argc, const char * argv[]){ hci_transport_usb_set_path(usb_path_len, usb_path); } - // use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT - char pklg_path[100]; strcpy(pklg_path, "/tmp/hci_dump"); if (usb_path_len){ @@ -218,7 +216,7 @@ int main(int argc, const char * argv[]){ } strcat(pklg_path, ".pklg"); printf("Packet Log: %s\n", pklg_path); - // hci_dump_open(pklg_path, HCI_DUMP_PACKETLOGGER); + hci_dump_init(pklg_path, hci_dump_posix); // init HCI hci_init(hci_transport_usb_instance(), NULL); diff --git a/test/flash_tlv/Makefile b/test/flash_tlv/Makefile index 0e10a6f83..b277af3ae 100644 --- a/test/flash_tlv/Makefile +++ b/test/flash_tlv/Makefile @@ -8,12 +8,14 @@ COMMON = \ btstack_util.c \ hal_flash_bank_memory.c \ hci_dump.c \ + hci_dump_posix_fs.c \ VPATH = \ ${BTSTACK_ROOT}/src \ ${BTSTACK_ROOT}/src/classic \ ${BTSTACK_ROOT}/src/ble \ ${BTSTACK_ROOT}/platform/embedded \ + ${BTSTACK_ROOT}/platform/posix \ CFLAGS = \ -DBTSTACK_TEST \ @@ -25,6 +27,7 @@ CFLAGS = \ -I.. \ -I${BTSTACK_ROOT}/src \ -I${BTSTACK_ROOT}/platform/embedded \ + -I${BTSTACK_ROOT}/platform/posix \ CFLAGS_COVERAGE = ${CFLAGS} -fprofile-arcs -ftest-coverage CFLAGS_ASAN = ${CFLAGS} -fsanitize=address -DHAVE_ASSERT diff --git a/test/flash_tlv/tlv_test.c b/test/flash_tlv/tlv_test.c index 88baec956..51317f0f8 100644 --- a/test/flash_tlv/tlv_test.c +++ b/test/flash_tlv/tlv_test.c @@ -7,6 +7,7 @@ #include "btstack_tlv.h" #include "btstack_tlv_flash_bank.h" #include "hci_dump.h" +#include "hci_dump_posix_fs.h" #include "classic/btstack_link_key_db.h" #include "classic/btstack_link_key_db_tlv.h" #include "btstack_util.h" @@ -327,6 +328,11 @@ TEST(LINK_KEY_DB, KeyReplacement){ } int main (int argc, const char * argv[]){ - // hci_dump_open("tlv_test.pklg", HCI_DUMP_PACKETLOGGER); + // log into file using HCI_DUMP_PACKETLOGGER format + const char * pklg_path = "hci_dump.pklg"; + hci_dump_posix_fs_open(pklg_path, HCI_DUMP_PACKETLOGGER); + hci_dump_init(hci_dump_posix_fs_get_instance()); + printf("Packet Log: %s\n", pklg_path); + return CommandLineTestRunner::RunAllTests(argc, argv); } diff --git a/test/gap/Makefile b/test/gap/Makefile index 62ad2c859..f183184d0 100644 --- a/test/gap/Makefile +++ b/test/gap/Makefile @@ -4,7 +4,7 @@ CC = g++ BTSTACK_ROOT = ../.. -CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null -I. -I${BTSTACK_ROOT}/src +CFLAGS = -DUNIT_TEST -x c++ -g -Wall -Wnarrowing -Wconversion-null -I. -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/platform/posix CFLAGS += -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION VPATH += ${BTSTACK_ROOT}/src @@ -21,6 +21,7 @@ COMMON = \ hci.c \ hci_cmd.c \ hci_dump.c \ + hci_dump_posix_fs.c \ le_device_db_memory.c \ CFLAGS_COVERAGE = ${CFLAGS} -fprofile-arcs -ftest-coverage diff --git a/test/gap/test_le_scan.c b/test/gap/test_le_scan.c index 63ce12f73..6c422be3a 100644 --- a/test/gap/test_le_scan.c +++ b/test/gap/test_le_scan.c @@ -14,6 +14,7 @@ #include "ble/gatt_client.h" #include "btstack_event.h" #include "hci_dump.h" +#include "hci_dump_posix_fs.h" #include "btstack_debug.h" typedef struct { @@ -132,8 +133,11 @@ TEST(GAP_LE, ScanStartParam){ } int main (int argc, const char * argv[]){ - const char * log_path = "/tmp/test_scan.pklg"; - printf("Log: %s\n", log_path); - // hci_dump_open(log_path, HCI_DUMP_PACKETLOGGER); + // log into file using HCI_DUMP_PACKETLOGGER format + const char * pklg_path = "hci_dump.pklg"; + hci_dump_posix_fs_open(pklg_path, HCI_DUMP_PACKETLOGGER); + hci_dump_init(hci_dump_posix_fs_get_instance()); + printf("Packet Log: %s\n", pklg_path); + return CommandLineTestRunner::RunAllTests(argc, argv); } diff --git a/test/hid_parser/Makefile b/test/hid_parser/Makefile index 968721679..406c9dabf 100644 --- a/test/hid_parser/Makefile +++ b/test/hid_parser/Makefile @@ -7,13 +7,14 @@ BTSTACK_ROOT = ../.. CPPFLAGS = -x c++ -Wall -Wno-unused CFLAGS = -DUNIT_TEST -g -CFLAGS += -I. -I${BTSTACK_ROOT}/src -VPATH += ${BTSTACK_ROOT}/src +CFLAGS += -I. -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/platform/posix +VPATH += ${BTSTACK_ROOT}/src ${BTSTACK_ROOT}/platform/posix COMMON = \ btstack_util.c \ btstack_hid_parser.c \ - hci_dump.c + hci_dump.c \ + hci_dump_posix_fs.c \ CFLAGS_COVERAGE = ${CFLAGS} -fprofile-arcs -ftest-coverage CFLAGS_ASAN = ${CFLAGS} -fsanitize=address -DHAVE_ASSERT diff --git a/test/hid_parser/hid_parser_test.c b/test/hid_parser/hid_parser_test.c index edd660f80..f1e13b810 100644 --- a/test/hid_parser/hid_parser_test.c +++ b/test/hid_parser/hid_parser_test.c @@ -15,6 +15,7 @@ #include "CppUTest/CommandLineTestRunner.h" #include "btstack_hid_parser.h" +#include "hci_dump_posix_fs.h" const uint8_t mouse_descriptor_without_report_id[] = { 0x05, 0x01, /* Usage Page (Desktop), */ @@ -345,6 +346,11 @@ TEST(HID, GetReportSize){ int main (int argc, const char * argv[]){ - // hci_dump_open("hci_dump.pklg", HCI_DUMP_PACKETLOGGER); + // log into file using HCI_DUMP_PACKETLOGGER format + const char * pklg_path = "hci_dump.pklg"; + hci_dump_posix_fs_open(pklg_path, HCI_DUMP_PACKETLOGGER); + hci_dump_init(hci_dump_posix_fs_get_instance()); + printf("Packet Log: %s\n", pklg_path); + return CommandLineTestRunner::RunAllTests(argc, argv); } diff --git a/test/mesh/Makefile b/test/mesh/Makefile index 7dd0d4206..3cfb44b2d 100644 --- a/test/mesh/Makefile +++ b/test/mesh/Makefile @@ -24,7 +24,7 @@ CORE += \ l2cap.c \ uECC.c \ rijndael.c \ - + hci_dump_posix_fs.c \ # examples @@ -112,13 +112,13 @@ build-asan/sniffer: ${CORE_OBJ_ASAN} ${COMMON_OBJ_ASAN} ${ATT_OBJ_ASAN} ${SM_OBJ ${CC} $^ ${LDFLAGS_ASAN} -o $@ -build-asan/mesh_message_test: $(addprefix build-asan/, mesh_message_test.o mesh_foundation.o mesh_node.o mesh_iv_index_seq_number.o mesh_network.o mesh_peer.o mesh_lower_transport.o mesh_upper_transport.o mesh_virtual_addresses.o mesh_keys.o mesh_crypto.o btstack_memory.o btstack_memory_pool.o btstack_util.o btstack_crypto.o btstack_linked_list.o hci_dump.o uECC.o mock.o rijndael.o hci_cmd.o) | build-asan +build-asan/mesh_message_test: $(addprefix build-asan/, mesh_message_test.o mesh_foundation.o mesh_node.o mesh_iv_index_seq_number.o mesh_network.o mesh_peer.o mesh_lower_transport.o mesh_upper_transport.o mesh_virtual_addresses.o mesh_keys.o mesh_crypto.o btstack_memory.o btstack_memory_pool.o btstack_util.o btstack_crypto.o btstack_linked_list.o hci_dump.o uECC.o mock.o rijndael.o hci_cmd.o hci_dump_posix_fs.o) | build-asan g++ $^ ${CFLAGS} ${LDFLAGS_ASAN} -o $@ -build-asan/provisioning_device_test: $(addprefix build-asan/, provisioning_device_test.o uECC.o mesh_crypto.o provisioning_device.o btstack_crypto.o btstack_util.o btstack_linked_list.o mesh_node.o mock.o rijndael.o hci_cmd.o hci_dump.o) | build-asan +build-asan/provisioning_device_test: $(addprefix build-asan/, provisioning_device_test.o uECC.o mesh_crypto.o provisioning_device.o btstack_crypto.o btstack_util.o btstack_linked_list.o mesh_node.o mock.o rijndael.o hci_cmd.o hci_dump.o hci_dump_posix_fs.o) | build-asan ${CC_UNIT} ${LDFLAGS_ASAN} $^ -lCppUTest -lCppUTestExt -o $@ -build-asan/provisioning_provisioner_test: $(addprefix build-asan/, provisioning_provisioner_test.o uECC.o mesh_crypto.o provisioning_provisioner.o btstack_crypto.o btstack_util.o btstack_linked_list.o mock.o rijndael.o hci_cmd.o hci_dump.o) | build-asan +build-asan/provisioning_provisioner_test: $(addprefix build-asan/, provisioning_provisioner_test.o uECC.o mesh_crypto.o provisioning_provisioner.o btstack_crypto.o btstack_util.o btstack_linked_list.o mock.o rijndael.o hci_cmd.o hci_dump.o hci_dump_posix_fs.o) | build-asan ${CC_UNIT} ${LDFLAGS_ASAN} $^ -lCppUTest -lCppUTestExt -o $@ build-asan/mesh_configuration_composition_data_message_test: ${CORE_OBJ_ASAN} ${COMMON_OBJ_ASAN} ${ATT_OBJ_ASAN} ${MESH_OBJ_ASAN} build-asan/mesh_configuration_composition_data_message_test.o | build-asan diff --git a/test/mesh/main.c b/test/mesh/main.c index 6f7cce8aa..d4e53c4bc 100644 --- a/test/mesh/main.c +++ b/test/mesh/main.c @@ -60,6 +60,7 @@ #include "bluetooth_company_id.h" #include "hci.h" #include "hci_dump.h" +#include "hci_dump_posix_fs.h" #include "btstack_stdin.h" #include "btstack_tlv.h" #include "btstack_tlv_posix.h" @@ -205,8 +206,10 @@ int main(int argc, const char * argv[]){ // use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT strcat(log_path, ".pklg"); + // log into file using HCI_DUMP_PACKETLOGGER format + hci_dump_posix_fs_open(log_path, HCI_DUMP_PACKETLOGGER); + hci_dump_init(hci_dump_posix_fs_get_instance()); printf("Packet Log: %s\n", log_path); - // hci_dump_open(log_path, HCI_DUMP_PACKETLOGGER); // init HCI const hci_transport_t * transport; diff --git a/test/mesh/provisioning_device_test.cpp b/test/mesh/provisioning_device_test.cpp index 37a861cae..40d797385 100644 --- a/test/mesh/provisioning_device_test.cpp +++ b/test/mesh/provisioning_device_test.cpp @@ -40,6 +40,7 @@ #include "btstack_memory.h" #include "ble/gatt-service/mesh_provisioning_service_server.h" #include "hci_dump.h" +#include "hci_dump_posix_fs.h" #include "mesh/mesh_node.h" #include "mesh/pb_adv.h" #include "mesh/pb_gatt.h" @@ -246,6 +247,11 @@ TEST(Provisioning, Prov1){ } int main (int argc, const char * argv[]){ - hci_dump_open("hci_dump.pklg", HCI_DUMP_PACKETLOGGER); + // log into file using HCI_DUMP_PACKETLOGGER format + const char * log_path = "hci_dump.pklg"; + hci_dump_posix_fs_open(log_path, HCI_DUMP_PACKETLOGGER); + hci_dump_init(hci_dump_posix_fs_get_instance()); + printf("Packet Log: %s\n", log_path); + return CommandLineTestRunner::RunAllTests(argc, argv); } diff --git a/test/mesh/provisioning_provisioner_test.cpp b/test/mesh/provisioning_provisioner_test.cpp index 1ea3fbede..cc369e50e 100644 --- a/test/mesh/provisioning_provisioner_test.cpp +++ b/test/mesh/provisioning_provisioner_test.cpp @@ -45,6 +45,7 @@ #include "mesh/provisioning.h" #include "mesh/provisioning_provisioner.h" #include "hci_dump.h" +#include "hci_dump_posix_fs.h" #include "mock.h" #include "CppUTest/TestHarness.h" @@ -255,6 +256,11 @@ TEST(Provisioning, Prov1){ } int main (int argc, const char * argv[]){ - hci_dump_open("hci_dump.pklg", HCI_DUMP_PACKETLOGGER); + // log into file using HCI_DUMP_PACKETLOGGER format + const char * log_path = "hci_dump.pklg"; + hci_dump_posix_fs_open(log_path, HCI_DUMP_PACKETLOGGER); + hci_dump_init(hci_dump_posix_fs_get_instance()); + printf("Packet Log: %s\n", log_path); + return CommandLineTestRunner::RunAllTests(argc, argv); } diff --git a/test/pts/Makefile b/test/pts/Makefile index ba60ef5b1..e8cb18b2d 100644 --- a/test/pts/Makefile +++ b/test/pts/Makefile @@ -21,6 +21,7 @@ COMMON += \ ad_parser.c \ hci_cmd.c \ hci_dump.c \ + hci_dump_posix_fs.c \ l2cap.c \ l2cap_signaling.c \ rfcomm.c \ diff --git a/test/security_manager/Makefile b/test/security_manager/Makefile index 8255bfa03..66b5d1dd6 100644 --- a/test/security_manager/Makefile +++ b/test/security_manager/Makefile @@ -8,6 +8,7 @@ CFLAGS = -DUNIT_TEST -g CFLAGS += -Wall -Wno-unused CFLAGS += -I. -I.. -I${BTSTACK_ROOT}/src CFLAGS += -I${BTSTACK_ROOT}/platform/embedded +CFLAGS += -I${BTSTACK_ROOT}/platform/posix CFLAGS += -I${BTSTACK_ROOT}/3rd-party/mbedtls/include CFLAGS += -I${BTSTACK_ROOT}/3rd-party/micro-ecc CFLAGS += -I${BTSTACK_ROOT}/3rd-party/rijndael @@ -16,7 +17,7 @@ LDFLAGS += -lCppUTest -lCppUTestExt VPATH += ${BTSTACK_ROOT}/src VPATH += ${BTSTACK_ROOT}/src/ble VPATH += ${BTSTACK_ROOT}/platform/embedded -# VPATH += ${BTSTACK_ROOT}/platform/posix +VPATH += ${BTSTACK_ROOT}/platform/posix VPATH += ${BTSTACK_ROOT}/3rd-party/micro-ecc VPATH += ${BTSTACK_ROOT}/3rd-party/rijndael @@ -29,6 +30,7 @@ COMMON = \ btstack_run_loop_embedded.c \ hci_cmd.c \ hci_dump.c \ + hci_dump_posix_fs.c \ le_device_db_memory.c \ mock.c \ rijndael.c \ diff --git a/test/security_manager/security_manager.c b/test/security_manager/security_manager.c index 0e433b169..498dc450c 100644 --- a/test/security_manager/security_manager.c +++ b/test/security_manager/security_manager.c @@ -22,6 +22,7 @@ #include "btstack_memory.h" #include "hci.h" #include "hci_dump.h" +#include "hci_dump_posix_fs.h" #include "l2cap.h" #include "ble/sm.h" @@ -223,7 +224,13 @@ TEST_GROUP(SecurityManager){ sm_set_authentication_requirements( SM_AUTHREQ_BONDING ); sm_event_callback_registration.callback = &app_packet_handler; sm_add_event_handler(&sm_event_callback_registration); - // hci_dump_open("security_manager.pklg", HCI_DUMP_PACKETLOGGER); + + + // log into file using HCI_DUMP_PACKETLOGGER format + const char * log_path = "hci_dump.pklg"; + hci_dump_posix_fs_open(log_path, HCI_DUMP_PACKETLOGGER); + hci_dump_init(hci_dump_posix_fs_get_instance()); + printf("Packet Log: %s\n", log_path); } }; @@ -404,6 +411,11 @@ TEST(SecurityManager, MainTest){ } int main (int argc, const char * argv[]){ - // hci_dump_open("hci_dump.pklg", HCI_DUMP_STDOUT); // HCI_DUMP_PACKETLOGGER + // log into file using HCI_DUMP_PACKETLOGGER format + const char * log_path = "hci_dump.pklg"; + hci_dump_posix_fs_open(log_path, HCI_DUMP_PACKETLOGGER); + hci_dump_init(hci_dump_posix_fs_get_instance()); + printf("Packet Log: %s\n", log_path); + return CommandLineTestRunner::RunAllTests(argc, argv); } diff --git a/test/security_manager_sc/main.c b/test/security_manager_sc/main.c index 50d4e6920..00aad4982 100644 --- a/test/security_manager_sc/main.c +++ b/test/security_manager_sc/main.c @@ -217,8 +217,11 @@ int main(int argc, const char * argv[]){ strcat(pklg_path, usb_path_string); } strcat(pklg_path, ".pklg"); + + // log into file using HCI_DUMP_PACKETLOGGER format + hci_dump_posix_fs_open(pklg_path, HCI_DUMP_PACKETLOGGER); + hci_dump_init(hci_dump_posix_fs_get_instance()); printf("Packet Log: %s\n", pklg_path); - // hci_dump_open(pklg_path, HCI_DUMP_PACKETLOGGER); // init HCI hci_init(hci_transport_usb_instance(), NULL); diff --git a/test/tlv_posix/tlv_test.c b/test/tlv_posix/tlv_test.c index 0149ee230..06edd4e4b 100644 --- a/test/tlv_posix/tlv_test.c +++ b/test/tlv_posix/tlv_test.c @@ -185,6 +185,11 @@ TEST(BSTACK_TLV, TestWriteDeleteResetReadDeleteRead){ int main (int argc, const char * argv[]){ - // hci_dump_open("tlv_test.pklg", HCI_DUMP_PACKETLOGGER); + // log into file using HCI_DUMP_PACKETLOGGER format + const char * log_path = "hci_dump.pklg"; + hci_dump_posix_fs_open(log_path, HCI_DUMP_PACKETLOGGER); + hci_dump_init(hci_dump_posix_fs_get_instance()); + printf("Packet Log: %s\n", log_path); + return CommandLineTestRunner::RunAllTests(argc, argv); }