2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-02-27 18:39:32 +08:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation
|
2018-09-18 15:11:08 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
#include "unit_tests/fixtures/device_fixture.h"
|
|
|
|
#include "unit_tests/mocks/mock_ostime.h"
|
|
|
|
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "cl_api_tests.h"
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
struct FailOSTime : public MockOSTime {
|
|
|
|
public:
|
|
|
|
bool getCpuGpuTime(TimeStampData *pGpuCpuTime) override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool getCpuTime(uint64_t *timeStamp) override {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef api_tests clGetDeviceAndHostTimerTest;
|
|
|
|
typedef api_tests clGetHostTimerTest;
|
|
|
|
|
|
|
|
namespace ULT {
|
|
|
|
|
2019-03-05 20:31:11 +08:00
|
|
|
TEST_F(clGetDeviceAndHostTimerTest, GivenNullDeviceWhenGettingDeviceAndHostTimerThenInvalidDeviceErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_ulong device_timestamp = 0;
|
|
|
|
cl_ulong host_timestamp = 0;
|
|
|
|
|
|
|
|
retVal = clGetDeviceAndHostTimer(
|
|
|
|
nullptr,
|
|
|
|
&device_timestamp,
|
|
|
|
&host_timestamp);
|
|
|
|
|
|
|
|
EXPECT_EQ(CL_INVALID_DEVICE, retVal);
|
|
|
|
}
|
|
|
|
|
2019-03-05 20:31:11 +08:00
|
|
|
TEST_F(clGetDeviceAndHostTimerTest, GivenNullHostTimerWhenGettingDeviceAndHostTimerThenInvalidValueErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_ulong device_timestamp = 0;
|
|
|
|
|
|
|
|
retVal = clGetDeviceAndHostTimer(
|
|
|
|
devices[0],
|
|
|
|
&device_timestamp,
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
|
|
|
}
|
|
|
|
|
2019-03-05 20:31:11 +08:00
|
|
|
TEST_F(clGetDeviceAndHostTimerTest, GivenNullDevicesTimerWhenGettingDeviceAndHostTimerThenInvalidValueErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_ulong host_timestamp = 0;
|
|
|
|
|
|
|
|
retVal = clGetDeviceAndHostTimer(
|
|
|
|
devices[0],
|
|
|
|
nullptr,
|
|
|
|
&host_timestamp);
|
|
|
|
|
|
|
|
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
|
|
|
}
|
|
|
|
|
2019-03-05 20:31:11 +08:00
|
|
|
TEST_F(clGetDeviceAndHostTimerTest, GivenValidOSTimeWhenGettingDeviceAndHostTimerThenSuccessIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_ulong device_timestamp = 0;
|
|
|
|
cl_ulong host_timestamp = 0;
|
|
|
|
cl_ulong zero_timestamp = 0;
|
|
|
|
|
2018-07-03 16:00:12 +08:00
|
|
|
auto mDev = MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
mDev->setOSTime(new MockOSTime());
|
|
|
|
|
|
|
|
retVal = clGetDeviceAndHostTimer(
|
|
|
|
mDev,
|
|
|
|
&device_timestamp,
|
|
|
|
&host_timestamp);
|
|
|
|
|
|
|
|
EXPECT_GT(device_timestamp, zero_timestamp);
|
|
|
|
EXPECT_GT(host_timestamp, zero_timestamp);
|
|
|
|
EXPECT_EQ(retVal, CL_SUCCESS);
|
|
|
|
|
|
|
|
delete mDev;
|
|
|
|
}
|
|
|
|
|
2019-03-05 20:31:11 +08:00
|
|
|
TEST_F(clGetDeviceAndHostTimerTest, GivenInvalidOSTimeWhenGettingDeviceAndHostTimerThenOutOfResourcesErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_ulong device_timestamp = 0;
|
|
|
|
cl_ulong host_timestamp = 0;
|
|
|
|
cl_ulong zero_timestamp = 0;
|
|
|
|
|
2018-07-03 16:00:12 +08:00
|
|
|
auto mDev = MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
mDev->setOSTime(new FailOSTime());
|
|
|
|
|
|
|
|
retVal = clGetDeviceAndHostTimer(
|
|
|
|
mDev,
|
|
|
|
&device_timestamp,
|
|
|
|
&host_timestamp);
|
|
|
|
|
|
|
|
EXPECT_EQ(device_timestamp, zero_timestamp);
|
|
|
|
EXPECT_EQ(host_timestamp, zero_timestamp);
|
|
|
|
EXPECT_EQ(retVal, CL_OUT_OF_RESOURCES);
|
|
|
|
|
|
|
|
delete mDev;
|
|
|
|
}
|
|
|
|
|
2019-03-05 20:31:11 +08:00
|
|
|
TEST_F(clGetHostTimerTest, GivenNullDeviceWhenGettingHostTimerThenInvalidDeviceErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_ulong host_timestamp = 0;
|
|
|
|
|
|
|
|
retVal = clGetHostTimer(
|
|
|
|
nullptr,
|
|
|
|
&host_timestamp);
|
|
|
|
|
|
|
|
EXPECT_EQ(CL_INVALID_DEVICE, retVal);
|
|
|
|
}
|
|
|
|
|
2019-03-05 20:31:11 +08:00
|
|
|
TEST_F(clGetHostTimerTest, GivenNullHostTimerWhenGettingHostTimerThenInvalidValueErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
retVal = clGetHostTimer(
|
|
|
|
devices[0],
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
|
|
|
}
|
|
|
|
|
2019-03-05 20:31:11 +08:00
|
|
|
TEST_F(clGetHostTimerTest, GivenCorrectParametersWhenGettingHostTimerThenSuccessIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_ulong host_timestamp = 0;
|
|
|
|
cl_ulong zero_timestamp = 0;
|
|
|
|
|
|
|
|
retVal = clGetHostTimer(
|
|
|
|
devices[0],
|
|
|
|
&host_timestamp);
|
|
|
|
|
|
|
|
EXPECT_GE(host_timestamp, zero_timestamp);
|
|
|
|
EXPECT_EQ(retVal, CL_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2019-03-05 20:31:11 +08:00
|
|
|
TEST_F(clGetHostTimerTest, GivenValidOSTimeWhenGettingHostTimerThenSuccessIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_ulong host_timestamp = 0;
|
|
|
|
cl_ulong zero_timestamp = 0;
|
|
|
|
|
2018-07-03 16:00:12 +08:00
|
|
|
auto mDev = MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
mDev->setOSTime(new MockOSTime());
|
|
|
|
|
|
|
|
retVal = clGetHostTimer(
|
|
|
|
mDev,
|
|
|
|
&host_timestamp);
|
|
|
|
|
|
|
|
EXPECT_GE(host_timestamp, zero_timestamp);
|
|
|
|
EXPECT_EQ(retVal, CL_SUCCESS);
|
|
|
|
|
|
|
|
delete mDev;
|
|
|
|
}
|
|
|
|
|
2019-03-05 20:31:11 +08:00
|
|
|
TEST_F(clGetHostTimerTest, GivenInvalidOSTimeWhenGettingHostTimerThenOutOfResourcesErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_ulong host_timestamp = 0;
|
|
|
|
cl_ulong zero_timestamp = 0;
|
|
|
|
|
2018-07-03 16:00:12 +08:00
|
|
|
auto mDev = MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
mDev->setOSTime(new FailOSTime());
|
|
|
|
|
|
|
|
retVal = clGetHostTimer(
|
|
|
|
mDev,
|
|
|
|
&host_timestamp);
|
|
|
|
|
|
|
|
EXPECT_EQ(host_timestamp, zero_timestamp);
|
|
|
|
EXPECT_EQ(retVal, CL_OUT_OF_RESOURCES);
|
|
|
|
|
|
|
|
delete mDev;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ULT
|