Exemplo n.º 1
0
static void
test_gf_calloc_mem_acct_enabled(void **state)
{
    xlator_t *xl;
    void *mem;
    size_t size;
    uint32_t type;

    // Initialize xl
    xl = helper_xlator_init(10);
    assert_int_equal(xl->ctx->mem_acct_enable, 0);
    xl->ctx->mem_acct_enable = 1;

    // For line mem-pool.c:115 and mem-pool:118
    will_return_always(__glusterfs_this_location, &xl);

    // Call __gf_calloc
    size = 1024;
    type = 3;
    mem = __gf_calloc(1, size, type, "3");
    assert_non_null(mem);
    memset(mem, 0x5A, size);

    // Check xl values
    assert_int_equal(xl->mem_acct->rec[type].size, size);
    assert_int_equal(xl->mem_acct->rec[type].num_allocs, 1);
    assert_int_equal(xl->mem_acct->rec[type].total_allocs, 1);
    assert_int_equal(xl->mem_acct->rec[type].max_size, size);
    assert_int_equal(xl->mem_acct->rec[type].max_num_allocs, 1);

    // Check memory
    helper_check_memory_headers(mem - sizeof(mem_header_t), xl, size, type);
    free(mem - sizeof(mem_header_t));
    helper_xlator_destroy(xl);
}
Exemplo n.º 2
0
static void
test_gf_calloc_default_calloc(void **state)
{
    xlator_t *xl;
    void *mem;
    size_t size;
    uint32_t type;

    // Initialize xl
    xl = helper_xlator_init(10);
    assert_int_equal(xl->ctx->mem_acct_enable, 0);
    will_return(__glusterfs_this_location, &xl);

    // Call __gf_calloc
    size = 1024;
    type = 3;
    mem = __gf_calloc(1, size, type, "3");
    assert_non_null(mem);
    memset(mem, 0x5A, size);

    // Check xl did not change
    assert_int_equal(xl->mem_acct->rec[type].size, 0);
    assert_int_equal(xl->mem_acct->rec[type].num_allocs, 0);
    assert_int_equal(xl->mem_acct->rec[type].total_allocs, 0);
    assert_int_equal(xl->mem_acct->rec[type].max_size, 0);
    assert_int_equal(xl->mem_acct->rec[type].max_num_allocs, 0);

    free(mem);
    helper_xlator_destroy(xl);
}
Exemplo n.º 3
0
static void
test_gf_realloc_ptr(void **state)
{
    xlator_t *xl;
    void *mem;
    size_t size;

    // Initialize xl
    xl = helper_xlator_init(10);
    assert_int_equal(xl->ctx->mem_acct_enable, 0);

    // For line mem-pool.c:115 and mem-pool:118
    will_return_always(__glusterfs_this_location, &xl);

    // Tests according to the manpage for realloc

    // Like a malloc
    size = 1024;
    mem = __gf_realloc(NULL, size);
    assert_non_null(mem);
    memset(mem, 0xA5, size);

    // Like a free
    mem = __gf_realloc(mem, 0);
    assert_null(mem);

    // Now enable xl context
    xl->ctx->mem_acct_enable = 1;
    expect_assert_failure(__gf_realloc(NULL, size));

    helper_xlator_destroy(xl);
}
Exemplo n.º 4
0
static void
test_gf_mem_set_acct_info_memory(void **state)
{
    xlator_t *xl;
    char *alloc_ptr;
    char *temp_ptr;
    size_t size;
    uint32_t type;
    const char *typestr = "TEST";

    size = 8196;
    type = 9;

    // Initialize xl
    xl = helper_xlator_init(10);
    assert_null(xl->mem_acct.rec[type].typestr);

    // Test allocation
    temp_ptr = test_calloc(1, size + GF_MEM_HEADER_SIZE + GF_MEM_TRAILER_SIZE);
    assert_non_null(temp_ptr);
    alloc_ptr = temp_ptr;
    gf_mem_set_acct_info(xl, &alloc_ptr, size, type, typestr);

    //Check values
    assert_ptr_equal(typestr, xl->mem_acct.rec[type].typestr);
    assert_int_equal(xl->mem_acct.rec[type].size, size);
    assert_int_equal(xl->mem_acct.rec[type].num_allocs, 1);
    assert_int_equal(xl->mem_acct.rec[type].total_allocs, 1);
    assert_int_equal(xl->mem_acct.rec[type].max_size, size);
    assert_int_equal(xl->mem_acct.rec[type].max_num_allocs, 1);

    // Check memory
    helper_check_memory_headers(temp_ptr, xl, size, type);

    // Check that alloc_ptr has been moved correctly
    // by gf_mem_set_acct_info
    {
        mem_header_t *p;

        p = (mem_header_t *)temp_ptr;
        p++;
        p->type = 1234;
        assert_int_equal(*(uint32_t *)alloc_ptr, p->type);
    }

    free(temp_ptr);
    helper_xlator_destroy(xl);
}
Exemplo n.º 5
0
static void
test_gf_realloc_mem_acct_enabled(void **state)
{
    xlator_t *xl;
    void *mem;
    size_t size;
    uint32_t type;

    // Initialize xl
    xl = helper_xlator_init(10);
    assert_int_equal(xl->ctx->mem_acct_enable, 0);
    xl->ctx->mem_acct_enable = 1;

    // For line mem-pool.c:115 and mem-pool:118
    will_always_return(__glusterfs_this_location, &xl);

    // Call __gf_malloc then realloc
    size = 1024;
    type = 3;
    mem = __gf_malloc(size, type, "3");
    assert_non_null(mem);
    memset(mem, 0xA5, size);

    size = 2048;
    mem = __gf_realloc(mem, size);
    assert_non_null(mem);
    memset(mem, 0x5A, size);

    // Check xl values
    //
    // :TODO: This is really weird.  I would have expected
    // xl to only have a size equal to that of the realloc
    // not to the realloc + the malloc.
    // Is this a bug?
    //
    assert_int_equal(xl->mem_acct.rec[type].size, size+1024);
    assert_int_equal(xl->mem_acct.rec[type].num_allocs, 2);
    assert_int_equal(xl->mem_acct.rec[type].total_allocs, 2);
    assert_int_equal(xl->mem_acct.rec[type].max_size, size+1024);
    assert_int_equal(xl->mem_acct.rec[type].max_num_allocs, 2);

    // Check memory
    helper_check_memory_headers(mem - sizeof(mem_header_t), xl, size, type);
    free(mem - sizeof(mem_header_t));
    helper_xlator_destroy(xl);
}
Exemplo n.º 6
0
static void
test_gf_mem_set_acct_info_asserts(void **state)
{
    xlator_t *xl;
    xlator_t xltest;
    char *alloc_ptr;
    size_t size;
    uint32_t type;

    memset(&xltest, 0, sizeof(xlator_t));
    xl = (xlator_t *)0xBADD;
    alloc_ptr = (char *)0xBADD;
    size = 8196;
    type = 0;

    // Check xl is NULL
    expect_assert_failure(
        gf_mem_set_acct_info(NULL, &alloc_ptr, size, type, ""));
    // Check xl->mem_acct = NULL
    expect_assert_failure(
        gf_mem_set_acct_info(&xltest, &alloc_ptr, 0, type, ""));
    // Check type <= xl->mem_acct->num_types
    type = 100;
    expect_assert_failure(
        gf_mem_set_acct_info(&xltest, &alloc_ptr, 0, type, ""));
    // Check alloc is NULL
    assert_int_equal(-1, gf_mem_set_acct_info(&xltest, NULL, size, type, ""));

    // Initialize xl
    xl = helper_xlator_init(10);

    // Test number of types
    type = 100;
    assert_true(NULL != xl->mem_acct);
    assert_true(type > xl->mem_acct->num_types);
    expect_assert_failure(gf_mem_set_acct_info(xl, &alloc_ptr, size, type, ""));

    helper_xlator_destroy(xl);
}