mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-05 17:39:51 +08:00
Move linear / tbx stream tests from opencl to shared
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
7a730200ee
commit
4694b7ac5c
@@ -7,8 +7,10 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/command_stream_receiver_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/linear_stream_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}stream_properties_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/stream_properties_tests_common.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/stream_properties_tests_common.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tbx_stream_tests.cpp
|
||||
)
|
||||
add_subdirectories()
|
||||
|
||||
111
shared/test/unit_test/command_stream/linear_stream_tests.cpp
Normal file
111
shared/test/unit_test/command_stream/linear_stream_tests.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/command_stream/linear_stream.h"
|
||||
#include "shared/source/memory_manager/graphics_allocation.h"
|
||||
#include "shared/test/common/fixtures/linear_stream_fixture.h"
|
||||
#include "shared/test/common/mocks/mock_graphics_allocation.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
TEST(LinearStreamCtorTest, WhenConstructingLinearStreamThenInitialValuesValuesAreSet) {
|
||||
LinearStream linearStream;
|
||||
EXPECT_EQ(nullptr, linearStream.getCpuBase());
|
||||
EXPECT_EQ(0u, linearStream.getMaxAvailableSpace());
|
||||
}
|
||||
|
||||
TEST(LinearStreamCtorTest, whenProvidedAllArgumentsThenExpectSameValuesSet) {
|
||||
GraphicsAllocation *gfxAllocation = reinterpret_cast<GraphicsAllocation *>(0x1234);
|
||||
void *buffer = reinterpret_cast<void *>(0x2000);
|
||||
size_t bufferSize = 0x1000u;
|
||||
LinearStream linearStream(gfxAllocation, buffer, bufferSize);
|
||||
EXPECT_EQ(buffer, linearStream.getCpuBase());
|
||||
EXPECT_EQ(bufferSize, linearStream.getMaxAvailableSpace());
|
||||
EXPECT_EQ(gfxAllocation, linearStream.getGraphicsAllocation());
|
||||
}
|
||||
|
||||
TEST_F(LinearStreamTest, GivenSizeZeroWhenGettingSpaceUsedThenNonNullPointerIsReturned) {
|
||||
EXPECT_NE(nullptr, linearStream.getSpace(0));
|
||||
}
|
||||
|
||||
TEST_F(LinearStreamTest, GivenSizeUint32WhenGettingSpaceUsedThenNonNullPointerIsReturned) {
|
||||
EXPECT_NE(nullptr, linearStream.getSpace(sizeof(uint32_t)));
|
||||
}
|
||||
|
||||
TEST_F(LinearStreamTest, WhenAllocatingMultipleTimesThenPointersIncrementedCorrectly) {
|
||||
size_t allocSize = 1;
|
||||
auto ptr1 = linearStream.getSpace(allocSize);
|
||||
ASSERT_NE(nullptr, ptr1);
|
||||
|
||||
auto ptr2 = linearStream.getSpace(2);
|
||||
ASSERT_NE(nullptr, ptr2);
|
||||
|
||||
EXPECT_EQ(allocSize, (uintptr_t)ptr2 - (uintptr_t)ptr1);
|
||||
}
|
||||
|
||||
TEST_F(LinearStreamTest, WhenGettingSpaceThenPointerIsWriteable) {
|
||||
uint32_t cmd = 0xbaddf00d;
|
||||
auto pCmd = linearStream.getSpace(sizeof(cmd));
|
||||
ASSERT_NE(nullptr, pCmd);
|
||||
*(uint32_t *)pCmd = cmd;
|
||||
}
|
||||
|
||||
TEST_F(LinearStreamTest, WhenRequestingMutltipleAllocationsThenDifferentPointersAreReturnedForEachRequest) {
|
||||
auto pCmd = linearStream.getSpace(sizeof(uint32_t));
|
||||
ASSERT_NE(nullptr, pCmd);
|
||||
auto pCmd2 = linearStream.getSpace(sizeof(uint32_t));
|
||||
ASSERT_NE(pCmd2, pCmd);
|
||||
}
|
||||
|
||||
TEST_F(LinearStreamTest, GivenNoAllocationsWhenGettingSpaceThenAvailableSpaceIsEqualMaximumSpace) {
|
||||
ASSERT_EQ(linearStream.getMaxAvailableSpace(), linearStream.getAvailableSpace());
|
||||
}
|
||||
|
||||
TEST_F(LinearStreamTest, GivenNoAllocationsWhenGettingSpaceThenAvailableSpaceIsGreaterThanZero) {
|
||||
EXPECT_NE(0u, linearStream.getAvailableSpace());
|
||||
}
|
||||
|
||||
TEST_F(LinearStreamTest, GivenAllocationWhenGettingSpaceThenAvailableSpaceIsReduced) {
|
||||
auto originalAvailable = linearStream.getAvailableSpace();
|
||||
linearStream.getSpace(sizeof(uint32_t));
|
||||
|
||||
EXPECT_LT(linearStream.getAvailableSpace(), originalAvailable);
|
||||
}
|
||||
|
||||
TEST_F(LinearStreamTest, GivenOneAllocationsWhenGettingSpaceThenSpaceUsedIsEqualToAllocationSize) {
|
||||
size_t sizeToAllocate = 2 * sizeof(uint32_t);
|
||||
ASSERT_NE(nullptr, linearStream.getSpace(sizeToAllocate));
|
||||
|
||||
EXPECT_EQ(sizeToAllocate, linearStream.getUsed());
|
||||
}
|
||||
|
||||
TEST_F(LinearStreamTest, givenLinearStreamWhenGetCpuBaseIsCalledThenCpuBaseAddressIsReturned) {
|
||||
ASSERT_EQ(pCmdBuffer, linearStream.getCpuBase());
|
||||
}
|
||||
|
||||
TEST_F(LinearStreamTest, givenNotEnoughSpaceWhenGetSpaceIsCalledThenThrowException) {
|
||||
linearStream.getSpace(linearStream.getMaxAvailableSpace());
|
||||
EXPECT_THROW(linearStream.getSpace(1), std::exception);
|
||||
}
|
||||
|
||||
TEST_F(LinearStreamTest, WhenReplacingBufferThenAvailableSizeIsEqualToBufferSizeAndAllSpaceIsAvailable) {
|
||||
char buffer[256];
|
||||
linearStream.replaceBuffer(buffer, sizeof(buffer));
|
||||
EXPECT_EQ(buffer, linearStream.getCpuBase());
|
||||
EXPECT_EQ(sizeof(buffer), linearStream.getAvailableSpace());
|
||||
EXPECT_EQ(0u, linearStream.getUsed());
|
||||
}
|
||||
|
||||
TEST_F(LinearStreamTest, givenNewGraphicsAllocationWhenReplaceIsCalledThenLinearStreamContainsNewGraphicsAllocation) {
|
||||
auto graphicsAllocation = linearStream.getGraphicsAllocation();
|
||||
EXPECT_NE(nullptr, graphicsAllocation);
|
||||
auto address = (void *)0x100000;
|
||||
MockGraphicsAllocation newGraphicsAllocation(address, 4096);
|
||||
EXPECT_NE(&newGraphicsAllocation, graphicsAllocation);
|
||||
linearStream.replaceGraphicsAllocation(&newGraphicsAllocation);
|
||||
EXPECT_EQ(&newGraphicsAllocation, linearStream.getGraphicsAllocation());
|
||||
}
|
||||
39
shared/test/unit_test/command_stream/tbx_stream_tests.cpp
Normal file
39
shared/test/unit_test/command_stream/tbx_stream_tests.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/command_stream/tbx_command_stream_receiver_hw.h"
|
||||
#include "shared/source/tbx/tbx_proto.h"
|
||||
#include "shared/test/common/mocks/mock_tbx_sockets.h"
|
||||
#include "shared/test/common/mocks/mock_tbx_stream.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
TEST(TbxStreamTests, givenTbxStreamWhenWriteMemoryIsCalledThenMemTypeIsSetCorrectly) {
|
||||
std::unique_ptr<TbxCommandStreamReceiver::TbxStream> mockTbxStream(new MockTbxStream());
|
||||
MockTbxStream *mockTbxStreamPtr = static_cast<MockTbxStream *>(mockTbxStream.get());
|
||||
|
||||
MockTbxSockets *mockTbxSocket = new MockTbxSockets();
|
||||
mockTbxStreamPtr->socket = mockTbxSocket;
|
||||
|
||||
uint32_t addressSpace = AubMemDump::AddressSpaceValues::TraceLocal;
|
||||
mockTbxStream->writeMemory(0, nullptr, 0, addressSpace, 0);
|
||||
EXPECT_EQ(mem_types::MEM_TYPE_LOCALMEM, mockTbxSocket->typeCapturedFromWriteMemory);
|
||||
|
||||
addressSpace = AubMemDump::AddressSpaceValues::TraceNonlocal;
|
||||
mockTbxStream->writeMemory(0, nullptr, 0, addressSpace, 0);
|
||||
EXPECT_EQ(mem_types::MEM_TYPE_SYSTEM, mockTbxSocket->typeCapturedFromWriteMemory);
|
||||
|
||||
addressSpace = AubMemDump::AddressSpaceValues::TraceLocal;
|
||||
mockTbxStream->writePTE(0, 0, addressSpace);
|
||||
EXPECT_EQ(mem_types::MEM_TYPE_LOCALMEM, mockTbxSocket->typeCapturedFromWriteMemory);
|
||||
|
||||
addressSpace = AubMemDump::AddressSpaceValues::TraceNonlocal;
|
||||
mockTbxStream->writePTE(0, 0, addressSpace);
|
||||
EXPECT_EQ(mem_types::MEM_TYPE_SYSTEM, mockTbxSocket->typeCapturedFromWriteMemory);
|
||||
}
|
||||
Reference in New Issue
Block a user