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 TEST(btstack_memory, l2cap_service_GetAndFree){ 131 l2cap_service_t * context; 132 #ifdef HAVE_MALLOC 133 context = btstack_memory_l2cap_service_get(); 134 CHECK(context != NULL); 135 btstack_memory_l2cap_service_free(context); 136 #else 137 #ifdef MAX_NR_L2CAP_SERVICES 138 // single 139 context = btstack_memory_l2cap_service_get(); 140 CHECK(context != NULL); 141 btstack_memory_l2cap_service_free(context); 142 #else 143 // none 144 context = btstack_memory_l2cap_service_get(); 145 CHECK(context == NULL); 146 btstack_memory_l2cap_service_free(context); 147 #endif 148 #endif 149 } 150 151 TEST(btstack_memory, l2cap_service_NotEnoughBuffers){ 152 l2cap_service_t * context; 153 #ifdef HAVE_MALLOC 154 simulate_no_memory = 1; 155 #else 156 #ifdef MAX_NR_L2CAP_SERVICES 157 int i; 158 // alloc all static buffers 159 for (i = 0; i < MAX_NR_L2CAP_SERVICES; i++){ 160 context = btstack_memory_l2cap_service_get(); 161 CHECK(context != NULL); 162 } 163 #endif 164 #endif 165 // get one more 166 context = btstack_memory_l2cap_service_get(); 167 CHECK(context == NULL); 168 } 169 170 171 172 TEST(btstack_memory, l2cap_channel_GetAndFree){ 173 l2cap_channel_t * context; 174 #ifdef HAVE_MALLOC 175 context = btstack_memory_l2cap_channel_get(); 176 CHECK(context != NULL); 177 btstack_memory_l2cap_channel_free(context); 178 #else 179 #ifdef MAX_NR_L2CAP_CHANNELS 180 // single 181 context = btstack_memory_l2cap_channel_get(); 182 CHECK(context != NULL); 183 btstack_memory_l2cap_channel_free(context); 184 #else 185 // none 186 context = btstack_memory_l2cap_channel_get(); 187 CHECK(context == NULL); 188 btstack_memory_l2cap_channel_free(context); 189 #endif 190 #endif 191 } 192 193 TEST(btstack_memory, l2cap_channel_NotEnoughBuffers){ 194 l2cap_channel_t * context; 195 #ifdef HAVE_MALLOC 196 simulate_no_memory = 1; 197 #else 198 #ifdef MAX_NR_L2CAP_CHANNELS 199 int i; 200 // alloc all static buffers 201 for (i = 0; i < MAX_NR_L2CAP_CHANNELS; i++){ 202 context = btstack_memory_l2cap_channel_get(); 203 CHECK(context != NULL); 204 } 205 #endif 206 #endif 207 // get one more 208 context = btstack_memory_l2cap_channel_get(); 209 CHECK(context == NULL); 210 } 211 212 #ifdef ENABLE_CLASSIC 213 214 215 TEST(btstack_memory, rfcomm_multiplexer_GetAndFree){ 216 rfcomm_multiplexer_t * context; 217 #ifdef HAVE_MALLOC 218 context = btstack_memory_rfcomm_multiplexer_get(); 219 CHECK(context != NULL); 220 btstack_memory_rfcomm_multiplexer_free(context); 221 #else 222 #ifdef MAX_NR_RFCOMM_MULTIPLEXERS 223 // single 224 context = btstack_memory_rfcomm_multiplexer_get(); 225 CHECK(context != NULL); 226 btstack_memory_rfcomm_multiplexer_free(context); 227 #else 228 // none 229 context = btstack_memory_rfcomm_multiplexer_get(); 230 CHECK(context == NULL); 231 btstack_memory_rfcomm_multiplexer_free(context); 232 #endif 233 #endif 234 } 235 236 TEST(btstack_memory, rfcomm_multiplexer_NotEnoughBuffers){ 237 rfcomm_multiplexer_t * context; 238 #ifdef HAVE_MALLOC 239 simulate_no_memory = 1; 240 #else 241 #ifdef MAX_NR_RFCOMM_MULTIPLEXERS 242 int i; 243 // alloc all static buffers 244 for (i = 0; i < MAX_NR_RFCOMM_MULTIPLEXERS; i++){ 245 context = btstack_memory_rfcomm_multiplexer_get(); 246 CHECK(context != NULL); 247 } 248 #endif 249 #endif 250 // get one more 251 context = btstack_memory_rfcomm_multiplexer_get(); 252 CHECK(context == NULL); 253 } 254 255 256 257 TEST(btstack_memory, rfcomm_service_GetAndFree){ 258 rfcomm_service_t * context; 259 #ifdef HAVE_MALLOC 260 context = btstack_memory_rfcomm_service_get(); 261 CHECK(context != NULL); 262 btstack_memory_rfcomm_service_free(context); 263 #else 264 #ifdef MAX_NR_RFCOMM_SERVICES 265 // single 266 context = btstack_memory_rfcomm_service_get(); 267 CHECK(context != NULL); 268 btstack_memory_rfcomm_service_free(context); 269 #else 270 // none 271 context = btstack_memory_rfcomm_service_get(); 272 CHECK(context == NULL); 273 btstack_memory_rfcomm_service_free(context); 274 #endif 275 #endif 276 } 277 278 TEST(btstack_memory, rfcomm_service_NotEnoughBuffers){ 279 rfcomm_service_t * context; 280 #ifdef HAVE_MALLOC 281 simulate_no_memory = 1; 282 #else 283 #ifdef MAX_NR_RFCOMM_SERVICES 284 int i; 285 // alloc all static buffers 286 for (i = 0; i < MAX_NR_RFCOMM_SERVICES; i++){ 287 context = btstack_memory_rfcomm_service_get(); 288 CHECK(context != NULL); 289 } 290 #endif 291 #endif 292 // get one more 293 context = btstack_memory_rfcomm_service_get(); 294 CHECK(context == NULL); 295 } 296 297 298 299 TEST(btstack_memory, rfcomm_channel_GetAndFree){ 300 rfcomm_channel_t * context; 301 #ifdef HAVE_MALLOC 302 context = btstack_memory_rfcomm_channel_get(); 303 CHECK(context != NULL); 304 btstack_memory_rfcomm_channel_free(context); 305 #else 306 #ifdef MAX_NR_RFCOMM_CHANNELS 307 // single 308 context = btstack_memory_rfcomm_channel_get(); 309 CHECK(context != NULL); 310 btstack_memory_rfcomm_channel_free(context); 311 #else 312 // none 313 context = btstack_memory_rfcomm_channel_get(); 314 CHECK(context == NULL); 315 btstack_memory_rfcomm_channel_free(context); 316 #endif 317 #endif 318 } 319 320 TEST(btstack_memory, rfcomm_channel_NotEnoughBuffers){ 321 rfcomm_channel_t * context; 322 #ifdef HAVE_MALLOC 323 simulate_no_memory = 1; 324 #else 325 #ifdef MAX_NR_RFCOMM_CHANNELS 326 int i; 327 // alloc all static buffers 328 for (i = 0; i < MAX_NR_RFCOMM_CHANNELS; i++){ 329 context = btstack_memory_rfcomm_channel_get(); 330 CHECK(context != NULL); 331 } 332 #endif 333 #endif 334 // get one more 335 context = btstack_memory_rfcomm_channel_get(); 336 CHECK(context == NULL); 337 } 338 339 340 341 TEST(btstack_memory, btstack_link_key_db_memory_entry_GetAndFree){ 342 btstack_link_key_db_memory_entry_t * context; 343 #ifdef HAVE_MALLOC 344 context = btstack_memory_btstack_link_key_db_memory_entry_get(); 345 CHECK(context != NULL); 346 btstack_memory_btstack_link_key_db_memory_entry_free(context); 347 #else 348 #ifdef MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 349 // single 350 context = btstack_memory_btstack_link_key_db_memory_entry_get(); 351 CHECK(context != NULL); 352 btstack_memory_btstack_link_key_db_memory_entry_free(context); 353 #else 354 // none 355 context = btstack_memory_btstack_link_key_db_memory_entry_get(); 356 CHECK(context == NULL); 357 btstack_memory_btstack_link_key_db_memory_entry_free(context); 358 #endif 359 #endif 360 } 361 362 TEST(btstack_memory, btstack_link_key_db_memory_entry_NotEnoughBuffers){ 363 btstack_link_key_db_memory_entry_t * context; 364 #ifdef HAVE_MALLOC 365 simulate_no_memory = 1; 366 #else 367 #ifdef MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 368 int i; 369 // alloc all static buffers 370 for (i = 0; i < MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES; i++){ 371 context = btstack_memory_btstack_link_key_db_memory_entry_get(); 372 CHECK(context != NULL); 373 } 374 #endif 375 #endif 376 // get one more 377 context = btstack_memory_btstack_link_key_db_memory_entry_get(); 378 CHECK(context == NULL); 379 } 380 381 382 383 TEST(btstack_memory, bnep_service_GetAndFree){ 384 bnep_service_t * context; 385 #ifdef HAVE_MALLOC 386 context = btstack_memory_bnep_service_get(); 387 CHECK(context != NULL); 388 btstack_memory_bnep_service_free(context); 389 #else 390 #ifdef MAX_NR_BNEP_SERVICES 391 // single 392 context = btstack_memory_bnep_service_get(); 393 CHECK(context != NULL); 394 btstack_memory_bnep_service_free(context); 395 #else 396 // none 397 context = btstack_memory_bnep_service_get(); 398 CHECK(context == NULL); 399 btstack_memory_bnep_service_free(context); 400 #endif 401 #endif 402 } 403 404 TEST(btstack_memory, bnep_service_NotEnoughBuffers){ 405 bnep_service_t * context; 406 #ifdef HAVE_MALLOC 407 simulate_no_memory = 1; 408 #else 409 #ifdef MAX_NR_BNEP_SERVICES 410 int i; 411 // alloc all static buffers 412 for (i = 0; i < MAX_NR_BNEP_SERVICES; i++){ 413 context = btstack_memory_bnep_service_get(); 414 CHECK(context != NULL); 415 } 416 #endif 417 #endif 418 // get one more 419 context = btstack_memory_bnep_service_get(); 420 CHECK(context == NULL); 421 } 422 423 424 425 TEST(btstack_memory, bnep_channel_GetAndFree){ 426 bnep_channel_t * context; 427 #ifdef HAVE_MALLOC 428 context = btstack_memory_bnep_channel_get(); 429 CHECK(context != NULL); 430 btstack_memory_bnep_channel_free(context); 431 #else 432 #ifdef MAX_NR_BNEP_CHANNELS 433 // single 434 context = btstack_memory_bnep_channel_get(); 435 CHECK(context != NULL); 436 btstack_memory_bnep_channel_free(context); 437 #else 438 // none 439 context = btstack_memory_bnep_channel_get(); 440 CHECK(context == NULL); 441 btstack_memory_bnep_channel_free(context); 442 #endif 443 #endif 444 } 445 446 TEST(btstack_memory, bnep_channel_NotEnoughBuffers){ 447 bnep_channel_t * context; 448 #ifdef HAVE_MALLOC 449 simulate_no_memory = 1; 450 #else 451 #ifdef MAX_NR_BNEP_CHANNELS 452 int i; 453 // alloc all static buffers 454 for (i = 0; i < MAX_NR_BNEP_CHANNELS; i++){ 455 context = btstack_memory_bnep_channel_get(); 456 CHECK(context != NULL); 457 } 458 #endif 459 #endif 460 // get one more 461 context = btstack_memory_bnep_channel_get(); 462 CHECK(context == NULL); 463 } 464 465 466 467 TEST(btstack_memory, hfp_connection_GetAndFree){ 468 hfp_connection_t * context; 469 #ifdef HAVE_MALLOC 470 context = btstack_memory_hfp_connection_get(); 471 CHECK(context != NULL); 472 btstack_memory_hfp_connection_free(context); 473 #else 474 #ifdef MAX_NR_HFP_CONNECTIONS 475 // single 476 context = btstack_memory_hfp_connection_get(); 477 CHECK(context != NULL); 478 btstack_memory_hfp_connection_free(context); 479 #else 480 // none 481 context = btstack_memory_hfp_connection_get(); 482 CHECK(context == NULL); 483 btstack_memory_hfp_connection_free(context); 484 #endif 485 #endif 486 } 487 488 TEST(btstack_memory, hfp_connection_NotEnoughBuffers){ 489 hfp_connection_t * context; 490 #ifdef HAVE_MALLOC 491 simulate_no_memory = 1; 492 #else 493 #ifdef MAX_NR_HFP_CONNECTIONS 494 int i; 495 // alloc all static buffers 496 for (i = 0; i < MAX_NR_HFP_CONNECTIONS; i++){ 497 context = btstack_memory_hfp_connection_get(); 498 CHECK(context != NULL); 499 } 500 #endif 501 #endif 502 // get one more 503 context = btstack_memory_hfp_connection_get(); 504 CHECK(context == NULL); 505 } 506 507 508 509 TEST(btstack_memory, hid_host_connection_GetAndFree){ 510 hid_host_connection_t * context; 511 #ifdef HAVE_MALLOC 512 context = btstack_memory_hid_host_connection_get(); 513 CHECK(context != NULL); 514 btstack_memory_hid_host_connection_free(context); 515 #else 516 #ifdef MAX_NR_HID_HOST_CONNECTIONS 517 // single 518 context = btstack_memory_hid_host_connection_get(); 519 CHECK(context != NULL); 520 btstack_memory_hid_host_connection_free(context); 521 #else 522 // none 523 context = btstack_memory_hid_host_connection_get(); 524 CHECK(context == NULL); 525 btstack_memory_hid_host_connection_free(context); 526 #endif 527 #endif 528 } 529 530 TEST(btstack_memory, hid_host_connection_NotEnoughBuffers){ 531 hid_host_connection_t * context; 532 #ifdef HAVE_MALLOC 533 simulate_no_memory = 1; 534 #else 535 #ifdef MAX_NR_HID_HOST_CONNECTIONS 536 int i; 537 // alloc all static buffers 538 for (i = 0; i < MAX_NR_HID_HOST_CONNECTIONS; i++){ 539 context = btstack_memory_hid_host_connection_get(); 540 CHECK(context != NULL); 541 } 542 #endif 543 #endif 544 // get one more 545 context = btstack_memory_hid_host_connection_get(); 546 CHECK(context == NULL); 547 } 548 549 550 551 TEST(btstack_memory, service_record_item_GetAndFree){ 552 service_record_item_t * context; 553 #ifdef HAVE_MALLOC 554 context = btstack_memory_service_record_item_get(); 555 CHECK(context != NULL); 556 btstack_memory_service_record_item_free(context); 557 #else 558 #ifdef MAX_NR_SERVICE_RECORD_ITEMS 559 // single 560 context = btstack_memory_service_record_item_get(); 561 CHECK(context != NULL); 562 btstack_memory_service_record_item_free(context); 563 #else 564 // none 565 context = btstack_memory_service_record_item_get(); 566 CHECK(context == NULL); 567 btstack_memory_service_record_item_free(context); 568 #endif 569 #endif 570 } 571 572 TEST(btstack_memory, service_record_item_NotEnoughBuffers){ 573 service_record_item_t * context; 574 #ifdef HAVE_MALLOC 575 simulate_no_memory = 1; 576 #else 577 #ifdef MAX_NR_SERVICE_RECORD_ITEMS 578 int i; 579 // alloc all static buffers 580 for (i = 0; i < MAX_NR_SERVICE_RECORD_ITEMS; i++){ 581 context = btstack_memory_service_record_item_get(); 582 CHECK(context != NULL); 583 } 584 #endif 585 #endif 586 // get one more 587 context = btstack_memory_service_record_item_get(); 588 CHECK(context == NULL); 589 } 590 591 592 593 TEST(btstack_memory, avdtp_stream_endpoint_GetAndFree){ 594 avdtp_stream_endpoint_t * context; 595 #ifdef HAVE_MALLOC 596 context = btstack_memory_avdtp_stream_endpoint_get(); 597 CHECK(context != NULL); 598 btstack_memory_avdtp_stream_endpoint_free(context); 599 #else 600 #ifdef MAX_NR_AVDTP_STREAM_ENDPOINTS 601 // single 602 context = btstack_memory_avdtp_stream_endpoint_get(); 603 CHECK(context != NULL); 604 btstack_memory_avdtp_stream_endpoint_free(context); 605 #else 606 // none 607 context = btstack_memory_avdtp_stream_endpoint_get(); 608 CHECK(context == NULL); 609 btstack_memory_avdtp_stream_endpoint_free(context); 610 #endif 611 #endif 612 } 613 614 TEST(btstack_memory, avdtp_stream_endpoint_NotEnoughBuffers){ 615 avdtp_stream_endpoint_t * context; 616 #ifdef HAVE_MALLOC 617 simulate_no_memory = 1; 618 #else 619 #ifdef MAX_NR_AVDTP_STREAM_ENDPOINTS 620 int i; 621 // alloc all static buffers 622 for (i = 0; i < MAX_NR_AVDTP_STREAM_ENDPOINTS; i++){ 623 context = btstack_memory_avdtp_stream_endpoint_get(); 624 CHECK(context != NULL); 625 } 626 #endif 627 #endif 628 // get one more 629 context = btstack_memory_avdtp_stream_endpoint_get(); 630 CHECK(context == NULL); 631 } 632 633 634 635 TEST(btstack_memory, avdtp_connection_GetAndFree){ 636 avdtp_connection_t * context; 637 #ifdef HAVE_MALLOC 638 context = btstack_memory_avdtp_connection_get(); 639 CHECK(context != NULL); 640 btstack_memory_avdtp_connection_free(context); 641 #else 642 #ifdef MAX_NR_AVDTP_CONNECTIONS 643 // single 644 context = btstack_memory_avdtp_connection_get(); 645 CHECK(context != NULL); 646 btstack_memory_avdtp_connection_free(context); 647 #else 648 // none 649 context = btstack_memory_avdtp_connection_get(); 650 CHECK(context == NULL); 651 btstack_memory_avdtp_connection_free(context); 652 #endif 653 #endif 654 } 655 656 TEST(btstack_memory, avdtp_connection_NotEnoughBuffers){ 657 avdtp_connection_t * context; 658 #ifdef HAVE_MALLOC 659 simulate_no_memory = 1; 660 #else 661 #ifdef MAX_NR_AVDTP_CONNECTIONS 662 int i; 663 // alloc all static buffers 664 for (i = 0; i < MAX_NR_AVDTP_CONNECTIONS; i++){ 665 context = btstack_memory_avdtp_connection_get(); 666 CHECK(context != NULL); 667 } 668 #endif 669 #endif 670 // get one more 671 context = btstack_memory_avdtp_connection_get(); 672 CHECK(context == NULL); 673 } 674 675 676 677 TEST(btstack_memory, avrcp_connection_GetAndFree){ 678 avrcp_connection_t * context; 679 #ifdef HAVE_MALLOC 680 context = btstack_memory_avrcp_connection_get(); 681 CHECK(context != NULL); 682 btstack_memory_avrcp_connection_free(context); 683 #else 684 #ifdef MAX_NR_AVRCP_CONNECTIONS 685 // single 686 context = btstack_memory_avrcp_connection_get(); 687 CHECK(context != NULL); 688 btstack_memory_avrcp_connection_free(context); 689 #else 690 // none 691 context = btstack_memory_avrcp_connection_get(); 692 CHECK(context == NULL); 693 btstack_memory_avrcp_connection_free(context); 694 #endif 695 #endif 696 } 697 698 TEST(btstack_memory, avrcp_connection_NotEnoughBuffers){ 699 avrcp_connection_t * context; 700 #ifdef HAVE_MALLOC 701 simulate_no_memory = 1; 702 #else 703 #ifdef MAX_NR_AVRCP_CONNECTIONS 704 int i; 705 // alloc all static buffers 706 for (i = 0; i < MAX_NR_AVRCP_CONNECTIONS; i++){ 707 context = btstack_memory_avrcp_connection_get(); 708 CHECK(context != NULL); 709 } 710 #endif 711 #endif 712 // get one more 713 context = btstack_memory_avrcp_connection_get(); 714 CHECK(context == NULL); 715 } 716 717 718 719 TEST(btstack_memory, avrcp_browsing_connection_GetAndFree){ 720 avrcp_browsing_connection_t * context; 721 #ifdef HAVE_MALLOC 722 context = btstack_memory_avrcp_browsing_connection_get(); 723 CHECK(context != NULL); 724 btstack_memory_avrcp_browsing_connection_free(context); 725 #else 726 #ifdef MAX_NR_AVRCP_BROWSING_CONNECTIONS 727 // single 728 context = btstack_memory_avrcp_browsing_connection_get(); 729 CHECK(context != NULL); 730 btstack_memory_avrcp_browsing_connection_free(context); 731 #else 732 // none 733 context = btstack_memory_avrcp_browsing_connection_get(); 734 CHECK(context == NULL); 735 btstack_memory_avrcp_browsing_connection_free(context); 736 #endif 737 #endif 738 } 739 740 TEST(btstack_memory, avrcp_browsing_connection_NotEnoughBuffers){ 741 avrcp_browsing_connection_t * context; 742 #ifdef HAVE_MALLOC 743 simulate_no_memory = 1; 744 #else 745 #ifdef MAX_NR_AVRCP_BROWSING_CONNECTIONS 746 int i; 747 // alloc all static buffers 748 for (i = 0; i < MAX_NR_AVRCP_BROWSING_CONNECTIONS; i++){ 749 context = btstack_memory_avrcp_browsing_connection_get(); 750 CHECK(context != NULL); 751 } 752 #endif 753 #endif 754 // get one more 755 context = btstack_memory_avrcp_browsing_connection_get(); 756 CHECK(context == NULL); 757 } 758 759 #endif 760 #ifdef ENABLE_BLE 761 762 763 TEST(btstack_memory, battery_service_client_GetAndFree){ 764 battery_service_client_t * context; 765 #ifdef HAVE_MALLOC 766 context = btstack_memory_battery_service_client_get(); 767 CHECK(context != NULL); 768 btstack_memory_battery_service_client_free(context); 769 #else 770 #ifdef MAX_NR_BATTERY_SERVICE_CLIENTS 771 // single 772 context = btstack_memory_battery_service_client_get(); 773 CHECK(context != NULL); 774 btstack_memory_battery_service_client_free(context); 775 #else 776 // none 777 context = btstack_memory_battery_service_client_get(); 778 CHECK(context == NULL); 779 btstack_memory_battery_service_client_free(context); 780 #endif 781 #endif 782 } 783 784 TEST(btstack_memory, battery_service_client_NotEnoughBuffers){ 785 battery_service_client_t * context; 786 #ifdef HAVE_MALLOC 787 simulate_no_memory = 1; 788 #else 789 #ifdef MAX_NR_BATTERY_SERVICE_CLIENTS 790 int i; 791 // alloc all static buffers 792 for (i = 0; i < MAX_NR_BATTERY_SERVICE_CLIENTS; i++){ 793 context = btstack_memory_battery_service_client_get(); 794 CHECK(context != NULL); 795 } 796 #endif 797 #endif 798 // get one more 799 context = btstack_memory_battery_service_client_get(); 800 CHECK(context == NULL); 801 } 802 803 804 805 TEST(btstack_memory, gatt_client_GetAndFree){ 806 gatt_client_t * context; 807 #ifdef HAVE_MALLOC 808 context = btstack_memory_gatt_client_get(); 809 CHECK(context != NULL); 810 btstack_memory_gatt_client_free(context); 811 #else 812 #ifdef MAX_NR_GATT_CLIENTS 813 // single 814 context = btstack_memory_gatt_client_get(); 815 CHECK(context != NULL); 816 btstack_memory_gatt_client_free(context); 817 #else 818 // none 819 context = btstack_memory_gatt_client_get(); 820 CHECK(context == NULL); 821 btstack_memory_gatt_client_free(context); 822 #endif 823 #endif 824 } 825 826 TEST(btstack_memory, gatt_client_NotEnoughBuffers){ 827 gatt_client_t * context; 828 #ifdef HAVE_MALLOC 829 simulate_no_memory = 1; 830 #else 831 #ifdef MAX_NR_GATT_CLIENTS 832 int i; 833 // alloc all static buffers 834 for (i = 0; i < MAX_NR_GATT_CLIENTS; i++){ 835 context = btstack_memory_gatt_client_get(); 836 CHECK(context != NULL); 837 } 838 #endif 839 #endif 840 // get one more 841 context = btstack_memory_gatt_client_get(); 842 CHECK(context == NULL); 843 } 844 845 846 847 TEST(btstack_memory, hids_client_GetAndFree){ 848 hids_client_t * context; 849 #ifdef HAVE_MALLOC 850 context = btstack_memory_hids_client_get(); 851 CHECK(context != NULL); 852 btstack_memory_hids_client_free(context); 853 #else 854 #ifdef MAX_NR_HIDS_CLIENTS 855 // single 856 context = btstack_memory_hids_client_get(); 857 CHECK(context != NULL); 858 btstack_memory_hids_client_free(context); 859 #else 860 // none 861 context = btstack_memory_hids_client_get(); 862 CHECK(context == NULL); 863 btstack_memory_hids_client_free(context); 864 #endif 865 #endif 866 } 867 868 TEST(btstack_memory, hids_client_NotEnoughBuffers){ 869 hids_client_t * context; 870 #ifdef HAVE_MALLOC 871 simulate_no_memory = 1; 872 #else 873 #ifdef MAX_NR_HIDS_CLIENTS 874 int i; 875 // alloc all static buffers 876 for (i = 0; i < MAX_NR_HIDS_CLIENTS; i++){ 877 context = btstack_memory_hids_client_get(); 878 CHECK(context != NULL); 879 } 880 #endif 881 #endif 882 // get one more 883 context = btstack_memory_hids_client_get(); 884 CHECK(context == NULL); 885 } 886 887 888 889 TEST(btstack_memory, scan_parameters_service_client_GetAndFree){ 890 scan_parameters_service_client_t * context; 891 #ifdef HAVE_MALLOC 892 context = btstack_memory_scan_parameters_service_client_get(); 893 CHECK(context != NULL); 894 btstack_memory_scan_parameters_service_client_free(context); 895 #else 896 #ifdef MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS 897 // single 898 context = btstack_memory_scan_parameters_service_client_get(); 899 CHECK(context != NULL); 900 btstack_memory_scan_parameters_service_client_free(context); 901 #else 902 // none 903 context = btstack_memory_scan_parameters_service_client_get(); 904 CHECK(context == NULL); 905 btstack_memory_scan_parameters_service_client_free(context); 906 #endif 907 #endif 908 } 909 910 TEST(btstack_memory, scan_parameters_service_client_NotEnoughBuffers){ 911 scan_parameters_service_client_t * context; 912 #ifdef HAVE_MALLOC 913 simulate_no_memory = 1; 914 #else 915 #ifdef MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS 916 int i; 917 // alloc all static buffers 918 for (i = 0; i < MAX_NR_SCAN_PARAMETERS_SERVICE_CLIENTS; i++){ 919 context = btstack_memory_scan_parameters_service_client_get(); 920 CHECK(context != NULL); 921 } 922 #endif 923 #endif 924 // get one more 925 context = btstack_memory_scan_parameters_service_client_get(); 926 CHECK(context == NULL); 927 } 928 929 930 931 TEST(btstack_memory, sm_lookup_entry_GetAndFree){ 932 sm_lookup_entry_t * context; 933 #ifdef HAVE_MALLOC 934 context = btstack_memory_sm_lookup_entry_get(); 935 CHECK(context != NULL); 936 btstack_memory_sm_lookup_entry_free(context); 937 #else 938 #ifdef MAX_NR_SM_LOOKUP_ENTRIES 939 // single 940 context = btstack_memory_sm_lookup_entry_get(); 941 CHECK(context != NULL); 942 btstack_memory_sm_lookup_entry_free(context); 943 #else 944 // none 945 context = btstack_memory_sm_lookup_entry_get(); 946 CHECK(context == NULL); 947 btstack_memory_sm_lookup_entry_free(context); 948 #endif 949 #endif 950 } 951 952 TEST(btstack_memory, sm_lookup_entry_NotEnoughBuffers){ 953 sm_lookup_entry_t * context; 954 #ifdef HAVE_MALLOC 955 simulate_no_memory = 1; 956 #else 957 #ifdef MAX_NR_SM_LOOKUP_ENTRIES 958 int i; 959 // alloc all static buffers 960 for (i = 0; i < MAX_NR_SM_LOOKUP_ENTRIES; i++){ 961 context = btstack_memory_sm_lookup_entry_get(); 962 CHECK(context != NULL); 963 } 964 #endif 965 #endif 966 // get one more 967 context = btstack_memory_sm_lookup_entry_get(); 968 CHECK(context == NULL); 969 } 970 971 972 973 TEST(btstack_memory, whitelist_entry_GetAndFree){ 974 whitelist_entry_t * context; 975 #ifdef HAVE_MALLOC 976 context = btstack_memory_whitelist_entry_get(); 977 CHECK(context != NULL); 978 btstack_memory_whitelist_entry_free(context); 979 #else 980 #ifdef MAX_NR_WHITELIST_ENTRIES 981 // single 982 context = btstack_memory_whitelist_entry_get(); 983 CHECK(context != NULL); 984 btstack_memory_whitelist_entry_free(context); 985 #else 986 // none 987 context = btstack_memory_whitelist_entry_get(); 988 CHECK(context == NULL); 989 btstack_memory_whitelist_entry_free(context); 990 #endif 991 #endif 992 } 993 994 TEST(btstack_memory, whitelist_entry_NotEnoughBuffers){ 995 whitelist_entry_t * context; 996 #ifdef HAVE_MALLOC 997 simulate_no_memory = 1; 998 #else 999 #ifdef MAX_NR_WHITELIST_ENTRIES 1000 int i; 1001 // alloc all static buffers 1002 for (i = 0; i < MAX_NR_WHITELIST_ENTRIES; i++){ 1003 context = btstack_memory_whitelist_entry_get(); 1004 CHECK(context != NULL); 1005 } 1006 #endif 1007 #endif 1008 // get one more 1009 context = btstack_memory_whitelist_entry_get(); 1010 CHECK(context == NULL); 1011 } 1012 1013 1014 1015 TEST(btstack_memory, periodic_advertiser_list_entry_GetAndFree){ 1016 periodic_advertiser_list_entry_t * context; 1017 #ifdef HAVE_MALLOC 1018 context = btstack_memory_periodic_advertiser_list_entry_get(); 1019 CHECK(context != NULL); 1020 btstack_memory_periodic_advertiser_list_entry_free(context); 1021 #else 1022 #ifdef MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES 1023 // single 1024 context = btstack_memory_periodic_advertiser_list_entry_get(); 1025 CHECK(context != NULL); 1026 btstack_memory_periodic_advertiser_list_entry_free(context); 1027 #else 1028 // none 1029 context = btstack_memory_periodic_advertiser_list_entry_get(); 1030 CHECK(context == NULL); 1031 btstack_memory_periodic_advertiser_list_entry_free(context); 1032 #endif 1033 #endif 1034 } 1035 1036 TEST(btstack_memory, periodic_advertiser_list_entry_NotEnoughBuffers){ 1037 periodic_advertiser_list_entry_t * context; 1038 #ifdef HAVE_MALLOC 1039 simulate_no_memory = 1; 1040 #else 1041 #ifdef MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES 1042 int i; 1043 // alloc all static buffers 1044 for (i = 0; i < MAX_NR_PERIODIC_ADVERTISER_LIST_ENTRIES; i++){ 1045 context = btstack_memory_periodic_advertiser_list_entry_get(); 1046 CHECK(context != NULL); 1047 } 1048 #endif 1049 #endif 1050 // get one more 1051 context = btstack_memory_periodic_advertiser_list_entry_get(); 1052 CHECK(context == NULL); 1053 } 1054 1055 #endif 1056 #ifdef ENABLE_MESH 1057 1058 1059 TEST(btstack_memory, mesh_network_pdu_GetAndFree){ 1060 mesh_network_pdu_t * context; 1061 #ifdef HAVE_MALLOC 1062 context = btstack_memory_mesh_network_pdu_get(); 1063 CHECK(context != NULL); 1064 btstack_memory_mesh_network_pdu_free(context); 1065 #else 1066 #ifdef MAX_NR_MESH_NETWORK_PDUS 1067 // single 1068 context = btstack_memory_mesh_network_pdu_get(); 1069 CHECK(context != NULL); 1070 btstack_memory_mesh_network_pdu_free(context); 1071 #else 1072 // none 1073 context = btstack_memory_mesh_network_pdu_get(); 1074 CHECK(context == NULL); 1075 btstack_memory_mesh_network_pdu_free(context); 1076 #endif 1077 #endif 1078 } 1079 1080 TEST(btstack_memory, mesh_network_pdu_NotEnoughBuffers){ 1081 mesh_network_pdu_t * context; 1082 #ifdef HAVE_MALLOC 1083 simulate_no_memory = 1; 1084 #else 1085 #ifdef MAX_NR_MESH_NETWORK_PDUS 1086 int i; 1087 // alloc all static buffers 1088 for (i = 0; i < MAX_NR_MESH_NETWORK_PDUS; i++){ 1089 context = btstack_memory_mesh_network_pdu_get(); 1090 CHECK(context != NULL); 1091 } 1092 #endif 1093 #endif 1094 // get one more 1095 context = btstack_memory_mesh_network_pdu_get(); 1096 CHECK(context == NULL); 1097 } 1098 1099 1100 1101 TEST(btstack_memory, mesh_segmented_pdu_GetAndFree){ 1102 mesh_segmented_pdu_t * context; 1103 #ifdef HAVE_MALLOC 1104 context = btstack_memory_mesh_segmented_pdu_get(); 1105 CHECK(context != NULL); 1106 btstack_memory_mesh_segmented_pdu_free(context); 1107 #else 1108 #ifdef MAX_NR_MESH_SEGMENTED_PDUS 1109 // single 1110 context = btstack_memory_mesh_segmented_pdu_get(); 1111 CHECK(context != NULL); 1112 btstack_memory_mesh_segmented_pdu_free(context); 1113 #else 1114 // none 1115 context = btstack_memory_mesh_segmented_pdu_get(); 1116 CHECK(context == NULL); 1117 btstack_memory_mesh_segmented_pdu_free(context); 1118 #endif 1119 #endif 1120 } 1121 1122 TEST(btstack_memory, mesh_segmented_pdu_NotEnoughBuffers){ 1123 mesh_segmented_pdu_t * context; 1124 #ifdef HAVE_MALLOC 1125 simulate_no_memory = 1; 1126 #else 1127 #ifdef MAX_NR_MESH_SEGMENTED_PDUS 1128 int i; 1129 // alloc all static buffers 1130 for (i = 0; i < MAX_NR_MESH_SEGMENTED_PDUS; i++){ 1131 context = btstack_memory_mesh_segmented_pdu_get(); 1132 CHECK(context != NULL); 1133 } 1134 #endif 1135 #endif 1136 // get one more 1137 context = btstack_memory_mesh_segmented_pdu_get(); 1138 CHECK(context == NULL); 1139 } 1140 1141 1142 1143 TEST(btstack_memory, mesh_upper_transport_pdu_GetAndFree){ 1144 mesh_upper_transport_pdu_t * context; 1145 #ifdef HAVE_MALLOC 1146 context = btstack_memory_mesh_upper_transport_pdu_get(); 1147 CHECK(context != NULL); 1148 btstack_memory_mesh_upper_transport_pdu_free(context); 1149 #else 1150 #ifdef MAX_NR_MESH_UPPER_TRANSPORT_PDUS 1151 // single 1152 context = btstack_memory_mesh_upper_transport_pdu_get(); 1153 CHECK(context != NULL); 1154 btstack_memory_mesh_upper_transport_pdu_free(context); 1155 #else 1156 // none 1157 context = btstack_memory_mesh_upper_transport_pdu_get(); 1158 CHECK(context == NULL); 1159 btstack_memory_mesh_upper_transport_pdu_free(context); 1160 #endif 1161 #endif 1162 } 1163 1164 TEST(btstack_memory, mesh_upper_transport_pdu_NotEnoughBuffers){ 1165 mesh_upper_transport_pdu_t * context; 1166 #ifdef HAVE_MALLOC 1167 simulate_no_memory = 1; 1168 #else 1169 #ifdef MAX_NR_MESH_UPPER_TRANSPORT_PDUS 1170 int i; 1171 // alloc all static buffers 1172 for (i = 0; i < MAX_NR_MESH_UPPER_TRANSPORT_PDUS; i++){ 1173 context = btstack_memory_mesh_upper_transport_pdu_get(); 1174 CHECK(context != NULL); 1175 } 1176 #endif 1177 #endif 1178 // get one more 1179 context = btstack_memory_mesh_upper_transport_pdu_get(); 1180 CHECK(context == NULL); 1181 } 1182 1183 1184 1185 TEST(btstack_memory, mesh_network_key_GetAndFree){ 1186 mesh_network_key_t * context; 1187 #ifdef HAVE_MALLOC 1188 context = btstack_memory_mesh_network_key_get(); 1189 CHECK(context != NULL); 1190 btstack_memory_mesh_network_key_free(context); 1191 #else 1192 #ifdef MAX_NR_MESH_NETWORK_KEYS 1193 // single 1194 context = btstack_memory_mesh_network_key_get(); 1195 CHECK(context != NULL); 1196 btstack_memory_mesh_network_key_free(context); 1197 #else 1198 // none 1199 context = btstack_memory_mesh_network_key_get(); 1200 CHECK(context == NULL); 1201 btstack_memory_mesh_network_key_free(context); 1202 #endif 1203 #endif 1204 } 1205 1206 TEST(btstack_memory, mesh_network_key_NotEnoughBuffers){ 1207 mesh_network_key_t * context; 1208 #ifdef HAVE_MALLOC 1209 simulate_no_memory = 1; 1210 #else 1211 #ifdef MAX_NR_MESH_NETWORK_KEYS 1212 int i; 1213 // alloc all static buffers 1214 for (i = 0; i < MAX_NR_MESH_NETWORK_KEYS; i++){ 1215 context = btstack_memory_mesh_network_key_get(); 1216 CHECK(context != NULL); 1217 } 1218 #endif 1219 #endif 1220 // get one more 1221 context = btstack_memory_mesh_network_key_get(); 1222 CHECK(context == NULL); 1223 } 1224 1225 1226 1227 TEST(btstack_memory, mesh_transport_key_GetAndFree){ 1228 mesh_transport_key_t * context; 1229 #ifdef HAVE_MALLOC 1230 context = btstack_memory_mesh_transport_key_get(); 1231 CHECK(context != NULL); 1232 btstack_memory_mesh_transport_key_free(context); 1233 #else 1234 #ifdef MAX_NR_MESH_TRANSPORT_KEYS 1235 // single 1236 context = btstack_memory_mesh_transport_key_get(); 1237 CHECK(context != NULL); 1238 btstack_memory_mesh_transport_key_free(context); 1239 #else 1240 // none 1241 context = btstack_memory_mesh_transport_key_get(); 1242 CHECK(context == NULL); 1243 btstack_memory_mesh_transport_key_free(context); 1244 #endif 1245 #endif 1246 } 1247 1248 TEST(btstack_memory, mesh_transport_key_NotEnoughBuffers){ 1249 mesh_transport_key_t * context; 1250 #ifdef HAVE_MALLOC 1251 simulate_no_memory = 1; 1252 #else 1253 #ifdef MAX_NR_MESH_TRANSPORT_KEYS 1254 int i; 1255 // alloc all static buffers 1256 for (i = 0; i < MAX_NR_MESH_TRANSPORT_KEYS; i++){ 1257 context = btstack_memory_mesh_transport_key_get(); 1258 CHECK(context != NULL); 1259 } 1260 #endif 1261 #endif 1262 // get one more 1263 context = btstack_memory_mesh_transport_key_get(); 1264 CHECK(context == NULL); 1265 } 1266 1267 1268 1269 TEST(btstack_memory, mesh_virtual_address_GetAndFree){ 1270 mesh_virtual_address_t * context; 1271 #ifdef HAVE_MALLOC 1272 context = btstack_memory_mesh_virtual_address_get(); 1273 CHECK(context != NULL); 1274 btstack_memory_mesh_virtual_address_free(context); 1275 #else 1276 #ifdef MAX_NR_MESH_VIRTUAL_ADDRESSS 1277 // single 1278 context = btstack_memory_mesh_virtual_address_get(); 1279 CHECK(context != NULL); 1280 btstack_memory_mesh_virtual_address_free(context); 1281 #else 1282 // none 1283 context = btstack_memory_mesh_virtual_address_get(); 1284 CHECK(context == NULL); 1285 btstack_memory_mesh_virtual_address_free(context); 1286 #endif 1287 #endif 1288 } 1289 1290 TEST(btstack_memory, mesh_virtual_address_NotEnoughBuffers){ 1291 mesh_virtual_address_t * context; 1292 #ifdef HAVE_MALLOC 1293 simulate_no_memory = 1; 1294 #else 1295 #ifdef MAX_NR_MESH_VIRTUAL_ADDRESSS 1296 int i; 1297 // alloc all static buffers 1298 for (i = 0; i < MAX_NR_MESH_VIRTUAL_ADDRESSS; i++){ 1299 context = btstack_memory_mesh_virtual_address_get(); 1300 CHECK(context != NULL); 1301 } 1302 #endif 1303 #endif 1304 // get one more 1305 context = btstack_memory_mesh_virtual_address_get(); 1306 CHECK(context == NULL); 1307 } 1308 1309 1310 1311 TEST(btstack_memory, mesh_subnet_GetAndFree){ 1312 mesh_subnet_t * context; 1313 #ifdef HAVE_MALLOC 1314 context = btstack_memory_mesh_subnet_get(); 1315 CHECK(context != NULL); 1316 btstack_memory_mesh_subnet_free(context); 1317 #else 1318 #ifdef MAX_NR_MESH_SUBNETS 1319 // single 1320 context = btstack_memory_mesh_subnet_get(); 1321 CHECK(context != NULL); 1322 btstack_memory_mesh_subnet_free(context); 1323 #else 1324 // none 1325 context = btstack_memory_mesh_subnet_get(); 1326 CHECK(context == NULL); 1327 btstack_memory_mesh_subnet_free(context); 1328 #endif 1329 #endif 1330 } 1331 1332 TEST(btstack_memory, mesh_subnet_NotEnoughBuffers){ 1333 mesh_subnet_t * context; 1334 #ifdef HAVE_MALLOC 1335 simulate_no_memory = 1; 1336 #else 1337 #ifdef MAX_NR_MESH_SUBNETS 1338 int i; 1339 // alloc all static buffers 1340 for (i = 0; i < MAX_NR_MESH_SUBNETS; i++){ 1341 context = btstack_memory_mesh_subnet_get(); 1342 CHECK(context != NULL); 1343 } 1344 #endif 1345 #endif 1346 // get one more 1347 context = btstack_memory_mesh_subnet_get(); 1348 CHECK(context == NULL); 1349 } 1350 1351 #endif 1352 1353 int main (int argc, const char * argv[]){ 1354 return CommandLineTestRunner::RunAllTests(argc, argv); 1355 } 1356 1357