From 9ffb7badfbbe757d17c4ff6d7222e37063e12cf6 Mon Sep 17 00:00:00 2001 From: ROCm CI Service Account <66695075+rocm-ci@users.noreply.github.com> Date: Tue, 17 May 2022 16:00:53 +0530 Subject: [PATCH] SWDEV-306122 - [catch2][dtest] Adding the following tests for hipGraphEventRecordNodeGetEvent (#2630) 1. Functional 2. Negative Change-Id: Ie96584f6be5bb62c12ee39aeaadc4a9a31a25d06 [ROCm/hip commit: 84da7bb1d0749cfa418bab386383199f68a590f7] --- .../hip/tests/catch/unit/graph/CMakeLists.txt | 1 + .../graph/hipGraphEventRecordNodeGetEvent.cc | 130 ++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 projects/hip/tests/catch/unit/graph/hipGraphEventRecordNodeGetEvent.cc diff --git a/projects/hip/tests/catch/unit/graph/CMakeLists.txt b/projects/hip/tests/catch/unit/graph/CMakeLists.txt index 2027d4203b..4be0361ff6 100644 --- a/projects/hip/tests/catch/unit/graph/CMakeLists.txt +++ b/projects/hip/tests/catch/unit/graph/CMakeLists.txt @@ -52,6 +52,7 @@ set(TEST_SRC hipGraphMemsetNodeGetParams.cc hipGraphMemsetNodeSetParams.cc hipGraphExecMemcpyNodeSetParamsFromSymbol.cc + hipGraphEventRecordNodeGetEvent.cc hipGraphEventWaitNodeGetEvent.cc hipGraphExecMemcpyNodeSetParams.cc ) diff --git a/projects/hip/tests/catch/unit/graph/hipGraphEventRecordNodeGetEvent.cc b/projects/hip/tests/catch/unit/graph/hipGraphEventRecordNodeGetEvent.cc new file mode 100644 index 0000000000..799841b6cb --- /dev/null +++ b/projects/hip/tests/catch/unit/graph/hipGraphEventRecordNodeGetEvent.cc @@ -0,0 +1,130 @@ +/* +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 +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/** +Testcase Scenarios : + 1) Validate that the event returned by hipGraphEventRecordNodeGetEvent matches +with the event set in hipGraphAddEventRecordNode. + 2) Negative Scenarios + - Input node is a nullptr. + - Output event is a nullptr. + - Input node is an empty node. + - Input node is a memset node. + - Input node is an uninitialized node. +*/ + +#include +#include +#include + +/** + * Local Function to set and get event record node property. + */ +static void validateEventRecordNodeGetEvent(unsigned flag) { + hipGraph_t graph; + HIP_CHECK(hipGraphCreate(&graph, 0)); + hipEvent_t event, event_out; + HIP_CHECK(hipEventCreateWithFlags(&event, flag)); + hipGraphNode_t eventrec; + HIP_CHECK(hipGraphAddEventRecordNode(&eventrec, graph, nullptr, 0, + event)); + HIP_CHECK(hipGraphEventRecordNodeGetEvent(eventrec, &event_out)); + // validate set event and get event are same + REQUIRE(event == event_out); + // Instantiate and launch the graph + HIP_CHECK(hipGraphDestroy(graph)); + HIP_CHECK(hipEventDestroy(event)); +} + +/** + * Scenario: Validate scenario 1 for different event flags. + */ +TEST_CASE("Unit_hipGraphEventRecordNodeGetEvent_Functional") { + // Create event nodes with different flags and validate with + // hipGraphEventRecordNodeGetEvent. + SECTION("Flag = hipEventDefault") { + validateEventRecordNodeGetEvent(hipEventDefault); + } + + SECTION("Flag = hipEventBlockingSync") { + validateEventRecordNodeGetEvent(hipEventBlockingSync); + } + + SECTION("Flag = hipEventDisableTiming") { + validateEventRecordNodeGetEvent(hipEventDisableTiming); + } +} + +/** + * Scenario 2: Negative tests. + */ +TEST_CASE("Unit_hipGraphEventRecordNodeGetEvent_Negative") { + hipGraph_t graph; + HIP_CHECK(hipGraphCreate(&graph, 0)); + hipEvent_t event, event_out; + HIP_CHECK(hipEventCreate(&event)); + hipGraphNode_t eventrec; + HIP_CHECK(hipGraphAddEventRecordNode(&eventrec, graph, nullptr, 0, + event)); + SECTION("node = nullptr") { + REQUIRE(hipErrorInvalidValue == hipGraphEventRecordNodeGetEvent(nullptr, + &event_out)); + } + + SECTION("event_out = nullptr") { + REQUIRE(hipErrorInvalidValue == hipGraphEventRecordNodeGetEvent(eventrec, + nullptr)); + } + + SECTION("input node is empty node") { + hipGraphNode_t EmptyGraphNode; + HIP_CHECK(hipGraphAddEmptyNode(&EmptyGraphNode, graph, nullptr, 0)); + REQUIRE(hipErrorInvalidValue == + hipGraphEventRecordNodeGetEvent(EmptyGraphNode, &event_out)); + } + + SECTION("input node is memset node") { + constexpr size_t Nbytes = 1024; + char *A_d; + hipGraphNode_t memset_A; + hipMemsetParams memsetParams{}; + HIP_CHECK(hipMalloc(&A_d, Nbytes)); + memset(&memsetParams, 0, sizeof(memsetParams)); + memsetParams.dst = reinterpret_cast(A_d); + memsetParams.value = 0; + memsetParams.pitch = 0; + memsetParams.elementSize = sizeof(char); + memsetParams.width = Nbytes; + memsetParams.height = 1; + HIP_CHECK(hipGraphAddMemsetNode(&memset_A, graph, nullptr, 0, + &memsetParams)); + REQUIRE(hipErrorInvalidValue == + hipGraphEventRecordNodeGetEvent(memset_A, &event_out)); + HIP_CHECK(hipFree(A_d)); + } + + SECTION("input node is uninitialized node") { + hipGraphNode_t node_unit{}; + REQUIRE(hipErrorInvalidValue == + hipGraphEventRecordNodeGetEvent(node_unit, &event_out)); + } + + HIP_CHECK(hipGraphDestroy(graph)); + HIP_CHECK(hipEventDestroy(event)); +}