Skip to content

Commit 77f7de7

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 77f7de7

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

verifier/basic/osh_basic_tc3.c

Lines changed: 85 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,80 @@ 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+
log_debug(OSH_TC, "testting malloc_with_hint\n");
779+
780+
p1 = shmemx_malloc_with_hint(alloc_base, SHMEM_HINT_DEVICE_NIC_MEM);
781+
if (!p1)
782+
{
783+
log_error(OSH_TC, "Failed to allocate hinted memory\n");
784+
return TC_FAIL;
785+
}
786+
787+
memset(p1, 0xEF, alloc_base);
788+
789+
p2 = shmem_realloc(p1, alloc_reduced);
790+
if (!p2)
791+
{
792+
log_error(OSH_TC, "Failed to realloc hinted memory\n");
793+
return TC_FAIL;
794+
}
795+
796+
if (__verify(p2, alloc_reduced, 0xEF) == TC_FAIL)
797+
{
798+
log_error(OSH_TC, "Failed to verify from %zu to %zu\n", alloc_base, alloc_reduced);
799+
return TC_FAIL;
800+
}
801+
802+
p1 = shmem_realloc(p2, alloc_growed);
803+
if (!p1)
804+
{
805+
log_error(OSH_TC, "Failed to realloc from %zu to %zu\n", alloc_reduced, alloc_growed);
806+
return TC_FAIL;
807+
}
808+
if (__verify(p1, alloc_reduced, 0xEF) == TC_FAIL)
809+
{
810+
log_error(OSH_TC, "Failed to verify from %zu to %zu\n", alloc_reduced, alloc_growed);
811+
return TC_FAIL;
812+
}
813+
814+
/* allocate one more buffer to block in-place realloc */
815+
p2 = shmemx_malloc_with_hint(alloc_base, SHMEM_HINT_DEVICE_NIC_MEM);
816+
if (!p2)
817+
{
818+
log_error(OSH_TC, "Failed to allocate hinted memory\n");
819+
return TC_FAIL;
820+
}
821+
p1 = shmem_realloc(p1, alloc_growed * 2);
822+
if (!p1)
823+
{
824+
log_error(OSH_TC, "Failed to realloc from %zu to %zu\n", alloc_growed, alloc_growed * 2);
825+
return TC_FAIL;
826+
}
827+
if (__verify(p1, alloc_reduced, 0xEF) == TC_FAIL)
828+
{
829+
log_error(OSH_TC, "Failed to verify from %zu to %zu (non-implace)\n", alloc_growed, alloc_growed * 2);
830+
return TC_FAIL;
831+
}
832+
shmem_free(p2);
833+
834+
/* corner cases */
835+
p2 = shmem_realloc(p1, 0); /* works as shfree() */
836+
if (!p2) /* returned pointer should NOT be NULL */
837+
{
838+
log_error(OSH_TC, "failed shrealloc as shfree()\n");
839+
return TC_FAIL;
840+
}
841+
842+
shmem_free(p2);
843+
#endif /* HAVE_DECL_SHMEMX_MALLOC_WITH_HINT */
844+
return TC_PASS;
845+
}
846+

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)