mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-10 12:53:42 +08:00
clGetPlatformIDs should check if platform initialization was successful
Change-Id: I3e9d78155e6a914ed0d755d81ddc13c4d3a8a291
This commit is contained in:

committed by
sys_ocldev

parent
5909a6b3d3
commit
a99d951c55
@ -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);
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user