/* * Copyright (c) Advanced Micro Devices, Inc., or its affiliates. * * SPDX-License-Identifier: MIT */ /** Testcase Scenarios : 1) Test hipHostMalloc() api with ptr as nullptr and check for return value. 2) Test hipHostMalloc() api with size as max(size_t) and check for OOM error. 3) Test hipHostMalloc() api with flags as max(unsigned int) and validate return value. 4) Pass size as zero for hipHostMalloc() api and check ptr is reset with with return value success. */ #include #include /** * Performs argument validation of hipHostMalloc api. */ HIP_TEST_CASE(Unit_hipHostMalloc_ArgValidation) { #if HT_NVIDIA HIP_SKIP_TEST("host malloc test path pending debug."); #endif constexpr size_t allocSize = 1000; char* ptr; SECTION("Pass ptr as nullptr") { HIP_CHECK_ERROR(hipHostMalloc(static_cast(nullptr), allocSize), hipErrorInvalidValue); } SECTION("Size as max(size_t)") { HIP_CHECK_ERROR(hipHostMalloc(&ptr, (std::numeric_limits::max)()), hipErrorMemoryAllocation); } SECTION("Flags as max(uint)") { HIP_CHECK_ERROR(hipHostMalloc(&ptr, allocSize, (std::numeric_limits::max)()), hipErrorInvalidValue); } SECTION("Pass size as zero and check ptr reset") { HIP_CHECK(hipHostMalloc(&ptr, 0)); REQUIRE(ptr == nullptr); } SECTION("Pass hipHostMallocCoherent and hipHostMallocNonCoherent simultaneously") { HIP_CHECK_ERROR( hipHostMalloc(&ptr, allocSize, hipHostMallocCoherent | hipHostMallocNonCoherent), hipErrorInvalidValue); } }