From 45eb04ea5c81153ec08e862534c5b14bd24c1c61 Mon Sep 17 00:00:00 2001 From: Konstantin Pyzhov Date: Fri, 3 May 2019 05:39:45 -0400 Subject: [PATCH] Refined hipSetDevice test. [ROCm/hip commit: 069fb7e486a9a0c3b2457f3c7aed15ee7db6f47c] --- .../src/Negative/Device/hipSetDevice.cpp | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/projects/hip/tests/src/Negative/Device/hipSetDevice.cpp b/projects/hip/tests/src/Negative/Device/hipSetDevice.cpp index 6e906ce8eb..ec0549e760 100644 --- a/projects/hip/tests/src/Negative/Device/hipSetDevice.cpp +++ b/projects/hip/tests/src/Negative/Device/hipSetDevice.cpp @@ -1,9 +1,19 @@ -#include "hip/hip_runtime.h" -#include "hip/hip_runtime_api.h" -#include "hipDeviceUtil.h" +#include "test_common.h" int main() { - HIP_CHECK(hipSetDevice(0), hipSetDevice); - HIP_CHECK(hipSetDevice(1026), hipSetDevice); - HIP_CHECK(hipSetDevice(-1), hipSetDevice); + int numDevices = 0; + + HIPCHECK_API(hipGetDeviceCount(&numDevices), hipSuccess); + if (numDevices > 0) { + for (int deviceId = 0; deviceId < numDevices; deviceId++) { + HIPCHECK_API(hipSetDevice(deviceId), hipSuccess); + } + HIPCHECK_API(hipSetDevice(numDevices), hipErrorInvalidDevice); + HIPCHECK_API(hipSetDevice(-1), hipErrorInvalidDevice); + } + else { + failed("Error: failed to find any compatible devices."); + } + + passed(); }