23 fprintf(stderr, "ucx_mempool_reg_destr failed\n"); |
23 fprintf(stderr, "ucx_mempool_reg_destr failed\n"); |
24 } |
24 } |
25 } |
25 } |
26 |
26 |
27 int mpool_tests() { |
27 int mpool_tests() { |
|
28 int r = 0; |
|
29 |
28 printf(" Test ucx_mempool_new\n"); |
30 printf(" Test ucx_mempool_new\n"); |
29 UcxMempool *pool = ucx_mempool_new(16); |
31 UcxMempool *pool = ucx_mempool_new(16); |
30 |
32 |
31 printf(" Test ucx_mempool_malloc\n"); |
33 printf(" Test ucx_mempool_malloc\n"); |
32 int *ptr1 = (int*)ucx_mempool_malloc(pool, sizeof(int)); |
34 int *ptr1 = (int*)ucx_mempool_malloc(pool, sizeof(int)); |
53 |
55 |
54 printf(" Test ucx_mempool_calloc\n"); |
56 printf(" Test ucx_mempool_calloc\n"); |
55 char *str = ucx_mempool_calloc(pool, 1, 3); |
57 char *str = ucx_mempool_calloc(pool, 1, 3); |
56 if(str[0] != 0 || str[1] != 0 || str[2] != 0) { |
58 if(str[0] != 0 || str[1] != 0 || str[2] != 0) { |
57 fprintf(stderr, "ucx_mempool_calloc failed\n"); |
59 fprintf(stderr, "ucx_mempool_calloc failed\n"); |
|
60 r--; |
58 } |
61 } |
59 str[0] = 'O'; |
62 str[0] = 'O'; |
60 str[1] = 'K'; |
63 str[1] = 'K'; |
61 |
64 |
62 printf(" Test ucx_mempool_realloc\n"); |
65 printf(" Test ucx_mempool_realloc\n"); |
63 str = ucx_mempool_realloc(pool, str, 4); |
66 str = ucx_mempool_realloc(pool, str, 4); |
64 str[2] = '!'; |
67 str[2] = '!'; |
65 str[3] = 0; |
68 str[3] = 0; |
66 if(strcmp(str, "OK!") != 0) { |
69 if(strcmp(str, "OK!") != 0) { |
67 fprintf(stderr, "Test ucx_mempool_realloc failed!\n"); |
70 fprintf(stderr, "Test ucx_mempool_realloc failed!\n"); |
|
71 r--; |
68 } |
72 } |
69 |
73 |
70 printf(" Test ucx_mempool_reg_destr\n"); |
74 printf(" Test ucx_mempool_reg_destr\n"); |
71 char *hello = "Hello World!"; |
75 char *hello = "Hello World!"; |
72 ucx_mempool_reg_destr(pool, hello, (ucx_destructor)hello_destructor); |
76 ucx_mempool_reg_destr(pool, hello, (ucx_destructor)hello_destructor); |
73 |
77 |
74 printf(" Test ucx_mempool_free\n"); |
78 printf(" Test ucx_mempool_free\n"); |
75 //ucx_mempool_free(pool); |
79 //ucx_mempool_free(pool); |
76 |
80 |
77 |
81 |
78 return 0; |
82 return r; |
79 } |
83 } |