/* * Copyright (C) 2018-2021 Intel Corporation * * SPDX-License-Identifier: MIT * */ #pragma once #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/unit_test_helper.h" #include "shared/test/common/test_macros/test.h" #include "opencl/test/unit_test/mocks/mock_cl_device.h" #include "opencl/test/unit_test/mocks/mock_command_queue.h" #include "opencl/test/unit_test/mocks/mock_context.h" #include "opencl/test/unit_test/mocks/mock_kernel.h" #include "opencl/test/unit_test/mocks/mock_platform.h" using namespace NEO; struct TimestampPacketSimpleTests : public ::testing::Test { class MockTimestampPacketStorage : public TimestampPackets { public: using TimestampPackets::packets; }; template void setTagToReadyState(TagNodeBase *tagNode) { auto packetsUsed = tagNode->getPacketsUsed(); tagNode->initialize(); typename FamilyType::TimestampPacketType zeros[4] = {}; for (uint32_t i = 0; i < TimestampPacketSizeControl::preferredPacketCount; i++) { tagNode->assignDataToAllTimestamps(i, zeros); } tagNode->setPacketsUsed(packetsUsed); } const size_t gws[3] = {1, 1, 1}; }; struct TimestampPacketTests : public TimestampPacketSimpleTests { struct MockTagNode : public TagNode> { using TagNode>::gpuAddress; }; void SetUp() override { DebugManager.flags.EnableTimestampPacket.set(1); executionEnvironment = platform()->peekExecutionEnvironment(); executionEnvironment->prepareRootDeviceEnvironments(2); for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(defaultHwInfo.get()); } device = std::make_unique(Device::create(executionEnvironment, 0u)); context = new MockContext(device.get()); kernel = std::make_unique(*device, context); mockCmdQ = new MockCommandQueue(context, device.get(), nullptr, false); } void TearDown() override { mockCmdQ->release(); context->release(); } template void verifySemaphore(MI_SEMAPHORE_WAIT *semaphoreCmd, TagNodeBase *timestampPacketNode, uint32_t packetId) { EXPECT_NE(nullptr, semaphoreCmd); EXPECT_EQ(semaphoreCmd->getCompareOperation(), MI_SEMAPHORE_WAIT::COMPARE_OPERATION::COMPARE_OPERATION_SAD_NOT_EQUAL_SDD); EXPECT_EQ(1u, semaphoreCmd->getSemaphoreDataDword()); uint64_t compareOffset = packetId * TimestampPackets::getSinglePacketSize(); auto dataAddress = TimestampPacketHelper::getContextEndGpuAddress(*timestampPacketNode) + compareOffset; EXPECT_EQ(dataAddress, semaphoreCmd->getSemaphoreGraphicsAddress()); }; ExecutionEnvironment *executionEnvironment; std::unique_ptr device; MockContext *context; std::unique_ptr kernel; MockCommandQueue *mockCmdQ; DebugManagerStateRestore restorer; };