Skip to content

Commit ef37478

Browse files
author
Sergey Oblomov
committed
BASE: added test of basic operations for malloc_with_hint
Signed-off-by: Sergey Oblomov <[email protected]>
1 parent e1d39bb commit ef37478

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

verifier/basic/osh_basic_tc3.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "osh_log.h"
1313

1414
#include "shmem.h"
15+
#include "shmemx.h"
1516

1617
#include "osh_basic_tests.h"
1718

@@ -32,6 +33,7 @@ static int test_shmem_ptr();
3233
static int test_allocation_size(void);
3334
static int test_global_vars(void);
3435
static int test_max_size(void);
36+
static int test_alloc_with_hint(void);
3537

3638
#ifdef QUICK_TEST
3739
#define LOOP_COUNT 100
@@ -153,6 +155,12 @@ int osh_basic_tc3(const TE_NODE *node, int argc, const char *argv[])
153155
log_item(node, 12, rc);
154156
}
155157

158+
if (rc == TC_PASS)
159+
{
160+
rc = test_alloc_with_hint();
161+
log_item(node, 12, rc);
162+
}
163+
156164
return rc;
157165
}
158166

@@ -759,3 +767,53 @@ static int test_global_vars()
759767
return TC_PASS;
760768
}
761769

770+
static int test_alloc_with_hint()
771+
{
772+
#if HAVE_DECL_SHMEMX_MALLOC_WITH_HINT
773+
const size_t alloc_base = 32;
774+
const size_t alloc_growed = 64;
775+
const size_t alloc_reduced = 16;
776+
char *p1, *p2;
777+
778+
p1 = shmemx_malloc_with_hint(alloc_base, SHMEM_HINT_DEVICE_NIC_MEM);
779+
if (!p1)
780+
return TC_FAIL;
781+
782+
memset(p1, 0xEF, alloc_base);
783+
784+
p2 = shmem_realloc(p1, alloc_reduced);
785+
if (!p2)
786+
{
787+
log_debug(OSH_TC, "Failed to realloc hinted memory\n");
788+
return TC_FAIL;
789+
}
790+
791+
if (__verify(p2, alloc_reduced, 0xEF) == TC_FAIL)
792+
{
793+
log_debug(OSH_TC, "Failed to verify from %zu to %zu\n", alloc_base, alloc_reduced);
794+
return TC_FAIL;
795+
}
796+
797+
p1 = shmem_realloc(p2, alloc_growed);
798+
if (!p1)
799+
{
800+
log_debug(OSH_TC, "Failed to realloc from %zu to %zu\n", alloc_reduced, alloc_growed);
801+
return TC_FAIL;
802+
}
803+
if (__verify(p1, alloc_reduced, 0xEF) == TC_FAIL)
804+
{
805+
log_debug(OSH_TC, "Failed to verify from %zu to %zu\n", alloc_reduced, alloc_growed);
806+
return TC_FAIL;
807+
}
808+
809+
/* corner cases */
810+
p2 = shmem_realloc(p1, 0); /* works as shfree() */
811+
if (p2)
812+
{
813+
log_debug(OSH_TC, "failed shrealloc as shfree()\n");
814+
return TC_FAIL;
815+
}
816+
#endif /* HAVE_DECL_SHMEMX_MALLOC_WITH_HINT */
817+
return TC_PASS;
818+
}
819+

verifier/configure.ac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ AC_CHECK_DECLS([shmem_uint_atomic_and, shmem_ulong_atomic_and, shmem_ulonglong_a
7474
shmem_uint_atomic_xor, shmem_ulong_atomic_xor, shmem_ulonglong_atomic_xor],
7575
[], [], [#include "shmem.h"])
7676

77+
AC_CHECK_DECLS([shmemx_malloc_with_hint], [], [], [#include "shmemx.h"])
78+
7779
AC_CHECK_HEADERS([unistd.h])
7880
AC_CONFIG_FILES([Makefile])
7981
AC_OUTPUT

0 commit comments

Comments
 (0)