From f6f8a0d1449c44e707e313c680da8ecd64729cd9 Mon Sep 17 00:00:00 2001 From: ROCm CI Service Account <66695075+rocm-ci@users.noreply.github.com> Date: Thu, 2 Jun 2022 17:02:19 +0530 Subject: [PATCH] SWDEV-228445 - New tests for HIP IPC Mem handle APIs (#2705) Change-Id: I721cbbadfdb8a38b53097a8ac8a1c8cb9ce05d49 --- tests/catch/multiproc/CMakeLists.txt | 1 + tests/catch/multiproc/hipIpcMemAccessTest.cc | 70 +++++++++++++++++++- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/tests/catch/multiproc/CMakeLists.txt b/tests/catch/multiproc/CMakeLists.txt index 93b97589b6..c8da597abd 100644 --- a/tests/catch/multiproc/CMakeLists.txt +++ b/tests/catch/multiproc/CMakeLists.txt @@ -13,6 +13,7 @@ set(LINUX_TEST_SRC hipMallocConcurrencyMproc.cc hipMemCoherencyTstMProc.cc hipIpcEventHandle.cc + hipIpcMemAccessTest.cc ) # the last argument linker libraries is required for this test but optional to the function diff --git a/tests/catch/multiproc/hipIpcMemAccessTest.cc b/tests/catch/multiproc/hipIpcMemAccessTest.cc index 183da51c24..6dd0941b4a 100644 --- a/tests/catch/multiproc/hipIpcMemAccessTest.cc +++ b/tests/catch/multiproc/hipIpcMemAccessTest.cc @@ -1,5 +1,5 @@ /* -Copyright (c) 2021 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights @@ -18,8 +18,9 @@ THE SOFTWARE. */ /* -This testcase verifies the hipIpcMemAccess APIs by creating memory handle + 1)Testcase verifies the hipIpcMemAccess APIs by creating memory handle in parent process and access it in child process. + 2)Test case performs Parameter validation of hipIpcMemAccess APIs. */ #include @@ -33,6 +34,11 @@ in parent process and access it in child process. #include #include + +#define NUM_ELMTS 1024 +#define NUM_THREADS 10 + + typedef struct mem_handle { int device; hipIpcMemHandle_t memHandle; @@ -40,6 +46,7 @@ typedef struct mem_handle { } hip_ipc_t; + // This testcase verifies the hipIpcMemAccess APIs as follows // The following program spawns a child process and does the following // Parent iterate through each device, create memory -- create hipIpcMemhandle @@ -153,4 +160,63 @@ TEST_CASE("Unit_hipIpcMemAccess_Semaphores") { waitpid(pid, &rFlag, 0); REQUIRE(shrd_mem->IfTestPassed == true); } + +TEST_CASE("Unit_hipIpcMemAccess_ParameterValidation") { + hipIpcMemHandle_t MemHandle; + hipIpcMemHandle_t MemHandleUninit; + void *Ad{}, *Ad2{}; + hipError_t ret; + + HIP_CHECK(hipMalloc(&Ad, 1024)); + +#if HT_AMD + // Test is disabled for nvidia as api resulting in seg fault. + SECTION("Get mem handle with handle as nullptr") { + ret = hipIpcGetMemHandle(nullptr, Ad); + REQUIRE(ret == hipErrorInvalidValue); + } +#endif + SECTION("Get mem handle with devptr as nullptr") { + ret = hipIpcGetMemHandle(&MemHandle, nullptr); + REQUIRE(ret == hipErrorInvalidValue); + } + + SECTION("Get mem handle with handle/devptr as nullptr") { + ret = hipIpcGetMemHandle(nullptr, nullptr); + REQUIRE(ret == hipErrorInvalidValue); + } + + SECTION("Get mem handle with valid devptr") { + ret = hipIpcGetMemHandle(&MemHandle, Ad); + REQUIRE(ret == hipSuccess); + } + + SECTION("Open mem handle with devptr as nullptr") { + ret = hipIpcOpenMemHandle(nullptr, MemHandle, + hipIpcMemLazyEnablePeerAccess); + REQUIRE(ret == hipErrorInvalidValue); + } + + SECTION("Open mem handle with handle as un-initialized") { + ret = hipIpcOpenMemHandle(&Ad2, MemHandleUninit, + hipIpcMemLazyEnablePeerAccess); + REQUIRE(ret == hipErrorInvalidValue); + } +#if HT_AMD + // Test is disabled for nvidia as api not returning expected value. + SECTION("Open mem handle with flags as random value") { + constexpr unsigned int flags = 123; + HIP_CHECK(hipIpcGetMemHandle(&MemHandle, Ad)); + ret = hipIpcOpenMemHandle(&Ad2, MemHandle, flags); + REQUIRE(ret == hipErrorInvalidValue); + } +#endif + SECTION("Close mem handle with devptr(nullptr)") { + ret = hipIpcCloseMemHandle(nullptr); + REQUIRE(ret == hipErrorInvalidValue); + } + + HIP_CHECK(hipFree(Ad)); +} + #endif