1 /* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN 24 * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 39 #include <stdint.h> 40 #include <stdio.h> 41 #include <stdlib.h> 42 #include <string.h> 43 44 // malloc hook 45 static int simulate_no_memory; 46 extern "C" void * test_malloc(size_t size); 47 void * test_malloc(size_t size){ 48 if (simulate_no_memory) return NULL; 49 return malloc(size); 50 } 51 52 #include "btstack_config.h" 53 54 #include "CppUTest/TestHarness.h" 55 #include "CppUTest/CommandLineTestRunner.h" 56 57 #include "bluetooth_data_types.h" 58 #include "btstack_util.h" 59 #include "btstack_memory.h" 60 61 62 TEST_GROUP(btstack_memory){ 63 void setup(void){ 64 btstack_memory_init(); 65 simulate_no_memory = 0; 66 } 67 }; 68 69 #ifdef HAVE_MALLOC 70 TEST(btstack_memory, deinit){ 71 // alloc buffers 1,2,3 72 hci_connection_t * buffer_1 = btstack_memory_hci_connection_get(); 73 hci_connection_t * buffer_2 = btstack_memory_hci_connection_get(); 74 hci_connection_t * buffer_3 = btstack_memory_hci_connection_get(); 75 // free first one in list 76 btstack_memory_hci_connection_free(buffer_3); 77 // free second one in list 78 btstack_memory_hci_connection_free(buffer_1); 79 // leave buffer in list 80 (void) buffer_2; 81 btstack_memory_deinit(); 82 } 83 #endif 84 85 86 87 88 TEST(btstack_memory, hci_connection_GetAndFree){ 89 hci_connection_t * context; 90 #ifdef HAVE_MALLOC 91 context = btstack_memory_hci_connection_get(); 92 CHECK(context != NULL); 93 btstack_memory_hci_connection_free(context); 94 #else 95 #ifdef MAX_NR_HCI_CONNECTIONS 96 // single 97 context = btstack_memory_hci_connection_get(); 98 CHECK(context != NULL); 99 btstack_memory_hci_connection_free(context); 100 #else 101 // none 102 context = btstack_memory_hci_connection_get(); 103 CHECK(context == NULL); 104 btstack_memory_hci_connection_free(context); 105 #endif 106 #endif 107 } 108 109 TEST(btstack_memory, hci_connection_NotEnoughBuffers){ 110 hci_connection_t * context; 111 #ifdef HAVE_MALLOC 112 simulate_no_memory = 1; 113 #else 114 #ifdef MAX_NR_HCI_CONNECTIONS 115 int i; 116 // alloc all static buffers 117 for (i = 0; i < MAX_NR_HCI_CONNECTIONS; i++){ 118 context = btstack_memory_hci_connection_get(); 119 CHECK(context != NULL); 120 } 121 #endif 122 #endif 123 // get one more 124 context = btstack_memory_hci_connection_get(); 125 CHECK(context == NULL); 126 } 127 128 129 130 131 TEST(btstack_memory, l2cap_service_GetAndFree){ 132 l2cap_service_t * context; 133 #ifdef HAVE_MALLOC 134 context = btstack_memory_l2cap_service_get(); 135 CHECK(context != NULL); 136 btstack_memory_l2cap_service_free(context); 137 #else 138 #ifdef MAX_NR_L2CAP_SERVICES 139 // single 140 context = btstack_memory_l2cap_service_get(); 141 CHECK(context != NULL); 142 btstack_memory_l2cap_service_free(context); 143 #else 144 // none 145 context = btstack_memory_l2cap_service_get(); 146 CHECK(context == NULL); 147 btstack_memory_l2cap_service_free(context); 148 #endif 149 #endif 150 } 151 152 TEST(btstack_memory, l2cap_service_NotEnoughBuffers){ 153 l2cap_service_t * context; 154 #ifdef HAVE_MALLOC 155 simulate_no_memory = 1; 156 #else 157 #ifdef MAX_NR_L2CAP_SERVICES 158 int i; 159 // alloc all static buffers 160 for (i = 0; i < MAX_NR_L2CAP_SERVICES; i++){ 161 context = btstack_memory_l2cap_service_get(); 162 CHECK(context != NULL); 163 } 164 #endif 165 #endif 166 // get one more 167 context = btstack_memory_l2cap_service_get(); 168 CHECK(context == NULL); 169 } 170 171 172 173 TEST(btstack_memory, l2cap_channel_GetAndFree){ 174 l2cap_channel_t * context; 175 #ifdef HAVE_MALLOC 176 context = btstack_memory_l2cap_channel_get(); 177 CHECK(context != NULL); 178 btstack_memory_l2cap_channel_free(context); 179 #else 180 #ifdef MAX_NR_L2CAP_CHANNELS 181 // single 182 context = btstack_memory_l2cap_channel_get(); 183 CHECK(context != NULL); 184 btstack_memory_l2cap_channel_free(context); 185 #else 186 // none 187 context = btstack_memory_l2cap_channel_get(); 188 CHECK(context == NULL); 189 btstack_memory_l2cap_channel_free(context); 190 #endif 191 #endif 192 } 193 194 TEST(btstack_memory, l2cap_channel_NotEnoughBuffers){ 195 l2cap_channel_t * context; 196 #ifdef HAVE_MALLOC 197 simulate_no_memory = 1; 198 #else 199 #ifdef MAX_NR_L2CAP_CHANNELS 200 int i; 201 // alloc all static buffers 202 for (i = 0; i < MAX_NR_L2CAP_CHANNELS; i++){ 203 context = btstack_memory_l2cap_channel_get(); 204 CHECK(context != NULL); 205 } 206 #endif 207 #endif 208 // get one more 209 context = btstack_memory_l2cap_channel_get(); 210 CHECK(context == NULL); 211 } 212 213 214 #ifdef ENABLE_CLASSIC 215 216 217 TEST(btstack_memory, rfcomm_multiplexer_GetAndFree){ 218 rfcomm_multiplexer_t * context; 219 #ifdef HAVE_MALLOC 220 context = btstack_memory_rfcomm_multiplexer_get(); 221 CHECK(context != NULL); 222 btstack_memory_rfcomm_multiplexer_free(context); 223 #else 224 #ifdef MAX_NR_RFCOMM_MULTIPLEXERS 225 // single 226 context = btstack_memory_rfcomm_multiplexer_get(); 227 CHECK(context != NULL); 228 btstack_memory_rfcomm_multiplexer_free(context); 229 #else 230 // none 231 context = btstack_memory_rfcomm_multiplexer_get(); 232 CHECK(context == NULL); 233 btstack_memory_rfcomm_multiplexer_free(context); 234 #endif 235 #endif 236 } 237 238 TEST(btstack_memory, rfcomm_multiplexer_NotEnoughBuffers){ 239 rfcomm_multiplexer_t * context; 240 #ifdef HAVE_MALLOC 241 simulate_no_memory = 1; 242 #else 243 #ifdef MAX_NR_RFCOMM_MULTIPLEXERS 244 int i; 245 // alloc all static buffers 246 for (i = 0; i < MAX_NR_RFCOMM_MULTIPLEXERS; i++){ 247 context = btstack_memory_rfcomm_multiplexer_get(); 248 CHECK(context != NULL); 249 } 250 #endif 251 #endif 252 // get one more 253 context = btstack_memory_rfcomm_multiplexer_get(); 254 CHECK(context == NULL); 255 } 256 257 258 259 TEST(btstack_memory, rfcomm_service_GetAndFree){ 260 rfcomm_service_t * context; 261 #ifdef HAVE_MALLOC 262 context = btstack_memory_rfcomm_service_get(); 263 CHECK(context != NULL); 264 btstack_memory_rfcomm_service_free(context); 265 #else 266 #ifdef MAX_NR_RFCOMM_SERVICES 267 // single 268 context = btstack_memory_rfcomm_service_get(); 269 CHECK(context != NULL); 270 btstack_memory_rfcomm_service_free(context); 271 #else 272 // none 273 context = btstack_memory_rfcomm_service_get(); 274 CHECK(context == NULL); 275 btstack_memory_rfcomm_service_free(context); 276 #endif 277 #endif 278 } 279 280 TEST(btstack_memory, rfcomm_service_NotEnoughBuffers){ 281 rfcomm_service_t * context; 282 #ifdef HAVE_MALLOC 283 simulate_no_memory = 1; 284 #else 285 #ifdef MAX_NR_RFCOMM_SERVICES 286 int i; 287 // alloc all static buffers 288 for (i = 0; i < MAX_NR_RFCOMM_SERVICES; i++){ 289 context = btstack_memory_rfcomm_service_get(); 290 CHECK(context != NULL); 291 } 292 #endif 293 #endif 294 // get one more 295 context = btstack_memory_rfcomm_service_get(); 296 CHECK(context == NULL); 297 } 298 299 300 301 TEST(btstack_memory, rfcomm_channel_GetAndFree){ 302 rfcomm_channel_t * context; 303 #ifdef HAVE_MALLOC 304 context = btstack_memory_rfcomm_channel_get(); 305 CHECK(context != NULL); 306 btstack_memory_rfcomm_channel_free(context); 307 #else 308 #ifdef MAX_NR_RFCOMM_CHANNELS 309 // single 310 context = btstack_memory_rfcomm_channel_get(); 311 CHECK(context != NULL); 312 btstack_memory_rfcomm_channel_free(context); 313 #else 314 // none 315 context = btstack_memory_rfcomm_channel_get(); 316 CHECK(context == NULL); 317 btstack_memory_rfcomm_channel_free(context); 318 #endif 319 #endif 320 } 321 322 TEST(btstack_memory, rfcomm_channel_NotEnoughBuffers){ 323 rfcomm_channel_t * context; 324 #ifdef HAVE_MALLOC 325 simulate_no_memory = 1; 326 #else 327 #ifdef MAX_NR_RFCOMM_CHANNELS 328 int i; 329 // alloc all static buffers 330 for (i = 0; i < MAX_NR_RFCOMM_CHANNELS; i++){ 331 context = btstack_memory_rfcomm_channel_get(); 332 CHECK(context != NULL); 333 } 334 #endif 335 #endif 336 // get one more 337 context = btstack_memory_rfcomm_channel_get(); 338 CHECK(context == NULL); 339 } 340 341 342 343 344 TEST(btstack_memory, btstack_link_key_db_memory_entry_GetAndFree){ 345 btstack_link_key_db_memory_entry_t * context; 346 #ifdef HAVE_MALLOC 347 context = btstack_memory_btstack_link_key_db_memory_entry_get(); 348 CHECK(context != NULL); 349 btstack_memory_btstack_link_key_db_memory_entry_free(context); 350 #else 351 #ifdef MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 352 // single 353 context = btstack_memory_btstack_link_key_db_memory_entry_get(); 354 CHECK(context != NULL); 355 btstack_memory_btstack_link_key_db_memory_entry_free(context); 356 #else 357 // none 358 context = btstack_memory_btstack_link_key_db_memory_entry_get(); 359 CHECK(context == NULL); 360 btstack_memory_btstack_link_key_db_memory_entry_free(context); 361 #endif 362 #endif 363 } 364 365 TEST(btstack_memory, btstack_link_key_db_memory_entry_NotEnoughBuffers){ 366 btstack_link_key_db_memory_entry_t * context; 367 #ifdef HAVE_MALLOC 368 simulate_no_memory = 1; 369 #else 370 #ifdef MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 371 int i; 372 // alloc all static buffers 373 for (i = 0; i < MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES; i++){ 374 context = btstack_memory_btstack_link_key_db_memory_entry_get(); 375 CHECK(context != NULL); 376 } 377 #endif 378 #endif 379 // get one more 380 context = btstack_memory_btstack_link_key_db_memory_entry_get(); 381 CHECK(context == NULL); 382 } 383 384 385 386 387 TEST(btstack_memory, bnep_service_GetAndFree){ 388 bnep_service_t * context; 389 #ifdef HAVE_MALLOC 390 context = btstack_memory_bnep_service_get(); 391 CHECK(context != NULL); 392 btstack_memory_bnep_service_free(context); 393 #else 394 #ifdef MAX_NR_BNEP_SERVICES 395 // single 396 context = btstack_memory_bnep_service_get(); 397 CHECK(context != NULL); 398 btstack_memory_bnep_service_free(context); 399 #else 400 // none 401 context = btstack_memory_bnep_service_get(); 402 CHECK(context == NULL); 403 btstack_memory_bnep_service_free(context); 404 #endif 405 #endif 406 } 407 408 TEST(btstack_memory, bnep_service_NotEnoughBuffers){ 409 bnep_service_t * context; 410 #ifdef HAVE_MALLOC 411 simulate_no_memory = 1; 412 #else 413 #ifdef MAX_NR_BNEP_SERVICES 414 int i; 415 // alloc all static buffers 416 for (i = 0; i < MAX_NR_BNEP_SERVICES; i++){ 417 context = btstack_memory_bnep_service_get(); 418 CHECK(context != NULL); 419 } 420 #endif 421 #endif 422 // get one more 423 context = btstack_memory_bnep_service_get(); 424 CHECK(context == NULL); 425 } 426 427 428 429 TEST(btstack_memory, bnep_channel_GetAndFree){ 430 bnep_channel_t * context; 431 #ifdef HAVE_MALLOC 432 context = btstack_memory_bnep_channel_get(); 433 CHECK(context != NULL); 434 btstack_memory_bnep_channel_free(context); 435 #else 436 #ifdef MAX_NR_BNEP_CHANNELS 437 // single 438 context = btstack_memory_bnep_channel_get(); 439 CHECK(context != NULL); 440 btstack_memory_bnep_channel_free(context); 441 #else 442 // none 443 context = btstack_memory_bnep_channel_get(); 444 CHECK(context == NULL); 445 btstack_memory_bnep_channel_free(context); 446 #endif 447 #endif 448 } 449 450 TEST(btstack_memory, bnep_channel_NotEnoughBuffers){ 451 bnep_channel_t * context; 452 #ifdef HAVE_MALLOC 453 simulate_no_memory = 1; 454 #else 455 #ifdef MAX_NR_BNEP_CHANNELS 456 int i; 457 // alloc all static buffers 458 for (i = 0; i < MAX_NR_BNEP_CHANNELS; i++){ 459 context = btstack_memory_bnep_channel_get(); 460 CHECK(context != NULL); 461 } 462 #endif 463 #endif 464 // get one more 465 context = btstack_memory_bnep_channel_get(); 466 CHECK(context == NULL); 467 } 468 469 470 471 472 TEST(btstack_memory, goep_server_service_GetAndFree){ 473 goep_server_service_t * context; 474 #ifdef HAVE_MALLOC 475 context = btstack_memory_goep_server_service_get(); 476 CHECK(context != NULL); 477 btstack_memory_goep_server_service_free(context); 478 #else 479 #ifdef MAX_NR_GOEP_SERVER_SERVICES 480 // single 481 context = btstack_memory_goep_server_service_get(); 482 CHECK(context != NULL); 483 btstack_memory_goep_server_service_free(context); 484 #else 485 // none 486 context = btstack_memory_goep_server_service_get(); 487 CHECK(context == NULL); 488 btstack_memory_goep_server_service_free(context); 489 #endif 490 #endif 491 } 492 493 TEST(btstack_memory, goep_server_service_NotEnoughBuffers){ 494 goep_server_service_t * context; 495 #ifdef HAVE_MALLOC 496 simulate_no_memory = 1; 497 #else 498 #ifdef MAX_NR_GOEP_SERVER_SERVICES 499 int i; 500 // alloc all static buffers 501 for (i = 0; i < MAX_NR_GOEP_SERVER_SERVICES; i++){ 502 context = btstack_memory_goep_server_service_get(); 503 CHECK(context != NULL); 504 } 505 #endif 506 #endif 507 // get one more 508 context = btstack_memory_goep_server_service_get(); 509 CHECK(context == NULL); 510 } 511 512 513 514 TEST(btstack_memory, goep_server_connection_GetAndFree){ 515 goep_server_connection_t * context; 516 #ifdef HAVE_MALLOC 517 context = btstack_memory_goep_server_connection_get(); 518 CHECK(context != NULL); 519 btstack_memory_goep_server_connection_free(context); 520 #else 521 #ifdef MAX_NR_GOEP_SERVER_CONNECTIONS 522 // single 523 context = btstack_memory_goep_server_connection_get(); 524 CHECK(context != NULL); 525 btstack_memory_goep_server_connection_free(context); 526 #else 527 // none 528 context = btstack_memory_goep_server_connection_get(); 529 CHECK(context == NULL); 530 btstack_memory_goep_server_connection_free(context); 531 #endif 532 #endif 533 } 534 535 TEST(btstack_memory, goep_server_connection_NotEnoughBuffers){ 536 goep_server_connection_t * context; 537 #ifdef HAVE_MALLOC 538 simulate_no_memory = 1; 539 #else 540 #ifdef MAX_NR_GOEP_SERVER_CONNECTIONS 541 int i; 542 // alloc all static buffers 543 for (i = 0; i < MAX_NR_GOEP_SERVER_CONNECTIONS; i++){ 544 context = btstack_memory_goep_server_connection_get(); 545 CHECK(context != NULL); 546 } 547 #endif 548 #endif 549 // get one more 550 context = btstack_memory_goep_server_connection_get(); 551 CHECK(context == NULL); 552 } 553 554 555 556 557 TEST(btstack_memory, hfp_connection_GetAndFree){ 558 hfp_connection_t * context; 559 #ifdef HAVE_MALLOC 560 context = btstack_memory_hfp_connection_get(); 561 CHECK(context != NULL); 562 btstack_memory_hfp_connection_free(context); 563 #else 564 #ifdef MAX_NR_HFP_CONNECTIONS 565 // single 566 context = btstack_memory_hfp_connection_get(); 567 CHECK(context != NULL); 568 btstack_memory_hfp_connection_free(context); 569 #else 570 // none 571 context = btstack_memory_hfp_connection_get(); 572 CHECK(context == NULL); 573 btstack_memory_hfp_connection_free(context); 574 #endif 575 #endif 576 } 577 578 TEST(btstack_memory, hfp_connection_NotEnoughBuffers){ 579 hfp_connection_t * context; 580 #ifdef HAVE_MALLOC 581 simulate_no_memory = 1; 582 #else 583 #ifdef MAX_NR_HFP_CONNECTIONS 584 int i; 585 // alloc all static buffers 586 for (i = 0; i < MAX_NR_HFP_CONNECTIONS; i++){ 587 context = btstack_memory_hfp_connection_get(); 588 CHECK(context != NULL); 589 } 590 #endif 591 #endif 592 // get one more 593 context = btstack_memory_hfp_connection_get(); 594 CHECK(context == NULL); 595 } 596 597 598 599 600 TEST(btstack_memory, hid_host_connection_GetAndFree){ 601 hid_host_connection_t * context; 602 #ifdef HAVE_MALLOC 603 context = btstack_memory_hid_host_connection_get(); 604 CHECK(context != NULL); 605 btstack_memory_hid_host_connection_free(context); 606 #else 607 #ifdef MAX_NR_HID_HOST_CONNECTIONS 608 // single 609 context = btstack_memory_hid_host_connection_get(); 610 CHECK(context != NULL); 611 btstack_memory_hid_host_connection_free(context); 612 #else 613 // none 614 context = btstack_memory_hid_host_connection_get(); 615 CHECK(context == NULL); 616 btstack_memory_hid_host_connection_free(context); 617 #endif 618 #endif 619 } 620 621 TEST(btstack_memory, hid_host_connection_NotEnoughBuffers){ 622 hid_host_connection_t * context; 623 #ifdef HAVE_MALLOC 624 simulate_no_memory = 1; 625 #else 626 #ifdef MAX_NR_HID_HOST_CONNECTIONS 627 int i; 628 // alloc all static buffers 629 for (i = 0; i < MAX_NR_HID_HOST_CONNECTIONS; i++){ 630 context = btstack_memory_hid_host_connection_get(); 631 CHECK(context != NULL); 632 } 633 #endif 634 #endif 635 // get one more 636 context = btstack_memory_hid_host_connection_get(); 637 CHECK(context == NULL); 638 } 639 640 641 642 643 TEST(btstack_memory, service_record_item_GetAndFree){ 644 service_record_item_t * context; 645 #ifdef HAVE_MALLOC 646 context = btstack_memory_service_record_item_get(); 647 CHECK(context != NULL); 648 btstack_memory_service_record_item_free(context); 649 #else 650 #ifdef MAX_NR_SERVICE_RECORD_ITEMS 651 // single 652 context = btstack_memory_service_record_item_get(); 653 CHECK(context != NULL); 654 btstack_memory_service_record_item_free(context); 655 #else 656 // none 657 context = btstack_memory_service_record_item_get(); 658 CHECK(context == NULL); 659 btstack_memory_service_record_item_free(context); 660 #endif 661 #endif 662 } 663 664 TEST(btstack_memory, service_record_item_NotEnoughBuffers){ 665 service_record_item_t * context; 666 #ifdef HAVE_MALLOC 667 simulate_no_memory = 1; 668 #else 669 #ifdef MAX_NR_SERVICE_RECORD_ITEMS 670 int i; 671 // alloc all static buffers 672 for (i = 0; i < MAX_NR_SERVICE_RECORD_ITEMS; i++){ 673 context = btstack_memory_service_record_item_get(); 674 CHECK(context != NULL); 675 } 676 #endif 677 #endif 678 // get one more 679 context = btstack_memory_service_record_item_get(); 680 CHECK(context == NULL); 681 } 682 683 684 685 686 TEST(btstack_memory, avdtp_stream_endpoint_GetAndFree){ 687 avdtp_stream_endpoint_t * context; 688 #ifdef HAVE_MALLOC 689 context = btstack_memory_avdtp_stream_endpoint_get(); 690 CHECK(context != NULL); 691 btstack_memory_avdtp_stream_endpoint_free(context); 692 #else 693 #ifdef MAX_NR_AVDTP_STREAM_ENDPOINTS 694 // single 695 context = btstack_memory_avdtp_stream_endpoint_get(); 696 CHECK(context != NULL); 697 btstack_memory_avdtp_stream_endpoint_free(context); 698 #else 699 // none 700 context = btstack_memory_avdtp_stream_endpoint_get(); 701 CHECK(context == NULL); 702 btstack_memory_avdtp_stream_endpoint_free(context); 703 #endif 704 #endif 705 } 706 707 TEST(btstack_memory, avdtp_stream_endpoint_NotEnoughBuffers){ 708 avdtp_stream_endpoint_t * context; 709 #ifdef HAVE_MALLOC 710 simulate_no_memory = 1; 711 #else 712 #ifdef MAX_NR_AVDTP_STREAM_ENDPOINTS 713 int i; 714 // alloc all static buffers 715 for (i = 0; i < MAX_NR_AVDTP_STREAM_ENDPOINTS; i++){ 716 context = btstack_memory_avdtp_stream_endpoint_get(); 717 CHECK(context != NULL); 718 } 719 #endif 720 #endif 721 // get one more 722 context = btstack_memory_avdtp_stream_endpoint_get(); 723 CHECK(context == NULL); 724 } 725 726 727 728 729 TEST(btstack_memory, avdtp_connection_GetAndFree){ 730 avdtp_connection_t * context; 731 #ifdef HAVE_MALLOC 732 context = btstack_memory_avdtp_connection_get(); 733 CHECK(context != NULL); 734 btstack_memory_avdtp_connection_free(context); 735 #else 736 #ifdef MAX_NR_AVDTP_CONNECTIONS 737 // single 738 context = btstack_memory_avdtp_connection_get(); 739 CHECK(context != NULL); 740 btstack_memory_avdtp_connection_free(context); 741 #else 742 // none 743 context = btstack_memory_avdtp_connection_get(); 744 CHECK(context == NULL); 745 btstack_memory_avdtp_connection_free(context); 746 #endif 747 #endif 748 } 749 750 TEST(btstack_memory, avdtp_connection_NotEnoughBuffers){ 751 avdtp_connection_t * context; 752 #ifdef HAVE_MALLOC 753 simulate_no_memory = 1; 754 #else 755 #ifdef MAX_NR_AVDTP_CONNECTIONS 756 int i; 757 // alloc all static buffers 758 for (i = 0; i < MAX_NR_AVDTP_CONNECTIONS; i++){ 759 context = btstack_memory_avdtp_connection_get(); 760 CHECK(context != NULL); 761 } 762 #endif 763 #endif 764 // get one more 765 context = btstack_memory_avdtp_connection_get(); 766 CHECK(context == NULL); 767 } 768 769 770 771 772 TEST(btstack_memory, avrcp_connection_GetAndFree){ 773 avrcp_connection_t * context; 774 #ifdef HAVE_MALLOC 775 context = btstack_memory_avrcp_connection_get(); 776 CHECK(context != NULL); 777 btstack_memory_avrcp_connection_free(context); 778 #else 779 #ifdef MAX_NR_AVRCP_CONNECTIONS 780 // single 781 context = btstack_memory_avrcp_connection_get(); 782 CHECK(context != NULL); 783 btstack_memory_avrcp_connection_free(context); 784 #else 785 // none 786 context = btstack_memory_avrcp_connection_get(); 787 CHECK(context == NULL); 788 btstack_memory_avrcp_connection_free(context); 789 #endif 790 #endif 791 } 792 793 TEST(btstack_memory, avrcp_connection_NotEnoughBuffers){ 794 avrcp_connection_t * context; 795 #ifdef HAVE_MALLOC 796 simulate_no_memory = 1; 797 #else 798 #ifdef MAX_NR_AVRCP_CONNECTIONS 799 int i; 800 // alloc all static buffers 801 for (i = 0; i < MAX_NR_AVRCP_CONNECTIONS; i++){ 802 context = btstack_memory_avrcp_connection_get(); 803 CHECK(context != NULL); 804 } 805 #endif 806 #endif 807 // get one more 808 context = btstack_memory_avrcp_connection_get(); 809 CHECK(context == NULL); 810 } 811 812 813 814 815 TEST(btstack_memory, avrcp_browsing_connection_GetAndFree){ 816 avrcp_browsing_connection_t * context; 817 #ifdef HAVE_MALLOC 818 context = btstack_memory_avrcp_browsing_connection_get(); 819 CHECK(context != NULL); 820 btstack_memory_avrcp_browsing_connection_free(context); 821 #else 822 #ifdef MAX_NR_AVRCP_BROWSING_CONNECTIONS 823 // single 824 context = btstack_memory_avrcp_browsing_connection_get(); 825 CHECK(context != NULL); 826 btstack_memory_avrcp_browsing_connection_free(context); 827 #else 828 // none 829 context = btstack_memory_avrcp_browsing_connection_get(); 830 CHECK(context == NULL); 831 btstack_memory_avrcp_browsing_connection_free(context); 832 #endif 833 #endif 834 } 835 836 TEST(btstack_memory, avrcp_browsing_connection_NotEnoughBuffers){ 837 avrcp_browsing_connection_t * context; 838 #ifdef HAVE_MALLOC 839 simulate_no_memory = 1; 840 #else 841 #ifdef MAX_NR_AVRCP_BROWSING_CONNECTIONS 842 int i; 843 // alloc all static buffers 844 for (i = 0; i < MAX_NR_AVRCP_BROWSING_CONNECTIONS; i++){ 845 context = btstack_memory_avrcp_browsing_connection_get(); 846 CHECK(context != NULL); 847 } 848 #endif 849 #endif 850 // get one more 851 context = btstack_memory_avrcp_browsing_connection_get(); 852 CHECK(context == NULL); 853 } 854 855 856 #endif 857 #ifdef ENABLE_BLE 858 859 860 TEST(btstack_memory, battery_service_client_GetAndFree){ 861 battery_service_client_t * context; 862 #ifdef HAVE_MALLOC 863 context = btstack_memory_battery_service_client_get(); 864 CHECK(context != NULL); 865 btstack_memory_battery_service_client_free(context); 866 #else 867 #ifdef MAX_NR_BATTERY_SERVICE_CLIENTS 868 // single 869 context = btstack_memory_battery_service_client_get(); 870 CHECK(context != NULL); 871 btstack_memory_battery_service_client_free(context); 872 #else 873 // none 874 context = btstack_memory_battery_service_client_get(); 875 CHECK(context == NULL); 876 btstack_memory_battery_service_client_free(context); 877 #endif 878 #endif 879 } 880 881 TEST(btstack_memory, battery_service_client_NotEnoughBuffers){ 882 battery_service_client_t * context; 883 #ifdef HAVE_MALLOC 884 simulate_no_memory = 1; 885 #else 886 #ifdef MAX_NR_BATTERY_SERVICE_CLIENTS 887 int i; 888 // alloc all static buffers 889 for (i = 0; i < MAX_NR_BATTERY_SERVICE_CLIENTS; i++){ 890 context = btstack_memory_battery_service_client_get(); 891 CHECK(context != NULL); 892 } 893 #endif 894 #endif 895 // get one more 896 context = btstack_memory_battery_service_client_get(); 897 CHECK(context == NULL); 898 } 899 900 901 902 TEST(btstack_memory, gatt_client_GetAndFree){ 903 gatt_client_t * context; 904 #ifdef HAVE_MALLOC 905 context = btstack_memory_gatt_client_get(); 906 CHECK(context != NULL); 907 btstack_memory_gatt_client_free(context); 908 #else 909 #ifdef MAX_NR_GATT_CLIENTS 910 // single 911 context = btstack_memory_gatt_client_get(); 912 CHECK(context != NULL); 913 btstack_memory_gatt_client_free(context); 914 #else 915 // none 916 context = btstack_memory_gatt_client_get(); 917 CHECK(context == NULL); 918 btstack_memory_gatt_client_free(context); 919 #endif 920 #endif 921 } 922 923 TEST(btstack_memory, gatt_client_NotEnoughBuffers){ 924 gatt_client_t * context; 925 #ifdef HAVE_MALLOC 926 simulate_no_memory = 1; 927 #else 928 #ifdef MAX_NR_GATT_CLIENTS 929 int i; 930 // alloc all static buffers 931 for (i = 0; i < MAX_NR_GATT_CLIENTS; i++){ 932 context = btstack_memory_gatt_client_get(); 933 CHECK(context != NULL); 934 } 935 #endif 936 #endif 937 // get one more 938 context = btstack_memory_gatt_client_get(); 939 CHECK(context == NULL); 940 } 941 942 943 944 TEST(btstack_memory, hids_client_GetAndFree){ 945 hids_client_t * context; 946 #ifdef HAVE_MALLOC 947 context = btstack_memory_hids_client_get(); 948 CHECK(context != NULL); 949 btstack_memory_hids_client_free(context); 950 #else 951 #ifdef MAX_NR_HIDS_CLIENTS 952 // single 953 context = btstack_memory_hids_client_get(); 954 CHECK(context != NULL); 955 btstack_memory_hids_client_free(context); 956 #else 957 // none 958 context = btstack_memory_hids_client_get(); 959 CHECK(context == NULL); 960 btstack_memory_hids_client_free(context); 961 #endif 962 #endif 963 } 964 965 TEST(btstack_memory, hids_client_NotEnoughBuffers){ 966 hids_client_t * context; 967 #ifdef HAVE_MALLOC 968 simulate_no_memory = 1; 969 #else 970 #ifdef MAX_NR_HIDS_CLIENTS 971 int i; 972 // alloc all static buffers 973 for (i = 0; i < MAX_NR_HIDS_CLIENTS; i++){ 974 context = btstack_memory_hids_client_get(); 975 CHECK(context != NULL); 976 } 977 #endif 978 #endif 979 // get one more 980 context = btstack_memory_hids_client_get(); 981 CHECK(context == NULL); 982 } 983 984 985 986 TEST(btstack_memory, scan_parameters_service_client_GetAndFree){ 987 scan_parameters_service_client_t * context; 988 #ifdef HAVE_MALLOC 989 context = btstack_memory_scan_parameters_service_client_get(); 990 CHECK(context != NULL); 991 btstack_memory_scan_parameters_service_client_free(context); 992 #else 993 #ifdef MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS 994 // single 995 context = btstack_memory_scan_parameters_service_client_get(); 996 CHECK(context != NULL); 997 btstack_memory_scan_parameters_service_client_free(context); 998 #else 999 // none 1000 context = btstack_memory_scan_parameters_service_client_get(); 1001 CHECK(context == NULL); 1002 btstack_memory_scan_parameters_service_client_free(context); 1003 #endif 1004 #endif 1005 } 1006 1007 TEST(btstack_memory, scan_parameters_service_client_NotEnoughBuffers){ 1008 scan_parameters_service_client_t * context; 1009 #ifdef HAVE_MALLOC 1010 simulate_no_memory = 1; 1011 #else 1012 #ifdef MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS 1013 int i; 1014 // alloc all static buffers 1015 for (i = 0; i < MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS; i++){ 1016 context = btstack_memory_scan_parameters_service_client_get(); 1017 CHECK(context != NULL); 1018 } 1019 #endif 1020 #endif 1021 // get one more 1022 context = btstack_memory_scan_parameters_service_client_get(); 1023 CHECK(context == NULL); 1024 } 1025 1026 1027 1028 TEST(btstack_memory, sm_lookup_entry_GetAndFree){ 1029 sm_lookup_entry_t * context; 1030 #ifdef HAVE_MALLOC 1031 context = btstack_memory_sm_lookup_entry_get(); 1032 CHECK(context != NULL); 1033 btstack_memory_sm_lookup_entry_free(context); 1034 #else 1035 #ifdef MAX_NR_SM_LOOKUP_ENTRIES 1036 // single 1037 context = btstack_memory_sm_lookup_entry_get(); 1038 CHECK(context != NULL); 1039 btstack_memory_sm_lookup_entry_free(context); 1040 #else 1041 // none 1042 context = btstack_memory_sm_lookup_entry_get(); 1043 CHECK(context == NULL); 1044 btstack_memory_sm_lookup_entry_free(context); 1045 #endif 1046 #endif 1047 } 1048 1049 TEST(btstack_memory, sm_lookup_entry_NotEnoughBuffers){ 1050 sm_lookup_entry_t * context; 1051 #ifdef HAVE_MALLOC 1052 simulate_no_memory = 1; 1053 #else 1054 #ifdef MAX_NR_SM_LOOKUP_ENTRIES 1055 int i; 1056 // alloc all static buffers 1057 for (i = 0; i < MAX_NR_SM_LOOKUP_ENTRIES; i++){ 1058 context = btstack_memory_sm_lookup_entry_get(); 1059 CHECK(context != NULL); 1060 } 1061 #endif 1062 #endif 1063 // get one more 1064 context = btstack_memory_sm_lookup_entry_get(); 1065 CHECK(context == NULL); 1066 } 1067 1068 1069 1070 TEST(btstack_memory, whitelist_entry_GetAndFree){ 1071 whitelist_entry_t * context; 1072 #ifdef HAVE_MALLOC 1073 context = btstack_memory_whitelist_entry_get(); 1074 CHECK(context != NULL); 1075 btstack_memory_whitelist_entry_free(context); 1076 #else 1077 #ifdef MAX_NR_WHITELIST_ENTRIES 1078 // single 1079 context = btstack_memory_whitelist_entry_get(); 1080 CHECK(context != NULL); 1081 btstack_memory_whitelist_entry_free(context); 1082 #else 1083 // none 1084 context = btstack_memory_whitelist_entry_get(); 1085 CHECK(context == NULL); 1086 btstack_memory_whitelist_entry_free(context); 1087 #endif 1088 #endif 1089 } 1090 1091 TEST(btstack_memory, whitelist_entry_NotEnoughBuffers){ 1092 whitelist_entry_t * context; 1093 #ifdef HAVE_MALLOC 1094 simulate_no_memory = 1; 1095 #else 1096 #ifdef MAX_NR_WHITELIST_ENTRIES 1097 int i; 1098 // alloc all static buffers 1099 for (i = 0; i < MAX_NR_WHITELIST_ENTRIES; i++){ 1100 context = btstack_memory_whitelist_entry_get(); 1101 CHECK(context != NULL); 1102 } 1103 #endif 1104 #endif 1105 // get one more 1106 context = btstack_memory_whitelist_entry_get(); 1107 CHECK(context == NULL); 1108 } 1109 1110 1111 1112 TEST(btstack_memory, periodic_advertiser_list_entry_GetAndFree){ 1113 periodic_advertiser_list_entry_t * context; 1114 #ifdef HAVE_MALLOC 1115 context = btstack_memory_periodic_advertiser_list_entry_get(); 1116 CHECK(context != NULL); 1117 btstack_memory_periodic_advertiser_list_entry_free(context); 1118 #else 1119 #ifdef MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES 1120 // single 1121 context = btstack_memory_periodic_advertiser_list_entry_get(); 1122 CHECK(context != NULL); 1123 btstack_memory_periodic_advertiser_list_entry_free(context); 1124 #else 1125 // none 1126 context = btstack_memory_periodic_advertiser_list_entry_get(); 1127 CHECK(context == NULL); 1128 btstack_memory_periodic_advertiser_list_entry_free(context); 1129 #endif 1130 #endif 1131 } 1132 1133 TEST(btstack_memory, periodic_advertiser_list_entry_NotEnoughBuffers){ 1134 periodic_advertiser_list_entry_t * context; 1135 #ifdef HAVE_MALLOC 1136 simulate_no_memory = 1; 1137 #else 1138 #ifdef MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES 1139 int i; 1140 // alloc all static buffers 1141 for (i = 0; i < MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES; i++){ 1142 context = btstack_memory_periodic_advertiser_list_entry_get(); 1143 CHECK(context != NULL); 1144 } 1145 #endif 1146 #endif 1147 // get one more 1148 context = btstack_memory_periodic_advertiser_list_entry_get(); 1149 CHECK(context == NULL); 1150 } 1151 1152 1153 #endif 1154 #ifdef ENABLE_MESH 1155 1156 1157 TEST(btstack_memory, mesh_network_pdu_GetAndFree){ 1158 mesh_network_pdu_t * context; 1159 #ifdef HAVE_MALLOC 1160 context = btstack_memory_mesh_network_pdu_get(); 1161 CHECK(context != NULL); 1162 btstack_memory_mesh_network_pdu_free(context); 1163 #else 1164 #ifdef MAX_NR_MESH_NETWORK_PDUS 1165 // single 1166 context = btstack_memory_mesh_network_pdu_get(); 1167 CHECK(context != NULL); 1168 btstack_memory_mesh_network_pdu_free(context); 1169 #else 1170 // none 1171 context = btstack_memory_mesh_network_pdu_get(); 1172 CHECK(context == NULL); 1173 btstack_memory_mesh_network_pdu_free(context); 1174 #endif 1175 #endif 1176 } 1177 1178 TEST(btstack_memory, mesh_network_pdu_NotEnoughBuffers){ 1179 mesh_network_pdu_t * context; 1180 #ifdef HAVE_MALLOC 1181 simulate_no_memory = 1; 1182 #else 1183 #ifdef MAX_NR_MESH_NETWORK_PDUS 1184 int i; 1185 // alloc all static buffers 1186 for (i = 0; i < MAX_NR_MESH_NETWORK_PDUS; i++){ 1187 context = btstack_memory_mesh_network_pdu_get(); 1188 CHECK(context != NULL); 1189 } 1190 #endif 1191 #endif 1192 // get one more 1193 context = btstack_memory_mesh_network_pdu_get(); 1194 CHECK(context == NULL); 1195 } 1196 1197 1198 1199 TEST(btstack_memory, mesh_segmented_pdu_GetAndFree){ 1200 mesh_segmented_pdu_t * context; 1201 #ifdef HAVE_MALLOC 1202 context = btstack_memory_mesh_segmented_pdu_get(); 1203 CHECK(context != NULL); 1204 btstack_memory_mesh_segmented_pdu_free(context); 1205 #else 1206 #ifdef MAX_NR_MESH_SEGMENTED_PDUS 1207 // single 1208 context = btstack_memory_mesh_segmented_pdu_get(); 1209 CHECK(context != NULL); 1210 btstack_memory_mesh_segmented_pdu_free(context); 1211 #else 1212 // none 1213 context = btstack_memory_mesh_segmented_pdu_get(); 1214 CHECK(context == NULL); 1215 btstack_memory_mesh_segmented_pdu_free(context); 1216 #endif 1217 #endif 1218 } 1219 1220 TEST(btstack_memory, mesh_segmented_pdu_NotEnoughBuffers){ 1221 mesh_segmented_pdu_t * context; 1222 #ifdef HAVE_MALLOC 1223 simulate_no_memory = 1; 1224 #else 1225 #ifdef MAX_NR_MESH_SEGMENTED_PDUS 1226 int i; 1227 // alloc all static buffers 1228 for (i = 0; i < MAX_NR_MESH_SEGMENTED_PDUS; i++){ 1229 context = btstack_memory_mesh_segmented_pdu_get(); 1230 CHECK(context != NULL); 1231 } 1232 #endif 1233 #endif 1234 // get one more 1235 context = btstack_memory_mesh_segmented_pdu_get(); 1236 CHECK(context == NULL); 1237 } 1238 1239 1240 1241 TEST(btstack_memory, mesh_upper_transport_pdu_GetAndFree){ 1242 mesh_upper_transport_pdu_t * context; 1243 #ifdef HAVE_MALLOC 1244 context = btstack_memory_mesh_upper_transport_pdu_get(); 1245 CHECK(context != NULL); 1246 btstack_memory_mesh_upper_transport_pdu_free(context); 1247 #else 1248 #ifdef MAX_NR_MESH_UPPER_TRANSPORT_PDUS 1249 // single 1250 context = btstack_memory_mesh_upper_transport_pdu_get(); 1251 CHECK(context != NULL); 1252 btstack_memory_mesh_upper_transport_pdu_free(context); 1253 #else 1254 // none 1255 context = btstack_memory_mesh_upper_transport_pdu_get(); 1256 CHECK(context == NULL); 1257 btstack_memory_mesh_upper_transport_pdu_free(context); 1258 #endif 1259 #endif 1260 } 1261 1262 TEST(btstack_memory, mesh_upper_transport_pdu_NotEnoughBuffers){ 1263 mesh_upper_transport_pdu_t * context; 1264 #ifdef HAVE_MALLOC 1265 simulate_no_memory = 1; 1266 #else 1267 #ifdef MAX_NR_MESH_UPPER_TRANSPORT_PDUS 1268 int i; 1269 // alloc all static buffers 1270 for (i = 0; i < MAX_NR_MESH_UPPER_TRANSPORT_PDUS; i++){ 1271 context = btstack_memory_mesh_upper_transport_pdu_get(); 1272 CHECK(context != NULL); 1273 } 1274 #endif 1275 #endif 1276 // get one more 1277 context = btstack_memory_mesh_upper_transport_pdu_get(); 1278 CHECK(context == NULL); 1279 } 1280 1281 1282 1283 TEST(btstack_memory, mesh_network_key_GetAndFree){ 1284 mesh_network_key_t * context; 1285 #ifdef HAVE_MALLOC 1286 context = btstack_memory_mesh_network_key_get(); 1287 CHECK(context != NULL); 1288 btstack_memory_mesh_network_key_free(context); 1289 #else 1290 #ifdef MAX_NR_MESH_NETWORK_KEYS 1291 // single 1292 context = btstack_memory_mesh_network_key_get(); 1293 CHECK(context != NULL); 1294 btstack_memory_mesh_network_key_free(context); 1295 #else 1296 // none 1297 context = btstack_memory_mesh_network_key_get(); 1298 CHECK(context == NULL); 1299 btstack_memory_mesh_network_key_free(context); 1300 #endif 1301 #endif 1302 } 1303 1304 TEST(btstack_memory, mesh_network_key_NotEnoughBuffers){ 1305 mesh_network_key_t * context; 1306 #ifdef HAVE_MALLOC 1307 simulate_no_memory = 1; 1308 #else 1309 #ifdef MAX_NR_MESH_NETWORK_KEYS 1310 int i; 1311 // alloc all static buffers 1312 for (i = 0; i < MAX_NR_MESH_NETWORK_KEYS; i++){ 1313 context = btstack_memory_mesh_network_key_get(); 1314 CHECK(context != NULL); 1315 } 1316 #endif 1317 #endif 1318 // get one more 1319 context = btstack_memory_mesh_network_key_get(); 1320 CHECK(context == NULL); 1321 } 1322 1323 1324 1325 TEST(btstack_memory, mesh_transport_key_GetAndFree){ 1326 mesh_transport_key_t * context; 1327 #ifdef HAVE_MALLOC 1328 context = btstack_memory_mesh_transport_key_get(); 1329 CHECK(context != NULL); 1330 btstack_memory_mesh_transport_key_free(context); 1331 #else 1332 #ifdef MAX_NR_MESH_TRANSPORT_KEYS 1333 // single 1334 context = btstack_memory_mesh_transport_key_get(); 1335 CHECK(context != NULL); 1336 btstack_memory_mesh_transport_key_free(context); 1337 #else 1338 // none 1339 context = btstack_memory_mesh_transport_key_get(); 1340 CHECK(context == NULL); 1341 btstack_memory_mesh_transport_key_free(context); 1342 #endif 1343 #endif 1344 } 1345 1346 TEST(btstack_memory, mesh_transport_key_NotEnoughBuffers){ 1347 mesh_transport_key_t * context; 1348 #ifdef HAVE_MALLOC 1349 simulate_no_memory = 1; 1350 #else 1351 #ifdef MAX_NR_MESH_TRANSPORT_KEYS 1352 int i; 1353 // alloc all static buffers 1354 for (i = 0; i < MAX_NR_MESH_TRANSPORT_KEYS; i++){ 1355 context = btstack_memory_mesh_transport_key_get(); 1356 CHECK(context != NULL); 1357 } 1358 #endif 1359 #endif 1360 // get one more 1361 context = btstack_memory_mesh_transport_key_get(); 1362 CHECK(context == NULL); 1363 } 1364 1365 1366 1367 TEST(btstack_memory, mesh_virtual_address_GetAndFree){ 1368 mesh_virtual_address_t * context; 1369 #ifdef HAVE_MALLOC 1370 context = btstack_memory_mesh_virtual_address_get(); 1371 CHECK(context != NULL); 1372 btstack_memory_mesh_virtual_address_free(context); 1373 #else 1374 #ifdef MAX_NR_MESH_VIRTUAL_ADDRESSS 1375 // single 1376 context = btstack_memory_mesh_virtual_address_get(); 1377 CHECK(context != NULL); 1378 btstack_memory_mesh_virtual_address_free(context); 1379 #else 1380 // none 1381 context = btstack_memory_mesh_virtual_address_get(); 1382 CHECK(context == NULL); 1383 btstack_memory_mesh_virtual_address_free(context); 1384 #endif 1385 #endif 1386 } 1387 1388 TEST(btstack_memory, mesh_virtual_address_NotEnoughBuffers){ 1389 mesh_virtual_address_t * context; 1390 #ifdef HAVE_MALLOC 1391 simulate_no_memory = 1; 1392 #else 1393 #ifdef MAX_NR_MESH_VIRTUAL_ADDRESSS 1394 int i; 1395 // alloc all static buffers 1396 for (i = 0; i < MAX_NR_MESH_VIRTUAL_ADDRESSS; i++){ 1397 context = btstack_memory_mesh_virtual_address_get(); 1398 CHECK(context != NULL); 1399 } 1400 #endif 1401 #endif 1402 // get one more 1403 context = btstack_memory_mesh_virtual_address_get(); 1404 CHECK(context == NULL); 1405 } 1406 1407 1408 1409 TEST(btstack_memory, mesh_subnet_GetAndFree){ 1410 mesh_subnet_t * context; 1411 #ifdef HAVE_MALLOC 1412 context = btstack_memory_mesh_subnet_get(); 1413 CHECK(context != NULL); 1414 btstack_memory_mesh_subnet_free(context); 1415 #else 1416 #ifdef MAX_NR_MESH_SUBNETS 1417 // single 1418 context = btstack_memory_mesh_subnet_get(); 1419 CHECK(context != NULL); 1420 btstack_memory_mesh_subnet_free(context); 1421 #else 1422 // none 1423 context = btstack_memory_mesh_subnet_get(); 1424 CHECK(context == NULL); 1425 btstack_memory_mesh_subnet_free(context); 1426 #endif 1427 #endif 1428 } 1429 1430 TEST(btstack_memory, mesh_subnet_NotEnoughBuffers){ 1431 mesh_subnet_t * context; 1432 #ifdef HAVE_MALLOC 1433 simulate_no_memory = 1; 1434 #else 1435 #ifdef MAX_NR_MESH_SUBNETS 1436 int i; 1437 // alloc all static buffers 1438 for (i = 0; i < MAX_NR_MESH_SUBNETS; i++){ 1439 context = btstack_memory_mesh_subnet_get(); 1440 CHECK(context != NULL); 1441 } 1442 #endif 1443 #endif 1444 // get one more 1445 context = btstack_memory_mesh_subnet_get(); 1446 CHECK(context == NULL); 1447 } 1448 1449 1450 #endif 1451 #ifdef ENABLE_LE_ISOCHRONOUS_STREAMS 1452 1453 1454 TEST(btstack_memory, hci_iso_stream_GetAndFree){ 1455 hci_iso_stream_t * context; 1456 #ifdef HAVE_MALLOC 1457 context = btstack_memory_hci_iso_stream_get(); 1458 CHECK(context != NULL); 1459 btstack_memory_hci_iso_stream_free(context); 1460 #else 1461 #ifdef MAX_NR_HCI_ISO_STREAMS 1462 // single 1463 context = btstack_memory_hci_iso_stream_get(); 1464 CHECK(context != NULL); 1465 btstack_memory_hci_iso_stream_free(context); 1466 #else 1467 // none 1468 context = btstack_memory_hci_iso_stream_get(); 1469 CHECK(context == NULL); 1470 btstack_memory_hci_iso_stream_free(context); 1471 #endif 1472 #endif 1473 } 1474 1475 TEST(btstack_memory, hci_iso_stream_NotEnoughBuffers){ 1476 hci_iso_stream_t * context; 1477 #ifdef HAVE_MALLOC 1478 simulate_no_memory = 1; 1479 #else 1480 #ifdef MAX_NR_HCI_ISO_STREAMS 1481 int i; 1482 // alloc all static buffers 1483 for (i = 0; i < MAX_NR_HCI_ISO_STREAMS; i++){ 1484 context = btstack_memory_hci_iso_stream_get(); 1485 CHECK(context != NULL); 1486 } 1487 #endif 1488 #endif 1489 // get one more 1490 context = btstack_memory_hci_iso_stream_get(); 1491 CHECK(context == NULL); 1492 } 1493 1494 1495 #endif 1496 1497 int main (int argc, const char * argv[]){ 1498 return CommandLineTestRunner::RunAllTests(argc, argv); 1499 } 1500 1501