|
8 | 8 | #include "shared/source/device/root_device.h" |
9 | 9 | #include "shared/source/helpers/bindless_heaps_helper.h" |
10 | 10 | #include "shared/source/os_interface/hw_info_config.h" |
| 11 | +#include "shared/source/os_interface/os_time.h" |
11 | 12 | #include "shared/test/common/helpers/debug_manager_state_restore.h" |
12 | 13 | #include "shared/test/common/mocks/mock_device.h" |
13 | 14 | #include "shared/test/common/mocks/ult_device_factory.h" |
@@ -326,6 +327,105 @@ TEST_F(DeviceTest, whenGetExternalMemoryPropertiesIsCalledThenSuccessIsReturnedA |
326 | 327 | EXPECT_TRUE(externalMemoryProperties.memoryAllocationImportTypes & ZE_EXTERNAL_MEMORY_TYPE_FLAG_DMA_BUF); |
327 | 328 | } |
328 | 329 |
|
| 330 | +TEST_F(DeviceTest, whenGetGlobalTimestampIsCalledThenSuccessIsReturnedAndValuesSetCorrectly) { |
| 331 | + uint64_t hostTs = 0u; |
| 332 | + uint64_t deviceTs = 0u; |
| 333 | + |
| 334 | + ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs); |
| 335 | + EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 336 | + |
| 337 | + EXPECT_NE(0u, hostTs); |
| 338 | + EXPECT_NE(0u, deviceTs); |
| 339 | +} |
| 340 | + |
| 341 | +class FalseCpuGpuTime : public NEO::OSTime { |
| 342 | + public: |
| 343 | + bool getCpuGpuTime(TimeStampData *pGpuCpuTime) override { |
| 344 | + return false; |
| 345 | + } |
| 346 | + bool getCpuTime(uint64_t *timeStamp) override { |
| 347 | + return true; |
| 348 | + }; |
| 349 | + double getHostTimerResolution() const override { |
| 350 | + return 0; |
| 351 | + } |
| 352 | + double getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const override { |
| 353 | + return NEO::OSTime::getDeviceTimerResolution(hwInfo); |
| 354 | + } |
| 355 | + uint64_t getCpuRawTimestamp() override { |
| 356 | + return 0; |
| 357 | + } |
| 358 | + static std::unique_ptr<OSTime> create() { |
| 359 | + return std::unique_ptr<OSTime>(new FalseCpuGpuTime()); |
| 360 | + } |
| 361 | +}; |
| 362 | + |
| 363 | +struct GlobalTimestampTest : public ::testing::Test { |
| 364 | + void SetUp() override { |
| 365 | + DebugManager.flags.CreateMultipleRootDevices.set(numRootDevices); |
| 366 | + neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get(), rootDeviceIndex); |
| 367 | + } |
| 368 | + |
| 369 | + DebugManagerStateRestore restorer; |
| 370 | + std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle; |
| 371 | + NEO::MockDevice *neoDevice = nullptr; |
| 372 | + L0::Device *device = nullptr; |
| 373 | + const uint32_t rootDeviceIndex = 1u; |
| 374 | + const uint32_t numRootDevices = 2u; |
| 375 | +}; |
| 376 | + |
| 377 | +TEST_F(GlobalTimestampTest, whenGetGlobalTimestampCalledAndGetCpuGpuTimeIsFalseReturnError) { |
| 378 | + uint64_t hostTs = 0u; |
| 379 | + uint64_t deviceTs = 0u; |
| 380 | + |
| 381 | + neoDevice->setOSTime(new FalseCpuGpuTime()); |
| 382 | + NEO::DeviceVector devices; |
| 383 | + devices.push_back(std::unique_ptr<NEO::Device>(neoDevice)); |
| 384 | + driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>(); |
| 385 | + driverHandle->initialize(std::move(devices)); |
| 386 | + device = driverHandle->devices[0]; |
| 387 | + |
| 388 | + ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs); |
| 389 | + EXPECT_EQ(ZE_RESULT_ERROR_DEVICE_LOST, result); |
| 390 | +} |
| 391 | + |
| 392 | +class FalseCpuTime : public NEO::OSTime { |
| 393 | + public: |
| 394 | + bool getCpuGpuTime(TimeStampData *pGpuCpuTime) override { |
| 395 | + return true; |
| 396 | + } |
| 397 | + bool getCpuTime(uint64_t *timeStamp) override { |
| 398 | + return false; |
| 399 | + }; |
| 400 | + double getHostTimerResolution() const override { |
| 401 | + return 0; |
| 402 | + } |
| 403 | + double getDynamicDeviceTimerResolution(HardwareInfo const &hwInfo) const override { |
| 404 | + return NEO::OSTime::getDeviceTimerResolution(hwInfo); |
| 405 | + } |
| 406 | + uint64_t getCpuRawTimestamp() override { |
| 407 | + return 0; |
| 408 | + } |
| 409 | + static std::unique_ptr<OSTime> create() { |
| 410 | + return std::unique_ptr<OSTime>(new FalseCpuTime()); |
| 411 | + } |
| 412 | +}; |
| 413 | + |
| 414 | +TEST_F(GlobalTimestampTest, whenGetGlobalTimestampCalledAndGetCpuTimeIsFalseReturnError) { |
| 415 | + uint64_t hostTs = 0u; |
| 416 | + uint64_t deviceTs = 0u; |
| 417 | + |
| 418 | + neoDevice->setOSTime(new FalseCpuTime()); |
| 419 | + NEO::DeviceVector devices; |
| 420 | + devices.push_back(std::unique_ptr<NEO::Device>(neoDevice)); |
| 421 | + driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>(); |
| 422 | + driverHandle->initialize(std::move(devices)); |
| 423 | + device = driverHandle->devices[0]; |
| 424 | + |
| 425 | + ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs); |
| 426 | + EXPECT_EQ(ZE_RESULT_ERROR_DEVICE_LOST, result); |
| 427 | +} |
| 428 | + |
329 | 429 | using DeviceGetMemoryTests = DeviceTest; |
330 | 430 |
|
331 | 431 | TEST_F(DeviceGetMemoryTests, whenCallingGetMemoryPropertiesWithCountZeroThenOneIsReturned) { |
|
0 commit comments