Skip to content

Commit a54c947

Browse files
test: create dedicated mock object for timestamp packet
Related-To: NEO-6871 Signed-off-by: Zbigniew Zdanowicz <[email protected]>
1 parent ab69e87 commit a54c947

File tree

8 files changed

+44
-53
lines changed

8 files changed

+44
-53
lines changed

level_zero/core/test/unit_tests/gen12lp/test_events_gen12lp.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/*
2-
* Copyright (C) 2020-2021 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
66
*/
77

8+
#include "shared/test/common/mocks/mock_timestamp_packet.h"
89
#include "shared/test/common/test_macros/test.h"
910

1011
#include "level_zero/core/source/driver/driver_handle_imp.h"
@@ -15,12 +16,6 @@
1516
namespace L0 {
1617
namespace ult {
1718
struct TimestampEvent : public Test<DeviceFixture> {
18-
public:
19-
class MockTimestampPackets32 : public TimestampPackets<uint32_t> {
20-
public:
21-
using typename TimestampPackets<uint32_t>::Packet;
22-
};
23-
2419
void SetUp() override {
2520
DeviceFixture::SetUp();
2621
ze_event_pool_desc_t eventPoolDesc = {};

level_zero/core/test/unit_tests/sources/event/test_event.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "shared/test/common/mocks/mock_csr.h"
1212
#include "shared/test/common/mocks/mock_memory_manager.h"
1313
#include "shared/test/common/mocks/mock_memory_operations_handler.h"
14+
#include "shared/test/common/mocks/mock_timestamp_packet.h"
1415
#include "shared/test/common/test_macros/test.h"
1516

1617
#include "level_zero/core/source/context/context_imp.h"
@@ -1150,11 +1151,6 @@ TEST_F(EventQueryTimestampExpWithSubDevice, givenEventWhenQuerytimestampExpWithS
11501151
event = std::unique_ptr<L0::EventImp<uint32_t>>(static_cast<L0::EventImp<uint32_t> *>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, subdevice)));
11511152
ASSERT_NE(nullptr, event);
11521153

1153-
class MockTimestampPackets32 : public TimestampPackets<uint32_t> {
1154-
public:
1155-
using typename TimestampPackets<uint32_t>::Packet;
1156-
};
1157-
11581154
typename MockTimestampPackets32::Packet packetData[2];
11591155
event->setPacketsInUse(2u);
11601156

@@ -1194,11 +1190,6 @@ TEST_F(EventQueryTimestampExpWithSubDevice, givenEventWhenQuerytimestampExpWithS
11941190
}
11951191

11961192
HWCMDTEST_F(IGFX_GEN9_CORE, TimestampEventCreate, givenEventTimestampsWhenQueryKernelTimestampThenCorrectDataAreSet) {
1197-
class MockTimestampPackets32 : public TimestampPackets<uint32_t> {
1198-
public:
1199-
using typename TimestampPackets<uint32_t>::Packet;
1200-
};
1201-
12021193
typename MockTimestampPackets32::Packet data = {};
12031194
data.contextStart = 1u;
12041195
data.contextEnd = 2u;
@@ -1216,11 +1207,6 @@ HWCMDTEST_F(IGFX_GEN9_CORE, TimestampEventCreate, givenEventTimestampsWhenQueryK
12161207
}
12171208

12181209
TEST_F(TimestampEventCreate, givenEventWhenQueryingTimestampExpThenCorrectDataSet) {
1219-
class MockTimestampPackets32 : public TimestampPackets<uint32_t> {
1220-
public:
1221-
using typename TimestampPackets<uint32_t>::Packet;
1222-
};
1223-
12241210
typename MockTimestampPackets32::Packet packetData[2];
12251211
event->setPacketsInUse(2u);
12261212

level_zero/core/test/unit_tests/xe_hp_core/test_cmdlist_xe_hp_core.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "shared/test/common/cmd_parse/gen_cmd_parse.h"
1313
#include "shared/test/common/helpers/unit_test_helper.h"
1414
#include "shared/test/common/mocks/mock_graphics_allocation.h"
15+
#include "shared/test/common/mocks/mock_timestamp_packet.h"
1516
#include "shared/test/common/test_macros/test.h"
1617

1718
#include "level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h"
@@ -355,11 +356,6 @@ HWTEST2_F(CommandListAppendLaunchKernelL3Flush, givenKernelWithEventZeroScopeWit
355356
HWTEST2_F(CommandListAppendLaunchKernelL3Flush, givenKernelWithEventHostScopeWithoutWalkerPartitionThenSkipOddPacketsDuringQuery, IsXeHpCore) {
356357
using MI_LOAD_REGISTER_IMM = typename FamilyType::MI_LOAD_REGISTER_IMM;
357358

358-
class MockTimestampPackets32 : public TimestampPackets<uint32_t> {
359-
public:
360-
using typename TimestampPackets<uint32_t>::Packet;
361-
};
362-
363359
Mock<::L0::Kernel> kernel;
364360
auto pMockModule = std::unique_ptr<Module>(new Mock<Module>(device, nullptr));
365361
kernel.module = pMockModule.get();

opencl/test/unit_test/helpers/timestamp_packet_1_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ TEST_F(TimestampPacketSimpleTests, givenTimestampPacketContainerWhenMovedThenMov
112112
HWTEST_F(TimestampPacketSimpleTests, whenNewTagIsTakenThenReinitialize) {
113113
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
114114
MockMemoryManager memoryManager(executionEnvironment);
115-
MockTagAllocator<MockTimestampPacketStorage> allocator(0, &memoryManager, 1);
115+
MockTagAllocator<MockTimestampPackets32> allocator(0, &memoryManager, 1);
116116

117-
using MockNode = TagNode<MockTimestampPacketStorage>;
117+
using MockNode = TagNode<MockTimestampPackets32>;
118118

119119
auto firstNode = static_cast<MockNode *>(allocator.getTag());
120120
auto i = 0u;
@@ -141,7 +141,7 @@ HWTEST_F(TimestampPacketSimpleTests, whenNewTagIsTakenThenReinitialize) {
141141
}
142142

143143
TEST_F(TimestampPacketSimpleTests, whenObjectIsCreatedThenInitializeAllStamps) {
144-
MockTimestampPacketStorage timestampPacketStorage;
144+
MockTimestampPackets32 timestampPacketStorage;
145145
EXPECT_EQ(TimestampPacketSizeControl::preferredPacketCount * sizeof(timestampPacketStorage.packets[0]), sizeof(timestampPacketStorage.packets));
146146

147147
for (const auto &packet : timestampPacketStorage.packets) {

opencl/test/unit_test/helpers/timestamp_packet_tests.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2021 Intel Corporation
2+
* Copyright (C) 2018-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -9,6 +9,7 @@
99

1010
#include "shared/test/common/helpers/debug_manager_state_restore.h"
1111
#include "shared/test/common/helpers/unit_test_helper.h"
12+
#include "shared/test/common/mocks/mock_timestamp_packet.h"
1213
#include "shared/test/common/test_macros/test.h"
1314

1415
#include "opencl/test/unit_test/mocks/mock_cl_device.h"
@@ -20,11 +21,6 @@
2021
using namespace NEO;
2122

2223
struct TimestampPacketSimpleTests : public ::testing::Test {
23-
class MockTimestampPacketStorage : public TimestampPackets<uint32_t> {
24-
public:
25-
using TimestampPackets<uint32_t>::packets;
26-
};
27-
2824
template <typename FamilyType>
2925
void setTagToReadyState(TagNodeBase *tagNode) {
3026
auto packetsUsed = tagNode->getPacketsUsed();

opencl/test/unit_test/utilities/tag_allocator_tests.cpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "shared/test/common/helpers/engine_descriptor_helper.h"
1313
#include "shared/test/common/libult/ult_command_stream_receiver.h"
1414
#include "shared/test/common/mocks/mock_graphics_allocation.h"
15+
#include "shared/test/common/mocks/mock_timestamp_packet.h"
1516
#include "shared/test/common/mocks/ult_device_factory.h"
1617
#include "shared/test/common/test_macros/test.h"
1718

@@ -22,23 +23,6 @@
2223
using namespace NEO;
2324

2425
struct TagAllocatorTest : public Test<MemoryAllocatorFixture> {
25-
class MockTimestampPackets32 : public TimestampPackets<uint32_t> {
26-
public:
27-
void setTagToReadyState() {
28-
initialize();
29-
30-
uint32_t zeros[4] = {};
31-
32-
for (uint32_t i = 0; i < TimestampPacketSizeControl::preferredPacketCount; i++) {
33-
assignDataToAllTimestamps(i, zeros);
34-
}
35-
}
36-
37-
void setToNonReadyState() {
38-
packets[0].contextEnd = 1;
39-
}
40-
};
41-
4226
void SetUp() override {
4327
DebugManager.flags.CreateMultipleSubDevices.set(4);
4428
MemoryAllocatorFixture::SetUp();

shared/test/common/mocks/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ set(NEO_CORE_tests_mocks
8181
${CMAKE_CURRENT_SOURCE_DIR}/mock_tbx_csr.h
8282
${CMAKE_CURRENT_SOURCE_DIR}/mock_tbx_stream.h
8383
${CMAKE_CURRENT_SOURCE_DIR}/mock_timestamp_container.h
84+
${CMAKE_CURRENT_SOURCE_DIR}/mock_timestamp_packet.h
8485
${CMAKE_CURRENT_SOURCE_DIR}/ult_device_factory.cpp
8586
${CMAKE_CURRENT_SOURCE_DIR}/ult_device_factory.h
8687
${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_client_context.cpp
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (C) 2022 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#pragma once
9+
#include "shared/source/helpers/timestamp_packet.h"
10+
11+
namespace NEO {
12+
13+
class MockTimestampPackets32 : public TimestampPackets<uint32_t> {
14+
public:
15+
using typename TimestampPackets<uint32_t>::Packet;
16+
using TimestampPackets<uint32_t>::packets;
17+
18+
void setTagToReadyState() {
19+
initialize();
20+
21+
uint32_t zeros[4] = {};
22+
23+
for (uint32_t i = 0; i < TimestampPacketSizeControl::preferredPacketCount; i++) {
24+
assignDataToAllTimestamps(i, zeros);
25+
}
26+
}
27+
28+
void setToNonReadyState() {
29+
packets[0].contextEnd = 1;
30+
}
31+
};
32+
33+
} // namespace NEO

0 commit comments

Comments
 (0)