2020-03-16 16:58:04 +01:00
|
|
|
/*
|
2021-05-16 20:51:16 +02:00
|
|
|
* Copyright (C) 2020-2021 Intel Corporation
|
2020-03-16 16:58:04 +01:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "shared/source/gmm_helper/gmm_helper.h"
|
2021-05-21 01:17:57 +02:00
|
|
|
#include "shared/source/os_interface/os_interface.h"
|
2021-01-21 13:10:13 +01:00
|
|
|
#include "shared/test/common/helpers/default_hw_info.h"
|
|
|
|
#include "shared/test/common/helpers/variable_backup.h"
|
2021-09-24 01:16:09 +00:00
|
|
|
#include "shared/test/common/libult/linux/drm_mock.h"
|
2021-07-06 15:44:16 +02:00
|
|
|
#include "shared/test/common/mocks/mock_execution_environment.h"
|
2021-12-14 17:40:08 +00:00
|
|
|
#include "shared/test/common/test_macros/test.h"
|
2020-03-16 16:58:04 +01:00
|
|
|
|
2021-09-24 01:16:09 +00:00
|
|
|
#include "opencl/test/unit_test/linux/mock_os_layer.h"
|
2020-03-16 16:58:04 +01:00
|
|
|
|
|
|
|
namespace NEO {
|
|
|
|
extern GMM_INIT_IN_ARGS passedInputArgs;
|
|
|
|
extern bool copyInputArgs;
|
|
|
|
|
2021-04-23 14:30:04 +00:00
|
|
|
TEST(OsInterfaceTest, whenOsInterfaceSetupsGmmInputArgsThenFileDescriptorIsSetWithValueOfAdapterBdf) {
|
2020-03-16 16:58:04 +01:00
|
|
|
MockExecutionEnvironment executionEnvironment;
|
|
|
|
auto rootDeviceEnvironment = executionEnvironment.rootDeviceEnvironments[0].get();
|
|
|
|
auto osInterface = new OSInterface();
|
|
|
|
rootDeviceEnvironment->osInterface.reset(osInterface);
|
|
|
|
|
2020-07-07 09:34:31 +02:00
|
|
|
auto drm = new DrmMock(fakeFd, *rootDeviceEnvironment);
|
2021-10-06 01:57:55 +00:00
|
|
|
drm->setPciPath("0000:01:23.4");
|
2021-05-31 16:58:10 +00:00
|
|
|
EXPECT_EQ(0, drm->queryAdapterBDF());
|
2021-04-23 14:30:04 +00:00
|
|
|
|
2021-05-21 01:17:57 +02:00
|
|
|
osInterface->setDriverModel(std::unique_ptr<DriverModel>(drm));
|
2020-03-16 16:58:04 +01:00
|
|
|
|
|
|
|
GMM_INIT_IN_ARGS gmmInputArgs = {};
|
|
|
|
EXPECT_EQ(0u, gmmInputArgs.FileDescriptor);
|
2021-05-21 01:17:57 +02:00
|
|
|
osInterface->getDriverModel()->setGmmInputArgs(&gmmInputArgs);
|
2020-03-16 16:58:04 +01:00
|
|
|
EXPECT_NE(0u, gmmInputArgs.FileDescriptor);
|
|
|
|
|
2021-04-23 14:30:04 +00:00
|
|
|
ADAPTER_BDF expectedAdapterBDF{};
|
|
|
|
expectedAdapterBDF.Bus = 0x1;
|
|
|
|
expectedAdapterBDF.Device = 0x23;
|
|
|
|
expectedAdapterBDF.Function = 0x4;
|
|
|
|
EXPECT_EQ(expectedAdapterBDF.Data, gmmInputArgs.FileDescriptor);
|
2020-07-22 12:51:48 +02:00
|
|
|
EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, gmmInputArgs.ClientType);
|
2020-03-16 16:58:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GmmHelperTest, whenCreateGmmHelperWithoutOsInterfaceThenPassedFileDescriptorIsZeroed) {
|
|
|
|
std::unique_ptr<GmmHelper> gmmHelper;
|
|
|
|
VariableBackup<decltype(passedInputArgs)> passedInputArgsBackup(&passedInputArgs);
|
|
|
|
VariableBackup<decltype(copyInputArgs)> copyInputArgsBackup(©InputArgs, true);
|
|
|
|
|
|
|
|
uint32_t expectedFileDescriptor = 0u;
|
|
|
|
|
2020-03-23 10:23:43 +01:00
|
|
|
gmmHelper.reset(new GmmHelper(nullptr, defaultHwInfo.get()));
|
2020-03-16 16:58:04 +01:00
|
|
|
EXPECT_EQ(expectedFileDescriptor, passedInputArgs.FileDescriptor);
|
2020-07-22 12:51:48 +02:00
|
|
|
EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, passedInputArgs.ClientType);
|
2020-03-16 16:58:04 +01:00
|
|
|
}
|
|
|
|
} // namespace NEO
|