From 99095ec70e960f1384f3151cfdf202c8fa92a448 Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Tue, 27 Sep 2016 13:04:35 -0500 Subject: [PATCH] added more device negative testing 1. Added fallback for nullptr to hipGetDeviceProperties and hipGetDeviceCount 2. Added negative tests for hipGetDeviceProperties and hipGetDeviceCount Change-Id: Iac93fd53d7d4794fb10546ddadf6ca802b047c87 [ROCm/clr commit: 42993160399c97398f9d3d167398bf22a6db31af] --- projects/clr/hipamd/src/hip_device.cpp | 29 +++++++++++++------ .../Negative/Device/hipGetDeviceCount.cpp | 10 +++++++ .../Device/hipGetDeviceProperties.cpp | 14 +++++++++ 3 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 projects/clr/hipamd/tests/src/Functional/Negative/Device/hipGetDeviceCount.cpp create mode 100644 projects/clr/hipamd/tests/src/Functional/Negative/Device/hipGetDeviceProperties.cpp diff --git a/projects/clr/hipamd/src/hip_device.cpp b/projects/clr/hipamd/src/hip_device.cpp index 760e00c5f1..407b8c2ae9 100644 --- a/projects/clr/hipamd/src/hip_device.cpp +++ b/projects/clr/hipamd/src/hip_device.cpp @@ -52,13 +52,20 @@ hipError_t hipGetDeviceCount(int *count) { HIP_INIT_API(count); - *count = g_deviceCnt; + hipError_t e = hipSuccess; - if (*count > 0) { - return ihipLogStatus(hipSuccess); + if(count != nullptr) { + *count = g_deviceCnt; + + if (*count > 0) { + e = ihipLogStatus(hipSuccess); + } else { + e = ihipLogStatus(hipErrorNoDevice); + } } else { - return ihipLogStatus(hipErrorNoDevice); + e = ihipLogStatus(hipErrorNoDevice); } + return e; } hipError_t hipDeviceSetCacheConfig ( hipFuncCache cacheConfig ) @@ -217,12 +224,16 @@ hipError_t hipGetDeviceProperties(hipDeviceProp_t* props, int device) hipError_t e; - auto * hipDevice = ihipGetDevice(device); - if (hipDevice) { + if(props != nullptr){ + auto * hipDevice = ihipGetDevice(device); + if (hipDevice) { // copy saved props - *props = hipDevice->_props; - e = hipSuccess; - } else { + *props = hipDevice->_props; + e = hipSuccess; + } else { + e = hipErrorInvalidDevice; + } + }else{ e = hipErrorInvalidDevice; } diff --git a/projects/clr/hipamd/tests/src/Functional/Negative/Device/hipGetDeviceCount.cpp b/projects/clr/hipamd/tests/src/Functional/Negative/Device/hipGetDeviceCount.cpp new file mode 100644 index 0000000000..c9f8ed3864 --- /dev/null +++ b/projects/clr/hipamd/tests/src/Functional/Negative/Device/hipGetDeviceCount.cpp @@ -0,0 +1,10 @@ +#include +#include +#include"hipDeviceUtil.h" + +int main() +{ + int deviceCnt; + HIP_CHECK(hipGetDeviceCount(&deviceCnt), hipGetDeviceCount); + HIP_CHECK(hipGetDeviceCount(0), hipGetDeviceCount); +} diff --git a/projects/clr/hipamd/tests/src/Functional/Negative/Device/hipGetDeviceProperties.cpp b/projects/clr/hipamd/tests/src/Functional/Negative/Device/hipGetDeviceProperties.cpp new file mode 100644 index 0000000000..964df95d20 --- /dev/null +++ b/projects/clr/hipamd/tests/src/Functional/Negative/Device/hipGetDeviceProperties.cpp @@ -0,0 +1,14 @@ +#include +#include +#include"hipDeviceUtil.h" + +int main() +{ + hipDeviceProp_t props; + HIP_CHECK(hipGetDeviceProperties(&props, 0), hipGetDeviceProperties); + HIP_CHECK(hipGetDeviceProperties(NULL, 0), hipGetDeviceProperties); + HIP_CHECK(hipGetDeviceProperties(NULL, -1), hipGetDeviceProperties); + HIP_CHECK(hipGetDeviceProperties(&props, -1), hipGetDeviceProperties); + HIP_CHECK(hipGetDeviceProperties(NULL, 1024), hipGetDeviceProperties); + HIP_CHECK(hipGetDeviceProperties(&props, 1024), hipGetDeviceProperties); +}