From ac00ca60f7f8daf078fe77b18e50c26c8771f490 Mon Sep 17 00:00:00 2001 From: Kamil Kopryk Date: Wed, 3 Jul 2024 14:44:03 +0000 Subject: [PATCH] test: introduce method for testing variant of walkers This commit adds a pattern that removes the strong dependency on the compile-time DefaultWalkerType typename in generic unit tests. Related-To: NEO-10641 Signed-off-by: Kamil Kopryk --- .../sources/cmdlist/test_in_order_cmdlist.cpp | 22 ++++++++++++------- shared/source/gen11/hw_cmds_base.h | 3 +++ shared/source/gen12lp/hw_cmds_base.h | 3 +++ shared/source/gen8/hw_cmds_base.h | 3 +++ shared/source/gen9/hw_cmds_base.h | 3 +++ shared/source/xe2_hpg_core/hw_cmds_base.h | 3 +++ .../xe_hpc_core/hw_cmds_xe_hpc_core_base.h | 2 ++ .../xe_hpg_core/hw_cmds_xe_hpg_core_base.h | 2 ++ shared/test/common/helpers/unit_test_helper.h | 2 ++ .../test/common/helpers/unit_test_helper.inl | 10 +++++++++ 10 files changed, 45 insertions(+), 8 deletions(-) diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_in_order_cmdlist.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_in_order_cmdlist.cpp index 3c92943739..f83f4fd308 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_in_order_cmdlist.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_in_order_cmdlist.cpp @@ -32,6 +32,7 @@ #include "level_zero/core/test/unit_tests/sources/helper/ze_object_utils.h" #include +#include namespace L0 { namespace ult { @@ -2888,8 +2889,7 @@ HWTEST2_F(InOrderCmdListTests, givenEventGeneratedByRegularCmdListWhenWaitingFro } HWTEST2_F(InOrderCmdListTests, givenInOrderModeWhenProgrammingKernelSplitThenDontSignalFromWalker, IsAtLeastXeHpCore) { - using DefaultWalkerType = typename FamilyType::DefaultWalkerType; - using POSTSYNC_DATA = typename FamilyType::POSTSYNC_DATA; + using WalkerVariant = typename FamilyType::WalkerVariant; auto immCmdList = createImmCmdList(); @@ -2905,18 +2905,24 @@ HWTEST2_F(InOrderCmdListTests, givenInOrderModeWhenProgrammingKernelSplitThenDon GenCmdList cmdList; ASSERT_TRUE(FamilyType::Parse::parseCommandBuffer(cmdList, cmdStream->getCpuBase(), cmdStream->getUsed())); - auto walkerItor = find(cmdList.begin(), cmdList.end()); + auto walkerItor = NEO::UnitTestHelper::findWalkerTypeCmd(cmdList.begin(), cmdList.end()); uint32_t walkersFound = 0; while (cmdList.end() != walkerItor) { walkersFound++; - auto walkerCmd = genCmdCast(*walkerItor); - auto &postSync = walkerCmd->getPostSync(); + WalkerVariant walkerCmd = NEO::UnitTestHelper::getWalkerVariant(*walkerItor); - EXPECT_EQ(POSTSYNC_DATA::OPERATION_NO_WRITE, postSync.getOperation()); + std::visit([](auto &&walker) { + using WalkerType = std::decay_t; + using PostSyncType = typename WalkerType::PostSyncType; - walkerItor = find(++walkerItor, cmdList.end()); + auto &postSync = walker->getPostSync(); + EXPECT_EQ(PostSyncType::OPERATION_NO_WRITE, postSync.getOperation()); + }, + walkerCmd); + + walkerItor = NEO::UnitTestHelper::findWalkerTypeCmd(++walkerItor, cmdList.end()); } EXPECT_TRUE(walkersFound > 1); @@ -3166,7 +3172,7 @@ HWTEST2_F(InOrderCmdListTests, givenInOrderModeWhenProgrammingFillWithoutSplitTh GenCmdList cmdList; ASSERT_TRUE(FamilyType::Parse::parseCommandBuffer(cmdList, cmdStream->getCpuBase(), cmdStream->getUsed())); - auto walkerItor = find(cmdList.begin(), cmdList.end()); + auto walkerItor = NEO::UnitTestHelper::findWalkerTypeCmd(cmdList.begin(), cmdList.end()); ASSERT_NE(cmdList.end(), walkerItor); auto walkerCmd = genCmdCast(*walkerItor); diff --git a/shared/source/gen11/hw_cmds_base.h b/shared/source/gen11/hw_cmds_base.h index 43ddd705f2..154818f2b1 100644 --- a/shared/source/gen11/hw_cmds_base.h +++ b/shared/source/gen11/hw_cmds_base.h @@ -14,6 +14,7 @@ #include #include +#include template struct CmdParse; @@ -158,5 +159,7 @@ struct Gen11Family : public Gen11 { static constexpr bool isHeaplessMode() { return false; } + + using WalkerVariant = std::variant; }; } // namespace NEO diff --git a/shared/source/gen12lp/hw_cmds_base.h b/shared/source/gen12lp/hw_cmds_base.h index ed83356f37..6c0b180e68 100644 --- a/shared/source/gen12lp/hw_cmds_base.h +++ b/shared/source/gen12lp/hw_cmds_base.h @@ -12,6 +12,7 @@ #include #include #include +#include template struct CmdParse; @@ -159,6 +160,8 @@ struct Gen12LpFamily : public Gen12Lp { static WalkerType getInitGpuWalker() { return cmdInitGpgpuWalker; } + + using WalkerVariant = std::variant; }; } // namespace NEO diff --git a/shared/source/gen8/hw_cmds_base.h b/shared/source/gen8/hw_cmds_base.h index cc77ff3f3c..8714e7cb9e 100644 --- a/shared/source/gen8/hw_cmds_base.h +++ b/shared/source/gen8/hw_cmds_base.h @@ -14,6 +14,7 @@ #include #include +#include // forward declaration for parsing logic template @@ -158,6 +159,8 @@ struct Gen8Family : public Gen8 { static constexpr bool isHeaplessMode() { return false; } + + using WalkerVariant = std::variant; }; } // namespace NEO diff --git a/shared/source/gen9/hw_cmds_base.h b/shared/source/gen9/hw_cmds_base.h index 146536272e..c23f35dce3 100644 --- a/shared/source/gen9/hw_cmds_base.h +++ b/shared/source/gen9/hw_cmds_base.h @@ -14,6 +14,7 @@ #include #include +#include template struct CmdParse; @@ -158,6 +159,8 @@ struct Gen9Family : public Gen9 { static constexpr bool isHeaplessMode() { return false; } + + using WalkerVariant = std::variant; }; } // namespace NEO diff --git a/shared/source/xe2_hpg_core/hw_cmds_base.h b/shared/source/xe2_hpg_core/hw_cmds_base.h index 5b7fdc3d6f..b5e9b9aafc 100644 --- a/shared/source/xe2_hpg_core/hw_cmds_base.h +++ b/shared/source/xe2_hpg_core/hw_cmds_base.h @@ -12,6 +12,7 @@ #include #include #include +#include template struct CmdParse; @@ -172,6 +173,8 @@ struct Xe2HpgCoreFamily : public Xe2HpgCore { static constexpr bool isHeaplessMode() { return false; } + + using WalkerVariant = std::variant; }; enum class MemoryCompressionState; diff --git a/shared/source/xe_hpc_core/hw_cmds_xe_hpc_core_base.h b/shared/source/xe_hpc_core/hw_cmds_xe_hpc_core_base.h index c807043ce9..63e890cdc4 100644 --- a/shared/source/xe_hpc_core/hw_cmds_xe_hpc_core_base.h +++ b/shared/source/xe_hpc_core/hw_cmds_xe_hpc_core_base.h @@ -15,6 +15,7 @@ #include #include +#include template struct CmdParse; @@ -153,6 +154,7 @@ struct XeHpcCoreFamily : public XeHpcCore { static constexpr bool isHeaplessMode() { return false; } + using WalkerVariant = std::variant; }; } // namespace NEO diff --git a/shared/source/xe_hpg_core/hw_cmds_xe_hpg_core_base.h b/shared/source/xe_hpg_core/hw_cmds_xe_hpg_core_base.h index 0bf457e523..ccb2687ce8 100644 --- a/shared/source/xe_hpg_core/hw_cmds_xe_hpg_core_base.h +++ b/shared/source/xe_hpg_core/hw_cmds_xe_hpg_core_base.h @@ -14,6 +14,7 @@ #include #include +#include template struct CmdParse; @@ -171,6 +172,7 @@ struct XeHpgCoreFamily : public XeHpgCore { static constexpr bool isHeaplessMode() { return false; } + using WalkerVariant = std::variant; }; } // namespace NEO diff --git a/shared/test/common/helpers/unit_test_helper.h b/shared/test/common/helpers/unit_test_helper.h index f67639670b..a9899d5b7c 100644 --- a/shared/test/common/helpers/unit_test_helper.h +++ b/shared/test/common/helpers/unit_test_helper.h @@ -102,6 +102,8 @@ struct UnitTestHelper { static void verifyDummyBlitWa(const RootDeviceEnvironment *rootDeviceEnvironment, GenCmdList::iterator &cmdIterator); static GenCmdList::iterator findWalkerCmd(GenCmdList::iterator begin, GenCmdList::iterator end, bool heapless); static GenCmdList::iterator findWalkerTypeCmd(GenCmdList::iterator begin, GenCmdList::iterator end); + + static typename GfxFamily::WalkerVariant getWalkerVariant(void *walkerItor); }; } // namespace NEO diff --git a/shared/test/common/helpers/unit_test_helper.inl b/shared/test/common/helpers/unit_test_helper.inl index f9d9291102..3488f17bf1 100644 --- a/shared/test/common/helpers/unit_test_helper.inl +++ b/shared/test/common/helpers/unit_test_helper.inl @@ -114,4 +114,14 @@ uint32_t UnitTestHelper::getMiLoadRegisterImmProgrammedCmdsCount(bool return (debuggingEnabled ? 2u : 0u); } +template +typename GfxFamily::WalkerVariant UnitTestHelper::getWalkerVariant(void *walkerItor) { + if (auto walker = genCmdCast(walkerItor); walker) { + return walker; + } + + UNRECOVERABLE_IF(true); + return {}; +} + } // namespace NEO