From 9d19cc9a572df37d4ca070145effdd7478402434 Mon Sep 17 00:00:00 2001 From: Marko Veniger <91256249+marko-veniger@users.noreply.github.com> Date: Mon, 6 Mar 2023 12:26:24 +0100 Subject: [PATCH] EXSWHTEC-171 - Hip graph creation and destruction tests (#35) * EXSWHTEC-171 - Implement positive and negative unit tests for the following API's: - hipGraphCreate - hipGraphDestroy [ROCm/hip-tests commit: 42ebc6cd102a7d5a37b261003f9c0181ad9f77b3] --- .../hip-tests/catch/unit/graph/CMakeLists.txt | 2 + .../catch/unit/graph/hipGraphCreate.cc | 62 +++++++++---- .../catch/unit/graph/hipGraphDestroy.cc | 92 ++++++++----------- 3 files changed, 85 insertions(+), 71 deletions(-) diff --git a/projects/hip-tests/catch/unit/graph/CMakeLists.txt b/projects/hip-tests/catch/unit/graph/CMakeLists.txt index 9c06e091b0..ee58c1672c 100644 --- a/projects/hip-tests/catch/unit/graph/CMakeLists.txt +++ b/projects/hip-tests/catch/unit/graph/CMakeLists.txt @@ -89,6 +89,8 @@ set(TEST_SRC hipGraphHostNodeGetParams.cc hipGraphExecChildGraphNodeSetParams.cc hipStreamGetCaptureInfo_v2.cc + hipGraphCreate.cc + hipGraphDestroy.cc hipStreamUpdateCaptureDependencies.cc hipThreadExchangeStreamCaptureMode.cc hipLaunchHostFunc.cc diff --git a/projects/hip-tests/catch/unit/graph/hipGraphCreate.cc b/projects/hip-tests/catch/unit/graph/hipGraphCreate.cc index befcc69c7e..301bf345a0 100644 --- a/projects/hip-tests/catch/unit/graph/hipGraphCreate.cc +++ b/projects/hip-tests/catch/unit/graph/hipGraphCreate.cc @@ -20,25 +20,53 @@ THE SOFTWARE. #include /** -Negative Testcase Scenarios : -1) Creating HipGraph with nullptr. -2) Creating hipGraph with non-zero mode. -*/ + * @addtogroup hipGraphCreate hipGraphCreate + * @{ + * @ingroup GraphTest + * `hipGraphCreate(hipGraph_t *pGraph, unsigned int flags)` - + * creates a graph + */ -TEST_CASE("Unit_hipGraphCreate_Negative") { - hipError_t ret; - SECTION("Creating HipGraph with nullptr") { - ret = hipGraphCreate(nullptr, 0); - REQUIRE(hipErrorInvalidValue == ret); +/** + * Test Description + * ------------------------ + * - Negative parameter test for hipGraphCreate: + * -# Expected hipErrorInvalidValue when pGraph is null + * -# Expected hipErrorInvalidValue when flags is not 0 + * Test source + * ------------------------ + * - unit/graph/hipGraphCreate.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.2 + */ +TEST_CASE("Unit_hipGraphCreate_Negative_Parameters") { + hipGraph_t graph = nullptr; + + SECTION("pGraph is nullptr") { + HIP_CHECK_ERROR(hipGraphCreate(nullptr, 0), hipErrorInvalidValue); } - SECTION("Creating hipGraph with non-zero mode") { - hipGraph_t graph{}; - ret = hipGraphCreate(&graph, -1); - REQUIRE(hipErrorInvalidValue == ret); - - ret = hipGraphCreate(nullptr, -1); - REQUIRE(hipErrorInvalidValue == ret); - } + SECTION("flags is not 0") { HIP_CHECK_ERROR(hipGraphCreate(&graph, 1), hipErrorInvalidValue); } } +/** + * Test Description + * ------------------------ + * - Basic positive test for hipGraphCreate + * - Create an emtpy graph + * Test source + * ------------------------ + * - unit/graph/hipGraphCreate.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.2 + */ +TEST_CASE("Unit_hipGraphCreate_Positive_Basic") { + hipGraph_t graph = nullptr; + + HIP_CHECK(hipGraphCreate(&graph, 0)); + REQUIRE(nullptr != graph); + + HIP_CHECK(hipGraphDestroy(graph)); +} diff --git a/projects/hip-tests/catch/unit/graph/hipGraphDestroy.cc b/projects/hip-tests/catch/unit/graph/hipGraphDestroy.cc index 15b8263f13..8ec41e4862 100644 --- a/projects/hip-tests/catch/unit/graph/hipGraphDestroy.cc +++ b/projects/hip-tests/catch/unit/graph/hipGraphDestroy.cc @@ -20,62 +20,46 @@ THE SOFTWARE. #include /** -Negative Testcase Scenarios : -1) Pass graph as nullptr and verify. -2) Destroy already destroyed graph and check api returns error code. -3) Destroy graph when is in use and make sure api handles it gracefully. -*/ + * @addtogroup hipGraphDestroy hipGraphDestroy + * @{ + * @ingroup GraphTest + * `hipGraphDestroy(hipGraph_t graph)` - + * Destroys a graph + */ -TEST_CASE("Unit_hipGraphDestroy_Negative") { - hipError_t ret; - SECTION("Deleting HipGraph with nullptr") { - ret = hipGraphDestroy(nullptr); - REQUIRE(hipErrorInvalidValue == ret); - } -#if HT_AMD - SECTION("Destroy already destroyed graph and check api returns error code") { - hipGraph_t graph; - HIP_CHECK(hipGraphCreate(&graph, 0)); - HIP_CHECK(hipGraphDestroy(graph)); +/** + * Test Description + * ------------------------ + * - Basic positive test for hipGraphDestroy + * - Create an emtpy graph and then destroy it + * Test source + * ------------------------ + * - unit/graph/hipGraphDestroy.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.2 + */ +TEST_CASE("Unit_hipGraphDestroy_Positive_Basic") { + hipGraph_t graph = nullptr; - ret = hipGraphDestroy(graph); - REQUIRE(hipErrorIllegalState == ret); - } -#endif - SECTION("Destroy graph when is in use and make sure api handles" - " it gracefully.") { - hipGraph_t graph; - hipGraphExec_t graphExec; - hipStream_t streamForGraph; - hipGraphNode_t memsetNode; + HIP_CHECK(hipGraphCreate(&graph, 0)); + REQUIRE(nullptr != graph); - HIP_CHECK(hipGraphCreate(&graph, 0)); - HIP_CHECK(hipStreamCreate(&streamForGraph)); - - char *devData; - HIP_CHECK(hipMalloc(&devData, 1024)); - hipMemsetParams memsetParams{}; - memset(&memsetParams, 0, sizeof(memsetParams)); - memsetParams.dst = reinterpret_cast(devData); - memsetParams.value = 0; - memsetParams.pitch = 0; - memsetParams.elementSize = sizeof(char); - memsetParams.width = 1024; - memsetParams.height = 1; - HIP_CHECK(hipGraphAddMemsetNode(&memsetNode, graph, nullptr, 0, - &memsetParams)); - - HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0)); - REQUIRE(graphExec != nullptr); - - HIP_CHECK(hipGraphDestroy(graph)); - - HIP_CHECK(hipGraphLaunch(graphExec, streamForGraph)); - HIP_CHECK(hipStreamSynchronize(streamForGraph)); - - HIP_CHECK(hipFree(devData)); - HIP_CHECK(hipGraphExecDestroy(graphExec)); - HIP_CHECK(hipStreamDestroy(streamForGraph)); - } + HIP_CHECK(hipGraphDestroy(graph)); } +/** + * Test Description + * ------------------------ + * - Basic negative parameter test for hipGraphDestroy + * -# Expected hipErrorInvalidValue when graph is invalid + * Test source + * ------------------------ + * - unit/graph/hipGraphDestroy.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.2 + */ +TEST_CASE("Unit_hipGraphDestroy_Negative_Parameters") { + HIP_CHECK_ERROR(hipGraphDestroy(static_cast(nullptr)), hipErrorInvalidValue); +}