From fcdbcd743a2d65d3b4960719929bef92bf092114 Mon Sep 17 00:00:00 2001 From: nives-vukovic <110852104+nives-vukovic@users.noreply.github.com> Date: Fri, 4 Nov 2022 14:59:26 +0100 Subject: [PATCH] EXSWHTEC-65 - Implement additional Initialization and Version tests (#2972) - Separate hipRuntimeGetVersion and hipDeviceGetUuid tests into positive and negative tests - Split Unit_hipDeviceGetUuid into Unit_hipDeviceGetUuid_Positive and Unit_hipDeviceGetUuid_Negative - Split Unit_hipRuntimeGetVersion_NegAndValTst into Unit_hipRuntimeGetVersion_Positive and Unit_hipRuntimeGetVersion_Negative - Modify tests to use hipDevice_t instead of integer for devices in hipDeviceGetUuid negative test - Implement additional Initialization and Version tests - Expand hipDeviceComputeCapability negative test with case when device is invalid - Expand hipDeviceGetP2PAttribute negative test with case when src and dst devices are the same - Expand hipDeviceGetP2PAttribute negative test with case when device is out of bound - Modify hipDeviceTotalMem negative test with case when device is invalid - Implement Unit_hipDeviceGetPCIBusId_PartialFill test which validates partial filling the bus id into a char array - Fix minor formatting issues and change hipDeviceGetPCIBusId partial fill test into negative - Modify negative tests to use integer device values - Disable hipDeviceGetPCIBusId negative test on AMD [ROCm/hip-tests commit: d7fafa86969b0bbe8e5d3e595a86713728b051fb] --- .../config/config_amd_linux_MI2xx.json | 3 +- .../config/config_amd_linux_common.json | 3 +- .../config/config_amd_windows_MI2xx.json | 3 +- .../config/config_amd_windows_common.json | 3 +- .../unit/device/hipDeviceComputeCapability.cc | 27 ++++++++--- .../unit/device/hipDeviceGetP2PAttribute.cc | 18 ++++++- .../catch/unit/device/hipDeviceGetPCIBusId.cc | 26 +++++++++- .../catch/unit/device/hipDeviceGetUuid.cc | 47 +++++++++++++------ .../catch/unit/device/hipDeviceTotalMem.cc | 5 +- .../catch/unit/device/hipRuntimeGetVersion.cc | 16 +++++-- 10 files changed, 119 insertions(+), 32 deletions(-) diff --git a/projects/hip-tests/catch/hipTestMain/config/config_amd_linux_MI2xx.json b/projects/hip-tests/catch/hipTestMain/config/config_amd_linux_MI2xx.json index 05276e392b..da05aeb2e7 100644 --- a/projects/hip-tests/catch/hipTestMain/config/config_amd_linux_MI2xx.json +++ b/projects/hip-tests/catch/hipTestMain/config/config_amd_linux_MI2xx.json @@ -2,7 +2,8 @@ "DisabledTests": [ "Unit_hipStreamPerThread_DeviceReset_1", - "Unit_hipMallocManaged_OverSubscription" + "Unit_hipMallocManaged_OverSubscription", + "Unit_hipDeviceGetPCIBusId_Negative_PartialFill" ] } diff --git a/projects/hip-tests/catch/hipTestMain/config/config_amd_linux_common.json b/projects/hip-tests/catch/hipTestMain/config/config_amd_linux_common.json index 45141c37ae..2a857c27d0 100644 --- a/projects/hip-tests/catch/hipTestMain/config/config_amd_linux_common.json +++ b/projects/hip-tests/catch/hipTestMain/config/config_amd_linux_common.json @@ -6,6 +6,7 @@ "Unit_hipDeviceGetCacheConfig_Positive_Basic", "Unit_hipDeviceGetCacheConfig_Positive_Threaded", "Unit_hipGetDeviceFlags_Positive_Context", - "Unit_hipIpcCloseMemHandle_Negative_Close_In_Originating_Process" + "Unit_hipIpcCloseMemHandle_Negative_Close_In_Originating_Process", + "Unit_hipDeviceGetPCIBusId_Negative_PartialFill" ] } diff --git a/projects/hip-tests/catch/hipTestMain/config/config_amd_windows_MI2xx.json b/projects/hip-tests/catch/hipTestMain/config/config_amd_windows_MI2xx.json index 6ee5669f0b..317bef4a9a 100644 --- a/projects/hip-tests/catch/hipTestMain/config/config_amd_windows_MI2xx.json +++ b/projects/hip-tests/catch/hipTestMain/config/config_amd_windows_MI2xx.json @@ -88,6 +88,7 @@ "Unit_hipStreamValue_Wait64_Blocking_NoMask_Gte", "Unit_hipStreamValue_Wait64_Blocking_NoMask_Eq", "Unit_hipStreamValue_Wait64_Blocking_NoMask_And", - "Unit_hipStreamValue_Wait64_Blocking_NoMask_Nor" + "Unit_hipStreamValue_Wait64_Blocking_NoMask_Nor", + "Unit_hipDeviceGetPCIBusId_Negative_PartialFill" ] } diff --git a/projects/hip-tests/catch/hipTestMain/config/config_amd_windows_common.json b/projects/hip-tests/catch/hipTestMain/config/config_amd_windows_common.json index 9c9c1e28e3..3c8570f63d 100644 --- a/projects/hip-tests/catch/hipTestMain/config/config_amd_windows_common.json +++ b/projects/hip-tests/catch/hipTestMain/config/config_amd_windows_common.json @@ -99,6 +99,7 @@ "Unit_hipStreamValue_Wait64_Blocking_NoMask_And", "Unit_hipStreamValue_Wait64_Blocking_NoMask_Nor", "Unit_hipGetDeviceFlags_Positive_Context", - "Unit_hipIpcCloseMemHandle_Negative_Close_In_Originating_Process" + "Unit_hipIpcCloseMemHandle_Negative_Close_In_Originating_Process", + "Unit_hipDeviceGetPCIBusId_Negative_PartialFill" ] } diff --git a/projects/hip-tests/catch/unit/device/hipDeviceComputeCapability.cc b/projects/hip-tests/catch/unit/device/hipDeviceComputeCapability.cc index d925594988..a44bfeae1b 100644 --- a/projects/hip-tests/catch/unit/device/hipDeviceComputeCapability.cc +++ b/projects/hip-tests/catch/unit/device/hipDeviceComputeCapability.cc @@ -16,6 +16,12 @@ 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 : +Unit_hipDeviceComputeCapability_ValidateVersion - Check if hipDeviceComputeCapability api returns valid Major and Minor versions +Unit_hipDeviceComputeCapability_Negative - Test unsuccessful execution of hipDeviceComputeCapability when nullptr + or invalid device is set as input parameter +*/ /* * Conformance test for checking functionality of @@ -24,14 +30,13 @@ THE SOFTWARE. #include /** - * hipDeviceComputeCapability tests + * hipDeviceComputeCapability negative tests * Scenario1: Validates if &major = nullptr returns error code * Scenario2: Validates if &minor = nullptr returns error code - * Scenario3: Check if Major and Minor Versions are valid + * Scenario3: Validates if device is -1 + * Scenario4: Validates if device is out of bounds */ - -// Scenario 1 and 2 -TEST_CASE("Unit_hipDeviceComputeCapability_NegTst") { +TEST_CASE("Unit_hipDeviceComputeCapability_Negative") { int major, minor, numDevices; hipDevice_t device; @@ -51,12 +56,22 @@ TEST_CASE("Unit_hipDeviceComputeCapability_NegTst") { REQUIRE_FALSE(hipDeviceComputeCapability(&major, nullptr, device) == hipSuccess); } + // Scenario3 + SECTION("device is -1") { + REQUIRE_FALSE(hipDeviceComputeCapability(&major, &minor, -1) + == hipSuccess); + } + // Scenario4 + SECTION("device is out of bounds") { + REQUIRE_FALSE(hipDeviceComputeCapability(&major, &minor, numDevices) + == hipSuccess); + } } else { WARN("Test skipped as no gpu devices available"); } } -// Scenario 3 : Check whether major and minor version value is valid. +// Scenario 5 : Check whether major and minor version value is valid. TEST_CASE("Unit_hipDeviceComputeCapability_ValidateVersion") { int major, minor; hipDevice_t device; diff --git a/projects/hip-tests/catch/unit/device/hipDeviceGetP2PAttribute.cc b/projects/hip-tests/catch/unit/device/hipDeviceGetP2PAttribute.cc index 805eb117ff..584257e616 100644 --- a/projects/hip-tests/catch/unit/device/hipDeviceGetP2PAttribute.cc +++ b/projects/hip-tests/catch/unit/device/hipDeviceGetP2PAttribute.cc @@ -96,7 +96,7 @@ TEST_CASE("Unit_hipDeviceGetP2PAttribute_Negative") { hipErrorInvalidValue); } - SECTION("Invalid device") { + SECTION("Device is -1") { int invalidDevice = -1; HIP_CHECK_ERROR(hipDeviceGetP2PAttribute(&value, validAttr, invalidDevice, validDstDevice), hipErrorInvalidDevice); @@ -104,6 +104,22 @@ TEST_CASE("Unit_hipDeviceGetP2PAttribute_Negative") { hipErrorInvalidDevice); } + SECTION("Device is out of bounds") { + int deviceCount = 0; + HIP_CHECK(hipGetDeviceCount(&deviceCount)); + REQUIRE_FALSE(deviceCount == 0); + + HIP_CHECK_ERROR(hipDeviceGetP2PAttribute(&value, validAttr, deviceCount, validDstDevice), + hipErrorInvalidDevice); + HIP_CHECK_ERROR(hipDeviceGetP2PAttribute(&value, validAttr, validSrcDevice, deviceCount), + hipErrorInvalidDevice); + } + + SECTION("Source and destination devices are the same") { + HIP_CHECK_ERROR(hipDeviceGetP2PAttribute(&value, validAttr, validSrcDevice, validSrcDevice), + hipErrorInvalidDevice); + } + /* https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#env-vars */ SECTION("Hidden devices using environment variables") { REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute").run("") == hipSuccess); diff --git a/projects/hip-tests/catch/unit/device/hipDeviceGetPCIBusId.cc b/projects/hip-tests/catch/unit/device/hipDeviceGetPCIBusId.cc index d070f8654b..4f82a59b0e 100644 --- a/projects/hip-tests/catch/unit/device/hipDeviceGetPCIBusId.cc +++ b/projects/hip-tests/catch/unit/device/hipDeviceGetPCIBusId.cc @@ -71,6 +71,30 @@ TEST_CASE("Unit_hipDeviceGetPCIBusId_Check_PciBusID_WithAttr") { " hipDeviceGetAttribute matched for all gpus\n"); } +TEST_CASE("Unit_hipDeviceGetPCIBusId_Negative_PartialFill") { + std::array busID; + + const int device = GENERATE(range(0, HipTest::getDeviceCount())); + + HIP_CHECK(hipDeviceGetPCIBusId(busID.data(), busID.size(), device)); + + auto start = std::begin(busID); + auto end = std::end(busID); + const auto len = std::distance(start, std::find(start, end, 0)); + + // fill up only half of the length + const auto fillLen = len / 2; + constexpr char fillValue = 1; + std::fill(start, end, fillValue); + + REQUIRE_FALSE(hipDeviceGetPCIBusId(busID.data(), fillLen, device) == hipSuccess); + + const auto strEnd = start + fillLen - 1; + REQUIRE(std::all_of(start, strEnd, [](char& c) { return c != 0; })); + REQUIRE(*strEnd == 0); + REQUIRE(std::all_of(strEnd+1, end, [](char& c) { return c == fillValue; })); +} + /** * Validates negative scenarios for hipDeviceGetPCIBusId @@ -107,7 +131,7 @@ TEST_CASE("Unit_hipDeviceGetPCIBusId_NegTst") { == hipSuccess); } // device = Non Existing Device - SECTION("device is -1") { + SECTION("device is out of bounds") { int deviceCount = 0; HIP_CHECK(hipGetDeviceCount(&deviceCount)); REQUIRE_FALSE(deviceCount == 0); diff --git a/projects/hip-tests/catch/unit/device/hipDeviceGetUuid.cc b/projects/hip-tests/catch/unit/device/hipDeviceGetUuid.cc index 512ddb6a2b..47a9bd2c4f 100644 --- a/projects/hip-tests/catch/unit/device/hipDeviceGetUuid.cc +++ b/projects/hip-tests/catch/unit/device/hipDeviceGetUuid.cc @@ -16,7 +16,12 @@ 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 : +Unit_hipDeviceGetUuid_Positive - Check if hipDeviceGetUuid api returns valid UUID +Unit_hipDeviceGetUuid_Negative - Test unsuccessful execution of hipDeviceGetUuid when nullptr + or invalid device is set as input parameter +*/ /* * Conformance test for checking functionality of * hipError_t hipDeviceGetUuid(hipUUID* uuid, hipDevice_t device); @@ -26,26 +31,40 @@ THE SOFTWARE. #include /** - * hipDeviceGetUuid tests + * hipDeviceGetUuid positive test * Scenario1: Validates the returned UUID - * Scenario2: Validates returned error code for UUID = nullptr - * Scenario3 & 4: Validates returned error code for invalid device */ -TEST_CASE("Unit_hipDeviceGetUuid") { +TEST_CASE("Unit_hipDeviceGetUuid_Positive") { + hipDevice_t device; + hipUUID uuid; + + const int deviceId = GENERATE(range(0, HipTest::getDeviceCount())); + HIP_CHECK(hipDeviceGet(&device, deviceId)); + + // Scenario 1 + HIP_CHECK(hipDeviceGetUuid(&uuid, device)); + REQUIRE(strcmp(uuid.bytes, "") != 0); +} + +/** + * hipDeviceGetUuid negative tests + * Scenario2: Validates returned error code for UUID = nullptr + * Scenario3: Validates returned error code if device is -1 + * Scenario4: Validates returned error code if device is out of bounds + */ +TEST_CASE("Unit_hipDeviceGetUuid_Negative") { int numDevices = 0; hipDevice_t device; hipUUID uuid; HIP_CHECK(hipGetDeviceCount(&numDevices)); - for (int i = 0; i < numDevices; i++) { - HIP_CHECK(hipDeviceGet(&device, i)); - // Scenario 1 - HIP_CHECK(hipDeviceGetUuid(&uuid, device)); - REQUIRE_FALSE(!strcmp(uuid.bytes, "")); + + if (numDevices > 0) { + HIP_CHECK(hipDeviceGet(&device, 0)); // Scenario 2 REQUIRE_FALSE(hipSuccess == hipDeviceGetUuid(nullptr, device)); + // Scenario 3 + REQUIRE_FALSE(hipSuccess == hipDeviceGetUuid(&uuid, -1)); + // Scenario 4 + REQUIRE_FALSE(hipSuccess == hipDeviceGetUuid(&uuid, numDevices)); } - // Scenario 3 - REQUIRE_FALSE(hipSuccess == hipDeviceGetUuid(&uuid, -1)); - // Scenario 4 - REQUIRE_FALSE(hipSuccess == hipDeviceGetUuid(&uuid, numDevices)); } diff --git a/projects/hip-tests/catch/unit/device/hipDeviceTotalMem.cc b/projects/hip-tests/catch/unit/device/hipDeviceTotalMem.cc index 6812b37873..0a236d2feb 100644 --- a/projects/hip-tests/catch/unit/device/hipDeviceTotalMem.cc +++ b/projects/hip-tests/catch/unit/device/hipDeviceTotalMem.cc @@ -35,22 +35,21 @@ TEST_CASE("Unit_hipDeviceTotalMem_NegTst") { #if HT_NVIDIA HIP_CHECK(hipInit(0)); #endif + size_t totMem; // Scenario 1 SECTION("bytes is nullptr") { HIP_CHECK_ERROR(hipDeviceTotalMem(nullptr, 0), hipErrorInvalidValue); } - size_t totMem; // Scenario 2 SECTION("device is -1") { HIP_CHECK_ERROR(hipDeviceTotalMem(&totMem, -1), hipErrorInvalidDevice); } // Scenario 3 - SECTION("pi is nullptr") { + SECTION("device is out of bounds") { int numDevices; HIP_CHECK(hipGetDeviceCount(&numDevices)); - size_t totMem; HIP_CHECK_ERROR(hipDeviceTotalMem(&totMem, numDevices), hipErrorInvalidDevice); } } diff --git a/projects/hip-tests/catch/unit/device/hipRuntimeGetVersion.cc b/projects/hip-tests/catch/unit/device/hipRuntimeGetVersion.cc index 3420316e0d..6e0def63b7 100644 --- a/projects/hip-tests/catch/unit/device/hipRuntimeGetVersion.cc +++ b/projects/hip-tests/catch/unit/device/hipRuntimeGetVersion.cc @@ -16,6 +16,11 @@ 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 : +Unit_hipRuntimeGetVersion_Positive - Test simple reading of HIP runtime version with hipRuntimeGetVersion api +Unit_hipRuntimeGetVersion_Negative - Test unsuccessful execution of hipRuntimeGetVersion when nullptr is set as input parameter +*/ /* * Conformance test for checking functionality of @@ -26,9 +31,14 @@ THE SOFTWARE. */ #include -TEST_CASE("Unit_hipRuntimeGetVersion_NegAndValTst") { +TEST_CASE("Unit_hipRuntimeGetVersion_Positive") { int runtimeVersion = -1; - CHECK_FALSE(hipRuntimeGetVersion(nullptr) == hipSuccess); HIP_CHECK(hipRuntimeGetVersion(&runtimeVersion)); - CHECK_FALSE(runtimeVersion <= 0); + REQUIRE(runtimeVersion > 0); + INFO("Runtime version " << runtimeVersion); +} + +TEST_CASE("Unit_hipRuntimeGetVersion_Negative") { + // If initialization is attempted with nullptr, error shall be reported + CHECK_FALSE(hipRuntimeGetVersion(nullptr) == hipSuccess); }