From 77f7de7154a2ac1850ac16782202fa57ecac7e1c Mon Sep 17 00:00:00 2001 From: Sergey Oblomov Date: Wed, 8 May 2019 11:44:53 +0300 Subject: [PATCH 1/2] BASE: added test of basic operations for malloc_with_hint Signed-off-by: Sergey Oblomov --- verifier/basic/osh_basic_tc3.c | 85 ++++++++++++++++++++++++++++++++++ verifier/configure.ac | 2 + 2 files changed, 87 insertions(+) diff --git a/verifier/basic/osh_basic_tc3.c b/verifier/basic/osh_basic_tc3.c index e503146..1ebb2a2 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,12 @@ 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, 12, rc); + } + return rc; } @@ -759,3 +767,80 @@ 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); +#endif /* HAVE_DECL_SHMEMX_MALLOC_WITH_HINT */ + return TC_PASS; +} + 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 From 529cf8ab3c194dfb0098248692c689b93d1dc8bc Mon Sep 17 00:00:00 2001 From: Sergey Oblomov Date: Fri, 24 May 2019 08:51:55 +0300 Subject: [PATCH 2/2] BASIC: skip test for shmem_malloc_with_hint if not implemented Signed-off-by: Sergey Oblomov --- verifier/basic/osh_basic_tc3.c | 10 ++++++++-- verifier/cmn/osh_log.h | 9 ++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/verifier/basic/osh_basic_tc3.c b/verifier/basic/osh_basic_tc3.c index 1ebb2a2..5e63699 100644 --- a/verifier/basic/osh_basic_tc3.c +++ b/verifier/basic/osh_basic_tc3.c @@ -158,7 +158,10 @@ int osh_basic_tc3(const TE_NODE *node, int argc, const char *argv[]) if (rc == TC_PASS) { rc = test_alloc_with_hint(); - log_item(node, 12, rc); + log_item(node, 13, rc); + if (rc == TC_NONE) { + rc = TC_PASS; + } } return rc; @@ -840,7 +843,10 @@ static int test_alloc_with_hint() } shmem_free(p2); -#endif /* HAVE_DECL_SHMEMX_MALLOC_WITH_HINT */ 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"))); \ }