xref: /btstack/test/btstack_memory/btstack_memory_test.cpp (revision 2281ada7921e55288a45180ce35a34d9af2af65c)
14902524cSMatthias Ringwald /*
24902524cSMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
34902524cSMatthias Ringwald  *
44902524cSMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
54902524cSMatthias Ringwald  * modification, are permitted provided that the following conditions
64902524cSMatthias Ringwald  * are met:
74902524cSMatthias Ringwald  *
84902524cSMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
94902524cSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
104902524cSMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
114902524cSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
124902524cSMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
134902524cSMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
144902524cSMatthias Ringwald  *    contributors may be used to endorse or promote products derived
154902524cSMatthias Ringwald  *    from this software without specific prior written permission.
164902524cSMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
174902524cSMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
184902524cSMatthias Ringwald  *    monetary gain.
194902524cSMatthias Ringwald  *
204902524cSMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
214902524cSMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
224902524cSMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
234902524cSMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
244902524cSMatthias Ringwald  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
254902524cSMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
264902524cSMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
274902524cSMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
284902524cSMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
294902524cSMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
304902524cSMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
314902524cSMatthias Ringwald  * SUCH DAMAGE.
324902524cSMatthias Ringwald  *
334902524cSMatthias Ringwald  * Please inquire about commercial licensing options at
344902524cSMatthias Ringwald  * [email protected]
354902524cSMatthias Ringwald  *
364902524cSMatthias Ringwald  */
374902524cSMatthias Ringwald 
384902524cSMatthias Ringwald 
394902524cSMatthias Ringwald #include <stdint.h>
404902524cSMatthias Ringwald #include <stdio.h>
414902524cSMatthias Ringwald #include <stdlib.h>
424902524cSMatthias Ringwald #include <string.h>
434902524cSMatthias Ringwald 
444902524cSMatthias Ringwald // malloc hook
454902524cSMatthias Ringwald static int simulate_no_memory;
464902524cSMatthias Ringwald extern "C" void * test_malloc(size_t size);
test_malloc(size_t size)474902524cSMatthias Ringwald void * test_malloc(size_t size){
484902524cSMatthias Ringwald     if (simulate_no_memory) return NULL;
494902524cSMatthias Ringwald     return malloc(size);
504902524cSMatthias Ringwald }
514902524cSMatthias Ringwald 
524902524cSMatthias Ringwald #include "btstack_config.h"
534902524cSMatthias Ringwald 
544902524cSMatthias Ringwald #include "CppUTest/TestHarness.h"
554902524cSMatthias Ringwald #include "CppUTest/CommandLineTestRunner.h"
564902524cSMatthias Ringwald 
574902524cSMatthias Ringwald #include "bluetooth_data_types.h"
584902524cSMatthias Ringwald #include "btstack_util.h"
594902524cSMatthias Ringwald #include "btstack_memory.h"
604902524cSMatthias Ringwald 
614902524cSMatthias Ringwald 
TEST_GROUP(btstack_memory)624902524cSMatthias Ringwald TEST_GROUP(btstack_memory){
634902524cSMatthias Ringwald     void setup(void){
644902524cSMatthias Ringwald         btstack_memory_init();
654902524cSMatthias Ringwald         simulate_no_memory = 0;
664902524cSMatthias Ringwald     }
674902524cSMatthias Ringwald };
684902524cSMatthias Ringwald 
694902524cSMatthias Ringwald #ifdef HAVE_MALLOC
TEST(btstack_memory,deinit)704902524cSMatthias Ringwald TEST(btstack_memory, deinit){
714902524cSMatthias Ringwald     // alloc buffers 1,2,3
724902524cSMatthias Ringwald     hci_connection_t * buffer_1 = btstack_memory_hci_connection_get();
734902524cSMatthias Ringwald     hci_connection_t * buffer_2 = btstack_memory_hci_connection_get();
744902524cSMatthias Ringwald     hci_connection_t * buffer_3 = btstack_memory_hci_connection_get();
754902524cSMatthias Ringwald     // free first one in list
764902524cSMatthias Ringwald     btstack_memory_hci_connection_free(buffer_3);
774902524cSMatthias Ringwald     // free second one in list
784902524cSMatthias Ringwald     btstack_memory_hci_connection_free(buffer_1);
794902524cSMatthias Ringwald     // leave buffer in list
804902524cSMatthias Ringwald     (void) buffer_2;
814902524cSMatthias Ringwald     btstack_memory_deinit();
824902524cSMatthias Ringwald }
834902524cSMatthias Ringwald #endif
844902524cSMatthias Ringwald 
854902524cSMatthias Ringwald 
864902524cSMatthias Ringwald 
874902524cSMatthias Ringwald 
TEST(btstack_memory,hci_connection_GetAndFree)884902524cSMatthias Ringwald TEST(btstack_memory, hci_connection_GetAndFree){
894902524cSMatthias Ringwald     hci_connection_t * context;
904902524cSMatthias Ringwald #ifdef HAVE_MALLOC
914902524cSMatthias Ringwald     context = btstack_memory_hci_connection_get();
924902524cSMatthias Ringwald     CHECK(context != NULL);
934902524cSMatthias Ringwald     btstack_memory_hci_connection_free(context);
944902524cSMatthias Ringwald #else
954902524cSMatthias Ringwald #ifdef MAX_NR_HCI_CONNECTIONS
964902524cSMatthias Ringwald     // single
974902524cSMatthias Ringwald     context = btstack_memory_hci_connection_get();
984902524cSMatthias Ringwald     CHECK(context != NULL);
994902524cSMatthias Ringwald     btstack_memory_hci_connection_free(context);
1004902524cSMatthias Ringwald #else
1014902524cSMatthias Ringwald     // none
1024902524cSMatthias Ringwald     context = btstack_memory_hci_connection_get();
1034902524cSMatthias Ringwald     CHECK(context == NULL);
1044902524cSMatthias Ringwald     btstack_memory_hci_connection_free(context);
1054902524cSMatthias Ringwald #endif
1064902524cSMatthias Ringwald #endif
1074902524cSMatthias Ringwald }
1084902524cSMatthias Ringwald 
TEST(btstack_memory,hci_connection_NotEnoughBuffers)1094902524cSMatthias Ringwald TEST(btstack_memory, hci_connection_NotEnoughBuffers){
1104902524cSMatthias Ringwald     hci_connection_t * context;
1114902524cSMatthias Ringwald #ifdef HAVE_MALLOC
1124902524cSMatthias Ringwald     simulate_no_memory = 1;
1134902524cSMatthias Ringwald #else
1144902524cSMatthias Ringwald #ifdef MAX_NR_HCI_CONNECTIONS
1154902524cSMatthias Ringwald     int i;
1164902524cSMatthias Ringwald     // alloc all static buffers
1174902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_HCI_CONNECTIONS; i++){
1184902524cSMatthias Ringwald         context = btstack_memory_hci_connection_get();
1194902524cSMatthias Ringwald         CHECK(context != NULL);
1204902524cSMatthias Ringwald     }
1214902524cSMatthias Ringwald #endif
1224902524cSMatthias Ringwald #endif
1234902524cSMatthias Ringwald     // get one more
1244902524cSMatthias Ringwald     context = btstack_memory_hci_connection_get();
1254902524cSMatthias Ringwald     CHECK(context == NULL);
1264902524cSMatthias Ringwald }
1274902524cSMatthias Ringwald 
1284902524cSMatthias Ringwald 
1294902524cSMatthias Ringwald 
130*2281ada7SMatthias Ringwald 
TEST(btstack_memory,l2cap_service_GetAndFree)1314902524cSMatthias Ringwald TEST(btstack_memory, l2cap_service_GetAndFree){
1324902524cSMatthias Ringwald     l2cap_service_t * context;
1334902524cSMatthias Ringwald #ifdef HAVE_MALLOC
1344902524cSMatthias Ringwald     context = btstack_memory_l2cap_service_get();
1354902524cSMatthias Ringwald     CHECK(context != NULL);
1364902524cSMatthias Ringwald     btstack_memory_l2cap_service_free(context);
1374902524cSMatthias Ringwald #else
1384902524cSMatthias Ringwald #ifdef MAX_NR_L2CAP_SERVICES
1394902524cSMatthias Ringwald     // single
1404902524cSMatthias Ringwald     context = btstack_memory_l2cap_service_get();
1414902524cSMatthias Ringwald     CHECK(context != NULL);
1424902524cSMatthias Ringwald     btstack_memory_l2cap_service_free(context);
1434902524cSMatthias Ringwald #else
1444902524cSMatthias Ringwald     // none
1454902524cSMatthias Ringwald     context = btstack_memory_l2cap_service_get();
1464902524cSMatthias Ringwald     CHECK(context == NULL);
1474902524cSMatthias Ringwald     btstack_memory_l2cap_service_free(context);
1484902524cSMatthias Ringwald #endif
1494902524cSMatthias Ringwald #endif
1504902524cSMatthias Ringwald }
1514902524cSMatthias Ringwald 
TEST(btstack_memory,l2cap_service_NotEnoughBuffers)1524902524cSMatthias Ringwald TEST(btstack_memory, l2cap_service_NotEnoughBuffers){
1534902524cSMatthias Ringwald     l2cap_service_t * context;
1544902524cSMatthias Ringwald #ifdef HAVE_MALLOC
1554902524cSMatthias Ringwald     simulate_no_memory = 1;
1564902524cSMatthias Ringwald #else
1574902524cSMatthias Ringwald #ifdef MAX_NR_L2CAP_SERVICES
1584902524cSMatthias Ringwald     int i;
1594902524cSMatthias Ringwald     // alloc all static buffers
1604902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_L2CAP_SERVICES; i++){
1614902524cSMatthias Ringwald         context = btstack_memory_l2cap_service_get();
1624902524cSMatthias Ringwald         CHECK(context != NULL);
1634902524cSMatthias Ringwald     }
1644902524cSMatthias Ringwald #endif
1654902524cSMatthias Ringwald #endif
1664902524cSMatthias Ringwald     // get one more
1674902524cSMatthias Ringwald     context = btstack_memory_l2cap_service_get();
1684902524cSMatthias Ringwald     CHECK(context == NULL);
1694902524cSMatthias Ringwald }
1704902524cSMatthias Ringwald 
1714902524cSMatthias Ringwald 
1724902524cSMatthias Ringwald 
TEST(btstack_memory,l2cap_channel_GetAndFree)1734902524cSMatthias Ringwald TEST(btstack_memory, l2cap_channel_GetAndFree){
1744902524cSMatthias Ringwald     l2cap_channel_t * context;
1754902524cSMatthias Ringwald #ifdef HAVE_MALLOC
1764902524cSMatthias Ringwald     context = btstack_memory_l2cap_channel_get();
1774902524cSMatthias Ringwald     CHECK(context != NULL);
1784902524cSMatthias Ringwald     btstack_memory_l2cap_channel_free(context);
1794902524cSMatthias Ringwald #else
1804902524cSMatthias Ringwald #ifdef MAX_NR_L2CAP_CHANNELS
1814902524cSMatthias Ringwald     // single
1824902524cSMatthias Ringwald     context = btstack_memory_l2cap_channel_get();
1834902524cSMatthias Ringwald     CHECK(context != NULL);
1844902524cSMatthias Ringwald     btstack_memory_l2cap_channel_free(context);
1854902524cSMatthias Ringwald #else
1864902524cSMatthias Ringwald     // none
1874902524cSMatthias Ringwald     context = btstack_memory_l2cap_channel_get();
1884902524cSMatthias Ringwald     CHECK(context == NULL);
1894902524cSMatthias Ringwald     btstack_memory_l2cap_channel_free(context);
1904902524cSMatthias Ringwald #endif
1914902524cSMatthias Ringwald #endif
1924902524cSMatthias Ringwald }
1934902524cSMatthias Ringwald 
TEST(btstack_memory,l2cap_channel_NotEnoughBuffers)1944902524cSMatthias Ringwald TEST(btstack_memory, l2cap_channel_NotEnoughBuffers){
1954902524cSMatthias Ringwald     l2cap_channel_t * context;
1964902524cSMatthias Ringwald #ifdef HAVE_MALLOC
1974902524cSMatthias Ringwald     simulate_no_memory = 1;
1984902524cSMatthias Ringwald #else
1994902524cSMatthias Ringwald #ifdef MAX_NR_L2CAP_CHANNELS
2004902524cSMatthias Ringwald     int i;
2014902524cSMatthias Ringwald     // alloc all static buffers
2024902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_L2CAP_CHANNELS; i++){
2034902524cSMatthias Ringwald         context = btstack_memory_l2cap_channel_get();
2044902524cSMatthias Ringwald         CHECK(context != NULL);
2054902524cSMatthias Ringwald     }
2064902524cSMatthias Ringwald #endif
2074902524cSMatthias Ringwald #endif
2084902524cSMatthias Ringwald     // get one more
2094902524cSMatthias Ringwald     context = btstack_memory_l2cap_channel_get();
2104902524cSMatthias Ringwald     CHECK(context == NULL);
2114902524cSMatthias Ringwald }
2124902524cSMatthias Ringwald 
213*2281ada7SMatthias Ringwald 
2144902524cSMatthias Ringwald #ifdef ENABLE_CLASSIC
2154902524cSMatthias Ringwald 
2164902524cSMatthias Ringwald 
TEST(btstack_memory,rfcomm_multiplexer_GetAndFree)2174902524cSMatthias Ringwald TEST(btstack_memory, rfcomm_multiplexer_GetAndFree){
2184902524cSMatthias Ringwald     rfcomm_multiplexer_t * context;
2194902524cSMatthias Ringwald #ifdef HAVE_MALLOC
2204902524cSMatthias Ringwald     context = btstack_memory_rfcomm_multiplexer_get();
2214902524cSMatthias Ringwald     CHECK(context != NULL);
2224902524cSMatthias Ringwald     btstack_memory_rfcomm_multiplexer_free(context);
2234902524cSMatthias Ringwald #else
2244902524cSMatthias Ringwald #ifdef MAX_NR_RFCOMM_MULTIPLEXERS
2254902524cSMatthias Ringwald     // single
2264902524cSMatthias Ringwald     context = btstack_memory_rfcomm_multiplexer_get();
2274902524cSMatthias Ringwald     CHECK(context != NULL);
2284902524cSMatthias Ringwald     btstack_memory_rfcomm_multiplexer_free(context);
2294902524cSMatthias Ringwald #else
2304902524cSMatthias Ringwald     // none
2314902524cSMatthias Ringwald     context = btstack_memory_rfcomm_multiplexer_get();
2324902524cSMatthias Ringwald     CHECK(context == NULL);
2334902524cSMatthias Ringwald     btstack_memory_rfcomm_multiplexer_free(context);
2344902524cSMatthias Ringwald #endif
2354902524cSMatthias Ringwald #endif
2364902524cSMatthias Ringwald }
2374902524cSMatthias Ringwald 
TEST(btstack_memory,rfcomm_multiplexer_NotEnoughBuffers)2384902524cSMatthias Ringwald TEST(btstack_memory, rfcomm_multiplexer_NotEnoughBuffers){
2394902524cSMatthias Ringwald     rfcomm_multiplexer_t * context;
2404902524cSMatthias Ringwald #ifdef HAVE_MALLOC
2414902524cSMatthias Ringwald     simulate_no_memory = 1;
2424902524cSMatthias Ringwald #else
2434902524cSMatthias Ringwald #ifdef MAX_NR_RFCOMM_MULTIPLEXERS
2444902524cSMatthias Ringwald     int i;
2454902524cSMatthias Ringwald     // alloc all static buffers
2464902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_RFCOMM_MULTIPLEXERS; i++){
2474902524cSMatthias Ringwald         context = btstack_memory_rfcomm_multiplexer_get();
2484902524cSMatthias Ringwald         CHECK(context != NULL);
2494902524cSMatthias Ringwald     }
2504902524cSMatthias Ringwald #endif
2514902524cSMatthias Ringwald #endif
2524902524cSMatthias Ringwald     // get one more
2534902524cSMatthias Ringwald     context = btstack_memory_rfcomm_multiplexer_get();
2544902524cSMatthias Ringwald     CHECK(context == NULL);
2554902524cSMatthias Ringwald }
2564902524cSMatthias Ringwald 
2574902524cSMatthias Ringwald 
2584902524cSMatthias Ringwald 
TEST(btstack_memory,rfcomm_service_GetAndFree)2594902524cSMatthias Ringwald TEST(btstack_memory, rfcomm_service_GetAndFree){
2604902524cSMatthias Ringwald     rfcomm_service_t * context;
2614902524cSMatthias Ringwald #ifdef HAVE_MALLOC
2624902524cSMatthias Ringwald     context = btstack_memory_rfcomm_service_get();
2634902524cSMatthias Ringwald     CHECK(context != NULL);
2644902524cSMatthias Ringwald     btstack_memory_rfcomm_service_free(context);
2654902524cSMatthias Ringwald #else
2664902524cSMatthias Ringwald #ifdef MAX_NR_RFCOMM_SERVICES
2674902524cSMatthias Ringwald     // single
2684902524cSMatthias Ringwald     context = btstack_memory_rfcomm_service_get();
2694902524cSMatthias Ringwald     CHECK(context != NULL);
2704902524cSMatthias Ringwald     btstack_memory_rfcomm_service_free(context);
2714902524cSMatthias Ringwald #else
2724902524cSMatthias Ringwald     // none
2734902524cSMatthias Ringwald     context = btstack_memory_rfcomm_service_get();
2744902524cSMatthias Ringwald     CHECK(context == NULL);
2754902524cSMatthias Ringwald     btstack_memory_rfcomm_service_free(context);
2764902524cSMatthias Ringwald #endif
2774902524cSMatthias Ringwald #endif
2784902524cSMatthias Ringwald }
2794902524cSMatthias Ringwald 
TEST(btstack_memory,rfcomm_service_NotEnoughBuffers)2804902524cSMatthias Ringwald TEST(btstack_memory, rfcomm_service_NotEnoughBuffers){
2814902524cSMatthias Ringwald     rfcomm_service_t * context;
2824902524cSMatthias Ringwald #ifdef HAVE_MALLOC
2834902524cSMatthias Ringwald     simulate_no_memory = 1;
2844902524cSMatthias Ringwald #else
2854902524cSMatthias Ringwald #ifdef MAX_NR_RFCOMM_SERVICES
2864902524cSMatthias Ringwald     int i;
2874902524cSMatthias Ringwald     // alloc all static buffers
2884902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_RFCOMM_SERVICES; i++){
2894902524cSMatthias Ringwald         context = btstack_memory_rfcomm_service_get();
2904902524cSMatthias Ringwald         CHECK(context != NULL);
2914902524cSMatthias Ringwald     }
2924902524cSMatthias Ringwald #endif
2934902524cSMatthias Ringwald #endif
2944902524cSMatthias Ringwald     // get one more
2954902524cSMatthias Ringwald     context = btstack_memory_rfcomm_service_get();
2964902524cSMatthias Ringwald     CHECK(context == NULL);
2974902524cSMatthias Ringwald }
2984902524cSMatthias Ringwald 
2994902524cSMatthias Ringwald 
3004902524cSMatthias Ringwald 
TEST(btstack_memory,rfcomm_channel_GetAndFree)3014902524cSMatthias Ringwald TEST(btstack_memory, rfcomm_channel_GetAndFree){
3024902524cSMatthias Ringwald     rfcomm_channel_t * context;
3034902524cSMatthias Ringwald #ifdef HAVE_MALLOC
3044902524cSMatthias Ringwald     context = btstack_memory_rfcomm_channel_get();
3054902524cSMatthias Ringwald     CHECK(context != NULL);
3064902524cSMatthias Ringwald     btstack_memory_rfcomm_channel_free(context);
3074902524cSMatthias Ringwald #else
3084902524cSMatthias Ringwald #ifdef MAX_NR_RFCOMM_CHANNELS
3094902524cSMatthias Ringwald     // single
3104902524cSMatthias Ringwald     context = btstack_memory_rfcomm_channel_get();
3114902524cSMatthias Ringwald     CHECK(context != NULL);
3124902524cSMatthias Ringwald     btstack_memory_rfcomm_channel_free(context);
3134902524cSMatthias Ringwald #else
3144902524cSMatthias Ringwald     // none
3154902524cSMatthias Ringwald     context = btstack_memory_rfcomm_channel_get();
3164902524cSMatthias Ringwald     CHECK(context == NULL);
3174902524cSMatthias Ringwald     btstack_memory_rfcomm_channel_free(context);
3184902524cSMatthias Ringwald #endif
3194902524cSMatthias Ringwald #endif
3204902524cSMatthias Ringwald }
3214902524cSMatthias Ringwald 
TEST(btstack_memory,rfcomm_channel_NotEnoughBuffers)3224902524cSMatthias Ringwald TEST(btstack_memory, rfcomm_channel_NotEnoughBuffers){
3234902524cSMatthias Ringwald     rfcomm_channel_t * context;
3244902524cSMatthias Ringwald #ifdef HAVE_MALLOC
3254902524cSMatthias Ringwald     simulate_no_memory = 1;
3264902524cSMatthias Ringwald #else
3274902524cSMatthias Ringwald #ifdef MAX_NR_RFCOMM_CHANNELS
3284902524cSMatthias Ringwald     int i;
3294902524cSMatthias Ringwald     // alloc all static buffers
3304902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_RFCOMM_CHANNELS; i++){
3314902524cSMatthias Ringwald         context = btstack_memory_rfcomm_channel_get();
3324902524cSMatthias Ringwald         CHECK(context != NULL);
3334902524cSMatthias Ringwald     }
3344902524cSMatthias Ringwald #endif
3354902524cSMatthias Ringwald #endif
3364902524cSMatthias Ringwald     // get one more
3374902524cSMatthias Ringwald     context = btstack_memory_rfcomm_channel_get();
3384902524cSMatthias Ringwald     CHECK(context == NULL);
3394902524cSMatthias Ringwald }
3404902524cSMatthias Ringwald 
3414902524cSMatthias Ringwald 
3424902524cSMatthias Ringwald 
343*2281ada7SMatthias Ringwald 
TEST(btstack_memory,btstack_link_key_db_memory_entry_GetAndFree)3444902524cSMatthias Ringwald TEST(btstack_memory, btstack_link_key_db_memory_entry_GetAndFree){
3454902524cSMatthias Ringwald     btstack_link_key_db_memory_entry_t * context;
3464902524cSMatthias Ringwald #ifdef HAVE_MALLOC
3474902524cSMatthias Ringwald     context = btstack_memory_btstack_link_key_db_memory_entry_get();
3484902524cSMatthias Ringwald     CHECK(context != NULL);
3494902524cSMatthias Ringwald     btstack_memory_btstack_link_key_db_memory_entry_free(context);
3504902524cSMatthias Ringwald #else
3514902524cSMatthias Ringwald #ifdef MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES
3524902524cSMatthias Ringwald     // single
3534902524cSMatthias Ringwald     context = btstack_memory_btstack_link_key_db_memory_entry_get();
3544902524cSMatthias Ringwald     CHECK(context != NULL);
3554902524cSMatthias Ringwald     btstack_memory_btstack_link_key_db_memory_entry_free(context);
3564902524cSMatthias Ringwald #else
3574902524cSMatthias Ringwald     // none
3584902524cSMatthias Ringwald     context = btstack_memory_btstack_link_key_db_memory_entry_get();
3594902524cSMatthias Ringwald     CHECK(context == NULL);
3604902524cSMatthias Ringwald     btstack_memory_btstack_link_key_db_memory_entry_free(context);
3614902524cSMatthias Ringwald #endif
3624902524cSMatthias Ringwald #endif
3634902524cSMatthias Ringwald }
3644902524cSMatthias Ringwald 
TEST(btstack_memory,btstack_link_key_db_memory_entry_NotEnoughBuffers)3654902524cSMatthias Ringwald TEST(btstack_memory, btstack_link_key_db_memory_entry_NotEnoughBuffers){
3664902524cSMatthias Ringwald     btstack_link_key_db_memory_entry_t * context;
3674902524cSMatthias Ringwald #ifdef HAVE_MALLOC
3684902524cSMatthias Ringwald     simulate_no_memory = 1;
3694902524cSMatthias Ringwald #else
3704902524cSMatthias Ringwald #ifdef MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES
3714902524cSMatthias Ringwald     int i;
3724902524cSMatthias Ringwald     // alloc all static buffers
3734902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES; i++){
3744902524cSMatthias Ringwald         context = btstack_memory_btstack_link_key_db_memory_entry_get();
3754902524cSMatthias Ringwald         CHECK(context != NULL);
3764902524cSMatthias Ringwald     }
3774902524cSMatthias Ringwald #endif
3784902524cSMatthias Ringwald #endif
3794902524cSMatthias Ringwald     // get one more
3804902524cSMatthias Ringwald     context = btstack_memory_btstack_link_key_db_memory_entry_get();
3814902524cSMatthias Ringwald     CHECK(context == NULL);
3824902524cSMatthias Ringwald }
3834902524cSMatthias Ringwald 
3844902524cSMatthias Ringwald 
3854902524cSMatthias Ringwald 
386*2281ada7SMatthias Ringwald 
TEST(btstack_memory,bnep_service_GetAndFree)3874902524cSMatthias Ringwald TEST(btstack_memory, bnep_service_GetAndFree){
3884902524cSMatthias Ringwald     bnep_service_t * context;
3894902524cSMatthias Ringwald #ifdef HAVE_MALLOC
3904902524cSMatthias Ringwald     context = btstack_memory_bnep_service_get();
3914902524cSMatthias Ringwald     CHECK(context != NULL);
3924902524cSMatthias Ringwald     btstack_memory_bnep_service_free(context);
3934902524cSMatthias Ringwald #else
3944902524cSMatthias Ringwald #ifdef MAX_NR_BNEP_SERVICES
3954902524cSMatthias Ringwald     // single
3964902524cSMatthias Ringwald     context = btstack_memory_bnep_service_get();
3974902524cSMatthias Ringwald     CHECK(context != NULL);
3984902524cSMatthias Ringwald     btstack_memory_bnep_service_free(context);
3994902524cSMatthias Ringwald #else
4004902524cSMatthias Ringwald     // none
4014902524cSMatthias Ringwald     context = btstack_memory_bnep_service_get();
4024902524cSMatthias Ringwald     CHECK(context == NULL);
4034902524cSMatthias Ringwald     btstack_memory_bnep_service_free(context);
4044902524cSMatthias Ringwald #endif
4054902524cSMatthias Ringwald #endif
4064902524cSMatthias Ringwald }
4074902524cSMatthias Ringwald 
TEST(btstack_memory,bnep_service_NotEnoughBuffers)4084902524cSMatthias Ringwald TEST(btstack_memory, bnep_service_NotEnoughBuffers){
4094902524cSMatthias Ringwald     bnep_service_t * context;
4104902524cSMatthias Ringwald #ifdef HAVE_MALLOC
4114902524cSMatthias Ringwald     simulate_no_memory = 1;
4124902524cSMatthias Ringwald #else
4134902524cSMatthias Ringwald #ifdef MAX_NR_BNEP_SERVICES
4144902524cSMatthias Ringwald     int i;
4154902524cSMatthias Ringwald     // alloc all static buffers
4164902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_BNEP_SERVICES; i++){
4174902524cSMatthias Ringwald         context = btstack_memory_bnep_service_get();
4184902524cSMatthias Ringwald         CHECK(context != NULL);
4194902524cSMatthias Ringwald     }
4204902524cSMatthias Ringwald #endif
4214902524cSMatthias Ringwald #endif
4224902524cSMatthias Ringwald     // get one more
4234902524cSMatthias Ringwald     context = btstack_memory_bnep_service_get();
4244902524cSMatthias Ringwald     CHECK(context == NULL);
4254902524cSMatthias Ringwald }
4264902524cSMatthias Ringwald 
4274902524cSMatthias Ringwald 
4284902524cSMatthias Ringwald 
TEST(btstack_memory,bnep_channel_GetAndFree)4294902524cSMatthias Ringwald TEST(btstack_memory, bnep_channel_GetAndFree){
4304902524cSMatthias Ringwald     bnep_channel_t * context;
4314902524cSMatthias Ringwald #ifdef HAVE_MALLOC
4324902524cSMatthias Ringwald     context = btstack_memory_bnep_channel_get();
4334902524cSMatthias Ringwald     CHECK(context != NULL);
4344902524cSMatthias Ringwald     btstack_memory_bnep_channel_free(context);
4354902524cSMatthias Ringwald #else
4364902524cSMatthias Ringwald #ifdef MAX_NR_BNEP_CHANNELS
4374902524cSMatthias Ringwald     // single
4384902524cSMatthias Ringwald     context = btstack_memory_bnep_channel_get();
4394902524cSMatthias Ringwald     CHECK(context != NULL);
4404902524cSMatthias Ringwald     btstack_memory_bnep_channel_free(context);
4414902524cSMatthias Ringwald #else
4424902524cSMatthias Ringwald     // none
4434902524cSMatthias Ringwald     context = btstack_memory_bnep_channel_get();
4444902524cSMatthias Ringwald     CHECK(context == NULL);
4454902524cSMatthias Ringwald     btstack_memory_bnep_channel_free(context);
4464902524cSMatthias Ringwald #endif
4474902524cSMatthias Ringwald #endif
4484902524cSMatthias Ringwald }
4494902524cSMatthias Ringwald 
TEST(btstack_memory,bnep_channel_NotEnoughBuffers)4504902524cSMatthias Ringwald TEST(btstack_memory, bnep_channel_NotEnoughBuffers){
4514902524cSMatthias Ringwald     bnep_channel_t * context;
4524902524cSMatthias Ringwald #ifdef HAVE_MALLOC
4534902524cSMatthias Ringwald     simulate_no_memory = 1;
4544902524cSMatthias Ringwald #else
4554902524cSMatthias Ringwald #ifdef MAX_NR_BNEP_CHANNELS
4564902524cSMatthias Ringwald     int i;
4574902524cSMatthias Ringwald     // alloc all static buffers
4584902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_BNEP_CHANNELS; i++){
4594902524cSMatthias Ringwald         context = btstack_memory_bnep_channel_get();
4604902524cSMatthias Ringwald         CHECK(context != NULL);
4614902524cSMatthias Ringwald     }
4624902524cSMatthias Ringwald #endif
4634902524cSMatthias Ringwald #endif
4644902524cSMatthias Ringwald     // get one more
4654902524cSMatthias Ringwald     context = btstack_memory_bnep_channel_get();
4664902524cSMatthias Ringwald     CHECK(context == NULL);
4674902524cSMatthias Ringwald }
4684902524cSMatthias Ringwald 
4694902524cSMatthias Ringwald 
4704902524cSMatthias Ringwald 
471*2281ada7SMatthias Ringwald 
TEST(btstack_memory,goep_server_service_GetAndFree)472*2281ada7SMatthias Ringwald TEST(btstack_memory, goep_server_service_GetAndFree){
473*2281ada7SMatthias Ringwald     goep_server_service_t * context;
474*2281ada7SMatthias Ringwald #ifdef HAVE_MALLOC
475*2281ada7SMatthias Ringwald     context = btstack_memory_goep_server_service_get();
476*2281ada7SMatthias Ringwald     CHECK(context != NULL);
477*2281ada7SMatthias Ringwald     btstack_memory_goep_server_service_free(context);
478*2281ada7SMatthias Ringwald #else
479*2281ada7SMatthias Ringwald #ifdef MAX_NR_GOEP_SERVER_SERVICES
480*2281ada7SMatthias Ringwald     // single
481*2281ada7SMatthias Ringwald     context = btstack_memory_goep_server_service_get();
482*2281ada7SMatthias Ringwald     CHECK(context != NULL);
483*2281ada7SMatthias Ringwald     btstack_memory_goep_server_service_free(context);
484*2281ada7SMatthias Ringwald #else
485*2281ada7SMatthias Ringwald     // none
486*2281ada7SMatthias Ringwald     context = btstack_memory_goep_server_service_get();
487*2281ada7SMatthias Ringwald     CHECK(context == NULL);
488*2281ada7SMatthias Ringwald     btstack_memory_goep_server_service_free(context);
489*2281ada7SMatthias Ringwald #endif
490*2281ada7SMatthias Ringwald #endif
491*2281ada7SMatthias Ringwald }
492*2281ada7SMatthias Ringwald 
TEST(btstack_memory,goep_server_service_NotEnoughBuffers)493*2281ada7SMatthias Ringwald TEST(btstack_memory, goep_server_service_NotEnoughBuffers){
494*2281ada7SMatthias Ringwald     goep_server_service_t * context;
495*2281ada7SMatthias Ringwald #ifdef HAVE_MALLOC
496*2281ada7SMatthias Ringwald     simulate_no_memory = 1;
497*2281ada7SMatthias Ringwald #else
498*2281ada7SMatthias Ringwald #ifdef MAX_NR_GOEP_SERVER_SERVICES
499*2281ada7SMatthias Ringwald     int i;
500*2281ada7SMatthias Ringwald     // alloc all static buffers
501*2281ada7SMatthias Ringwald     for (i = 0; i < MAX_NR_GOEP_SERVER_SERVICES; i++){
502*2281ada7SMatthias Ringwald         context = btstack_memory_goep_server_service_get();
503*2281ada7SMatthias Ringwald         CHECK(context != NULL);
504*2281ada7SMatthias Ringwald     }
505*2281ada7SMatthias Ringwald #endif
506*2281ada7SMatthias Ringwald #endif
507*2281ada7SMatthias Ringwald     // get one more
508*2281ada7SMatthias Ringwald     context = btstack_memory_goep_server_service_get();
509*2281ada7SMatthias Ringwald     CHECK(context == NULL);
510*2281ada7SMatthias Ringwald }
511*2281ada7SMatthias Ringwald 
512*2281ada7SMatthias Ringwald 
513*2281ada7SMatthias Ringwald 
TEST(btstack_memory,goep_server_connection_GetAndFree)514*2281ada7SMatthias Ringwald TEST(btstack_memory, goep_server_connection_GetAndFree){
515*2281ada7SMatthias Ringwald     goep_server_connection_t * context;
516*2281ada7SMatthias Ringwald #ifdef HAVE_MALLOC
517*2281ada7SMatthias Ringwald     context = btstack_memory_goep_server_connection_get();
518*2281ada7SMatthias Ringwald     CHECK(context != NULL);
519*2281ada7SMatthias Ringwald     btstack_memory_goep_server_connection_free(context);
520*2281ada7SMatthias Ringwald #else
521*2281ada7SMatthias Ringwald #ifdef MAX_NR_GOEP_SERVER_CONNECTIONS
522*2281ada7SMatthias Ringwald     // single
523*2281ada7SMatthias Ringwald     context = btstack_memory_goep_server_connection_get();
524*2281ada7SMatthias Ringwald     CHECK(context != NULL);
525*2281ada7SMatthias Ringwald     btstack_memory_goep_server_connection_free(context);
526*2281ada7SMatthias Ringwald #else
527*2281ada7SMatthias Ringwald     // none
528*2281ada7SMatthias Ringwald     context = btstack_memory_goep_server_connection_get();
529*2281ada7SMatthias Ringwald     CHECK(context == NULL);
530*2281ada7SMatthias Ringwald     btstack_memory_goep_server_connection_free(context);
531*2281ada7SMatthias Ringwald #endif
532*2281ada7SMatthias Ringwald #endif
533*2281ada7SMatthias Ringwald }
534*2281ada7SMatthias Ringwald 
TEST(btstack_memory,goep_server_connection_NotEnoughBuffers)535*2281ada7SMatthias Ringwald TEST(btstack_memory, goep_server_connection_NotEnoughBuffers){
536*2281ada7SMatthias Ringwald     goep_server_connection_t * context;
537*2281ada7SMatthias Ringwald #ifdef HAVE_MALLOC
538*2281ada7SMatthias Ringwald     simulate_no_memory = 1;
539*2281ada7SMatthias Ringwald #else
540*2281ada7SMatthias Ringwald #ifdef MAX_NR_GOEP_SERVER_CONNECTIONS
541*2281ada7SMatthias Ringwald     int i;
542*2281ada7SMatthias Ringwald     // alloc all static buffers
543*2281ada7SMatthias Ringwald     for (i = 0; i < MAX_NR_GOEP_SERVER_CONNECTIONS; i++){
544*2281ada7SMatthias Ringwald         context = btstack_memory_goep_server_connection_get();
545*2281ada7SMatthias Ringwald         CHECK(context != NULL);
546*2281ada7SMatthias Ringwald     }
547*2281ada7SMatthias Ringwald #endif
548*2281ada7SMatthias Ringwald #endif
549*2281ada7SMatthias Ringwald     // get one more
550*2281ada7SMatthias Ringwald     context = btstack_memory_goep_server_connection_get();
551*2281ada7SMatthias Ringwald     CHECK(context == NULL);
552*2281ada7SMatthias Ringwald }
553*2281ada7SMatthias Ringwald 
554*2281ada7SMatthias Ringwald 
555*2281ada7SMatthias Ringwald 
556*2281ada7SMatthias Ringwald 
TEST(btstack_memory,hfp_connection_GetAndFree)5574902524cSMatthias Ringwald TEST(btstack_memory, hfp_connection_GetAndFree){
5584902524cSMatthias Ringwald     hfp_connection_t * context;
5594902524cSMatthias Ringwald #ifdef HAVE_MALLOC
5604902524cSMatthias Ringwald     context = btstack_memory_hfp_connection_get();
5614902524cSMatthias Ringwald     CHECK(context != NULL);
5624902524cSMatthias Ringwald     btstack_memory_hfp_connection_free(context);
5634902524cSMatthias Ringwald #else
5644902524cSMatthias Ringwald #ifdef MAX_NR_HFP_CONNECTIONS
5654902524cSMatthias Ringwald     // single
5664902524cSMatthias Ringwald     context = btstack_memory_hfp_connection_get();
5674902524cSMatthias Ringwald     CHECK(context != NULL);
5684902524cSMatthias Ringwald     btstack_memory_hfp_connection_free(context);
5694902524cSMatthias Ringwald #else
5704902524cSMatthias Ringwald     // none
5714902524cSMatthias Ringwald     context = btstack_memory_hfp_connection_get();
5724902524cSMatthias Ringwald     CHECK(context == NULL);
5734902524cSMatthias Ringwald     btstack_memory_hfp_connection_free(context);
5744902524cSMatthias Ringwald #endif
5754902524cSMatthias Ringwald #endif
5764902524cSMatthias Ringwald }
5774902524cSMatthias Ringwald 
TEST(btstack_memory,hfp_connection_NotEnoughBuffers)5784902524cSMatthias Ringwald TEST(btstack_memory, hfp_connection_NotEnoughBuffers){
5794902524cSMatthias Ringwald     hfp_connection_t * context;
5804902524cSMatthias Ringwald #ifdef HAVE_MALLOC
5814902524cSMatthias Ringwald     simulate_no_memory = 1;
5824902524cSMatthias Ringwald #else
5834902524cSMatthias Ringwald #ifdef MAX_NR_HFP_CONNECTIONS
5844902524cSMatthias Ringwald     int i;
5854902524cSMatthias Ringwald     // alloc all static buffers
5864902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_HFP_CONNECTIONS; i++){
5874902524cSMatthias Ringwald         context = btstack_memory_hfp_connection_get();
5884902524cSMatthias Ringwald         CHECK(context != NULL);
5894902524cSMatthias Ringwald     }
5904902524cSMatthias Ringwald #endif
5914902524cSMatthias Ringwald #endif
5924902524cSMatthias Ringwald     // get one more
5934902524cSMatthias Ringwald     context = btstack_memory_hfp_connection_get();
5944902524cSMatthias Ringwald     CHECK(context == NULL);
5954902524cSMatthias Ringwald }
5964902524cSMatthias Ringwald 
5974902524cSMatthias Ringwald 
5984902524cSMatthias Ringwald 
599*2281ada7SMatthias Ringwald 
TEST(btstack_memory,hid_host_connection_GetAndFree)6004902524cSMatthias Ringwald TEST(btstack_memory, hid_host_connection_GetAndFree){
6014902524cSMatthias Ringwald     hid_host_connection_t * context;
6024902524cSMatthias Ringwald #ifdef HAVE_MALLOC
6034902524cSMatthias Ringwald     context = btstack_memory_hid_host_connection_get();
6044902524cSMatthias Ringwald     CHECK(context != NULL);
6054902524cSMatthias Ringwald     btstack_memory_hid_host_connection_free(context);
6064902524cSMatthias Ringwald #else
6074902524cSMatthias Ringwald #ifdef MAX_NR_HID_HOST_CONNECTIONS
6084902524cSMatthias Ringwald     // single
6094902524cSMatthias Ringwald     context = btstack_memory_hid_host_connection_get();
6104902524cSMatthias Ringwald     CHECK(context != NULL);
6114902524cSMatthias Ringwald     btstack_memory_hid_host_connection_free(context);
6124902524cSMatthias Ringwald #else
6134902524cSMatthias Ringwald     // none
6144902524cSMatthias Ringwald     context = btstack_memory_hid_host_connection_get();
6154902524cSMatthias Ringwald     CHECK(context == NULL);
6164902524cSMatthias Ringwald     btstack_memory_hid_host_connection_free(context);
6174902524cSMatthias Ringwald #endif
6184902524cSMatthias Ringwald #endif
6194902524cSMatthias Ringwald }
6204902524cSMatthias Ringwald 
TEST(btstack_memory,hid_host_connection_NotEnoughBuffers)6214902524cSMatthias Ringwald TEST(btstack_memory, hid_host_connection_NotEnoughBuffers){
6224902524cSMatthias Ringwald     hid_host_connection_t * context;
6234902524cSMatthias Ringwald #ifdef HAVE_MALLOC
6244902524cSMatthias Ringwald     simulate_no_memory = 1;
6254902524cSMatthias Ringwald #else
6264902524cSMatthias Ringwald #ifdef MAX_NR_HID_HOST_CONNECTIONS
6274902524cSMatthias Ringwald     int i;
6284902524cSMatthias Ringwald     // alloc all static buffers
6294902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_HID_HOST_CONNECTIONS; i++){
6304902524cSMatthias Ringwald         context = btstack_memory_hid_host_connection_get();
6314902524cSMatthias Ringwald         CHECK(context != NULL);
6324902524cSMatthias Ringwald     }
6334902524cSMatthias Ringwald #endif
6344902524cSMatthias Ringwald #endif
6354902524cSMatthias Ringwald     // get one more
6364902524cSMatthias Ringwald     context = btstack_memory_hid_host_connection_get();
6374902524cSMatthias Ringwald     CHECK(context == NULL);
6384902524cSMatthias Ringwald }
6394902524cSMatthias Ringwald 
6404902524cSMatthias Ringwald 
6414902524cSMatthias Ringwald 
642*2281ada7SMatthias Ringwald 
TEST(btstack_memory,service_record_item_GetAndFree)6434902524cSMatthias Ringwald TEST(btstack_memory, service_record_item_GetAndFree){
6444902524cSMatthias Ringwald     service_record_item_t * context;
6454902524cSMatthias Ringwald #ifdef HAVE_MALLOC
6464902524cSMatthias Ringwald     context = btstack_memory_service_record_item_get();
6474902524cSMatthias Ringwald     CHECK(context != NULL);
6484902524cSMatthias Ringwald     btstack_memory_service_record_item_free(context);
6494902524cSMatthias Ringwald #else
6504902524cSMatthias Ringwald #ifdef MAX_NR_SERVICE_RECORD_ITEMS
6514902524cSMatthias Ringwald     // single
6524902524cSMatthias Ringwald     context = btstack_memory_service_record_item_get();
6534902524cSMatthias Ringwald     CHECK(context != NULL);
6544902524cSMatthias Ringwald     btstack_memory_service_record_item_free(context);
6554902524cSMatthias Ringwald #else
6564902524cSMatthias Ringwald     // none
6574902524cSMatthias Ringwald     context = btstack_memory_service_record_item_get();
6584902524cSMatthias Ringwald     CHECK(context == NULL);
6594902524cSMatthias Ringwald     btstack_memory_service_record_item_free(context);
6604902524cSMatthias Ringwald #endif
6614902524cSMatthias Ringwald #endif
6624902524cSMatthias Ringwald }
6634902524cSMatthias Ringwald 
TEST(btstack_memory,service_record_item_NotEnoughBuffers)6644902524cSMatthias Ringwald TEST(btstack_memory, service_record_item_NotEnoughBuffers){
6654902524cSMatthias Ringwald     service_record_item_t * context;
6664902524cSMatthias Ringwald #ifdef HAVE_MALLOC
6674902524cSMatthias Ringwald     simulate_no_memory = 1;
6684902524cSMatthias Ringwald #else
6694902524cSMatthias Ringwald #ifdef MAX_NR_SERVICE_RECORD_ITEMS
6704902524cSMatthias Ringwald     int i;
6714902524cSMatthias Ringwald     // alloc all static buffers
6724902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_SERVICE_RECORD_ITEMS; i++){
6734902524cSMatthias Ringwald         context = btstack_memory_service_record_item_get();
6744902524cSMatthias Ringwald         CHECK(context != NULL);
6754902524cSMatthias Ringwald     }
6764902524cSMatthias Ringwald #endif
6774902524cSMatthias Ringwald #endif
6784902524cSMatthias Ringwald     // get one more
6794902524cSMatthias Ringwald     context = btstack_memory_service_record_item_get();
6804902524cSMatthias Ringwald     CHECK(context == NULL);
6814902524cSMatthias Ringwald }
6824902524cSMatthias Ringwald 
6834902524cSMatthias Ringwald 
6844902524cSMatthias Ringwald 
685*2281ada7SMatthias Ringwald 
TEST(btstack_memory,avdtp_stream_endpoint_GetAndFree)6864902524cSMatthias Ringwald TEST(btstack_memory, avdtp_stream_endpoint_GetAndFree){
6874902524cSMatthias Ringwald     avdtp_stream_endpoint_t * context;
6884902524cSMatthias Ringwald #ifdef HAVE_MALLOC
6894902524cSMatthias Ringwald     context = btstack_memory_avdtp_stream_endpoint_get();
6904902524cSMatthias Ringwald     CHECK(context != NULL);
6914902524cSMatthias Ringwald     btstack_memory_avdtp_stream_endpoint_free(context);
6924902524cSMatthias Ringwald #else
6934902524cSMatthias Ringwald #ifdef MAX_NR_AVDTP_STREAM_ENDPOINTS
6944902524cSMatthias Ringwald     // single
6954902524cSMatthias Ringwald     context = btstack_memory_avdtp_stream_endpoint_get();
6964902524cSMatthias Ringwald     CHECK(context != NULL);
6974902524cSMatthias Ringwald     btstack_memory_avdtp_stream_endpoint_free(context);
6984902524cSMatthias Ringwald #else
6994902524cSMatthias Ringwald     // none
7004902524cSMatthias Ringwald     context = btstack_memory_avdtp_stream_endpoint_get();
7014902524cSMatthias Ringwald     CHECK(context == NULL);
7024902524cSMatthias Ringwald     btstack_memory_avdtp_stream_endpoint_free(context);
7034902524cSMatthias Ringwald #endif
7044902524cSMatthias Ringwald #endif
7054902524cSMatthias Ringwald }
7064902524cSMatthias Ringwald 
TEST(btstack_memory,avdtp_stream_endpoint_NotEnoughBuffers)7074902524cSMatthias Ringwald TEST(btstack_memory, avdtp_stream_endpoint_NotEnoughBuffers){
7084902524cSMatthias Ringwald     avdtp_stream_endpoint_t * context;
7094902524cSMatthias Ringwald #ifdef HAVE_MALLOC
7104902524cSMatthias Ringwald     simulate_no_memory = 1;
7114902524cSMatthias Ringwald #else
7124902524cSMatthias Ringwald #ifdef MAX_NR_AVDTP_STREAM_ENDPOINTS
7134902524cSMatthias Ringwald     int i;
7144902524cSMatthias Ringwald     // alloc all static buffers
7154902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_AVDTP_STREAM_ENDPOINTS; i++){
7164902524cSMatthias Ringwald         context = btstack_memory_avdtp_stream_endpoint_get();
7174902524cSMatthias Ringwald         CHECK(context != NULL);
7184902524cSMatthias Ringwald     }
7194902524cSMatthias Ringwald #endif
7204902524cSMatthias Ringwald #endif
7214902524cSMatthias Ringwald     // get one more
7224902524cSMatthias Ringwald     context = btstack_memory_avdtp_stream_endpoint_get();
7234902524cSMatthias Ringwald     CHECK(context == NULL);
7244902524cSMatthias Ringwald }
7254902524cSMatthias Ringwald 
7264902524cSMatthias Ringwald 
7274902524cSMatthias Ringwald 
728*2281ada7SMatthias Ringwald 
TEST(btstack_memory,avdtp_connection_GetAndFree)7294902524cSMatthias Ringwald TEST(btstack_memory, avdtp_connection_GetAndFree){
7304902524cSMatthias Ringwald     avdtp_connection_t * context;
7314902524cSMatthias Ringwald #ifdef HAVE_MALLOC
7324902524cSMatthias Ringwald     context = btstack_memory_avdtp_connection_get();
7334902524cSMatthias Ringwald     CHECK(context != NULL);
7344902524cSMatthias Ringwald     btstack_memory_avdtp_connection_free(context);
7354902524cSMatthias Ringwald #else
7364902524cSMatthias Ringwald #ifdef MAX_NR_AVDTP_CONNECTIONS
7374902524cSMatthias Ringwald     // single
7384902524cSMatthias Ringwald     context = btstack_memory_avdtp_connection_get();
7394902524cSMatthias Ringwald     CHECK(context != NULL);
7404902524cSMatthias Ringwald     btstack_memory_avdtp_connection_free(context);
7414902524cSMatthias Ringwald #else
7424902524cSMatthias Ringwald     // none
7434902524cSMatthias Ringwald     context = btstack_memory_avdtp_connection_get();
7444902524cSMatthias Ringwald     CHECK(context == NULL);
7454902524cSMatthias Ringwald     btstack_memory_avdtp_connection_free(context);
7464902524cSMatthias Ringwald #endif
7474902524cSMatthias Ringwald #endif
7484902524cSMatthias Ringwald }
7494902524cSMatthias Ringwald 
TEST(btstack_memory,avdtp_connection_NotEnoughBuffers)7504902524cSMatthias Ringwald TEST(btstack_memory, avdtp_connection_NotEnoughBuffers){
7514902524cSMatthias Ringwald     avdtp_connection_t * context;
7524902524cSMatthias Ringwald #ifdef HAVE_MALLOC
7534902524cSMatthias Ringwald     simulate_no_memory = 1;
7544902524cSMatthias Ringwald #else
7554902524cSMatthias Ringwald #ifdef MAX_NR_AVDTP_CONNECTIONS
7564902524cSMatthias Ringwald     int i;
7574902524cSMatthias Ringwald     // alloc all static buffers
7584902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_AVDTP_CONNECTIONS; i++){
7594902524cSMatthias Ringwald         context = btstack_memory_avdtp_connection_get();
7604902524cSMatthias Ringwald         CHECK(context != NULL);
7614902524cSMatthias Ringwald     }
7624902524cSMatthias Ringwald #endif
7634902524cSMatthias Ringwald #endif
7644902524cSMatthias Ringwald     // get one more
7654902524cSMatthias Ringwald     context = btstack_memory_avdtp_connection_get();
7664902524cSMatthias Ringwald     CHECK(context == NULL);
7674902524cSMatthias Ringwald }
7684902524cSMatthias Ringwald 
7694902524cSMatthias Ringwald 
7704902524cSMatthias Ringwald 
771*2281ada7SMatthias Ringwald 
TEST(btstack_memory,avrcp_connection_GetAndFree)7724902524cSMatthias Ringwald TEST(btstack_memory, avrcp_connection_GetAndFree){
7734902524cSMatthias Ringwald     avrcp_connection_t * context;
7744902524cSMatthias Ringwald #ifdef HAVE_MALLOC
7754902524cSMatthias Ringwald     context = btstack_memory_avrcp_connection_get();
7764902524cSMatthias Ringwald     CHECK(context != NULL);
7774902524cSMatthias Ringwald     btstack_memory_avrcp_connection_free(context);
7784902524cSMatthias Ringwald #else
7794902524cSMatthias Ringwald #ifdef MAX_NR_AVRCP_CONNECTIONS
7804902524cSMatthias Ringwald     // single
7814902524cSMatthias Ringwald     context = btstack_memory_avrcp_connection_get();
7824902524cSMatthias Ringwald     CHECK(context != NULL);
7834902524cSMatthias Ringwald     btstack_memory_avrcp_connection_free(context);
7844902524cSMatthias Ringwald #else
7854902524cSMatthias Ringwald     // none
7864902524cSMatthias Ringwald     context = btstack_memory_avrcp_connection_get();
7874902524cSMatthias Ringwald     CHECK(context == NULL);
7884902524cSMatthias Ringwald     btstack_memory_avrcp_connection_free(context);
7894902524cSMatthias Ringwald #endif
7904902524cSMatthias Ringwald #endif
7914902524cSMatthias Ringwald }
7924902524cSMatthias Ringwald 
TEST(btstack_memory,avrcp_connection_NotEnoughBuffers)7934902524cSMatthias Ringwald TEST(btstack_memory, avrcp_connection_NotEnoughBuffers){
7944902524cSMatthias Ringwald     avrcp_connection_t * context;
7954902524cSMatthias Ringwald #ifdef HAVE_MALLOC
7964902524cSMatthias Ringwald     simulate_no_memory = 1;
7974902524cSMatthias Ringwald #else
7984902524cSMatthias Ringwald #ifdef MAX_NR_AVRCP_CONNECTIONS
7994902524cSMatthias Ringwald     int i;
8004902524cSMatthias Ringwald     // alloc all static buffers
8014902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_AVRCP_CONNECTIONS; i++){
8024902524cSMatthias Ringwald         context = btstack_memory_avrcp_connection_get();
8034902524cSMatthias Ringwald         CHECK(context != NULL);
8044902524cSMatthias Ringwald     }
8054902524cSMatthias Ringwald #endif
8064902524cSMatthias Ringwald #endif
8074902524cSMatthias Ringwald     // get one more
8084902524cSMatthias Ringwald     context = btstack_memory_avrcp_connection_get();
8094902524cSMatthias Ringwald     CHECK(context == NULL);
8104902524cSMatthias Ringwald }
8114902524cSMatthias Ringwald 
8124902524cSMatthias Ringwald 
8134902524cSMatthias Ringwald 
814*2281ada7SMatthias Ringwald 
TEST(btstack_memory,avrcp_browsing_connection_GetAndFree)8154902524cSMatthias Ringwald TEST(btstack_memory, avrcp_browsing_connection_GetAndFree){
8164902524cSMatthias Ringwald     avrcp_browsing_connection_t * context;
8174902524cSMatthias Ringwald #ifdef HAVE_MALLOC
8184902524cSMatthias Ringwald     context = btstack_memory_avrcp_browsing_connection_get();
8194902524cSMatthias Ringwald     CHECK(context != NULL);
8204902524cSMatthias Ringwald     btstack_memory_avrcp_browsing_connection_free(context);
8214902524cSMatthias Ringwald #else
8224902524cSMatthias Ringwald #ifdef MAX_NR_AVRCP_BROWSING_CONNECTIONS
8234902524cSMatthias Ringwald     // single
8244902524cSMatthias Ringwald     context = btstack_memory_avrcp_browsing_connection_get();
8254902524cSMatthias Ringwald     CHECK(context != NULL);
8264902524cSMatthias Ringwald     btstack_memory_avrcp_browsing_connection_free(context);
8274902524cSMatthias Ringwald #else
8284902524cSMatthias Ringwald     // none
8294902524cSMatthias Ringwald     context = btstack_memory_avrcp_browsing_connection_get();
8304902524cSMatthias Ringwald     CHECK(context == NULL);
8314902524cSMatthias Ringwald     btstack_memory_avrcp_browsing_connection_free(context);
8324902524cSMatthias Ringwald #endif
8334902524cSMatthias Ringwald #endif
8344902524cSMatthias Ringwald }
8354902524cSMatthias Ringwald 
TEST(btstack_memory,avrcp_browsing_connection_NotEnoughBuffers)8364902524cSMatthias Ringwald TEST(btstack_memory, avrcp_browsing_connection_NotEnoughBuffers){
8374902524cSMatthias Ringwald     avrcp_browsing_connection_t * context;
8384902524cSMatthias Ringwald #ifdef HAVE_MALLOC
8394902524cSMatthias Ringwald     simulate_no_memory = 1;
8404902524cSMatthias Ringwald #else
8414902524cSMatthias Ringwald #ifdef MAX_NR_AVRCP_BROWSING_CONNECTIONS
8424902524cSMatthias Ringwald     int i;
8434902524cSMatthias Ringwald     // alloc all static buffers
8444902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_AVRCP_BROWSING_CONNECTIONS; i++){
8454902524cSMatthias Ringwald         context = btstack_memory_avrcp_browsing_connection_get();
8464902524cSMatthias Ringwald         CHECK(context != NULL);
8474902524cSMatthias Ringwald     }
8484902524cSMatthias Ringwald #endif
8494902524cSMatthias Ringwald #endif
8504902524cSMatthias Ringwald     // get one more
8514902524cSMatthias Ringwald     context = btstack_memory_avrcp_browsing_connection_get();
8524902524cSMatthias Ringwald     CHECK(context == NULL);
8534902524cSMatthias Ringwald }
8544902524cSMatthias Ringwald 
855*2281ada7SMatthias Ringwald 
8564902524cSMatthias Ringwald #endif
8574902524cSMatthias Ringwald #ifdef ENABLE_BLE
8584902524cSMatthias Ringwald 
8594902524cSMatthias Ringwald 
TEST(btstack_memory,battery_service_client_GetAndFree)8604902524cSMatthias Ringwald TEST(btstack_memory, battery_service_client_GetAndFree){
8614902524cSMatthias Ringwald     battery_service_client_t * context;
8624902524cSMatthias Ringwald #ifdef HAVE_MALLOC
8634902524cSMatthias Ringwald     context = btstack_memory_battery_service_client_get();
8644902524cSMatthias Ringwald     CHECK(context != NULL);
8654902524cSMatthias Ringwald     btstack_memory_battery_service_client_free(context);
8664902524cSMatthias Ringwald #else
8674902524cSMatthias Ringwald #ifdef MAX_NR_BATTERY_SERVICE_CLIENTS
8684902524cSMatthias Ringwald     // single
8694902524cSMatthias Ringwald     context = btstack_memory_battery_service_client_get();
8704902524cSMatthias Ringwald     CHECK(context != NULL);
8714902524cSMatthias Ringwald     btstack_memory_battery_service_client_free(context);
8724902524cSMatthias Ringwald #else
8734902524cSMatthias Ringwald     // none
8744902524cSMatthias Ringwald     context = btstack_memory_battery_service_client_get();
8754902524cSMatthias Ringwald     CHECK(context == NULL);
8764902524cSMatthias Ringwald     btstack_memory_battery_service_client_free(context);
8774902524cSMatthias Ringwald #endif
8784902524cSMatthias Ringwald #endif
8794902524cSMatthias Ringwald }
8804902524cSMatthias Ringwald 
TEST(btstack_memory,battery_service_client_NotEnoughBuffers)8814902524cSMatthias Ringwald TEST(btstack_memory, battery_service_client_NotEnoughBuffers){
8824902524cSMatthias Ringwald     battery_service_client_t * context;
8834902524cSMatthias Ringwald #ifdef HAVE_MALLOC
8844902524cSMatthias Ringwald     simulate_no_memory = 1;
8854902524cSMatthias Ringwald #else
8864902524cSMatthias Ringwald #ifdef MAX_NR_BATTERY_SERVICE_CLIENTS
8874902524cSMatthias Ringwald     int i;
8884902524cSMatthias Ringwald     // alloc all static buffers
8894902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_BATTERY_SERVICE_CLIENTS; i++){
8904902524cSMatthias Ringwald         context = btstack_memory_battery_service_client_get();
8914902524cSMatthias Ringwald         CHECK(context != NULL);
8924902524cSMatthias Ringwald     }
8934902524cSMatthias Ringwald #endif
8944902524cSMatthias Ringwald #endif
8954902524cSMatthias Ringwald     // get one more
8964902524cSMatthias Ringwald     context = btstack_memory_battery_service_client_get();
8974902524cSMatthias Ringwald     CHECK(context == NULL);
8984902524cSMatthias Ringwald }
8994902524cSMatthias Ringwald 
9004902524cSMatthias Ringwald 
9014902524cSMatthias Ringwald 
TEST(btstack_memory,gatt_client_GetAndFree)9024902524cSMatthias Ringwald TEST(btstack_memory, gatt_client_GetAndFree){
9034902524cSMatthias Ringwald     gatt_client_t * context;
9044902524cSMatthias Ringwald #ifdef HAVE_MALLOC
9054902524cSMatthias Ringwald     context = btstack_memory_gatt_client_get();
9064902524cSMatthias Ringwald     CHECK(context != NULL);
9074902524cSMatthias Ringwald     btstack_memory_gatt_client_free(context);
9084902524cSMatthias Ringwald #else
9094902524cSMatthias Ringwald #ifdef MAX_NR_GATT_CLIENTS
9104902524cSMatthias Ringwald     // single
9114902524cSMatthias Ringwald     context = btstack_memory_gatt_client_get();
9124902524cSMatthias Ringwald     CHECK(context != NULL);
9134902524cSMatthias Ringwald     btstack_memory_gatt_client_free(context);
9144902524cSMatthias Ringwald #else
9154902524cSMatthias Ringwald     // none
9164902524cSMatthias Ringwald     context = btstack_memory_gatt_client_get();
9174902524cSMatthias Ringwald     CHECK(context == NULL);
9184902524cSMatthias Ringwald     btstack_memory_gatt_client_free(context);
9194902524cSMatthias Ringwald #endif
9204902524cSMatthias Ringwald #endif
9214902524cSMatthias Ringwald }
9224902524cSMatthias Ringwald 
TEST(btstack_memory,gatt_client_NotEnoughBuffers)9234902524cSMatthias Ringwald TEST(btstack_memory, gatt_client_NotEnoughBuffers){
9244902524cSMatthias Ringwald     gatt_client_t * context;
9254902524cSMatthias Ringwald #ifdef HAVE_MALLOC
9264902524cSMatthias Ringwald     simulate_no_memory = 1;
9274902524cSMatthias Ringwald #else
9284902524cSMatthias Ringwald #ifdef MAX_NR_GATT_CLIENTS
9294902524cSMatthias Ringwald     int i;
9304902524cSMatthias Ringwald     // alloc all static buffers
9314902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_GATT_CLIENTS; i++){
9324902524cSMatthias Ringwald         context = btstack_memory_gatt_client_get();
9334902524cSMatthias Ringwald         CHECK(context != NULL);
9344902524cSMatthias Ringwald     }
9354902524cSMatthias Ringwald #endif
9364902524cSMatthias Ringwald #endif
9374902524cSMatthias Ringwald     // get one more
9384902524cSMatthias Ringwald     context = btstack_memory_gatt_client_get();
9394902524cSMatthias Ringwald     CHECK(context == NULL);
9404902524cSMatthias Ringwald }
9414902524cSMatthias Ringwald 
9424902524cSMatthias Ringwald 
9434902524cSMatthias Ringwald 
TEST(btstack_memory,hids_client_GetAndFree)9444902524cSMatthias Ringwald TEST(btstack_memory, hids_client_GetAndFree){
9454902524cSMatthias Ringwald     hids_client_t * context;
9464902524cSMatthias Ringwald #ifdef HAVE_MALLOC
9474902524cSMatthias Ringwald     context = btstack_memory_hids_client_get();
9484902524cSMatthias Ringwald     CHECK(context != NULL);
9494902524cSMatthias Ringwald     btstack_memory_hids_client_free(context);
9504902524cSMatthias Ringwald #else
9514902524cSMatthias Ringwald #ifdef MAX_NR_HIDS_CLIENTS
9524902524cSMatthias Ringwald     // single
9534902524cSMatthias Ringwald     context = btstack_memory_hids_client_get();
9544902524cSMatthias Ringwald     CHECK(context != NULL);
9554902524cSMatthias Ringwald     btstack_memory_hids_client_free(context);
9564902524cSMatthias Ringwald #else
9574902524cSMatthias Ringwald     // none
9584902524cSMatthias Ringwald     context = btstack_memory_hids_client_get();
9594902524cSMatthias Ringwald     CHECK(context == NULL);
9604902524cSMatthias Ringwald     btstack_memory_hids_client_free(context);
9614902524cSMatthias Ringwald #endif
9624902524cSMatthias Ringwald #endif
9634902524cSMatthias Ringwald }
9644902524cSMatthias Ringwald 
TEST(btstack_memory,hids_client_NotEnoughBuffers)9654902524cSMatthias Ringwald TEST(btstack_memory, hids_client_NotEnoughBuffers){
9664902524cSMatthias Ringwald     hids_client_t * context;
9674902524cSMatthias Ringwald #ifdef HAVE_MALLOC
9684902524cSMatthias Ringwald     simulate_no_memory = 1;
9694902524cSMatthias Ringwald #else
9704902524cSMatthias Ringwald #ifdef MAX_NR_HIDS_CLIENTS
9714902524cSMatthias Ringwald     int i;
9724902524cSMatthias Ringwald     // alloc all static buffers
9734902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_HIDS_CLIENTS; i++){
9744902524cSMatthias Ringwald         context = btstack_memory_hids_client_get();
9754902524cSMatthias Ringwald         CHECK(context != NULL);
9764902524cSMatthias Ringwald     }
9774902524cSMatthias Ringwald #endif
9784902524cSMatthias Ringwald #endif
9794902524cSMatthias Ringwald     // get one more
9804902524cSMatthias Ringwald     context = btstack_memory_hids_client_get();
9814902524cSMatthias Ringwald     CHECK(context == NULL);
9824902524cSMatthias Ringwald }
9834902524cSMatthias Ringwald 
9844902524cSMatthias Ringwald 
9854902524cSMatthias Ringwald 
TEST(btstack_memory,scan_parameters_service_client_GetAndFree)9864902524cSMatthias Ringwald TEST(btstack_memory, scan_parameters_service_client_GetAndFree){
9874902524cSMatthias Ringwald     scan_parameters_service_client_t * context;
9884902524cSMatthias Ringwald #ifdef HAVE_MALLOC
9894902524cSMatthias Ringwald     context = btstack_memory_scan_parameters_service_client_get();
9904902524cSMatthias Ringwald     CHECK(context != NULL);
9914902524cSMatthias Ringwald     btstack_memory_scan_parameters_service_client_free(context);
9924902524cSMatthias Ringwald #else
9934902524cSMatthias Ringwald #ifdef MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS
9944902524cSMatthias Ringwald     // single
9954902524cSMatthias Ringwald     context = btstack_memory_scan_parameters_service_client_get();
9964902524cSMatthias Ringwald     CHECK(context != NULL);
9974902524cSMatthias Ringwald     btstack_memory_scan_parameters_service_client_free(context);
9984902524cSMatthias Ringwald #else
9994902524cSMatthias Ringwald     // none
10004902524cSMatthias Ringwald     context = btstack_memory_scan_parameters_service_client_get();
10014902524cSMatthias Ringwald     CHECK(context == NULL);
10024902524cSMatthias Ringwald     btstack_memory_scan_parameters_service_client_free(context);
10034902524cSMatthias Ringwald #endif
10044902524cSMatthias Ringwald #endif
10054902524cSMatthias Ringwald }
10064902524cSMatthias Ringwald 
TEST(btstack_memory,scan_parameters_service_client_NotEnoughBuffers)10074902524cSMatthias Ringwald TEST(btstack_memory, scan_parameters_service_client_NotEnoughBuffers){
10084902524cSMatthias Ringwald     scan_parameters_service_client_t * context;
10094902524cSMatthias Ringwald #ifdef HAVE_MALLOC
10104902524cSMatthias Ringwald     simulate_no_memory = 1;
10114902524cSMatthias Ringwald #else
10124902524cSMatthias Ringwald #ifdef MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS
10134902524cSMatthias Ringwald     int i;
10144902524cSMatthias Ringwald     // alloc all static buffers
10154902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS; i++){
10164902524cSMatthias Ringwald         context = btstack_memory_scan_parameters_service_client_get();
10174902524cSMatthias Ringwald         CHECK(context != NULL);
10184902524cSMatthias Ringwald     }
10194902524cSMatthias Ringwald #endif
10204902524cSMatthias Ringwald #endif
10214902524cSMatthias Ringwald     // get one more
10224902524cSMatthias Ringwald     context = btstack_memory_scan_parameters_service_client_get();
10234902524cSMatthias Ringwald     CHECK(context == NULL);
10244902524cSMatthias Ringwald }
10254902524cSMatthias Ringwald 
10264902524cSMatthias Ringwald 
10274902524cSMatthias Ringwald 
TEST(btstack_memory,sm_lookup_entry_GetAndFree)10284902524cSMatthias Ringwald TEST(btstack_memory, sm_lookup_entry_GetAndFree){
10294902524cSMatthias Ringwald     sm_lookup_entry_t * context;
10304902524cSMatthias Ringwald #ifdef HAVE_MALLOC
10314902524cSMatthias Ringwald     context = btstack_memory_sm_lookup_entry_get();
10324902524cSMatthias Ringwald     CHECK(context != NULL);
10334902524cSMatthias Ringwald     btstack_memory_sm_lookup_entry_free(context);
10344902524cSMatthias Ringwald #else
10354902524cSMatthias Ringwald #ifdef MAX_NR_SM_LOOKUP_ENTRIES
10364902524cSMatthias Ringwald     // single
10374902524cSMatthias Ringwald     context = btstack_memory_sm_lookup_entry_get();
10384902524cSMatthias Ringwald     CHECK(context != NULL);
10394902524cSMatthias Ringwald     btstack_memory_sm_lookup_entry_free(context);
10404902524cSMatthias Ringwald #else
10414902524cSMatthias Ringwald     // none
10424902524cSMatthias Ringwald     context = btstack_memory_sm_lookup_entry_get();
10434902524cSMatthias Ringwald     CHECK(context == NULL);
10444902524cSMatthias Ringwald     btstack_memory_sm_lookup_entry_free(context);
10454902524cSMatthias Ringwald #endif
10464902524cSMatthias Ringwald #endif
10474902524cSMatthias Ringwald }
10484902524cSMatthias Ringwald 
TEST(btstack_memory,sm_lookup_entry_NotEnoughBuffers)10494902524cSMatthias Ringwald TEST(btstack_memory, sm_lookup_entry_NotEnoughBuffers){
10504902524cSMatthias Ringwald     sm_lookup_entry_t * context;
10514902524cSMatthias Ringwald #ifdef HAVE_MALLOC
10524902524cSMatthias Ringwald     simulate_no_memory = 1;
10534902524cSMatthias Ringwald #else
10544902524cSMatthias Ringwald #ifdef MAX_NR_SM_LOOKUP_ENTRIES
10554902524cSMatthias Ringwald     int i;
10564902524cSMatthias Ringwald     // alloc all static buffers
10574902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_SM_LOOKUP_ENTRIES; i++){
10584902524cSMatthias Ringwald         context = btstack_memory_sm_lookup_entry_get();
10594902524cSMatthias Ringwald         CHECK(context != NULL);
10604902524cSMatthias Ringwald     }
10614902524cSMatthias Ringwald #endif
10624902524cSMatthias Ringwald #endif
10634902524cSMatthias Ringwald     // get one more
10644902524cSMatthias Ringwald     context = btstack_memory_sm_lookup_entry_get();
10654902524cSMatthias Ringwald     CHECK(context == NULL);
10664902524cSMatthias Ringwald }
10674902524cSMatthias Ringwald 
10684902524cSMatthias Ringwald 
10694902524cSMatthias Ringwald 
TEST(btstack_memory,whitelist_entry_GetAndFree)10704902524cSMatthias Ringwald TEST(btstack_memory, whitelist_entry_GetAndFree){
10714902524cSMatthias Ringwald     whitelist_entry_t * context;
10724902524cSMatthias Ringwald #ifdef HAVE_MALLOC
10734902524cSMatthias Ringwald     context = btstack_memory_whitelist_entry_get();
10744902524cSMatthias Ringwald     CHECK(context != NULL);
10754902524cSMatthias Ringwald     btstack_memory_whitelist_entry_free(context);
10764902524cSMatthias Ringwald #else
10774902524cSMatthias Ringwald #ifdef MAX_NR_WHITELIST_ENTRIES
10784902524cSMatthias Ringwald     // single
10794902524cSMatthias Ringwald     context = btstack_memory_whitelist_entry_get();
10804902524cSMatthias Ringwald     CHECK(context != NULL);
10814902524cSMatthias Ringwald     btstack_memory_whitelist_entry_free(context);
10824902524cSMatthias Ringwald #else
10834902524cSMatthias Ringwald     // none
10844902524cSMatthias Ringwald     context = btstack_memory_whitelist_entry_get();
10854902524cSMatthias Ringwald     CHECK(context == NULL);
10864902524cSMatthias Ringwald     btstack_memory_whitelist_entry_free(context);
10874902524cSMatthias Ringwald #endif
10884902524cSMatthias Ringwald #endif
10894902524cSMatthias Ringwald }
10904902524cSMatthias Ringwald 
TEST(btstack_memory,whitelist_entry_NotEnoughBuffers)10914902524cSMatthias Ringwald TEST(btstack_memory, whitelist_entry_NotEnoughBuffers){
10924902524cSMatthias Ringwald     whitelist_entry_t * context;
10934902524cSMatthias Ringwald #ifdef HAVE_MALLOC
10944902524cSMatthias Ringwald     simulate_no_memory = 1;
10954902524cSMatthias Ringwald #else
10964902524cSMatthias Ringwald #ifdef MAX_NR_WHITELIST_ENTRIES
10974902524cSMatthias Ringwald     int i;
10984902524cSMatthias Ringwald     // alloc all static buffers
10994902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_WHITELIST_ENTRIES; i++){
11004902524cSMatthias Ringwald         context = btstack_memory_whitelist_entry_get();
11014902524cSMatthias Ringwald         CHECK(context != NULL);
11024902524cSMatthias Ringwald     }
11034902524cSMatthias Ringwald #endif
11044902524cSMatthias Ringwald #endif
11054902524cSMatthias Ringwald     // get one more
11064902524cSMatthias Ringwald     context = btstack_memory_whitelist_entry_get();
11074902524cSMatthias Ringwald     CHECK(context == NULL);
11084902524cSMatthias Ringwald }
11094902524cSMatthias Ringwald 
1110dbca66ffSMatthias Ringwald 
1111dbca66ffSMatthias Ringwald 
TEST(btstack_memory,periodic_advertiser_list_entry_GetAndFree)1112dbca66ffSMatthias Ringwald TEST(btstack_memory, periodic_advertiser_list_entry_GetAndFree){
1113dbca66ffSMatthias Ringwald     periodic_advertiser_list_entry_t * context;
1114dbca66ffSMatthias Ringwald #ifdef HAVE_MALLOC
1115dbca66ffSMatthias Ringwald     context = btstack_memory_periodic_advertiser_list_entry_get();
1116dbca66ffSMatthias Ringwald     CHECK(context != NULL);
1117dbca66ffSMatthias Ringwald     btstack_memory_periodic_advertiser_list_entry_free(context);
1118dbca66ffSMatthias Ringwald #else
1119dbca66ffSMatthias Ringwald #ifdef MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES
1120dbca66ffSMatthias Ringwald     // single
1121dbca66ffSMatthias Ringwald     context = btstack_memory_periodic_advertiser_list_entry_get();
1122dbca66ffSMatthias Ringwald     CHECK(context != NULL);
1123dbca66ffSMatthias Ringwald     btstack_memory_periodic_advertiser_list_entry_free(context);
1124dbca66ffSMatthias Ringwald #else
1125dbca66ffSMatthias Ringwald     // none
1126dbca66ffSMatthias Ringwald     context = btstack_memory_periodic_advertiser_list_entry_get();
1127dbca66ffSMatthias Ringwald     CHECK(context == NULL);
1128dbca66ffSMatthias Ringwald     btstack_memory_periodic_advertiser_list_entry_free(context);
1129dbca66ffSMatthias Ringwald #endif
1130dbca66ffSMatthias Ringwald #endif
1131dbca66ffSMatthias Ringwald }
1132dbca66ffSMatthias Ringwald 
TEST(btstack_memory,periodic_advertiser_list_entry_NotEnoughBuffers)1133dbca66ffSMatthias Ringwald TEST(btstack_memory, periodic_advertiser_list_entry_NotEnoughBuffers){
1134dbca66ffSMatthias Ringwald     periodic_advertiser_list_entry_t * context;
1135dbca66ffSMatthias Ringwald #ifdef HAVE_MALLOC
1136dbca66ffSMatthias Ringwald     simulate_no_memory = 1;
1137dbca66ffSMatthias Ringwald #else
1138dbca66ffSMatthias Ringwald #ifdef MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES
1139dbca66ffSMatthias Ringwald     int i;
1140dbca66ffSMatthias Ringwald     // alloc all static buffers
1141dbca66ffSMatthias Ringwald     for (i = 0; i < MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES; i++){
1142dbca66ffSMatthias Ringwald         context = btstack_memory_periodic_advertiser_list_entry_get();
1143dbca66ffSMatthias Ringwald         CHECK(context != NULL);
1144dbca66ffSMatthias Ringwald     }
1145dbca66ffSMatthias Ringwald #endif
1146dbca66ffSMatthias Ringwald #endif
1147dbca66ffSMatthias Ringwald     // get one more
1148dbca66ffSMatthias Ringwald     context = btstack_memory_periodic_advertiser_list_entry_get();
1149dbca66ffSMatthias Ringwald     CHECK(context == NULL);
1150dbca66ffSMatthias Ringwald }
1151dbca66ffSMatthias Ringwald 
1152*2281ada7SMatthias Ringwald 
11534902524cSMatthias Ringwald #endif
11544902524cSMatthias Ringwald #ifdef ENABLE_MESH
11554902524cSMatthias Ringwald 
11564902524cSMatthias Ringwald 
TEST(btstack_memory,mesh_network_pdu_GetAndFree)11574902524cSMatthias Ringwald TEST(btstack_memory, mesh_network_pdu_GetAndFree){
11584902524cSMatthias Ringwald     mesh_network_pdu_t * context;
11594902524cSMatthias Ringwald #ifdef HAVE_MALLOC
11604902524cSMatthias Ringwald     context = btstack_memory_mesh_network_pdu_get();
11614902524cSMatthias Ringwald     CHECK(context != NULL);
11624902524cSMatthias Ringwald     btstack_memory_mesh_network_pdu_free(context);
11634902524cSMatthias Ringwald #else
11644902524cSMatthias Ringwald #ifdef MAX_NR_MESH_NETWORK_PDUS
11654902524cSMatthias Ringwald     // single
11664902524cSMatthias Ringwald     context = btstack_memory_mesh_network_pdu_get();
11674902524cSMatthias Ringwald     CHECK(context != NULL);
11684902524cSMatthias Ringwald     btstack_memory_mesh_network_pdu_free(context);
11694902524cSMatthias Ringwald #else
11704902524cSMatthias Ringwald     // none
11714902524cSMatthias Ringwald     context = btstack_memory_mesh_network_pdu_get();
11724902524cSMatthias Ringwald     CHECK(context == NULL);
11734902524cSMatthias Ringwald     btstack_memory_mesh_network_pdu_free(context);
11744902524cSMatthias Ringwald #endif
11754902524cSMatthias Ringwald #endif
11764902524cSMatthias Ringwald }
11774902524cSMatthias Ringwald 
TEST(btstack_memory,mesh_network_pdu_NotEnoughBuffers)11784902524cSMatthias Ringwald TEST(btstack_memory, mesh_network_pdu_NotEnoughBuffers){
11794902524cSMatthias Ringwald     mesh_network_pdu_t * context;
11804902524cSMatthias Ringwald #ifdef HAVE_MALLOC
11814902524cSMatthias Ringwald     simulate_no_memory = 1;
11824902524cSMatthias Ringwald #else
11834902524cSMatthias Ringwald #ifdef MAX_NR_MESH_NETWORK_PDUS
11844902524cSMatthias Ringwald     int i;
11854902524cSMatthias Ringwald     // alloc all static buffers
11864902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_MESH_NETWORK_PDUS; i++){
11874902524cSMatthias Ringwald         context = btstack_memory_mesh_network_pdu_get();
11884902524cSMatthias Ringwald         CHECK(context != NULL);
11894902524cSMatthias Ringwald     }
11904902524cSMatthias Ringwald #endif
11914902524cSMatthias Ringwald #endif
11924902524cSMatthias Ringwald     // get one more
11934902524cSMatthias Ringwald     context = btstack_memory_mesh_network_pdu_get();
11944902524cSMatthias Ringwald     CHECK(context == NULL);
11954902524cSMatthias Ringwald }
11964902524cSMatthias Ringwald 
11974902524cSMatthias Ringwald 
11984902524cSMatthias Ringwald 
TEST(btstack_memory,mesh_segmented_pdu_GetAndFree)11994902524cSMatthias Ringwald TEST(btstack_memory, mesh_segmented_pdu_GetAndFree){
12004902524cSMatthias Ringwald     mesh_segmented_pdu_t * context;
12014902524cSMatthias Ringwald #ifdef HAVE_MALLOC
12024902524cSMatthias Ringwald     context = btstack_memory_mesh_segmented_pdu_get();
12034902524cSMatthias Ringwald     CHECK(context != NULL);
12044902524cSMatthias Ringwald     btstack_memory_mesh_segmented_pdu_free(context);
12054902524cSMatthias Ringwald #else
12064902524cSMatthias Ringwald #ifdef MAX_NR_MESH_SEGMENTED_PDUS
12074902524cSMatthias Ringwald     // single
12084902524cSMatthias Ringwald     context = btstack_memory_mesh_segmented_pdu_get();
12094902524cSMatthias Ringwald     CHECK(context != NULL);
12104902524cSMatthias Ringwald     btstack_memory_mesh_segmented_pdu_free(context);
12114902524cSMatthias Ringwald #else
12124902524cSMatthias Ringwald     // none
12134902524cSMatthias Ringwald     context = btstack_memory_mesh_segmented_pdu_get();
12144902524cSMatthias Ringwald     CHECK(context == NULL);
12154902524cSMatthias Ringwald     btstack_memory_mesh_segmented_pdu_free(context);
12164902524cSMatthias Ringwald #endif
12174902524cSMatthias Ringwald #endif
12184902524cSMatthias Ringwald }
12194902524cSMatthias Ringwald 
TEST(btstack_memory,mesh_segmented_pdu_NotEnoughBuffers)12204902524cSMatthias Ringwald TEST(btstack_memory, mesh_segmented_pdu_NotEnoughBuffers){
12214902524cSMatthias Ringwald     mesh_segmented_pdu_t * context;
12224902524cSMatthias Ringwald #ifdef HAVE_MALLOC
12234902524cSMatthias Ringwald     simulate_no_memory = 1;
12244902524cSMatthias Ringwald #else
12254902524cSMatthias Ringwald #ifdef MAX_NR_MESH_SEGMENTED_PDUS
12264902524cSMatthias Ringwald     int i;
12274902524cSMatthias Ringwald     // alloc all static buffers
12284902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_MESH_SEGMENTED_PDUS; i++){
12294902524cSMatthias Ringwald         context = btstack_memory_mesh_segmented_pdu_get();
12304902524cSMatthias Ringwald         CHECK(context != NULL);
12314902524cSMatthias Ringwald     }
12324902524cSMatthias Ringwald #endif
12334902524cSMatthias Ringwald #endif
12344902524cSMatthias Ringwald     // get one more
12354902524cSMatthias Ringwald     context = btstack_memory_mesh_segmented_pdu_get();
12364902524cSMatthias Ringwald     CHECK(context == NULL);
12374902524cSMatthias Ringwald }
12384902524cSMatthias Ringwald 
12394902524cSMatthias Ringwald 
12404902524cSMatthias Ringwald 
TEST(btstack_memory,mesh_upper_transport_pdu_GetAndFree)12414902524cSMatthias Ringwald TEST(btstack_memory, mesh_upper_transport_pdu_GetAndFree){
12424902524cSMatthias Ringwald     mesh_upper_transport_pdu_t * context;
12434902524cSMatthias Ringwald #ifdef HAVE_MALLOC
12444902524cSMatthias Ringwald     context = btstack_memory_mesh_upper_transport_pdu_get();
12454902524cSMatthias Ringwald     CHECK(context != NULL);
12464902524cSMatthias Ringwald     btstack_memory_mesh_upper_transport_pdu_free(context);
12474902524cSMatthias Ringwald #else
12484902524cSMatthias Ringwald #ifdef MAX_NR_MESH_UPPER_TRANSPORT_PDUS
12494902524cSMatthias Ringwald     // single
12504902524cSMatthias Ringwald     context = btstack_memory_mesh_upper_transport_pdu_get();
12514902524cSMatthias Ringwald     CHECK(context != NULL);
12524902524cSMatthias Ringwald     btstack_memory_mesh_upper_transport_pdu_free(context);
12534902524cSMatthias Ringwald #else
12544902524cSMatthias Ringwald     // none
12554902524cSMatthias Ringwald     context = btstack_memory_mesh_upper_transport_pdu_get();
12564902524cSMatthias Ringwald     CHECK(context == NULL);
12574902524cSMatthias Ringwald     btstack_memory_mesh_upper_transport_pdu_free(context);
12584902524cSMatthias Ringwald #endif
12594902524cSMatthias Ringwald #endif
12604902524cSMatthias Ringwald }
12614902524cSMatthias Ringwald 
TEST(btstack_memory,mesh_upper_transport_pdu_NotEnoughBuffers)12624902524cSMatthias Ringwald TEST(btstack_memory, mesh_upper_transport_pdu_NotEnoughBuffers){
12634902524cSMatthias Ringwald     mesh_upper_transport_pdu_t * context;
12644902524cSMatthias Ringwald #ifdef HAVE_MALLOC
12654902524cSMatthias Ringwald     simulate_no_memory = 1;
12664902524cSMatthias Ringwald #else
12674902524cSMatthias Ringwald #ifdef MAX_NR_MESH_UPPER_TRANSPORT_PDUS
12684902524cSMatthias Ringwald     int i;
12694902524cSMatthias Ringwald     // alloc all static buffers
12704902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_MESH_UPPER_TRANSPORT_PDUS; i++){
12714902524cSMatthias Ringwald         context = btstack_memory_mesh_upper_transport_pdu_get();
12724902524cSMatthias Ringwald         CHECK(context != NULL);
12734902524cSMatthias Ringwald     }
12744902524cSMatthias Ringwald #endif
12754902524cSMatthias Ringwald #endif
12764902524cSMatthias Ringwald     // get one more
12774902524cSMatthias Ringwald     context = btstack_memory_mesh_upper_transport_pdu_get();
12784902524cSMatthias Ringwald     CHECK(context == NULL);
12794902524cSMatthias Ringwald }
12804902524cSMatthias Ringwald 
12814902524cSMatthias Ringwald 
12824902524cSMatthias Ringwald 
TEST(btstack_memory,mesh_network_key_GetAndFree)12834902524cSMatthias Ringwald TEST(btstack_memory, mesh_network_key_GetAndFree){
12844902524cSMatthias Ringwald     mesh_network_key_t * context;
12854902524cSMatthias Ringwald #ifdef HAVE_MALLOC
12864902524cSMatthias Ringwald     context = btstack_memory_mesh_network_key_get();
12874902524cSMatthias Ringwald     CHECK(context != NULL);
12884902524cSMatthias Ringwald     btstack_memory_mesh_network_key_free(context);
12894902524cSMatthias Ringwald #else
12904902524cSMatthias Ringwald #ifdef MAX_NR_MESH_NETWORK_KEYS
12914902524cSMatthias Ringwald     // single
12924902524cSMatthias Ringwald     context = btstack_memory_mesh_network_key_get();
12934902524cSMatthias Ringwald     CHECK(context != NULL);
12944902524cSMatthias Ringwald     btstack_memory_mesh_network_key_free(context);
12954902524cSMatthias Ringwald #else
12964902524cSMatthias Ringwald     // none
12974902524cSMatthias Ringwald     context = btstack_memory_mesh_network_key_get();
12984902524cSMatthias Ringwald     CHECK(context == NULL);
12994902524cSMatthias Ringwald     btstack_memory_mesh_network_key_free(context);
13004902524cSMatthias Ringwald #endif
13014902524cSMatthias Ringwald #endif
13024902524cSMatthias Ringwald }
13034902524cSMatthias Ringwald 
TEST(btstack_memory,mesh_network_key_NotEnoughBuffers)13044902524cSMatthias Ringwald TEST(btstack_memory, mesh_network_key_NotEnoughBuffers){
13054902524cSMatthias Ringwald     mesh_network_key_t * context;
13064902524cSMatthias Ringwald #ifdef HAVE_MALLOC
13074902524cSMatthias Ringwald     simulate_no_memory = 1;
13084902524cSMatthias Ringwald #else
13094902524cSMatthias Ringwald #ifdef MAX_NR_MESH_NETWORK_KEYS
13104902524cSMatthias Ringwald     int i;
13114902524cSMatthias Ringwald     // alloc all static buffers
13124902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_MESH_NETWORK_KEYS; i++){
13134902524cSMatthias Ringwald         context = btstack_memory_mesh_network_key_get();
13144902524cSMatthias Ringwald         CHECK(context != NULL);
13154902524cSMatthias Ringwald     }
13164902524cSMatthias Ringwald #endif
13174902524cSMatthias Ringwald #endif
13184902524cSMatthias Ringwald     // get one more
13194902524cSMatthias Ringwald     context = btstack_memory_mesh_network_key_get();
13204902524cSMatthias Ringwald     CHECK(context == NULL);
13214902524cSMatthias Ringwald }
13224902524cSMatthias Ringwald 
13234902524cSMatthias Ringwald 
13244902524cSMatthias Ringwald 
TEST(btstack_memory,mesh_transport_key_GetAndFree)13254902524cSMatthias Ringwald TEST(btstack_memory, mesh_transport_key_GetAndFree){
13264902524cSMatthias Ringwald     mesh_transport_key_t * context;
13274902524cSMatthias Ringwald #ifdef HAVE_MALLOC
13284902524cSMatthias Ringwald     context = btstack_memory_mesh_transport_key_get();
13294902524cSMatthias Ringwald     CHECK(context != NULL);
13304902524cSMatthias Ringwald     btstack_memory_mesh_transport_key_free(context);
13314902524cSMatthias Ringwald #else
13324902524cSMatthias Ringwald #ifdef MAX_NR_MESH_TRANSPORT_KEYS
13334902524cSMatthias Ringwald     // single
13344902524cSMatthias Ringwald     context = btstack_memory_mesh_transport_key_get();
13354902524cSMatthias Ringwald     CHECK(context != NULL);
13364902524cSMatthias Ringwald     btstack_memory_mesh_transport_key_free(context);
13374902524cSMatthias Ringwald #else
13384902524cSMatthias Ringwald     // none
13394902524cSMatthias Ringwald     context = btstack_memory_mesh_transport_key_get();
13404902524cSMatthias Ringwald     CHECK(context == NULL);
13414902524cSMatthias Ringwald     btstack_memory_mesh_transport_key_free(context);
13424902524cSMatthias Ringwald #endif
13434902524cSMatthias Ringwald #endif
13444902524cSMatthias Ringwald }
13454902524cSMatthias Ringwald 
TEST(btstack_memory,mesh_transport_key_NotEnoughBuffers)13464902524cSMatthias Ringwald TEST(btstack_memory, mesh_transport_key_NotEnoughBuffers){
13474902524cSMatthias Ringwald     mesh_transport_key_t * context;
13484902524cSMatthias Ringwald #ifdef HAVE_MALLOC
13494902524cSMatthias Ringwald     simulate_no_memory = 1;
13504902524cSMatthias Ringwald #else
13514902524cSMatthias Ringwald #ifdef MAX_NR_MESH_TRANSPORT_KEYS
13524902524cSMatthias Ringwald     int i;
13534902524cSMatthias Ringwald     // alloc all static buffers
13544902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_MESH_TRANSPORT_KEYS; i++){
13554902524cSMatthias Ringwald         context = btstack_memory_mesh_transport_key_get();
13564902524cSMatthias Ringwald         CHECK(context != NULL);
13574902524cSMatthias Ringwald     }
13584902524cSMatthias Ringwald #endif
13594902524cSMatthias Ringwald #endif
13604902524cSMatthias Ringwald     // get one more
13614902524cSMatthias Ringwald     context = btstack_memory_mesh_transport_key_get();
13624902524cSMatthias Ringwald     CHECK(context == NULL);
13634902524cSMatthias Ringwald }
13644902524cSMatthias Ringwald 
13654902524cSMatthias Ringwald 
13664902524cSMatthias Ringwald 
TEST(btstack_memory,mesh_virtual_address_GetAndFree)13674902524cSMatthias Ringwald TEST(btstack_memory, mesh_virtual_address_GetAndFree){
13684902524cSMatthias Ringwald     mesh_virtual_address_t * context;
13694902524cSMatthias Ringwald #ifdef HAVE_MALLOC
13704902524cSMatthias Ringwald     context = btstack_memory_mesh_virtual_address_get();
13714902524cSMatthias Ringwald     CHECK(context != NULL);
13724902524cSMatthias Ringwald     btstack_memory_mesh_virtual_address_free(context);
13734902524cSMatthias Ringwald #else
13744902524cSMatthias Ringwald #ifdef MAX_NR_MESH_VIRTUAL_ADDRESSS
13754902524cSMatthias Ringwald     // single
13764902524cSMatthias Ringwald     context = btstack_memory_mesh_virtual_address_get();
13774902524cSMatthias Ringwald     CHECK(context != NULL);
13784902524cSMatthias Ringwald     btstack_memory_mesh_virtual_address_free(context);
13794902524cSMatthias Ringwald #else
13804902524cSMatthias Ringwald     // none
13814902524cSMatthias Ringwald     context = btstack_memory_mesh_virtual_address_get();
13824902524cSMatthias Ringwald     CHECK(context == NULL);
13834902524cSMatthias Ringwald     btstack_memory_mesh_virtual_address_free(context);
13844902524cSMatthias Ringwald #endif
13854902524cSMatthias Ringwald #endif
13864902524cSMatthias Ringwald }
13874902524cSMatthias Ringwald 
TEST(btstack_memory,mesh_virtual_address_NotEnoughBuffers)13884902524cSMatthias Ringwald TEST(btstack_memory, mesh_virtual_address_NotEnoughBuffers){
13894902524cSMatthias Ringwald     mesh_virtual_address_t * context;
13904902524cSMatthias Ringwald #ifdef HAVE_MALLOC
13914902524cSMatthias Ringwald     simulate_no_memory = 1;
13924902524cSMatthias Ringwald #else
13934902524cSMatthias Ringwald #ifdef MAX_NR_MESH_VIRTUAL_ADDRESSS
13944902524cSMatthias Ringwald     int i;
13954902524cSMatthias Ringwald     // alloc all static buffers
13964902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_MESH_VIRTUAL_ADDRESSS; i++){
13974902524cSMatthias Ringwald         context = btstack_memory_mesh_virtual_address_get();
13984902524cSMatthias Ringwald         CHECK(context != NULL);
13994902524cSMatthias Ringwald     }
14004902524cSMatthias Ringwald #endif
14014902524cSMatthias Ringwald #endif
14024902524cSMatthias Ringwald     // get one more
14034902524cSMatthias Ringwald     context = btstack_memory_mesh_virtual_address_get();
14044902524cSMatthias Ringwald     CHECK(context == NULL);
14054902524cSMatthias Ringwald }
14064902524cSMatthias Ringwald 
14074902524cSMatthias Ringwald 
14084902524cSMatthias Ringwald 
TEST(btstack_memory,mesh_subnet_GetAndFree)14094902524cSMatthias Ringwald TEST(btstack_memory, mesh_subnet_GetAndFree){
14104902524cSMatthias Ringwald     mesh_subnet_t * context;
14114902524cSMatthias Ringwald #ifdef HAVE_MALLOC
14124902524cSMatthias Ringwald     context = btstack_memory_mesh_subnet_get();
14134902524cSMatthias Ringwald     CHECK(context != NULL);
14144902524cSMatthias Ringwald     btstack_memory_mesh_subnet_free(context);
14154902524cSMatthias Ringwald #else
14164902524cSMatthias Ringwald #ifdef MAX_NR_MESH_SUBNETS
14174902524cSMatthias Ringwald     // single
14184902524cSMatthias Ringwald     context = btstack_memory_mesh_subnet_get();
14194902524cSMatthias Ringwald     CHECK(context != NULL);
14204902524cSMatthias Ringwald     btstack_memory_mesh_subnet_free(context);
14214902524cSMatthias Ringwald #else
14224902524cSMatthias Ringwald     // none
14234902524cSMatthias Ringwald     context = btstack_memory_mesh_subnet_get();
14244902524cSMatthias Ringwald     CHECK(context == NULL);
14254902524cSMatthias Ringwald     btstack_memory_mesh_subnet_free(context);
14264902524cSMatthias Ringwald #endif
14274902524cSMatthias Ringwald #endif
14284902524cSMatthias Ringwald }
14294902524cSMatthias Ringwald 
TEST(btstack_memory,mesh_subnet_NotEnoughBuffers)14304902524cSMatthias Ringwald TEST(btstack_memory, mesh_subnet_NotEnoughBuffers){
14314902524cSMatthias Ringwald     mesh_subnet_t * context;
14324902524cSMatthias Ringwald #ifdef HAVE_MALLOC
14334902524cSMatthias Ringwald     simulate_no_memory = 1;
14344902524cSMatthias Ringwald #else
14354902524cSMatthias Ringwald #ifdef MAX_NR_MESH_SUBNETS
14364902524cSMatthias Ringwald     int i;
14374902524cSMatthias Ringwald     // alloc all static buffers
14384902524cSMatthias Ringwald     for (i = 0; i < MAX_NR_MESH_SUBNETS; i++){
14394902524cSMatthias Ringwald         context = btstack_memory_mesh_subnet_get();
14404902524cSMatthias Ringwald         CHECK(context != NULL);
14414902524cSMatthias Ringwald     }
14424902524cSMatthias Ringwald #endif
14434902524cSMatthias Ringwald #endif
14444902524cSMatthias Ringwald     // get one more
14454902524cSMatthias Ringwald     context = btstack_memory_mesh_subnet_get();
14464902524cSMatthias Ringwald     CHECK(context == NULL);
14474902524cSMatthias Ringwald }
14484902524cSMatthias Ringwald 
1449*2281ada7SMatthias Ringwald 
1450*2281ada7SMatthias Ringwald #endif
1451*2281ada7SMatthias Ringwald #ifdef ENABLE_LE_ISOCHRONOUS_STREAMS
1452*2281ada7SMatthias Ringwald 
1453*2281ada7SMatthias Ringwald 
TEST(btstack_memory,hci_iso_stream_GetAndFree)1454*2281ada7SMatthias Ringwald TEST(btstack_memory, hci_iso_stream_GetAndFree){
1455*2281ada7SMatthias Ringwald     hci_iso_stream_t * context;
1456*2281ada7SMatthias Ringwald #ifdef HAVE_MALLOC
1457*2281ada7SMatthias Ringwald     context = btstack_memory_hci_iso_stream_get();
1458*2281ada7SMatthias Ringwald     CHECK(context != NULL);
1459*2281ada7SMatthias Ringwald     btstack_memory_hci_iso_stream_free(context);
1460*2281ada7SMatthias Ringwald #else
1461*2281ada7SMatthias Ringwald #ifdef MAX_NR_HCI_ISO_STREAMS
1462*2281ada7SMatthias Ringwald     // single
1463*2281ada7SMatthias Ringwald     context = btstack_memory_hci_iso_stream_get();
1464*2281ada7SMatthias Ringwald     CHECK(context != NULL);
1465*2281ada7SMatthias Ringwald     btstack_memory_hci_iso_stream_free(context);
1466*2281ada7SMatthias Ringwald #else
1467*2281ada7SMatthias Ringwald     // none
1468*2281ada7SMatthias Ringwald     context = btstack_memory_hci_iso_stream_get();
1469*2281ada7SMatthias Ringwald     CHECK(context == NULL);
1470*2281ada7SMatthias Ringwald     btstack_memory_hci_iso_stream_free(context);
1471*2281ada7SMatthias Ringwald #endif
1472*2281ada7SMatthias Ringwald #endif
1473*2281ada7SMatthias Ringwald }
1474*2281ada7SMatthias Ringwald 
TEST(btstack_memory,hci_iso_stream_NotEnoughBuffers)1475*2281ada7SMatthias Ringwald TEST(btstack_memory, hci_iso_stream_NotEnoughBuffers){
1476*2281ada7SMatthias Ringwald     hci_iso_stream_t * context;
1477*2281ada7SMatthias Ringwald #ifdef HAVE_MALLOC
1478*2281ada7SMatthias Ringwald     simulate_no_memory = 1;
1479*2281ada7SMatthias Ringwald #else
1480*2281ada7SMatthias Ringwald #ifdef MAX_NR_HCI_ISO_STREAMS
1481*2281ada7SMatthias Ringwald     int i;
1482*2281ada7SMatthias Ringwald     // alloc all static buffers
1483*2281ada7SMatthias Ringwald     for (i = 0; i < MAX_NR_HCI_ISO_STREAMS; i++){
1484*2281ada7SMatthias Ringwald         context = btstack_memory_hci_iso_stream_get();
1485*2281ada7SMatthias Ringwald         CHECK(context != NULL);
1486*2281ada7SMatthias Ringwald     }
1487*2281ada7SMatthias Ringwald #endif
1488*2281ada7SMatthias Ringwald #endif
1489*2281ada7SMatthias Ringwald     // get one more
1490*2281ada7SMatthias Ringwald     context = btstack_memory_hci_iso_stream_get();
1491*2281ada7SMatthias Ringwald     CHECK(context == NULL);
1492*2281ada7SMatthias Ringwald }
1493*2281ada7SMatthias Ringwald 
1494*2281ada7SMatthias Ringwald 
14954902524cSMatthias Ringwald #endif
14964902524cSMatthias Ringwald 
main(int argc,const char * argv[])14974902524cSMatthias Ringwald int main (int argc, const char * argv[]){
14984902524cSMatthias Ringwald     return CommandLineTestRunner::RunAllTests(argc, argv);
14994902524cSMatthias Ringwald }
15004902524cSMatthias Ringwald 
1501