diff --git a/verifier/basic/osh_basic_tc3.c b/verifier/basic/osh_basic_tc3.c index e503146..5e63699 100644 --- a/verifier/basic/osh_basic_tc3.c +++ b/verifier/basic/osh_basic_tc3.c @@ -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; +#else + log_warn(OSH_TC, "shmemx_malloc_with_hint is not implemented\n"); + return TC_NONE; +#endif /* HAVE_DECL_SHMEMX_MALLOC_WITH_HINT */ +} + diff --git a/verifier/cmn/osh_log.h b/verifier/cmn/osh_log.h index b4e0ce0..319d757 100644 --- a/verifier/cmn/osh_log.h +++ b/verifier/cmn/osh_log.h @@ -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"))); \ } diff --git a/verifier/configure.ac b/verifier/configure.ac index 0c3f655..941b440 100644 --- a/verifier/configure.ac +++ b/verifier/configure.ac @@ -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