| 434 | #else |
| 435 | |
| 436 | static int |
| 437 | test_realloc_socket(int socket) |
| 438 | { |
| 439 | const char hello_str[] = "Hello, world!"; |
| 440 | const unsigned size1 = 1024; |
| 441 | const unsigned size2 = size1 + 1024; |
| 442 | const unsigned size3 = size2; |
| 443 | const unsigned size4 = size3 + 1024; |
| 444 | |
| 445 | /* test data is the same even if element is moved*/ |
| 446 | char *ptr1 = rte_zmalloc_socket( |
| 447 | NULL, size1, RTE_CACHE_LINE_SIZE, socket); |
| 448 | if (!ptr1){ |
| 449 | printf("NULL pointer returned from rte_zmalloc\n"); |
| 450 | return -1; |
| 451 | } |
| 452 | strlcpy(ptr1, hello_str, size1); |
| 453 | char *ptr2 = rte_realloc_socket( |
| 454 | ptr1, size2, RTE_CACHE_LINE_SIZE, socket); |
| 455 | if (!ptr2){ |
| 456 | rte_free(ptr1); |
| 457 | printf("NULL pointer returned from rte_realloc\n"); |
| 458 | return -1; |
| 459 | } |
| 460 | if (ptr1 == ptr2){ |
| 461 | printf("unexpected - ptr1 == ptr2\n"); |
| 462 | } |
| 463 | if (strcmp(ptr2, hello_str) != 0){ |
| 464 | printf("Error - lost data from pointed area\n"); |
| 465 | rte_free(ptr2); |
| 466 | return -1; |
| 467 | } |
| 468 | unsigned i; |
| 469 | for (i = strnlen(hello_str, sizeof(hello_str)); i < size1; i++) |
| 470 | if (ptr2[i] != 0){ |
| 471 | printf("Bad data in realloc\n"); |
| 472 | rte_free(ptr2); |
| 473 | return -1; |
| 474 | } |
| 475 | /* now allocate third element, free the second |
| 476 | * and resize third. It should not move. (ptr1 is now invalid) |
| 477 | */ |
| 478 | char *ptr3 = rte_zmalloc_socket( |
| 479 | NULL, size3, RTE_CACHE_LINE_SIZE, socket); |
| 480 | if (!ptr3){ |
| 481 | printf("NULL pointer returned from rte_zmalloc\n"); |
| 482 | rte_free(ptr2); |
| 483 | return -1; |
| 484 | } |
| 485 | for (i = 0; i < size3; i++) |
| 486 | if (ptr3[i] != 0){ |
| 487 | printf("Bad data in zmalloc\n"); |
| 488 | rte_free(ptr3); |
| 489 | rte_free(ptr2); |
| 490 | return -1; |
| 491 | } |
| 492 | rte_free(ptr2); |
| 493 | /* first resize to half the size of the freed block */ |
no test coverage detected