Skip to content

Commit

Permalink
BASE: added test of basic operations for malloc_with_hint
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey Oblomov <[email protected]>
  • Loading branch information
Sergey Oblomov committed May 15, 2019
1 parent e1d39bb commit 77f7de7
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
85 changes: 85 additions & 0 deletions verifier/basic/osh_basic_tc3.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "osh_log.h"

#include "shmem.h"
#include "shmemx.h"

#include "osh_basic_tests.h"

Expand All @@ -32,6 +33,7 @@ static int test_shmem_ptr();
static int test_allocation_size(void);
static int test_global_vars(void);
static int test_max_size(void);
static int test_alloc_with_hint(void);

#ifdef QUICK_TEST
#define LOOP_COUNT 100
Expand Down Expand Up @@ -153,6 +155,12 @@ int osh_basic_tc3(const TE_NODE *node, int argc, const char *argv[])
log_item(node, 12, rc);
}

if (rc == TC_PASS)
{
rc = test_alloc_with_hint();
log_item(node, 12, rc);
}

return rc;
}

Expand Down Expand Up @@ -759,3 +767,80 @@ static int test_global_vars()
return TC_PASS;
}

static int test_alloc_with_hint()
{
#if HAVE_DECL_SHMEMX_MALLOC_WITH_HINT
const size_t alloc_base = 32;
const size_t alloc_growed = 64;
const size_t alloc_reduced = 16;
char *p1, *p2;

log_debug(OSH_TC, "testting malloc_with_hint\n");

p1 = shmemx_malloc_with_hint(alloc_base, SHMEM_HINT_DEVICE_NIC_MEM);
if (!p1)
{
log_error(OSH_TC, "Failed to allocate hinted memory\n");
return TC_FAIL;
}

memset(p1, 0xEF, alloc_base);

p2 = shmem_realloc(p1, alloc_reduced);
if (!p2)
{
log_error(OSH_TC, "Failed to realloc hinted memory\n");
return TC_FAIL;
}

if (__verify(p2, alloc_reduced, 0xEF) == TC_FAIL)
{
log_error(OSH_TC, "Failed to verify from %zu to %zu\n", alloc_base, alloc_reduced);
return TC_FAIL;
}

p1 = shmem_realloc(p2, alloc_growed);
if (!p1)
{
log_error(OSH_TC, "Failed to realloc from %zu to %zu\n", alloc_reduced, alloc_growed);
return TC_FAIL;
}
if (__verify(p1, alloc_reduced, 0xEF) == TC_FAIL)
{
log_error(OSH_TC, "Failed to verify from %zu to %zu\n", alloc_reduced, alloc_growed);
return TC_FAIL;
}

/* allocate one more buffer to block in-place realloc */
p2 = shmemx_malloc_with_hint(alloc_base, SHMEM_HINT_DEVICE_NIC_MEM);
if (!p2)
{
log_error(OSH_TC, "Failed to allocate hinted memory\n");
return TC_FAIL;
}
p1 = shmem_realloc(p1, alloc_growed * 2);
if (!p1)
{
log_error(OSH_TC, "Failed to realloc from %zu to %zu\n", alloc_growed, alloc_growed * 2);
return TC_FAIL;
}
if (__verify(p1, alloc_reduced, 0xEF) == TC_FAIL)
{
log_error(OSH_TC, "Failed to verify from %zu to %zu (non-implace)\n", alloc_growed, alloc_growed * 2);
return TC_FAIL;
}
shmem_free(p2);

/* corner cases */
p2 = shmem_realloc(p1, 0); /* works as shfree() */
if (!p2) /* returned pointer should NOT be NULL */
{
log_error(OSH_TC, "failed shrealloc as shfree()\n");
return TC_FAIL;
}

shmem_free(p2);
#endif /* HAVE_DECL_SHMEMX_MALLOC_WITH_HINT */
return TC_PASS;
}

2 changes: 2 additions & 0 deletions verifier/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ AC_CHECK_DECLS([shmem_uint_atomic_and, shmem_ulong_atomic_and, shmem_ulonglong_a
shmem_uint_atomic_xor, shmem_ulong_atomic_xor, shmem_ulonglong_atomic_xor],
[], [], [#include "shmem.h"])

AC_CHECK_DECLS([shmemx_malloc_with_hint], [], [], [#include "shmemx.h"])

AC_CHECK_HEADERS([unistd.h])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

0 comments on commit 77f7de7

Please sign in to comment.