From 4011006a3a85fda87fd51f84a02406b47c0deb10 Mon Sep 17 00:00:00 2001 From: shubham kumar Date: Thu, 24 Jul 2025 11:47:29 +0000 Subject: [PATCH] fix: Handle multiple device interface paths for windows PMT init Related-To: NEO-15620 Signed-off-by: shubham kumar --- .../source/shared/windows/pmt/sysman_pmt.cpp | 33 +++++++--- .../source/shared/windows/pmt/sysman_pmt.h | 8 +-- .../shared/windows/zes_os_sysman_imp.cpp | 1 - .../sources/memory/windows/mock_memory.h | 2 +- .../unit_tests/sources/pci/windows/mock_pci.h | 4 +- .../sources/pci/windows/test_zes_pci.cpp | 3 +- .../sources/power/windows/mock_power.h | 4 +- .../sysman_product_helper_memory_tests.cpp | 3 +- .../sysman_product_helper_power_tests.cpp | 3 +- ...ysman_product_helper_temperature_tests.cpp | 4 +- .../temperature/windows/mock_temperature.h | 4 +- .../windows/test_zes_temperature.cpp | 4 +- .../unit_tests/sources/windows/pmt/mock_pmt.h | 4 +- .../sources/windows/pmt/test_pmt.cpp | 62 ++++++++++++++----- 14 files changed, 91 insertions(+), 48 deletions(-) diff --git a/level_zero/sysman/source/shared/windows/pmt/sysman_pmt.cpp b/level_zero/sysman/source/shared/windows/pmt/sysman_pmt.cpp index 53caf2f649..225b0889b6 100644 --- a/level_zero/sysman/source/shared/windows/pmt/sysman_pmt.cpp +++ b/level_zero/sysman/source/shared/windows/pmt/sysman_pmt.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Intel Corporation + * Copyright (C) 2024-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -163,7 +163,7 @@ ze_result_t PlatformMonitoringTech::init() { } std::unique_ptr PlatformMonitoringTech::create(SysmanProductHelper *pSysmanProductHelper) { - std::vector deviceInterface; + std::wstring deviceInterface; if (enumeratePMTInterface(&PmtSysman::GuidIntefacePmtTelemetry, deviceInterface) == ZE_RESULT_SUCCESS) { std::unique_ptr pPmt; pPmt = std::make_unique(deviceInterface, pSysmanProductHelper); @@ -179,10 +179,11 @@ std::unique_ptr PlatformMonitoringTech::create(SysmanPro PlatformMonitoringTech::~PlatformMonitoringTech() { } -ze_result_t PlatformMonitoringTech::enumeratePMTInterface(const GUID *guid, std::vector &deviceInterface) { +ze_result_t PlatformMonitoringTech::enumeratePMTInterface(const GUID *guid, std::wstring &deviceInterface) { unsigned long cmListCharCount = 0; CONFIGRET status = CR_SUCCESS; + std::vector deviceInterfaceList; do { // Get the total size of list of all instances @@ -193,21 +194,20 @@ ze_result_t PlatformMonitoringTech::enumeratePMTInterface(const GUID *guid, std: break; } // Free previous allocation if present. - if (!deviceInterface.empty()) { - deviceInterface.clear(); + if (!deviceInterfaceList.empty()) { + deviceInterfaceList.clear(); } // Allocate buffer - deviceInterface.resize(cmListCharCount); + deviceInterfaceList.resize(cmListCharCount); - if (deviceInterface.empty()) { + if (deviceInterfaceList.empty()) { NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Could not allocate memory to store the PMT device interface path.\n"); DEBUG_BREAK_IF(true); return ZE_RESULT_ERROR_UNKNOWN; } // N.B. cmListCharCount is length in characters - status = NEO::SysCalls::cmGetDeviceInterfaceList((LPGUID)guid, NULL, &deviceInterface[0], cmListCharCount, CM_GET_DEVICE_INTERFACE_LIST_PRESENT); - + status = NEO::SysCalls::cmGetDeviceInterfaceList((LPGUID)guid, NULL, deviceInterfaceList.data(), cmListCharCount, CM_GET_DEVICE_INTERFACE_LIST_PRESENT); } while (status == CR_BUFFER_SMALL); if (status != CR_SUCCESS) { @@ -217,10 +217,23 @@ ze_result_t PlatformMonitoringTech::enumeratePMTInterface(const GUID *guid, std: return ZE_RESULT_ERROR_UNKNOWN; } + wchar_t *pDeviceInterface = deviceInterfaceList.data(); + + while (*pDeviceInterface) { + std::wstring deviceInterfaceName(pDeviceInterface); + std::wstring::size_type found = deviceInterfaceName.find(L"INTC_PMT"); + size_t interfaceCharCount = wcslen(pDeviceInterface); + if (found != std::wstring::npos) { + deviceInterface = std::move(deviceInterfaceName); + break; + } + pDeviceInterface += interfaceCharCount + 1; + } + return ZE_RESULT_SUCCESS; } -ze_result_t PlatformMonitoringTech::ioctlReadWriteData(std::vector &path, uint32_t ioctl, void *bufferIn, uint32_t inSize, void *bufferOut, uint32_t outSize, uint32_t *sizeReturned) { +ze_result_t PlatformMonitoringTech::ioctlReadWriteData(std::wstring &path, uint32_t ioctl, void *bufferIn, uint32_t inSize, void *bufferOut, uint32_t outSize, uint32_t *sizeReturned) { void *handle; BOOL status = FALSE; diff --git a/level_zero/sysman/source/shared/windows/pmt/sysman_pmt.h b/level_zero/sysman/source/shared/windows/pmt/sysman_pmt.h index ba48185264..6639a96570 100644 --- a/level_zero/sysman/source/shared/windows/pmt/sysman_pmt.h +++ b/level_zero/sysman/source/shared/windows/pmt/sysman_pmt.h @@ -26,19 +26,19 @@ class SysmanProductHelper; class PlatformMonitoringTech : NEO::NonCopyableAndNonMovableClass { public: PlatformMonitoringTech() = delete; - PlatformMonitoringTech(std::vector deviceInterface, SysmanProductHelper *pSysmanProductHelper) : deviceInterface(std::move(deviceInterface)), pSysmanProductHelper(pSysmanProductHelper) {} + PlatformMonitoringTech(std::wstring deviceInterface, SysmanProductHelper *pSysmanProductHelper) : deviceInterface(std::move(deviceInterface)), pSysmanProductHelper(pSysmanProductHelper) {} virtual ~PlatformMonitoringTech(); virtual ze_result_t readValue(const std::string &key, uint32_t &value); virtual ze_result_t readValue(const std::string &key, uint64_t &value); ze_result_t getKeyOffsetMap(std::map> &keyOffsetMap); static std::unique_ptr create(SysmanProductHelper *pSysmanProductHelper); - static ze_result_t enumeratePMTInterface(const GUID *Guid, std::vector &deviceInterface); + static ze_result_t enumeratePMTInterface(const GUID *Guid, std::wstring &deviceInterface); protected: std::map> keyOffsetMap; unsigned long guidToIndexList[PmtSysman::PmtMaxInterfaces] = {0}; - ze_result_t ioctlReadWriteData(std::vector &path, uint32_t ioctl, void *bufferIn, uint32_t inSize, void *bufferOut, uint32_t outSize, uint32_t *sizeReturned); + ze_result_t ioctlReadWriteData(std::wstring &path, uint32_t ioctl, void *bufferIn, uint32_t inSize, void *bufferOut, uint32_t outSize, uint32_t *sizeReturned); virtual ze_result_t init(); ze_result_t getGuid(); decltype(&NEO::SysCalls::deviceIoControl) pdeviceIoControl = NEO::SysCalls::deviceIoControl; @@ -48,7 +48,7 @@ class PlatformMonitoringTech : NEO::NonCopyableAndNonMovableClass { decltype(&NEO::SysCalls::heapFree) heapFreeFunction = NEO::SysCalls::heapFree; private: - std::vector deviceInterface; + std::wstring deviceInterface; SysmanProductHelper *pSysmanProductHelper = nullptr; uint32_t baseOffset = 0; }; diff --git a/level_zero/sysman/source/shared/windows/zes_os_sysman_imp.cpp b/level_zero/sysman/source/shared/windows/zes_os_sysman_imp.cpp index fecb18359d..f5aef1be3e 100644 --- a/level_zero/sysman/source/shared/windows/zes_os_sysman_imp.cpp +++ b/level_zero/sysman/source/shared/windows/zes_os_sysman_imp.cpp @@ -53,7 +53,6 @@ ze_result_t WddmSysmanImp::init() { } pPmt = PlatformMonitoringTech::create(pSysmanProductHelper.get()); - return ZE_RESULT_SUCCESS; } diff --git a/level_zero/sysman/test/unit_tests/sources/memory/windows/mock_memory.h b/level_zero/sysman/test/unit_tests/sources/memory/windows/mock_memory.h index 267cb39a98..2a9c435da5 100644 --- a/level_zero/sysman/test/unit_tests/sources/memory/windows/mock_memory.h +++ b/level_zero/sysman/test/unit_tests/sources/memory/windows/mock_memory.h @@ -207,7 +207,7 @@ class PublicWddmPowerImp : public L0::Sysman::WddmMemoryImp { class PublicPlatformMonitoringTech : public L0::Sysman::PlatformMonitoringTech { public: - PublicPlatformMonitoringTech(std::vector deviceInterfaceList, SysmanProductHelper *pSysmanProductHelper) : PlatformMonitoringTech(deviceInterfaceList, pSysmanProductHelper) {} + PublicPlatformMonitoringTech(std::wstring deviceInterfaceList, SysmanProductHelper *pSysmanProductHelper) : PlatformMonitoringTech(deviceInterfaceList, pSysmanProductHelper) {} using PlatformMonitoringTech::keyOffsetMap; }; diff --git a/level_zero/sysman/test/unit_tests/sources/pci/windows/mock_pci.h b/level_zero/sysman/test/unit_tests/sources/pci/windows/mock_pci.h index 823fa51e07..b25a487e40 100644 --- a/level_zero/sysman/test/unit_tests/sources/pci/windows/mock_pci.h +++ b/level_zero/sysman/test/unit_tests/sources/pci/windows/mock_pci.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2024 Intel Corporation + * Copyright (C) 2023-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -127,7 +127,7 @@ struct PciKmdSysManager : public MockKmdSysManager { class PublicPlatformMonitoringTech : public L0::Sysman::PlatformMonitoringTech { public: - PublicPlatformMonitoringTech(std::vector deviceInterfaceList, SysmanProductHelper *pSysmanProductHelper) : PlatformMonitoringTech(deviceInterfaceList, pSysmanProductHelper) {} + PublicPlatformMonitoringTech(std::wstring deviceInterfaceList, SysmanProductHelper *pSysmanProductHelper) : PlatformMonitoringTech(deviceInterfaceList, pSysmanProductHelper) {} using PlatformMonitoringTech::keyOffsetMap; }; diff --git a/level_zero/sysman/test/unit_tests/sources/pci/windows/test_zes_pci.cpp b/level_zero/sysman/test/unit_tests/sources/pci/windows/test_zes_pci.cpp index 6d1930901e..67256909b9 100644 --- a/level_zero/sysman/test/unit_tests/sources/pci/windows/test_zes_pci.cpp +++ b/level_zero/sysman/test/unit_tests/sources/pci/windows/test_zes_pci.cpp @@ -31,8 +31,7 @@ const std::map> dummyKeyOffsetMap = { {"GDDR_TELEM_CAPTURE_TIMESTAMP_UPPER", {92, 1}}, {"GDDR_TELEM_CAPTURE_TIMESTAMP_LOWER", {93, 1}}}}; -const std::wstring pmtInterfaceName = L"TEST\0"; -std::vector deviceInterfacePci(pmtInterfaceName.begin(), pmtInterfaceName.end()); +const std::wstring deviceInterfacePci = L"TEST\0"; class SysmanDevicePciFixture : public SysmanDeviceFixture { protected: diff --git a/level_zero/sysman/test/unit_tests/sources/power/windows/mock_power.h b/level_zero/sysman/test/unit_tests/sources/power/windows/mock_power.h index 9e07fe5db5..9a34ef5cdf 100644 --- a/level_zero/sysman/test/unit_tests/sources/power/windows/mock_power.h +++ b/level_zero/sysman/test/unit_tests/sources/power/windows/mock_power.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2024 Intel Corporation + * Copyright (C) 2020-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -228,7 +228,7 @@ struct PowerKmdSysManager : public MockKmdSysManager { class PublicPlatformMonitoringTech : public L0::Sysman::PlatformMonitoringTech { public: - PublicPlatformMonitoringTech(std::vector deviceInterfaceList, SysmanProductHelper *pSysmanProductHelper) : PlatformMonitoringTech(deviceInterfaceList, pSysmanProductHelper) {} + PublicPlatformMonitoringTech(std::wstring deviceInterfaceList, SysmanProductHelper *pSysmanProductHelper) : PlatformMonitoringTech(deviceInterfaceList, pSysmanProductHelper) {} using PlatformMonitoringTech::keyOffsetMap; }; diff --git a/level_zero/sysman/test/unit_tests/sources/shared/windows/product_helper/sysman_product_helper_memory_tests.cpp b/level_zero/sysman/test/unit_tests/sources/shared/windows/product_helper/sysman_product_helper_memory_tests.cpp index 171931ce55..b8ccceda0a 100644 --- a/level_zero/sysman/test/unit_tests/sources/shared/windows/product_helper/sysman_product_helper_memory_tests.cpp +++ b/level_zero/sysman/test/unit_tests/sources/shared/windows/product_helper/sysman_product_helper_memory_tests.cpp @@ -63,8 +63,7 @@ const std::map> dummyKeyOffsetMap = { {"GDDR0_CH1_GT_64B_WR_REQ_UPPER", {120, 1}}, {"GDDR0_CH1_GT_64B_WR_REQ_LOWER", {121, 1}}}}; -const std::wstring pmtInterfaceName = L"TEST\0"; -std::vector deviceInterfaceMemory(pmtInterfaceName.begin(), pmtInterfaceName.end()); +const std::wstring deviceInterfaceMemory = L"TEST\0"; class SysmanDeviceMemoryHelperFixture : public SysmanDeviceFixture { protected: std::unique_ptr pKmdSysManager; diff --git a/level_zero/sysman/test/unit_tests/sources/shared/windows/product_helper/sysman_product_helper_power_tests.cpp b/level_zero/sysman/test/unit_tests/sources/shared/windows/product_helper/sysman_product_helper_power_tests.cpp index 6dd70c109b..3c0aa4c6ba 100644 --- a/level_zero/sysman/test/unit_tests/sources/shared/windows/product_helper/sysman_product_helper_power_tests.cpp +++ b/level_zero/sysman/test/unit_tests/sources/shared/windows/product_helper/sysman_product_helper_power_tests.cpp @@ -18,8 +18,7 @@ namespace L0 { namespace Sysman { namespace ult { -const std::wstring pmtInterfaceName = L"TEST\0"; -std::vector pmtInterfacePower(pmtInterfaceName.begin(), pmtInterfaceName.end()); +const std::wstring pmtInterfacePower = L"TEST\0"; const std::map> dummyKeyOffsetMap = { {{"XTAL_CLK_FREQUENCY", {1, 0}}, diff --git a/level_zero/sysman/test/unit_tests/sources/shared/windows/product_helper/sysman_product_helper_temperature_tests.cpp b/level_zero/sysman/test/unit_tests/sources/shared/windows/product_helper/sysman_product_helper_temperature_tests.cpp index 290670ccc8..9f2b601b1e 100644 --- a/level_zero/sysman/test/unit_tests/sources/shared/windows/product_helper/sysman_product_helper_temperature_tests.cpp +++ b/level_zero/sysman/test/unit_tests/sources/shared/windows/product_helper/sysman_product_helper_temperature_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Intel Corporation + * Copyright (C) 2024-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -17,7 +17,7 @@ namespace L0 { namespace Sysman { namespace ult { -std::vector pmtInterface(pmtInterfaceName.begin(), pmtInterfaceName.end()); +std::wstring pmtInterface = std::move(pmtInterfaceName); const std::map> dummyKeyOffsetMap = { {{"SOC_THERMAL_SENSORS_TEMPERATURE_0_2_0_GTTMMADR[1]", {41, 1}}, {"VRAM_TEMPERATURE_0_2_0_GTTMMADR", {42, 1}}}}; diff --git a/level_zero/sysman/test/unit_tests/sources/temperature/windows/mock_temperature.h b/level_zero/sysman/test/unit_tests/sources/temperature/windows/mock_temperature.h index 1e730c03c0..b9b22ce8ce 100644 --- a/level_zero/sysman/test/unit_tests/sources/temperature/windows/mock_temperature.h +++ b/level_zero/sysman/test/unit_tests/sources/temperature/windows/mock_temperature.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2024 Intel Corporation + * Copyright (C) 2020-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -101,7 +101,7 @@ struct TemperatureKmdSysManager : public MockKmdSysManager { class PublicPlatformMonitoringTech : public L0::Sysman::PlatformMonitoringTech { public: - PublicPlatformMonitoringTech(std::vector deviceInterfaceList, SysmanProductHelper *pSysmanProductHelper) : PlatformMonitoringTech(deviceInterfaceList, pSysmanProductHelper) {} + PublicPlatformMonitoringTech(std::wstring deviceInterfaceList, SysmanProductHelper *pSysmanProductHelper) : PlatformMonitoringTech(deviceInterfaceList, pSysmanProductHelper) {} using PlatformMonitoringTech::keyOffsetMap; }; diff --git a/level_zero/sysman/test/unit_tests/sources/temperature/windows/test_zes_temperature.cpp b/level_zero/sysman/test/unit_tests/sources/temperature/windows/test_zes_temperature.cpp index 415f57a76f..81e12662aa 100644 --- a/level_zero/sysman/test/unit_tests/sources/temperature/windows/test_zes_temperature.cpp +++ b/level_zero/sysman/test/unit_tests/sources/temperature/windows/test_zes_temperature.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2024 Intel Corporation + * Copyright (C) 2020-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -20,7 +20,7 @@ class SysmanDeviceTemperatureFixture : public SysmanDeviceFixture { L0::Sysman::KmdSysManager *pOriginalKmdSysManager = nullptr; std::vector deviceHandles; void SetUp() override { - std::vector deviceInterfacePmt(pmtInterfaceName.begin(), pmtInterfaceName.end()); + std::wstring deviceInterfacePmt = std::move(pmtInterfaceName); SysmanDeviceFixture::SetUp(); pKmdSysManager.reset(new TemperatureKmdSysManager); diff --git a/level_zero/sysman/test/unit_tests/sources/windows/pmt/mock_pmt.h b/level_zero/sysman/test/unit_tests/sources/windows/pmt/mock_pmt.h index 73777aaf97..a6a545cd56 100644 --- a/level_zero/sysman/test/unit_tests/sources/windows/pmt/mock_pmt.h +++ b/level_zero/sysman/test/unit_tests/sources/windows/pmt/mock_pmt.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Intel Corporation + * Copyright (C) 2024-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -17,7 +17,7 @@ namespace ult { class PublicPlatformMonitoringTech : public L0::Sysman::PlatformMonitoringTech { public: - PublicPlatformMonitoringTech(std::vector deviceInterfaceList, SysmanProductHelper *pSysmanProductHelper) : PlatformMonitoringTech(deviceInterfaceList, pSysmanProductHelper) {} + PublicPlatformMonitoringTech(std::wstring deviceInterfaceList, SysmanProductHelper *pSysmanProductHelper) : PlatformMonitoringTech(deviceInterfaceList, pSysmanProductHelper) {} using PlatformMonitoringTech::keyOffsetMap; using PlatformMonitoringTech::pcreateFile; using PlatformMonitoringTech::pdeviceIoControl; diff --git a/level_zero/sysman/test/unit_tests/sources/windows/pmt/test_pmt.cpp b/level_zero/sysman/test/unit_tests/sources/windows/pmt/test_pmt.cpp index 59d6e3d9f3..d40eb65aef 100644 --- a/level_zero/sysman/test/unit_tests/sources/windows/pmt/test_pmt.cpp +++ b/level_zero/sysman/test/unit_tests/sources/windows/pmt/test_pmt.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Intel Corporation + * Copyright (C) 2024-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -16,8 +16,7 @@ namespace L0 { namespace Sysman { namespace ult { -const std::wstring interfaceName = L"TEST\0"; -std::vector deviceInterface(interfaceName.begin(), interfaceName.end()); +const std::wstring deviceInterface = L"TEST_INTC_PMT\0"; const std::map> dummyKeyOffsetMap = { {"DUMMY_KEY", {0x0, 1}}}; @@ -37,7 +36,7 @@ class SysmanDevicePmtFixture : public SysmanDeviceFixture { std::unique_ptr pPmt; void SetUp() override { SysmanDeviceFixture::SetUp(); - std::vector deviceInterface; + std::wstring deviceInterface; pPmt = std::make_unique(deviceInterface, pWddmSysmanImp->getSysmanProductHelper()); } @@ -165,10 +164,11 @@ TEST_F(SysmanDevicePmtFixture, GivenValidPmtInterfaceWithUnsupportedGuidWhenCall return true; }); VariableBackup psysCallsInterfaceListSize(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceListSize, [](PULONG pulLen, LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, ULONG ulFlags) -> CONFIGRET { - *pulLen = 4; + *pulLen = 40; return CR_SUCCESS; }); VariableBackup psysCallsInterfaceList(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceList, [](LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, PZZWSTR buffer, ULONG bufferLen, ULONG ulFlags) -> CONFIGRET { + wcscpy(buffer, L"TEST_INTC_PMT"); return CR_SUCCESS; }); struct MockSysmanProductHelperPmt : L0::Sysman::SysmanProductHelperHw { @@ -195,16 +195,42 @@ HWTEST2_F(SysmanDevicePmtFixture, GivenValidPmtInterfaceWhenCallingCreateThenCal return true; }); VariableBackup psysCallsInterfaceListSize(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceListSize, [](PULONG pulLen, LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, ULONG ulFlags) -> CONFIGRET { - *pulLen = 4; + *pulLen = 40; return CR_SUCCESS; }); VariableBackup psysCallsInterfaceList(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceList, [](LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, PZZWSTR buffer, ULONG bufferLen, ULONG ulFlags) -> CONFIGRET { + wcscpy(buffer, L"TEST_INTC_PMT"); return CR_SUCCESS; }); std::unique_ptr pPmt = PublicPlatformMonitoringTech::create(pWddmSysmanImp->getSysmanProductHelper()); EXPECT_NE(nullptr, pPmt); } +HWTEST2_F(SysmanDevicePmtFixture, GivenInValidPmtInterfaceNameWhenCallingCreateThenCallFails, IsBMG) { + VariableBackup psysCallsCreateFile(&NEO::SysCalls::sysCallsCreateFile, [](LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) -> HANDLE { + return reinterpret_cast(static_cast(0x7)); + }); + VariableBackup psysCallsDeviceIoControl(&NEO::SysCalls::sysCallsDeviceIoControl, [](HANDLE hDevice, DWORD dwIoControlCode, LPVOID lpInBuffer, DWORD nInBufferSize, LPVOID lpOutBuffer, DWORD nOutBufferSize, LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped) -> BOOL { + if (static_cast(dwIoControlCode) == PmtSysman::IoctlPmtGetTelemetryDiscoverySize) { + *static_cast(lpOutBuffer) = 40; + } else if (static_cast(dwIoControlCode) == PmtSysman::IoctlPmtGetTelemetryDiscovery) { + PmtSysman::PmtTelemetryDiscovery temp = {1, 2, {{1, 1, 0x5e2f8210, 10}}}; + *static_cast(lpOutBuffer) = temp; + } + return true; + }); + VariableBackup psysCallsInterfaceListSize(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceListSize, [](PULONG pulLen, LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, ULONG ulFlags) -> CONFIGRET { + *pulLen = 40; + return CR_SUCCESS; + }); + VariableBackup psysCallsInterfaceList(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceList, [](LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, PZZWSTR buffer, ULONG bufferLen, ULONG ulFlags) -> CONFIGRET { + wcscpy(buffer, L"TEST_WRONG_INTERFACE"); + return CR_SUCCESS; + }); + std::unique_ptr pPmt = PublicPlatformMonitoringTech::create(pWddmSysmanImp->getSysmanProductHelper()); + EXPECT_EQ(nullptr, pPmt); +} + HWTEST2_F(SysmanDevicePmtFixture, GivenValidPmtInterfaceWhenCallingCreateWithNoGuidsFoundThenCallFails, IsBMG) { VariableBackup psysCallsCreateFile(&NEO::SysCalls::sysCallsCreateFile, [](LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) -> HANDLE { return reinterpret_cast(static_cast(0x7)); @@ -216,10 +242,11 @@ HWTEST2_F(SysmanDevicePmtFixture, GivenValidPmtInterfaceWhenCallingCreateWithNoG return true; }); VariableBackup psysCallsInterfaceListSize(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceListSize, [](PULONG pulLen, LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, ULONG ulFlags) -> CONFIGRET { - *pulLen = 4; + *pulLen = 40; return CR_SUCCESS; }); VariableBackup psysCallsInterfaceList(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceList, [](LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, PZZWSTR buffer, ULONG bufferLen, ULONG ulFlags) -> CONFIGRET { + wcscpy(buffer, L"TEST_INTC_PMT"); return CR_SUCCESS; }); std::unique_ptr pPmt = PublicPlatformMonitoringTech::create(pWddmSysmanImp->getSysmanProductHelper()); @@ -237,10 +264,11 @@ HWTEST2_F(SysmanDevicePmtFixture, GivenValidPmtInterfaceWhenCallingCreateAndTele return true; }); VariableBackup psysCallsInterfaceListSize(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceListSize, [](PULONG pulLen, LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, ULONG ulFlags) -> CONFIGRET { - *pulLen = 4; + *pulLen = 40; return CR_SUCCESS; }); VariableBackup psysCallsInterfaceList(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceList, [](LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, PZZWSTR buffer, ULONG bufferLen, ULONG ulFlags) -> CONFIGRET { + wcscpy(buffer, L"TEST_INTC_PMT"); return CR_SUCCESS; }); std::unique_ptr pPmt = PublicPlatformMonitoringTech::create(pWddmSysmanImp->getSysmanProductHelper()); @@ -260,10 +288,11 @@ HWTEST2_F(SysmanDevicePmtFixture, GivenValidPmtInterfaceWhenCallingCreateAndTele return true; }); VariableBackup psysCallsInterfaceListSize(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceListSize, [](PULONG pulLen, LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, ULONG ulFlags) -> CONFIGRET { - *pulLen = 4; + *pulLen = 40; return CR_SUCCESS; }); VariableBackup psysCallsInterfaceList(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceList, [](LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, PZZWSTR buffer, ULONG bufferLen, ULONG ulFlags) -> CONFIGRET { + wcscpy(buffer, L"TEST_INTC_PMT"); return CR_SUCCESS; }); std::unique_ptr pPmt = PublicPlatformMonitoringTech::create(pWddmSysmanImp->getSysmanProductHelper()); @@ -275,10 +304,11 @@ HWTEST2_F(SysmanDevicePmtFixture, GivenValidPmtInterfaceWhenCallingCreateAndTele return reinterpret_cast(static_cast(0x7)); }); VariableBackup psysCallsInterfaceListSize(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceListSize, [](PULONG pulLen, LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, ULONG ulFlags) -> CONFIGRET { - *pulLen = 4; + *pulLen = 40; return CR_SUCCESS; }); VariableBackup psysCallsInterfaceList(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceList, [](LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, PZZWSTR buffer, ULONG bufferLen, ULONG ulFlags) -> CONFIGRET { + wcscpy(buffer, L"TEST_INTC_PMT"); return CR_SUCCESS; }); std::unique_ptr pPmt = PublicPlatformMonitoringTech::create(pWddmSysmanImp->getSysmanProductHelper()); @@ -299,12 +329,13 @@ HWTEST2_F(SysmanDevicePmtFixture, GivenValidPmtInterfaceWhenCallingCreateThenCal return true; }); VariableBackup psysCallsInterfaceListSize(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceListSize, [](PULONG pulLen, LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, ULONG ulFlags) -> CONFIGRET { - *pulLen = 4; + *pulLen = 40; return CR_SUCCESS; }); VariableBackup psysCallsInterfaceList(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceList, [](LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, PZZWSTR buffer, ULONG bufferLen, ULONG ulFlags) -> CONFIGRET { static int sysCallsInterfaceListCounter = 0; if (sysCallsInterfaceListCounter) { + wcscpy(buffer, L"TEST_INTC_PMT"); return CR_SUCCESS; } sysCallsInterfaceListCounter++; @@ -351,10 +382,11 @@ HWTEST2_F(SysmanDevicePmtFixture, GivenValidPmtInterfaceWhenCallingCreateAndHeap return true; }); VariableBackup mockCmGetDeviceInterfaceListSize(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceListSize, [](PULONG pulLen, LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, ULONG ulFlags) -> CONFIGRET { - *pulLen = 4; + *pulLen = 40; return CR_SUCCESS; }); VariableBackup mockCmGetDeviceInterfaceList(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceList, [](LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, PZZWSTR buffer, ULONG bufferLen, ULONG ulFlags) -> CONFIGRET { + wcscpy(buffer, L"TEST_INTC_PMT"); return CR_SUCCESS; }); VariableBackup mockHeapAlloc(&NEO::SysCalls::sysCallsHeapAlloc, [](HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes) -> LPVOID { @@ -380,10 +412,11 @@ HWTEST2_F(SysmanDevicePmtFixture, GivenValidPmtInterfaceWhenCallingCreateAndTele return true; }); VariableBackup mockCmGetDeviceInterfaceListSize(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceListSize, [](PULONG pulLen, LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, ULONG ulFlags) -> CONFIGRET { - *pulLen = 4; + *pulLen = 40; return CR_SUCCESS; }); VariableBackup mockCmGetDeviceInterfaceList(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceList, [](LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, PZZWSTR buffer, ULONG bufferLen, ULONG ulFlags) -> CONFIGRET { + wcscpy(buffer, L"TEST_INTC_PMT"); return CR_SUCCESS; }); std::unique_ptr pPmt = PublicPlatformMonitoringTech::create(pWddmSysmanImp->getSysmanProductHelper()); @@ -404,10 +437,11 @@ HWTEST2_F(SysmanDevicePmtFixture, GivenValidPmtInterfaceWhenCallingCreateAndHeap return true; }); VariableBackup mockCmGetDeviceInterfaceListSize(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceListSize, [](PULONG pulLen, LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, ULONG ulFlags) -> CONFIGRET { - *pulLen = 4; + *pulLen = 40; return CR_SUCCESS; }); VariableBackup mockCmGetDeviceInterfaceList(&NEO::SysCalls::sysCallsCmGetDeviceInterfaceList, [](LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, PZZWSTR buffer, ULONG bufferLen, ULONG ulFlags) -> CONFIGRET { + wcscpy(buffer, L"TEST_INTC_PMT"); return CR_SUCCESS; }); VariableBackup mocksHeapFree(&NEO::SysCalls::sysCallsHeapFree, [](HANDLE hHeap, DWORD dwFlags, LPVOID lpMem) -> BOOL {