| 734 | #endif /* !RTE_EXEC_ENV_WINDOWS */ |
| 735 | |
| 736 | static int |
| 737 | test_random_alloc_free(void *_ __rte_unused) |
| 738 | { |
| 739 | struct mem_list { |
| 740 | struct mem_list *next; |
| 741 | char data[0]; |
| 742 | } *list_head = NULL; |
| 743 | unsigned i; |
| 744 | unsigned count = 0; |
| 745 | |
| 746 | rte_srand((unsigned)rte_rdtsc()); |
| 747 | |
| 748 | for (i = 0; i < N; i++){ |
| 749 | unsigned free_mem = 0; |
| 750 | size_t allocated_size; |
| 751 | while (!free_mem){ |
| 752 | const unsigned mem_size = sizeof(struct mem_list) + \ |
| 753 | rte_rand() % (64 * 1024); |
| 754 | const unsigned align = 1 << (rte_rand() % 12); /* up to 4k alignment */ |
| 755 | struct mem_list *entry = rte_malloc(NULL, |
| 756 | mem_size, align); |
| 757 | if (entry == NULL) |
| 758 | return -1; |
| 759 | if (RTE_PTR_ALIGN(entry, align)!= entry) |
| 760 | return -1; |
| 761 | if (rte_malloc_validate(entry, &allocated_size) == -1 |
| 762 | || allocated_size < mem_size) |
| 763 | return -1; |
| 764 | memset(entry->data, rte_lcore_id(), |
| 765 | mem_size - sizeof(*entry)); |
| 766 | entry->next = list_head; |
| 767 | if (rte_malloc_validate(entry, NULL) == -1) |
| 768 | return -1; |
| 769 | list_head = entry; |
| 770 | |
| 771 | count++; |
| 772 | /* switch to freeing the memory with a 20% probability */ |
| 773 | free_mem = ((rte_rand() % 10) >= 8); |
| 774 | } |
| 775 | while (list_head){ |
| 776 | struct mem_list *entry = list_head; |
| 777 | list_head = list_head->next; |
| 778 | rte_free(entry); |
| 779 | } |
| 780 | } |
| 781 | printf("Lcore %u allocated/freed %u blocks\n", rte_lcore_id(), count); |
| 782 | return 0; |
| 783 | } |
| 784 | |
| 785 | #define err_return() do { \ |
| 786 | printf("%s: %d - Error\n", __func__, __LINE__); \ |
nothing calls this directly
no test coverage detected