test/mpool_tests.c

changeset 113
8693d7874773
parent 103
08018864fb91
child 131
fc3af16818a3
     1.1 --- a/test/mpool_tests.c	Mon Jul 15 15:43:18 2013 +0200
     1.2 +++ b/test/mpool_tests.c	Mon Jul 15 16:59:52 2013 +0200
     1.3 @@ -37,7 +37,7 @@
     1.4      UCX_TEST_ASSERT(pool->ndata == 0, "uninitialized counter");
     1.5      UCX_TEST_ASSERT(pool->data != NULL, "no memory addressed");
     1.6      UCX_TEST_END
     1.7 -    ucx_mempool_free(pool);
     1.8 +    ucx_mempool_destroy(pool);
     1.9  }
    1.10  
    1.11  UCX_TEST_IMPLEMENT(test_ucx_mempool_malloc) {
    1.12 @@ -56,7 +56,7 @@
    1.13      UCX_TEST_ASSERT(*test == 5, "wrong pointer");
    1.14      
    1.15      UCX_TEST_END
    1.16 -    ucx_mempool_free(pool);
    1.17 +    ucx_mempool_destroy(pool);
    1.18  }
    1.19  
    1.20  UCX_TEST_IMPLEMENT(test_ucx_mempool_malloc_with_chcap) {
    1.21 @@ -76,7 +76,7 @@
    1.22      UCX_TEST_ASSERT(*test == 5, "wrong pointer");
    1.23      
    1.24      UCX_TEST_END
    1.25 -    ucx_mempool_free(pool);
    1.26 +    ucx_mempool_destroy(pool);
    1.27  }
    1.28  
    1.29  UCX_TEST_IMPLEMENT(test_ucx_mempool_calloc) {
    1.30 @@ -90,7 +90,37 @@
    1.31      UCX_TEST_ASSERT(test[0] == 0 && test[1] == 0, "failed");
    1.32      
    1.33      UCX_TEST_END
    1.34 -    ucx_mempool_free(pool);
    1.35 +    ucx_mempool_destroy(pool);
    1.36 +}
    1.37 +
    1.38 +UCX_TEST_IMPLEMENT(test_ucx_mempool_free) {
    1.39 +    UcxMempool *pool = ucx_mempool_new(16);
    1.40 +    void *mem1;
    1.41 +    void *mem2;
    1.42 +    
    1.43 +    UCX_TEST_BEGIN
    1.44 +    
    1.45 +    mem1 = ucx_mempool_malloc(pool, 16);
    1.46 +    ucx_mempool_free(pool, mem1);
    1.47 +    
    1.48 +    UCX_TEST_ASSERT(pool->ndata == 0, "mempool not empty");
    1.49 +    
    1.50 +    ucx_mempool_malloc(pool, 16);
    1.51 +    ucx_mempool_malloc(pool, 16);
    1.52 +    mem1 = ucx_mempool_malloc(pool, 16);
    1.53 +    ucx_mempool_malloc(pool, 16);
    1.54 +    mem2 = ucx_mempool_malloc(pool, 16);
    1.55 +    
    1.56 +    ucx_mempool_free(pool, mem1);
    1.57 +    
    1.58 +    UCX_TEST_ASSERT(pool->ndata == 4, "wrong mempool size");
    1.59 +    
    1.60 +    ucx_mempool_free(pool, mem2);
    1.61 +    
    1.62 +    UCX_TEST_ASSERT(pool->ndata == 3, "wrong mempool size");
    1.63 +    
    1.64 +    UCX_TEST_END
    1.65 +    ucx_mempool_destroy(pool);
    1.66  }
    1.67  
    1.68  void test_setdestr(void* elem) {
    1.69 @@ -118,7 +148,7 @@
    1.70      UCX_TEST_ASSERT(
    1.71              test[0] == 5 && test[1] == (intptr_t) cb, "setdestr destroyed data")
    1.72      
    1.73 -    ucx_mempool_free(pool);
    1.74 +    ucx_mempool_destroy(pool);
    1.75      
    1.76      UCX_TEST_ASSERT(*cb == 42, "destructor not called");
    1.77      
    1.78 @@ -146,7 +176,7 @@
    1.79      
    1.80      UCX_TEST_ASSERT(*pooladdr == test_setdestr, "failed");
    1.81      
    1.82 -    ucx_mempool_free(pool);
    1.83 +    ucx_mempool_destroy(pool);
    1.84      UCX_TEST_ASSERT(*cb == 42, "destructor not called");
    1.85      UCX_TEST_END
    1.86  
    1.87 @@ -183,7 +213,7 @@
    1.88      UCX_TEST_ASSERT(
    1.89              test[0] == 5 && test[1] == (intptr_t) cb, "realloc destroyed data")
    1.90      
    1.91 -    ucx_mempool_free(pool);
    1.92 +    ucx_mempool_destroy(pool);
    1.93      
    1.94      UCX_TEST_ASSERT(*cb == 42, "destructor not called");
    1.95      

mercurial