1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
/*
* Copyright (C) 2019-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/linux/drm_memory_operations_handler_default.h"
#include "opencl/test/unit_test/mocks/mock_graphics_allocation.h"
#include "test.h"
#include <memory>
using namespace NEO;
struct MockDrmMemoryOperationsHandlerDefault : public DrmMemoryOperationsHandlerDefault {
using DrmMemoryOperationsHandlerDefault::residency;
};
struct DrmMemoryOperationsHandlerBaseTest : public ::testing::Test {
void SetUp() override {
drmMemoryOperationsHandler = std::make_unique<MockDrmMemoryOperationsHandlerDefault>();
allocationPtr = &graphicsAllocation;
}
MockGraphicsAllocation graphicsAllocation;
GraphicsAllocation *allocationPtr;
std::unique_ptr<MockDrmMemoryOperationsHandlerDefault> drmMemoryOperationsHandler;
};
TEST_F(DrmMemoryOperationsHandlerBaseTest, whenMakingResidentAllocaionExpectMakeResidentFail) {
EXPECT_EQ(drmMemoryOperationsHandler->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 1u);
EXPECT_TRUE(drmMemoryOperationsHandler->residency.find(allocationPtr) != drmMemoryOperationsHandler->residency.end());
EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, graphicsAllocation), MemoryOperationsStatus::SUCCESS);
}
TEST_F(DrmMemoryOperationsHandlerBaseTest, whenEvictingResidentAllocationExpectEvictFalse) {
EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 0u);
EXPECT_EQ(drmMemoryOperationsHandler->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, graphicsAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 1u);
EXPECT_TRUE(drmMemoryOperationsHandler->residency.find(allocationPtr) != drmMemoryOperationsHandler->residency.end());
EXPECT_EQ(drmMemoryOperationsHandler->evict(nullptr, graphicsAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, graphicsAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND);
EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 0u);
}
|