|
| 1 | +/* |
| 2 | + * Copyright (C) 2018-2022 Intel Corporation |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: MIT |
| 5 | + * |
| 6 | + */ |
| 7 | + |
| 8 | +#include "shared/source/execution_environment/root_device_environment.h" |
| 9 | +#include "shared/test/common/mocks/mock_execution_environment.h" |
| 10 | +#include "shared/test/common/mocks/mock_ostime.h" |
| 11 | +#include "shared/test/common/mocks/mock_ostime_win.h" |
| 12 | +#include "shared/test/common/mocks/mock_wddm.h" |
| 13 | +#include "shared/test/common/test_macros/test.h" |
| 14 | + |
| 15 | +#include "opencl/test/unit_test/fixtures/cl_device_fixture.h" |
| 16 | + |
| 17 | +using namespace NEO; |
| 18 | + |
| 19 | +namespace ULT { |
| 20 | + |
| 21 | +typedef ::testing::Test MockOSTimeWinTest; |
| 22 | + |
| 23 | +TEST_F(MockOSTimeWinTest, whenCreatingTimerThenResolutionIsSetCorrectly) { |
| 24 | + MockExecutionEnvironment executionEnvironment; |
| 25 | + RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); |
| 26 | + auto wddmMock = new WddmMock(rootDeviceEnvironment); |
| 27 | + auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr)); |
| 28 | + |
| 29 | + wddmMock->init(); |
| 30 | + |
| 31 | + wddmMock->timestampFrequency = 1000; |
| 32 | + |
| 33 | + std::unique_ptr<MockOSTimeWin> timeWin(new MockOSTimeWin(wddmMock)); |
| 34 | + |
| 35 | + double res = 0.0; |
| 36 | + res = timeWin->getDynamicDeviceTimerResolution(device->getHardwareInfo()); |
| 37 | + EXPECT_EQ(res, 1e+06); |
| 38 | +} |
| 39 | + |
| 40 | +TEST(GetDeviceInfo, givenClDeviceWhenGettingDeviceInfoThenCorrectAdapterLuidIsReturned) { |
| 41 | + auto clDevice = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr)); |
| 42 | + clDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new NEO::OSInterface); |
| 43 | + auto mockWddm = new WddmMock(*clDevice->executionEnvironment->rootDeviceEnvironments[0]); |
| 44 | + clDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(mockWddm)); |
| 45 | + |
| 46 | + std::array<uint8_t, CL_LUID_SIZE_KHR> deviceLuidKHR; |
| 47 | + auto luid = clDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Wddm>()->getAdapterLuid(); |
| 48 | + auto retVal = clDevice->getDeviceInfo(CL_DEVICE_LUID_KHR, CL_LUID_SIZE_KHR, deviceLuidKHR.data(), 0); |
| 49 | + |
| 50 | + ASSERT_EQ(retVal, CL_SUCCESS); |
| 51 | + EXPECT_EQ(std::memcmp(deviceLuidKHR.data(), &luid, CL_LUID_SIZE_KHR), 0); |
| 52 | +} |
| 53 | + |
| 54 | +TEST(GetDeviceInfo, givenClDeviceWhenVerifyAdapterLuidThenGetTrue) { |
| 55 | + auto clDevice = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr)); |
| 56 | + clDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new NEO::OSInterface); |
| 57 | + auto mockWddm = new WddmMock(*clDevice->executionEnvironment->rootDeviceEnvironments[0]); |
| 58 | + clDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(mockWddm)); |
| 59 | + |
| 60 | + cl_bool isValid = false; |
| 61 | + auto retVal = clDevice->getDeviceInfo(CL_DEVICE_LUID_VALID_KHR, sizeof(cl_bool), &isValid, 0); |
| 62 | + |
| 63 | + ASSERT_EQ(retVal, CL_SUCCESS); |
| 64 | + EXPECT_TRUE(isValid); |
| 65 | +} |
| 66 | + |
| 67 | +TEST(GetDeviceInfo, givenClDeviceWhenGettingDeviceInfoThenGetNodeMask) { |
| 68 | + auto clDevice = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr)); |
| 69 | + clDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(new NEO::OSInterface); |
| 70 | + auto mockWddm = new WddmMock(*clDevice->executionEnvironment->rootDeviceEnvironments[0]); |
| 71 | + clDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(mockWddm)); |
| 72 | + |
| 73 | + cl_uint nodeMask = 0b0; |
| 74 | + auto retVal = clDevice->getDeviceInfo(CL_DEVICE_NODE_MASK_KHR, sizeof(cl_uint), &nodeMask, 0); |
| 75 | + |
| 76 | + ASSERT_EQ(retVal, CL_SUCCESS); |
| 77 | + EXPECT_EQ(nodeMask, 0b1); |
| 78 | +} |
| 79 | +} // namespace ULT |
0 commit comments