|
23 | 23 | #include "unit_tests/mocks/mock_event.h" |
24 | 24 | #include "unit_tests/mocks/mock_kernel.h" |
25 | 25 | #include "unit_tests/mocks/mock_mdi.h" |
| 26 | +#include "unit_tests/mocks/mock_memory_manager.h" |
26 | 27 | #include "unit_tests/mocks/mock_program.h" |
27 | 28 | #include "unit_tests/os_interface/mock_performance_counters.h" |
28 | 29 | #include <memory> |
@@ -382,22 +383,41 @@ TEST_F(EventTest, Event_Wait_NonBlocking) { |
382 | 383 | EXPECT_FALSE(result); |
383 | 384 | } |
384 | 385 |
|
385 | | -TEST_F(EventTest, givenEventContainingCommandQueueWhenItsStatusIsUpdatedToCompletedThenTemporaryAllocationsAreDeleted) { |
| 386 | +struct UpdateEventTest : public ::testing::Test { |
386 | 387 |
|
387 | | - auto memoryManager = pCmdQ->getDevice().getMemoryManager(); |
| 388 | + void SetUp() override { |
| 389 | + executionEnvironment = new ExecutionEnvironment; |
| 390 | + memoryManager = new MockMemoryManager(*executionEnvironment); |
| 391 | + hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager()); |
| 392 | + executionEnvironment->memoryManager.reset(memoryManager); |
| 393 | + device.reset(Device::create<Device>(*platformDevices, executionEnvironment, 0u)); |
| 394 | + context = std::make_unique<MockContext>(device.get()); |
| 395 | + cl_int retVal = CL_OUT_OF_RESOURCES; |
| 396 | + commandQueue.reset(CommandQueue::create(context.get(), device.get(), nullptr, retVal)); |
| 397 | + EXPECT_EQ(CL_SUCCESS, retVal); |
| 398 | + } |
| 399 | + |
| 400 | + ExecutionEnvironment *executionEnvironment; |
| 401 | + MockMemoryManager *memoryManager; |
| 402 | + MockHostPtrManager *hostPtrManager; |
| 403 | + std::unique_ptr<Device> device; |
| 404 | + std::unique_ptr<Context> context; |
| 405 | + std::unique_ptr<CommandQueue> commandQueue; |
| 406 | +}; |
388 | 407 |
|
| 408 | +TEST_F(UpdateEventTest, givenEventContainingCommandQueueWhenItsStatusIsUpdatedToCompletedThenTemporaryAllocationsAreDeleted) { |
389 | 409 | void *ptr = (void *)0x1000; |
390 | 410 | size_t size = 4096; |
391 | 411 | auto temporary = memoryManager->allocateGraphicsMemory(size, ptr); |
392 | 412 | temporary->taskCount = 3; |
393 | 413 | memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(temporary), TEMPORARY_ALLOCATION); |
394 | | - Event event(pCmdQ, CL_COMMAND_NDRANGE_KERNEL, 3, 3); |
| 414 | + Event event(commandQueue.get(), CL_COMMAND_NDRANGE_KERNEL, 3, 3); |
395 | 415 |
|
396 | | - EXPECT_EQ(1u, memoryManager->hostPtrManager.getFragmentCount()); |
| 416 | + EXPECT_EQ(1u, hostPtrManager->getFragmentCount()); |
397 | 417 |
|
398 | 418 | event.updateExecutionStatus(); |
399 | 419 |
|
400 | | - EXPECT_EQ(0u, memoryManager->hostPtrManager.getFragmentCount()); |
| 420 | + EXPECT_EQ(0u, hostPtrManager->getFragmentCount()); |
401 | 421 | } |
402 | 422 |
|
403 | 423 | class SurfaceMock : public Surface { |
|
0 commit comments