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();
3233static int test_allocation_size (void );
3334static int test_global_vars (void );
3435static 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+
0 commit comments