mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Templated SetUp and TearDown in fixtures
Change-Id: I86b0e88db1ed52966ed5f0a6474deda09a415768 Signed-off-by: Dunajski, Bartosz <bartosz.dunajski@intel.com>
This commit is contained in:

committed by
sys_ocldev

parent
e7a4635dd6
commit
40d4314670
@ -40,6 +40,7 @@ set(IGDRCL_SRCS_tests_fixtures
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/scenario_test_fixture.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/simple_arg_fixture.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/simple_arg_kernel_fixture.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/templated_fixture_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/two_walker_fixture.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ult_command_stream_receiver_fixture.h
|
||||
)
|
||||
|
93
unit_tests/fixtures/templated_fixture_tests.cpp
Normal file
93
unit_tests/fixtures/templated_fixture_tests.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "runtime/helpers/hardware_commands_helper.h"
|
||||
#include "test.h"
|
||||
|
||||
namespace NEO {
|
||||
struct TemplatedFixtureTests : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
baseSetUpCallId = callsOrder++;
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
EXPECT_EQ(idForBaseTearDown, callsOrder);
|
||||
EXPECT_EQ((idForBaseTearDown - 1), templateBaseTearDownCallId);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void SetUpT() {
|
||||
templateBaseSetUpCallId = callsOrder++;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void TearDownT() {
|
||||
templateBaseTearDownCallId = callsOrder++;
|
||||
}
|
||||
|
||||
uint32_t callsOrder = 0;
|
||||
uint32_t baseSetUpCallId = -1;
|
||||
uint32_t templateBaseSetUpCallId = -1;
|
||||
uint32_t templateBaseTearDownCallId = -1;
|
||||
|
||||
uint32_t idForBaseTearDown = -1;
|
||||
};
|
||||
|
||||
HWTEST_F_T(TemplatedFixtureTests, whenExecutingTemplatedTestThenCallTemplatedSetupAndTeardown) {
|
||||
EXPECT_EQ(2u, callsOrder);
|
||||
|
||||
EXPECT_EQ(0u, baseSetUpCallId);
|
||||
EXPECT_EQ(1u, templateBaseSetUpCallId);
|
||||
|
||||
idForBaseTearDown = callsOrder + 1;
|
||||
}
|
||||
|
||||
struct DerivedTemplatedFixtureTests : public TemplatedFixtureTests {
|
||||
template <typename T>
|
||||
void SetUpT() {
|
||||
TemplatedFixtureTests::SetUpT<T>();
|
||||
templateDerivedSetUpCallId = callsOrder++;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void TearDownT() {
|
||||
templateDerivedTearDownCallId = callsOrder++;
|
||||
TemplatedFixtureTests::TearDownT<T>();
|
||||
}
|
||||
|
||||
uint32_t templateDerivedSetUpCallId = -1;
|
||||
uint32_t templateDerivedTearDownCallId = -1;
|
||||
};
|
||||
|
||||
HWTEST_F_T(DerivedTemplatedFixtureTests, whenExecutingTemplatedTestThenCallTemplatedSetupAndTeardown) {
|
||||
EXPECT_EQ(3u, callsOrder);
|
||||
|
||||
EXPECT_EQ(0u, baseSetUpCallId);
|
||||
EXPECT_EQ(1u, templateBaseSetUpCallId);
|
||||
EXPECT_EQ(2u, templateDerivedSetUpCallId);
|
||||
|
||||
idForBaseTearDown = callsOrder + 2;
|
||||
}
|
||||
|
||||
struct TemplatedFixtureBaseTests : public ::testing::Test {
|
||||
template <typename T>
|
||||
void SetUpT() {
|
||||
capturedPipeControlWaRequiredInSetUp = HardwareCommandsHelper<T>::isPipeControlWArequired(**platformDevices);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void TearDownT() {}
|
||||
|
||||
bool capturedPipeControlWaRequiredInSetUp = false;
|
||||
};
|
||||
|
||||
HWTEST_F_T(TemplatedFixtureBaseTests, whenExecutingTemplatedSetupThenTemplateTargetsCorrectPlatform) {
|
||||
bool capturedPipeControlWaRequiredInTestBody = HardwareCommandsHelper<FamilyType>::isPipeControlWArequired(**platformDevices);
|
||||
|
||||
EXPECT_EQ(capturedPipeControlWaRequiredInTestBody, capturedPipeControlWaRequiredInSetUp);
|
||||
}
|
||||
} // namespace NEO
|
@ -21,33 +21,49 @@ extern PRODUCT_FAMILY productFamily;
|
||||
extern GFXCORE_FAMILY renderCoreFamily;
|
||||
|
||||
#ifdef TESTS_GEN8
|
||||
#define BDW_TYPED_TEST_BODY testBodyHw<typename NEO::GfxFamilyMapper<IGFX_GEN8_CORE>::GfxFamily>();
|
||||
#define BDW_TYPED_TEST(method) method<typename NEO::GfxFamilyMapper<IGFX_GEN8_CORE>::GfxFamily>();
|
||||
#define BDW_TYPED_CMDTEST_BODY runCmdTestHwIfSupported<typename NEO::GfxFamilyMapper<IGFX_GEN8_CORE>::GfxFamily>();
|
||||
#define BDW_SUPPORTED_TEST(cmdSetBase) NEO::GfxFamilyMapper<IGFX_GEN8_CORE>::GfxFamily::supportsCmdSet(cmdSetBase)
|
||||
#else
|
||||
#define BDW_TYPED_TEST_BODY
|
||||
#define BDW_TYPED_TEST(method)
|
||||
#define BDW_TYPED_CMDTEST_BODY
|
||||
#define BDW_SUPPORTED_TEST(cmdSetBase) false
|
||||
#endif
|
||||
#ifdef TESTS_GEN9
|
||||
#define SKL_TYPED_TEST_BODY testBodyHw<typename NEO::GfxFamilyMapper<IGFX_GEN9_CORE>::GfxFamily>();
|
||||
#define SKL_TYPED_TEST(method) method<typename NEO::GfxFamilyMapper<IGFX_GEN9_CORE>::GfxFamily>();
|
||||
#define SKL_TYPED_CMDTEST_BODY runCmdTestHwIfSupported<typename NEO::GfxFamilyMapper<IGFX_GEN9_CORE>::GfxFamily>();
|
||||
#define SKL_SUPPORTED_TEST(cmdSetBase) NEO::GfxFamilyMapper<IGFX_GEN9_CORE>::GfxFamily::supportsCmdSet(cmdSetBase)
|
||||
#else
|
||||
#define SKL_TYPED_TEST_BODY
|
||||
#define SKL_TYPED_TEST(method)
|
||||
#define SKL_TYPED_CMDTEST_BODY
|
||||
#define SKL_SUPPORTED_TEST(cmdSetBase) false
|
||||
#endif
|
||||
#ifdef TESTS_GEN11
|
||||
#define ICL_TYPED_TEST_BODY testBodyHw<typename NEO::GfxFamilyMapper<IGFX_GEN11_CORE>::GfxFamily>();
|
||||
#define ICL_TYPED_TEST(method) method<typename NEO::GfxFamilyMapper<IGFX_GEN11_CORE>::GfxFamily>();
|
||||
#define ICL_TYPED_CMDTEST_BODY runCmdTestHwIfSupported<typename NEO::GfxFamilyMapper<IGFX_GEN11_CORE>::GfxFamily>();
|
||||
#define ICL_SUPPORTED_TEST(cmdSetBase) NEO::GfxFamilyMapper<IGFX_GEN11_CORE>::GfxFamily::supportsCmdSet(cmdSetBase)
|
||||
#else
|
||||
#define ICL_TYPED_TEST_BODY
|
||||
#define ICL_TYPED_TEST(method)
|
||||
#define ICL_TYPED_CMDTEST_BODY
|
||||
#define ICL_SUPPORTED_TEST(cmdSetBase) false
|
||||
#endif
|
||||
|
||||
#define FAMILY_SELECTOR(family, methodName) \
|
||||
switch (family) { \
|
||||
case IGFX_GEN8_CORE: \
|
||||
BDW_TYPED_TEST(methodName) \
|
||||
break; \
|
||||
case IGFX_GEN9_CORE: \
|
||||
SKL_TYPED_TEST(methodName) \
|
||||
break; \
|
||||
case IGFX_GEN11_CORE: \
|
||||
ICL_TYPED_TEST(methodName) \
|
||||
break; \
|
||||
default: \
|
||||
ASSERT_TRUE((false && "Unknown hardware family")); \
|
||||
break; \
|
||||
}
|
||||
|
||||
#define TO_STR2(x) #x
|
||||
#define TO_STR(x) TO_STR2(x)
|
||||
|
||||
@ -103,90 +119,85 @@ extern GFXCORE_FAMILY renderCoreFamily;
|
||||
|
||||
// Macros to provide template based testing.
|
||||
// Test can use FamilyType in the test -- equivalent to SKLFamily
|
||||
#define HWTEST_TEST_(test_suite_name, test_name, parent_class, parent_id) \
|
||||
CHECK_TEST_NAME_LENGTH(test_suite_name, test_name) \
|
||||
class PLATFORM_EXCLUDES_CLASS_NAME(test_suite_name, test_name) { \
|
||||
public: \
|
||||
static std::unique_ptr<std::unordered_set<uint32_t>> &getExcludes() { \
|
||||
static std::unique_ptr<std::unordered_set<uint32_t>> excludes; \
|
||||
return excludes; \
|
||||
} \
|
||||
static void addExclude(uint32_t product) { \
|
||||
auto &excludes = getExcludes(); \
|
||||
if (excludes == nullptr) { \
|
||||
excludes = std::make_unique<std::unordered_set<uint32_t>>(); \
|
||||
} \
|
||||
excludes->insert(product); \
|
||||
} \
|
||||
}; \
|
||||
\
|
||||
class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) : public parent_class { \
|
||||
\
|
||||
public: \
|
||||
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \
|
||||
() {} \
|
||||
\
|
||||
private: \
|
||||
template <typename FamilyType> \
|
||||
void testBodyHw(); \
|
||||
bool notExcluded() const { \
|
||||
using ExcludesT = PLATFORM_EXCLUDES_CLASS_NAME(test_suite_name, test_name); \
|
||||
auto &excludes = ExcludesT::getExcludes(); \
|
||||
if (excludes == nullptr) { \
|
||||
return true; \
|
||||
} \
|
||||
return excludes->count(::productFamily) == 0; \
|
||||
} \
|
||||
void SetUp() override { \
|
||||
if (notExcluded()) { \
|
||||
parent_class::SetUp(); \
|
||||
} \
|
||||
} \
|
||||
void TearDown() override { \
|
||||
if (notExcluded()) { \
|
||||
parent_class::TearDown(); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
void TestBody() override { \
|
||||
if (notExcluded()) { \
|
||||
switch (::renderCoreFamily) { \
|
||||
case IGFX_GEN8_CORE: \
|
||||
BDW_TYPED_TEST_BODY \
|
||||
break; \
|
||||
case IGFX_GEN9_CORE: \
|
||||
SKL_TYPED_TEST_BODY \
|
||||
break; \
|
||||
case IGFX_GEN11_CORE: \
|
||||
ICL_TYPED_TEST_BODY \
|
||||
break; \
|
||||
default: \
|
||||
ASSERT_TRUE((false && "Unknown hardware family")); \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
static ::testing::TestInfo *const test_info_ GTEST_ATTRIBUTE_UNUSED_; \
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_( \
|
||||
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)); \
|
||||
}; \
|
||||
\
|
||||
::testing::TestInfo *const GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::test_info_ = \
|
||||
::testing::internal::MakeAndRegisterTestInfo( \
|
||||
#test_suite_name, #test_name, nullptr, nullptr, \
|
||||
::testing::internal::CodeLocation(__FILE__, __LINE__), (parent_id), \
|
||||
::testing::internal::SuiteApiResolver< \
|
||||
parent_class>::GetSetUpCaseOrSuite(), \
|
||||
::testing::internal::SuiteApiResolver< \
|
||||
parent_class>::GetTearDownCaseOrSuite(), \
|
||||
new ::testing::internal::TestFactoryImpl<GTEST_TEST_CLASS_NAME_( \
|
||||
test_suite_name, test_name)>); \
|
||||
template <typename FamilyType> \
|
||||
#define HWTEST_TEST_(test_suite_name, test_name, parent_class, parent_id, SetUpT_name, TearDownT_name) \
|
||||
CHECK_TEST_NAME_LENGTH(test_suite_name, test_name) \
|
||||
class PLATFORM_EXCLUDES_CLASS_NAME(test_suite_name, test_name) { \
|
||||
public: \
|
||||
static std::unique_ptr<std::unordered_set<uint32_t>> &getExcludes() { \
|
||||
static std::unique_ptr<std::unordered_set<uint32_t>> excludes; \
|
||||
return excludes; \
|
||||
} \
|
||||
static void addExclude(uint32_t product) { \
|
||||
auto &excludes = getExcludes(); \
|
||||
if (excludes == nullptr) { \
|
||||
excludes = std::make_unique<std::unordered_set<uint32_t>>(); \
|
||||
} \
|
||||
excludes->insert(product); \
|
||||
} \
|
||||
}; \
|
||||
\
|
||||
class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) : public parent_class { \
|
||||
\
|
||||
public: \
|
||||
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \
|
||||
() {} \
|
||||
\
|
||||
private: \
|
||||
template <typename FamilyType> \
|
||||
void testBodyHw(); \
|
||||
bool notExcluded() const { \
|
||||
using ExcludesT = PLATFORM_EXCLUDES_CLASS_NAME(test_suite_name, test_name); \
|
||||
auto &excludes = ExcludesT::getExcludes(); \
|
||||
if (excludes == nullptr) { \
|
||||
return true; \
|
||||
} \
|
||||
return excludes->count(::productFamily) == 0; \
|
||||
} \
|
||||
template <typename T> \
|
||||
void emptyFcn() {} \
|
||||
void SetUp() override { \
|
||||
if (notExcluded()) { \
|
||||
parent_class::SetUp(); \
|
||||
FAMILY_SELECTOR(::renderCoreFamily, SetUpT_name) \
|
||||
} \
|
||||
} \
|
||||
void TearDown() override { \
|
||||
if (notExcluded()) { \
|
||||
FAMILY_SELECTOR(::renderCoreFamily, TearDownT_name) \
|
||||
parent_class::TearDown(); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
void TestBody() override { \
|
||||
if (notExcluded()) { \
|
||||
FAMILY_SELECTOR(::renderCoreFamily, testBodyHw) \
|
||||
} \
|
||||
} \
|
||||
static ::testing::TestInfo *const test_info_ GTEST_ATTRIBUTE_UNUSED_; \
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_( \
|
||||
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)); \
|
||||
}; \
|
||||
\
|
||||
::testing::TestInfo *const GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::test_info_ = \
|
||||
::testing::internal::MakeAndRegisterTestInfo( \
|
||||
#test_suite_name, #test_name, nullptr, nullptr, \
|
||||
::testing::internal::CodeLocation(__FILE__, __LINE__), (parent_id), \
|
||||
::testing::internal::SuiteApiResolver< \
|
||||
parent_class>::GetSetUpCaseOrSuite(), \
|
||||
::testing::internal::SuiteApiResolver< \
|
||||
parent_class>::GetTearDownCaseOrSuite(), \
|
||||
new ::testing::internal::TestFactoryImpl<GTEST_TEST_CLASS_NAME_( \
|
||||
test_suite_name, test_name)>); \
|
||||
template <typename FamilyType> \
|
||||
void GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::testBodyHw()
|
||||
|
||||
#define HWTEST_F(test_fixture, test_name) \
|
||||
HWTEST_TEST_(test_fixture, test_name, test_fixture, \
|
||||
::testing::internal::GetTypeId<test_fixture>())
|
||||
::testing::internal::GetTypeId<test_fixture>(), emptyFcn, emptyFcn)
|
||||
|
||||
#define HWTEST_F_T(test_fixture, test_name) \
|
||||
HWTEST_TEST_(test_fixture, test_name, test_fixture, \
|
||||
::testing::internal::GetTypeId<test_fixture>(), SetUpT, TearDownT)
|
||||
|
||||
#define PLATFORM_EXCLUDES_CLASS_NAME(test_suite_name, test_name) \
|
||||
PLATFORM_EXCLUDES_##test_suite_name##test_name
|
||||
@ -392,20 +403,7 @@ extern GFXCORE_FAMILY renderCoreFamily;
|
||||
void testBodyHw(); \
|
||||
\
|
||||
virtual void TestBody() override { \
|
||||
switch (::renderCoreFamily) { \
|
||||
case IGFX_GEN8_CORE: \
|
||||
BDW_TYPED_TEST_BODY \
|
||||
break; \
|
||||
case IGFX_GEN9_CORE: \
|
||||
SKL_TYPED_TEST_BODY \
|
||||
break; \
|
||||
case IGFX_GEN11_CORE: \
|
||||
ICL_TYPED_TEST_BODY \
|
||||
break; \
|
||||
default: \
|
||||
ASSERT_TRUE((false && "Unknown hardware family")); \
|
||||
break; \
|
||||
} \
|
||||
FAMILY_SELECTOR(::renderCoreFamily, testBodyHw) \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
@ -651,20 +649,7 @@ extern GFXCORE_FAMILY renderCoreFamily;
|
||||
void testBodyHw(); \
|
||||
\
|
||||
void TestBody() override { \
|
||||
switch (::renderCoreFamily) { \
|
||||
case IGFX_GEN8_CORE: \
|
||||
BDW_TYPED_TEST_BODY \
|
||||
break; \
|
||||
case IGFX_GEN9_CORE: \
|
||||
SKL_TYPED_TEST_BODY \
|
||||
break; \
|
||||
case IGFX_GEN11_CORE: \
|
||||
ICL_TYPED_TEST_BODY \
|
||||
break; \
|
||||
default: \
|
||||
ASSERT_TRUE((false && "Unknown hardware family")); \
|
||||
break; \
|
||||
} \
|
||||
FAMILY_SELECTOR(::renderCoreFamily, testBodyHw) \
|
||||
} \
|
||||
}; \
|
||||
bool gtest_##CaseName##_##TestName##_registered_ GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
|
Reference in New Issue
Block a user