1 /* 2 * Copyright (C) 2018-2021 Intel Corporation 3 * 4 * SPDX-License-Identifier: MIT 5 * 6 */ 7 8 #pragma once 9 10 #include "shared/source/memory_manager/memory_manager.h" 11 #include "shared/source/program/kernel_info.h" 12 #include "shared/test/common/mocks/mock_kernel_info.h" 13 14 #include "opencl/source/cl_device/cl_device.h" 15 #include "opencl/test/unit_test/mocks/mock_context.h" 16 #include "opencl/test/unit_test/mocks/mock_program.h" 17 18 #include "gtest/gtest.h" 19 20 using namespace NEO; 21 using namespace iOpenCL; 22 23 class KernelDataTest : public testing::Test { 24 public: KernelDataTest()25 KernelDataTest() { 26 memset(&kernelBinaryHeader, 0x00, sizeof(SKernelBinaryHeaderCommon)); 27 pCurPtr = nullptr; 28 pKernelData = nullptr; 29 kernelName = "test"; 30 pDsh = nullptr; 31 pGsh = nullptr; 32 pKernelHeap = nullptr; 33 pSsh = nullptr; 34 pPatchList = nullptr; 35 36 kernelDataSize = 0; 37 kernelNameSize = (uint32_t)alignUp(strlen(kernelName.c_str()) + 1, sizeof(uint32_t)); 38 dshSize = 0; 39 gshSize = 0; 40 kernelHeapSize = 0; 41 sshSize = 0; 42 patchListSize = 0; 43 44 checkSum = 0; 45 shaderHashCode = 0; 46 kernelUnpaddedSize = 0; 47 48 pKernelInfo = nullptr; 49 } 50 51 void buildAndDecode(); 52 53 protected: SetUp()54 void SetUp() override { 55 kernelBinaryHeader.KernelNameSize = kernelNameSize; 56 pContext = new MockContext; 57 rootDeviceIndex = pContext->getDevice(0)->getRootDeviceIndex(); 58 program = std::make_unique<MockProgram>(pContext, false, toClDeviceVector(*pContext->getDevice(0))); 59 } 60 TearDown()61 void TearDown() override { 62 if (pKernelInfo->kernelAllocation) { 63 pContext->getDevice(0)->getMemoryManager()->freeGraphicsMemory(pKernelInfo->kernelAllocation); 64 const_cast<KernelInfo *>(pKernelInfo)->kernelAllocation = nullptr; 65 } 66 program.reset(); 67 delete pContext; 68 alignedFree(pKernelData); 69 } 70 71 char *pCurPtr; 72 char *pKernelData; 73 SKernelBinaryHeaderCommon kernelBinaryHeader; 74 std::string kernelName; 75 void *pDsh; 76 void *pGsh; 77 void *pKernelHeap; 78 void *pSsh; 79 void *pPatchList; 80 81 uint32_t kernelDataSize; 82 uint32_t kernelNameSize; 83 uint32_t dshSize; 84 uint32_t gshSize; 85 uint32_t kernelHeapSize; 86 uint32_t sshSize; 87 uint32_t patchListSize; 88 89 uint32_t checkSum; 90 uint64_t shaderHashCode; 91 uint32_t kernelUnpaddedSize; 92 93 std::unique_ptr<MockProgram> program; 94 MockContext *pContext; 95 const KernelInfo *pKernelInfo; 96 uint32_t rootDeviceIndex = std::numeric_limits<uint32_t>::max(); 97 }; 98