| 1 |
/* |
| 2 |
* Copyright (C) 2020-2022 Intel Corporation |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "shared/source/direct_submission/dispatchers/dispatcher.h" |
| 9 |
#include "shared/test/common/cmd_parse/hw_parse.h" |
| 10 |
#include "shared/test/common/test_macros/hw_test.h" |
| 11 |
#include "shared/test/unit_test/direct_submission/dispatchers/dispatcher_fixture.h" |
| 12 |
|
| 13 |
using namespace NEO; |
| 14 |
|
| 15 |
using DispatcherTest = Test<DispatcherFixture>; |
| 16 |
|
| 17 |
HWTEST_F(DispatcherTest, givenBaseDispatcherWhenAskingForStartCmdSizeThenReturnBbStartCmdSize) { |
| 18 |
using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START; |
| 19 |
EXPECT_EQ(sizeof(MI_BATCH_BUFFER_START), Dispatcher<FamilyType>::getSizeStartCommandBuffer()); |
| 20 |
} |
| 21 |
|
| 22 |
HWTEST_F(DispatcherTest, givenBaseDispatcherWhenAddingStartCmdThenExpectBbStart) { |
| 23 |
using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START; |
| 24 |
|
| 25 |
uint64_t gpuVa = 0xFF0000; |
| 26 |
Dispatcher<FamilyType>::dispatchStartCommandBuffer(cmdBuffer, gpuVa); |
| 27 |
|
| 28 |
HardwareParse hwParse; |
| 29 |
hwParse.parseCommands<FamilyType>(cmdBuffer); |
| 30 |
MI_BATCH_BUFFER_START *start = hwParse.getCommand<MI_BATCH_BUFFER_START>(); |
| 31 |
ASSERT_NE(nullptr, start); |
| 32 |
EXPECT_EQ(gpuVa, start->getBatchBufferStartAddress()); |
| 33 |
} |
| 34 |
|
| 35 |
HWTEST_F(DispatcherTest, givenBaseDispatcherWhenAskingForStopCmdSizeThenReturnBbStopCmdSize) { |
| 36 |
using MI_BATCH_BUFFER_END = typename FamilyType::MI_BATCH_BUFFER_END; |
| 37 |
EXPECT_EQ(sizeof(MI_BATCH_BUFFER_END), Dispatcher<FamilyType>::getSizeStopCommandBuffer()); |
| 38 |
} |
| 39 |
|
| 40 |
HWTEST_F(DispatcherTest, givenBaseDispatcherWhenAddingStopCmdThenExpectBbStop) { |
| 41 |
using MI_BATCH_BUFFER_END = typename FamilyType::MI_BATCH_BUFFER_END; |
| 42 |
|
| 43 |
Dispatcher<FamilyType>::dispatchStopCommandBuffer(cmdBuffer); |
| 44 |
|
| 45 |
HardwareParse hwParse; |
| 46 |
hwParse.parseCommands<FamilyType>(cmdBuffer); |
| 47 |
MI_BATCH_BUFFER_END *stop = hwParse.getCommand<MI_BATCH_BUFFER_END>(); |
| 48 |
ASSERT_NE(nullptr, stop); |
| 49 |
} |
| 50 |
|
| 51 |
HWTEST_F(DispatcherTest, givenBaseDispatcherWhenAskingForStoreCmdSizeThenReturnStoreDataImmCmdSize) { |
| 52 |
using MI_STORE_DATA_IMM = typename FamilyType::MI_STORE_DATA_IMM; |
| 53 |
|
| 54 |
EXPECT_EQ(sizeof(MI_STORE_DATA_IMM), Dispatcher<FamilyType>::getSizeStoreDwordCommand()); |
| 55 |
} |
| 56 |
|
| 57 |
HWTEST_F(DispatcherTest, givenBaseDispatcherWhenAddingStoreCmdThenExpectStoreDataImm) { |
| 58 |
using MI_STORE_DATA_IMM = typename FamilyType::MI_STORE_DATA_IMM; |
| 59 |
|
| 60 |
uint64_t gpuVa = 0xFF0000; |
| 61 |
uint32_t val = 123; |
| 62 |
Dispatcher<FamilyType>::dispatchStoreDwordCommand(cmdBuffer, gpuVa, val); |
| 63 |
|
| 64 |
HardwareParse hwParse; |
| 65 |
hwParse.parseCommands<FamilyType>(cmdBuffer); |
| 66 |
MI_STORE_DATA_IMM *sdi = hwParse.getCommand<MI_STORE_DATA_IMM>(); |
| 67 |
ASSERT_NE(nullptr, sdi); |
| 68 |
EXPECT_EQ(gpuVa, sdi->getAddress()); |
| 69 |
EXPECT_EQ(val, sdi->getDataDword0()); |
| 70 |
} |