Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BASE: added test of basic operations for malloc_with_hint #45

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 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,15 @@ 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, 13, rc);
if (rc == TC_NONE) {
rc = TC_PASS;
}
}

return rc;
}

Expand Down Expand Up @@ -759,3 +770,83 @@ 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() */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we also check realloc(NULL)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

realloc(NULL) is tested in another case (

p1 = shrealloc(0, 333); /* works as malloc() */
)

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

shmem_free(p2);
return TC_PASS;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there something like TC_SKIP?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is, but it is used in aggregate test state (higher level). here is no way to set personal test result.
I updated logging of tests to print more accurate results, also added warning message on missing API

#else
log_warn(OSH_TC, "shmemx_malloc_with_hint is not implemented\n");
return TC_NONE;
#endif /* HAVE_DECL_SHMEMX_MALLOC_WITH_HINT */
}

9 changes: 8 additions & 1 deletion verifier/cmn/osh_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,14 @@ void log_help(const char* format, ...);
#define log_item( node, id, rc ) \
{ \
_shmem_sync_result(rc); \
log_trace(OSH_TC, "...TC: %s TI #%d result: %s\n", (node && node->name ? node->name : "unknown" ), (id), ( !(rc) ? "PASS" : "FAIL" ) ); \
log_trace(OSH_TC, "...TC: %s TI #%d result: %s\n", \
(node && node->name ? node->name : "unknown"), \
(id), \
((rc == TC_PASS) ? "PASS" : \
(rc == TC_FAIL) ? "FAIL" : \
(rc == TC_SETUP_FAIL) ? "SETUP FAIL" : \
(rc == TC_NONE ? "NONE" : \
"UNKNOWN"))); \
}


Expand Down
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