clGetPlatformIDs should check if platform initialization was successful

Change-Id: I3e9d78155e6a914ed0d755d81ddc13c4d3a8a291
This commit is contained in:
Artur Harasimiuk
2018-02-16 16:01:21 +01:00
committed by sys_ocldev
parent 5909a6b3d3
commit a99d951c55
2 changed files with 29 additions and 3 deletions

View File

@ -77,19 +77,23 @@ cl_int CL_API_CALL clGetPlatformIDs(cl_uint numEntries,
}
// if the platforms are non-nullptr, we need to fill in the platform IDs
if (platforms != nullptr) {
while (platforms != nullptr) {
auto pPlatform = platform();
bool ret = pPlatform->initialize(numPlatformDevices, platformDevices);
DEBUG_BREAK_IF(ret != true);
((void)(ret));
if (!ret) {
retVal = CL_INVALID_VALUE;
break;
}
// we only have one platform so we can program that directly
platforms[0] = pPlatform;
break;
}
// we only have a single platform at this time, so return 1 if num_platforms
// is non-nullptr
if (numPlatforms) {
if (numPlatforms && retVal == CL_SUCCESS) {
*numPlatforms = 1;
}
} while (false);

View File

@ -23,9 +23,14 @@
#include "cl_api_tests.h"
#include "runtime/context/context.h"
#include "runtime/platform/platform.h"
#include "unit_tests/helpers/variable_backup.h"
using namespace OCLRT;
namespace OCLRT {
extern bool getDevicesResult;
}; // namespace OCLRT
typedef api_tests clGetPlatformIDsTests;
namespace ULT {
@ -57,4 +62,21 @@ TEST_F(clGetPlatformIDsTests, NoPlatformListReturnsError) {
EXPECT_EQ(CL_INVALID_VALUE, retVal);
}
TEST(clGetPlatformIDsNegativeTests, WhenInitFailedThenErrorIsReturned) {
VariableBackup<decltype(getDevicesResult)> bkp(&getDevicesResult);
bkp = false;
cl_int retVal = CL_SUCCESS;
cl_platform_id platformRet = nullptr;
cl_uint numPlatforms = 0;
retVal = clGetPlatformIDs(1, &platformRet, &numPlatforms);
EXPECT_EQ(CL_INVALID_VALUE, retVal);
EXPECT_EQ(0u, numPlatforms);
EXPECT_EQ(nullptr, platformRet);
platform()->shutdown();
}
} // namespace ULT