mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 06:49:52 +08:00
Redesign ULT by mocking sysfs and implementing for standby
Change-Id: Id2558122406f23e96e3115d57e7b82d04463bfc4
This commit is contained in:
@@ -80,13 +80,13 @@ class SysfsAccess : private FsAccess {
|
||||
ze_result_t getFileMode(const std::string file, ::mode_t &mode);
|
||||
|
||||
MOCKABLE_VIRTUAL ze_result_t read(const std::string file, std::string &val);
|
||||
ze_result_t read(const std::string file, int &val);
|
||||
MOCKABLE_VIRTUAL ze_result_t read(const std::string file, int &val);
|
||||
MOCKABLE_VIRTUAL ze_result_t read(const std::string file, uint64_t &val);
|
||||
ze_result_t read(const std::string file, double &val);
|
||||
ze_result_t read(const std::string file, std::vector<std::string> &val);
|
||||
|
||||
ze_result_t write(const std::string file, const std::string val);
|
||||
ze_result_t write(const std::string file, const int val);
|
||||
MOCKABLE_VIRTUAL ze_result_t write(const std::string file, const int val);
|
||||
MOCKABLE_VIRTUAL ze_result_t write(const std::string file, const uint64_t val);
|
||||
ze_result_t write(const std::string file, const double val);
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
|
||||
set(L0_SRCS_TOOLS_SYSMAN_STANDBY_LINUX
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/os_standby_imp.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_standby_imp.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_standby_imp.h
|
||||
)
|
||||
|
||||
if(UNIX)
|
||||
|
||||
@@ -5,37 +5,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/os_interface/linux/drm_neo.h"
|
||||
#include "shared/source/os_interface/linux/os_interface.h"
|
||||
|
||||
#include "level_zero/core/source/device/device.h"
|
||||
|
||||
#include "sysman/linux/os_sysman_imp.h"
|
||||
#include "sysman/standby/os_standby.h"
|
||||
#include "sysman/standby/standby_imp.h"
|
||||
#include "level_zero/tools/source/sysman/standby/linux/os_standby_imp.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
class LinuxStandbyImp : public OsStandby {
|
||||
public:
|
||||
ze_result_t getMode(zet_standby_promo_mode_t &mode) override;
|
||||
ze_result_t setMode(zet_standby_promo_mode_t mode) override;
|
||||
|
||||
LinuxStandbyImp(OsSysman *pOsSysman);
|
||||
~LinuxStandbyImp() override = default;
|
||||
|
||||
// Don't allow copies of the LinuxStandbyImp object
|
||||
LinuxStandbyImp(const LinuxStandbyImp &obj) = delete;
|
||||
LinuxStandbyImp &operator=(const LinuxStandbyImp &obj) = delete;
|
||||
|
||||
private:
|
||||
SysfsAccess *pSysfsAccess;
|
||||
|
||||
static const std::string standbyModeFile;
|
||||
static const int standbyModeDefault = 1;
|
||||
static const int standbyModeNever = 0;
|
||||
};
|
||||
|
||||
const std::string LinuxStandbyImp::standbyModeFile("power/rc6_enable");
|
||||
|
||||
ze_result_t LinuxStandbyImp::getMode(zet_standby_promo_mode_t &mode) {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||
|
||||
#include "sysman/linux/os_sysman_imp.h"
|
||||
#include "sysman/standby/os_standby.h"
|
||||
#include "sysman/standby/standby_imp.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
class LinuxStandbyImp : public OsStandby, public NEO::NonCopyableClass {
|
||||
public:
|
||||
ze_result_t getMode(zet_standby_promo_mode_t &mode) override;
|
||||
ze_result_t setMode(zet_standby_promo_mode_t mode) override;
|
||||
LinuxStandbyImp() = default;
|
||||
LinuxStandbyImp(OsSysman *pOsSysman);
|
||||
~LinuxStandbyImp() override = default;
|
||||
|
||||
protected:
|
||||
SysfsAccess *pSysfsAccess = nullptr;
|
||||
|
||||
private:
|
||||
static const std::string standbyModeFile;
|
||||
static const int standbyModeDefault = 1;
|
||||
static const int standbyModeNever = 0;
|
||||
};
|
||||
|
||||
} // namespace L0
|
||||
@@ -5,8 +5,7 @@
|
||||
#
|
||||
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_standby.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_standby.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
)
|
||||
|
||||
add_subdirectories()
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#
|
||||
# Copyright (C) 2020 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
if(UNIX)
|
||||
target_sources(${TARGET_NAME}
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_standby.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_sysfs_standby.h
|
||||
)
|
||||
endif()
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "level_zero/core/test/unit_tests/mock.h"
|
||||
#include "level_zero/tools/source/sysman/standby/linux/os_standby_imp.h"
|
||||
|
||||
#include "sysman/linux/fs_access.h"
|
||||
#include "sysman/standby/os_standby.h"
|
||||
#include "sysman/standby/standby_imp.h"
|
||||
#include "sysman/sysman.h"
|
||||
#include "sysman/sysman_imp.h"
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Winconsistent-missing-override"
|
||||
#endif
|
||||
|
||||
using ::testing::_;
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
const std::string standbyModeFile("power/rc6_enable");
|
||||
|
||||
class StandbySysfsAccess : public SysfsAccess {};
|
||||
|
||||
template <>
|
||||
struct Mock<StandbySysfsAccess> : public StandbySysfsAccess {
|
||||
int mockStandbyMode = -1;
|
||||
MOCK_METHOD2(read, ze_result_t(const std::string file, int &val));
|
||||
MOCK_METHOD2(write, ze_result_t(const std::string file, const int val));
|
||||
|
||||
ze_result_t getVal(const std::string file, int &val) {
|
||||
if (file.compare(standbyModeFile) == 0) {
|
||||
val = mockStandbyMode;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t setVal(const std::string file, const int val) {
|
||||
if (file.compare(standbyModeFile) == 0) {
|
||||
mockStandbyMode = val;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
Mock<StandbySysfsAccess>() = default;
|
||||
};
|
||||
|
||||
class PublicLinuxStandbyImp : public L0::LinuxStandbyImp {
|
||||
public:
|
||||
using LinuxStandbyImp::pSysfsAccess;
|
||||
};
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||
#include "level_zero/tools/source/sysman/standby/linux/os_standby_imp.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "mock_sysfs_standby.h"
|
||||
#include "sysman/standby/os_standby.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::DoAll;
|
||||
using ::testing::InSequence;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::Matcher;
|
||||
using ::testing::NiceMock;
|
||||
using ::testing::Return;
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
constexpr int standbyModeDefault = 1;
|
||||
|
||||
class SysmanStandbyFixture : public DeviceFixture, public ::testing::Test {
|
||||
|
||||
protected:
|
||||
std::unique_ptr<SysmanImp> sysmanImp;
|
||||
zet_sysman_handle_t hSysman;
|
||||
zet_sysman_standby_handle_t hSysmanStandby;
|
||||
Mock<StandbySysfsAccess> *pSysfsAccess = nullptr;
|
||||
|
||||
OsStandby *pOsStandby = nullptr;
|
||||
PublicLinuxStandbyImp linuxStandbyImp;
|
||||
StandbyImp *pStandbyImp = nullptr;
|
||||
|
||||
void SetUp() override {
|
||||
DeviceFixture::SetUp();
|
||||
sysmanImp = std::make_unique<SysmanImp>(device->toHandle());
|
||||
pSysfsAccess = new NiceMock<Mock<StandbySysfsAccess>>;
|
||||
linuxStandbyImp.pSysfsAccess = pSysfsAccess;
|
||||
pOsStandby = static_cast<OsStandby *>(&linuxStandbyImp);
|
||||
pStandbyImp = new StandbyImp();
|
||||
pStandbyImp->pOsStandby = pOsStandby;
|
||||
pSysfsAccess->setVal(standbyModeFile, standbyModeDefault);
|
||||
ON_CALL(*pSysfsAccess, read(_, Matcher<int &>(_)))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess, &Mock<StandbySysfsAccess>::getVal));
|
||||
|
||||
pStandbyImp->init();
|
||||
sysmanImp->pStandbyHandleContext->handle_list.push_back(pStandbyImp);
|
||||
|
||||
hSysman = sysmanImp->toHandle();
|
||||
hSysmanStandby = pStandbyImp->toHandle();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
pStandbyImp->pOsStandby = nullptr;
|
||||
|
||||
if (pSysfsAccess != nullptr) {
|
||||
delete pSysfsAccess;
|
||||
pSysfsAccess = nullptr;
|
||||
}
|
||||
DeviceFixture::TearDown();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(SysmanStandbyFixture, GivenComponentCountZeroWhenCallingzetSysmanStandbyGetThenNonZeroCountIsReturnedAndVerifyzetSysmanStandbyGetCallSucceeds) {
|
||||
zet_sysman_standby_handle_t standbyHandle;
|
||||
uint32_t count;
|
||||
|
||||
ze_result_t result = zetSysmanStandbyGet(hSysman, &count, NULL);
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_GT(count, 0u);
|
||||
|
||||
uint32_t testCount = count + 1;
|
||||
|
||||
result = zetSysmanStandbyGet(hSysman, &testCount, NULL);
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(testCount, count);
|
||||
|
||||
result = zetSysmanStandbyGet(hSysman, &count, &standbyHandle);
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_NE(nullptr, standbyHandle);
|
||||
EXPECT_GT(count, 0u);
|
||||
}
|
||||
|
||||
TEST_F(SysmanStandbyFixture, GivenValidStandbyHandleWhenCallingzetSysmanStandbyGetPropertiesThenVerifyzetSysmanStandbyGetPropertiesCallSucceeds) {
|
||||
zet_standby_properties_t properties;
|
||||
|
||||
ze_result_t result = zetSysmanStandbyGetProperties(hSysmanStandby, &properties);
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(ZET_STANDBY_TYPE_GLOBAL, properties.type);
|
||||
EXPECT_FALSE(properties.onSubdevice);
|
||||
}
|
||||
|
||||
TEST_F(SysmanStandbyFixture, GivenValidStandbyHandleWhenCallingzetSysmanStandbyGetModeThenVerifyzetSysmanStandbyGetModeCallSucceeds) {
|
||||
zet_standby_promo_mode_t mode;
|
||||
|
||||
ze_result_t result = zetSysmanStandbyGetMode(hSysmanStandby, &mode);
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(ZET_STANDBY_PROMO_MODE_DEFAULT, mode);
|
||||
}
|
||||
|
||||
TEST_F(SysmanStandbyFixture, GivenValidStandbyHandleWhenCallingzetSysmanStandbySetModeThenVerifySysmanzetStandbySetModeCallSucceeds) {
|
||||
ze_result_t result = zetSysmanStandbySetMode(hSysmanStandby, ZET_STANDBY_PROMO_MODE_NEVER);
|
||||
|
||||
EXPECT_EQ(result, ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
@@ -0,0 +1,14 @@
|
||||
#
|
||||
# Copyright (C) 2020 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
if(WIN32)
|
||||
target_sources(${TARGET_NAME}
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_standby.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_standby.h
|
||||
)
|
||||
endif()
|
||||
Reference in New Issue
Block a user