From 983aee310ea25d63bda763402a50c9cc26f0ff22 Mon Sep 17 00:00:00 2001 From: Marko Veniger <91256249+marko-veniger@users.noreply.github.com> Date: Tue, 11 Jul 2023 10:36:37 +0200 Subject: [PATCH] EXSWHTEC-19 - hipMallocAsync negative tests (#37) - negative tests for hipMallocAsync: - nullptr for device pointer parameter - invalid stream for stream parameter - size required larger than size of available memoryr - Extend the PREDEFINED list to define all macro names to include #if and #ifdef sections in documentation - Resolve unresolved merge conflicts [ROCm/hip-tests commit: 6d62387c3405344c787ca8e2457e04226cf167f0] --- .../catch/unit/memory/CMakeLists.txt | 1 + .../catch/unit/memory/hipMallocAsync.cc | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 projects/hip-tests/catch/unit/memory/hipMallocAsync.cc diff --git a/projects/hip-tests/catch/unit/memory/CMakeLists.txt b/projects/hip-tests/catch/unit/memory/CMakeLists.txt index ff9eaa4f71..46d8bdf994 100644 --- a/projects/hip-tests/catch/unit/memory/CMakeLists.txt +++ b/projects/hip-tests/catch/unit/memory/CMakeLists.txt @@ -108,6 +108,7 @@ set(TEST_SRC hipMemAdvise_old.cc hipMemAdvise.cc hipMemRangeGetAttributes.cc + hipMallocAsync.cc hipStreamAttachMemAsync.cc hipMemRangeGetAttributes_old.cc hipMemGetAddressRange.cc) diff --git a/projects/hip-tests/catch/unit/memory/hipMallocAsync.cc b/projects/hip-tests/catch/unit/memory/hipMallocAsync.cc new file mode 100644 index 0000000000..db74c99459 --- /dev/null +++ b/projects/hip-tests/catch/unit/memory/hipMallocAsync.cc @@ -0,0 +1,47 @@ +/* + 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, INNCLUDING 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 ANNY 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. + */ + +#include +#include + +#include + +TEST_CASE("Unit_hipMallocAsync_negative") { + HIP_CHECK(hipSetDevice(0)); + + void* p = nullptr; + size_t max_size = std::numeric_limits::max(); + hipStream_t stream{nullptr}; + HIP_CHECK(hipStreamCreate(&stream)); + + + SECTION("Device pointer is null") { REQUIRE(hipMallocAsync(nullptr, 100, stream) != hipSuccess); } + + SECTION("stream is invalid") { + REQUIRE(hipMallocAsync(static_cast(&p), 100, reinterpret_cast(-1)) != + hipSuccess); + } + + SECTION("out of memory") { + REQUIRE(hipMallocAsync(static_cast(&p), max_size, stream) != hipSuccess); + } + + HIP_CHECK(hipStreamSynchronize(stream)); + HIP_CHECK(hipStreamDestroy(stream)); +}