test/fuzz: test hci

This commit is contained in:
Matthias Ringwald 2020-01-20 18:08:59 +01:00
parent 1f805efefd
commit eddac6153d
4 changed files with 25 additions and 7 deletions

View File

@ -5312,3 +5312,15 @@ void hci_halting_defer(void){
break; break;
} }
} }
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
void hci_free_connections_fuzz(void){
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &hci_stack->connections);
while (btstack_linked_list_iterator_has_next(&it)){
hci_connection_t * con = (hci_connection_t*) btstack_linked_list_iterator_next(&it);
btstack_linked_list_iterator_remove(&it);
btstack_memory_hci_connection_free(con);
}
}
#endif

View File

@ -1229,6 +1229,11 @@ void hci_le_set_own_address_type(uint8_t own_address_type);
*/ */
uint16_t hci_get_manufacturer(void); uint16_t hci_get_manufacturer(void);
/**
* Defer halt. Used by btstack_crypto to allow current HCI operation to complete
*/
void hci_halting_defer(void);
// Only for PTS testing // Only for PTS testing
/** /**
@ -1241,10 +1246,8 @@ void hci_disable_l2cap_timeout_check(void);
*/ */
HCI_STATE hci_get_state(void); HCI_STATE hci_get_state(void);
/** // free all connections, used for fuzzing
* Defer halt. Used by btstack_crypto to allow current HCI operation to complete void hci_free_connections_fuzz(void);
*/
void hci_halting_defer(void);
#if defined __cplusplus #if defined __cplusplus
} }

View File

@ -101,15 +101,15 @@ set(SOURCES
) )
list(SORT SOURCES) list(SORT SOURCES)
add_compile_options( -fsanitize=fuzzer,address -fprofile-instr-generate -fcoverage-mapping)
add_link_options( -fsanitize=fuzzer,address)
# create static lib # create static lib
add_library(btstack STATIC ${SOURCES}) add_library(btstack STATIC ${SOURCES})
# create fuzz targets # create fuzz targets
file(GLOB TARGETS_C "fuzz_*.c") file(GLOB TARGETS_C "fuzz_*.c")
add_compile_options( -fsanitize=fuzzer,address)
add_link_options( -fsanitize=fuzzer,address)
# create targets # create targets
foreach(TARGET_FILE ${TARGETS_C}) foreach(TARGET_FILE ${TARGETS_C})
get_filename_component(EXAMPLE ${TARGET_FILE} NAME_WE) get_filename_component(EXAMPLE ${TARGET_FILE} NAME_WE)

View File

@ -5,11 +5,14 @@
#ifndef __BTSTACK_CONFIG #ifndef __BTSTACK_CONFIG
#define __BTSTACK_CONFIG #define __BTSTACK_CONFIG
#define FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
// Port related features // Port related features
#define HAVE_MALLOC #define HAVE_MALLOC
#define HAVE_POSIX_FILE_IO #define HAVE_POSIX_FILE_IO
#define HAVE_BTSTACK_STDIN #define HAVE_BTSTACK_STDIN
#define HAVE_POSIX_TIME #define HAVE_POSIX_TIME
#define HAVE_ASSERT
// BTstack features that can be enabled // BTstack features that can be enabled
#define ENABLE_BLE #define ENABLE_BLE