/* * Copyright (C) 2019 Intel Corporation * * SPDX-License-Identifier: MIT * */ #include "test.h" #include "unit_tests/helpers/cmd_buffer_validator.h" #include "hw_parse.h" using HwParseTest = ::testing::Test; using namespace NEO; HWTEST_F(HwParseTest, WhenEmptyBufferThenDontExpectCommands) { using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL; bool cmdBuffOk = false; GenCmdList::iterator beg, end; end = beg; cmdBuffOk = expectCmdBuff(beg, end, std::vector{}); EXPECT_TRUE(cmdBuffOk); cmdBuffOk = expectCmdBuff(beg, end, std::vector{ new MatchHwCmd(0), }); EXPECT_TRUE(cmdBuffOk); cmdBuffOk = expectCmdBuff(beg, end, std::vector{ new MatchHwCmd(AnyNumber), }); EXPECT_TRUE(cmdBuffOk); cmdBuffOk = expectCmdBuff(beg, end, std::vector{ new MatchHwCmd(AtLeastOne), }); EXPECT_FALSE(cmdBuffOk); cmdBuffOk = expectCmdBuff(beg, end, std::vector{ new MatchHwCmd(1), }); EXPECT_FALSE(cmdBuffOk); } HWTEST_F(HwParseTest, WhenExpectingAnyCommandThenAllCommandsAreValidAsLongAsTheCountMatches) { using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL; using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS; bool cmdBuffOk = false; char buffer[8192]; LinearStream stream{alignUp(buffer, 4096), 4096}; *stream.getSpaceForCmd() = FamilyType::cmdInitPipeControl; *stream.getSpaceForCmd() = FamilyType::cmdInitStateBaseAddress; *stream.getSpaceForCmd() = FamilyType::cmdInitPipeControl; cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchAnyCmd(1), new MatchAnyCmd(1), new MatchAnyCmd(1)}); EXPECT_TRUE(cmdBuffOk); cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchAnyCmd(AtLeastOne), }); EXPECT_TRUE(cmdBuffOk); cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchAnyCmd(AnyNumber), }); EXPECT_TRUE(cmdBuffOk); cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchAnyCmd(1), new MatchAnyCmd(1), new MatchAnyCmd(1), new MatchAnyCmd(1)}); EXPECT_FALSE(cmdBuffOk); cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchAnyCmd(1), new MatchAnyCmd(1), new MatchAnyCmd(1), new MatchAnyCmd(AtLeastOne)}); EXPECT_FALSE(cmdBuffOk); cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchAnyCmd(1), new MatchAnyCmd(1), new MatchAnyCmd(1), new MatchAnyCmd(AnyNumber)}); EXPECT_TRUE(cmdBuffOk); cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchAnyCmd(AtLeastOne), new MatchAnyCmd(1)}); EXPECT_FALSE(cmdBuffOk); cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchAnyCmd(AnyNumber), new MatchAnyCmd(1)}); EXPECT_FALSE(cmdBuffOk); cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchAnyCmd(1), new MatchAnyCmd(1), }); EXPECT_FALSE(cmdBuffOk); cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchAnyCmd(1)}); EXPECT_FALSE(cmdBuffOk); } HWTEST_F(HwParseTest, WhenExpectingSpecificSetOfCommandsThenNoOtherCommandBufferIsValid) { using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL; using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS; bool cmdBuffOk = false; char buffer[8192]; LinearStream stream{alignUp(buffer, 4096), 4096}; *stream.getSpaceForCmd() = FamilyType::cmdInitPipeControl; *stream.getSpaceForCmd() = FamilyType::cmdInitStateBaseAddress; *stream.getSpaceForCmd() = FamilyType::cmdInitPipeControl; cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchHwCmd(1), new MatchHwCmd(1), new MatchHwCmd(1)}); EXPECT_TRUE(cmdBuffOk); cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchHwCmd(1), new MatchHwCmd(1), new MatchHwCmd(1), new MatchHwCmd(1)}); EXPECT_FALSE(cmdBuffOk); cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchHwCmd(1), new MatchHwCmd(1), }); EXPECT_FALSE(cmdBuffOk); cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchHwCmd(1), new MatchHwCmd(1), new MatchHwCmd(1), new MatchHwCmd(1)}); EXPECT_FALSE(cmdBuffOk); cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchHwCmd(1), new MatchHwCmd(1), new MatchHwCmd(1)}); EXPECT_FALSE(cmdBuffOk); cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchHwCmd(1), new MatchHwCmd(1), new MatchHwCmd(1)}); EXPECT_FALSE(cmdBuffOk); } HWTEST_F(HwParseTest, WhenExpectingAnyNumberOfCommandsThenOnlyTypeOfCommandMatters) { using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL; using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS; bool cmdBuffOk = false; char buffer[8192]; LinearStream stream{alignUp(buffer, 4096), 4096}; *stream.getSpaceForCmd() = FamilyType::cmdInitPipeControl; *stream.getSpaceForCmd() = FamilyType::cmdInitStateBaseAddress; *stream.getSpaceForCmd() = FamilyType::cmdInitStateBaseAddress; *stream.getSpaceForCmd() = FamilyType::cmdInitStateBaseAddress; *stream.getSpaceForCmd() = FamilyType::cmdInitStateBaseAddress; *stream.getSpaceForCmd() = FamilyType::cmdInitPipeControl; cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchHwCmd(1), new MatchHwCmd(1), new MatchHwCmd(1), new MatchHwCmd(1), new MatchHwCmd(1), new MatchHwCmd(1)}); EXPECT_TRUE(cmdBuffOk); cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchHwCmd(1), new MatchHwCmd(1), new MatchHwCmd(1)}); EXPECT_FALSE(cmdBuffOk); cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchHwCmd(1), new MatchHwCmd(AnyNumber), new MatchHwCmd(1)}); EXPECT_TRUE(cmdBuffOk); cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchHwCmd(AnyNumber), new MatchHwCmd(AnyNumber), new MatchHwCmd(AnyNumber)}); EXPECT_TRUE(cmdBuffOk); cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchHwCmd(AtLeastOne), new MatchHwCmd(AtLeastOne), new MatchHwCmd(AtLeastOne)}); EXPECT_TRUE(cmdBuffOk); cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchHwCmd(AtLeastOne), new MatchHwCmd(AtLeastOne), new MatchHwCmd(AtLeastOne), new MatchHwCmd(AtLeastOne), new MatchHwCmd(AtLeastOne), }); EXPECT_FALSE(cmdBuffOk); cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchHwCmd(AnyNumber), new MatchHwCmd(0), new MatchHwCmd(AnyNumber), new MatchHwCmd(AnyNumber), new MatchHwCmd(0)}); EXPECT_TRUE(cmdBuffOk); } HWTEST_F(HwParseTest, WhenCommandMemberValidatorFailsThenCommandBufferValidationFails) { using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL; using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS; bool cmdBuffOk = false; char buffer[8192]; LinearStream stream{alignUp(buffer, 4096), 4096}; *stream.getSpaceForCmd() = FamilyType::cmdInitPipeControl; auto sba = stream.getSpaceForCmd(); *sba = FamilyType::cmdInitStateBaseAddress; sba->setGeneralStateBaseAddressModifyEnable(true); *stream.getSpaceForCmd() = FamilyType::cmdInitPipeControl; cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchHwCmd(AnyNumber), new MatchHwCmd(AnyNumber, Expects{EXPECT_MEMBER(STATE_BASE_ADDRESS, getGeneralStateBaseAddressModifyEnable, true)}), new MatchHwCmd(AnyNumber)}); EXPECT_TRUE(cmdBuffOk); cmdBuffOk = expectCmdBuff(stream, 0, std::vector{ new MatchHwCmd(AnyNumber), new MatchHwCmd(AnyNumber, Expects{EXPECT_MEMBER(STATE_BASE_ADDRESS, getGeneralStateBaseAddressModifyEnable, false)}), new MatchHwCmd(AnyNumber)}); EXPECT_FALSE(cmdBuffOk); }