-
Notifications
You must be signed in to change notification settings - Fork 21
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
base: master
Are you sure you want to change the base?
Changes from all commits
77f7de7
529cf8a
0279dbe
5bf4fef
d0dc980
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
#include "osh_log.h" | ||
|
||
#include "shmem.h" | ||
#include "shmemx.h" | ||
|
||
#include "osh_basic_tests.h" | ||
|
||
|
@@ -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 | ||
|
@@ -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; | ||
} | ||
|
||
|
@@ -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() */ | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there something like TC_SKIP? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
#else | ||
log_warn(OSH_TC, "shmemx_malloc_with_hint is not implemented\n"); | ||
return TC_NONE; | ||
#endif /* HAVE_DECL_SHMEMX_MALLOC_WITH_HINT */ | ||
} | ||
|
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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 (
tests-mellanox/verifier/basic/osh_basic_tc3.c
Line 405 in e1d39bb