File: multi_graphics_allocation_tests.cpp

package info (click to toggle)
intel-compute-runtime 20.44.18297-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 34,780 kB
  • sloc: cpp: 379,729; lisp: 4,931; python: 299; sh: 196; makefile: 8
file content (103 lines) | stat: -rw-r--r-- 5,065 bytes parent folder | download
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 * Copyright (C) 2020 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "shared/source/memory_manager/multi_graphics_allocation.h"

#include "gtest/gtest.h"

using namespace NEO;

struct MockMultiGraphicsAllocation : public MultiGraphicsAllocation {
    using MultiGraphicsAllocation::graphicsAllocations;
    using MultiGraphicsAllocation::MultiGraphicsAllocation;
};

TEST(MultiGraphicsAllocationTest, whenCreatingMultiGraphicsAllocationThenTheAllocationIsObtainableAsADefault) {
    GraphicsAllocation graphicsAllocation(1, // rootDeviceIndex
                                          GraphicsAllocation::AllocationType::BUFFER,
                                          nullptr, 0, 0, MemoryPool::System4KBPages, 0);

    MockMultiGraphicsAllocation multiGraphicsAllocation(1);
    EXPECT_EQ(2u, multiGraphicsAllocation.graphicsAllocations.size());

    multiGraphicsAllocation.addAllocation(&graphicsAllocation);

    EXPECT_EQ(&graphicsAllocation, multiGraphicsAllocation.getDefaultGraphicsAllocation());

    EXPECT_EQ(&graphicsAllocation, multiGraphicsAllocation.getGraphicsAllocation(graphicsAllocation.getRootDeviceIndex()));
    EXPECT_EQ(nullptr, multiGraphicsAllocation.getGraphicsAllocation(0));
}

TEST(MultiGraphicsAllocationTest, givenMultiGraphicsAllocationWhenAddingMultipleGraphicsAllocationsThenTheyAreObtainableByRootDeviceIndex) {
    GraphicsAllocation graphicsAllocation0(0, // rootDeviceIndex
                                           GraphicsAllocation::AllocationType::BUFFER,
                                           nullptr, 0, 0, MemoryPool::System4KBPages, 0);
    GraphicsAllocation graphicsAllocation1(1, // rootDeviceIndex
                                           GraphicsAllocation::AllocationType::BUFFER,
                                           nullptr, 0, 0, MemoryPool::System4KBPages, 0);

    MockMultiGraphicsAllocation multiGraphicsAllocation(1);

    EXPECT_EQ(2u, multiGraphicsAllocation.graphicsAllocations.size());
    multiGraphicsAllocation.addAllocation(&graphicsAllocation0);
    multiGraphicsAllocation.addAllocation(&graphicsAllocation1);

    EXPECT_EQ(&graphicsAllocation0, multiGraphicsAllocation.getGraphicsAllocation(graphicsAllocation0.getRootDeviceIndex()));
    EXPECT_EQ(&graphicsAllocation1, multiGraphicsAllocation.getGraphicsAllocation(graphicsAllocation1.getRootDeviceIndex()));
}

TEST(MultiGraphicsAllocationTest, givenMultiGraphicsAllocationWhenGettingAllocationTypeThenReturnAllocationTypeFromDefaultAllocation) {
    auto expectedAllocationType = GraphicsAllocation::AllocationType::BUFFER;
    GraphicsAllocation graphicsAllocation(1, // rootDeviceIndex
                                          expectedAllocationType,
                                          nullptr, 0, 0, MemoryPool::System4KBPages, 0);

    MockMultiGraphicsAllocation multiGraphicsAllocation(1);
    multiGraphicsAllocation.addAllocation(&graphicsAllocation);

    EXPECT_EQ(multiGraphicsAllocation.getDefaultGraphicsAllocation()->getAllocationType(), multiGraphicsAllocation.getAllocationType());
    EXPECT_EQ(expectedAllocationType, multiGraphicsAllocation.getAllocationType());
}

TEST(MultiGraphicsAllocationTest, givenMultiGraphicsAllocationWhenGettingCoherencyStatusThenReturnCoherencyStatusFromDefaultAllocation) {
    auto expectedAllocationType = GraphicsAllocation::AllocationType::BUFFER;
    GraphicsAllocation graphicsAllocation(1, // rootDeviceIndex
                                          expectedAllocationType,
                                          nullptr, 0, 0, MemoryPool::System4KBPages, 0);

    MockMultiGraphicsAllocation multiGraphicsAllocation(1);
    multiGraphicsAllocation.addAllocation(&graphicsAllocation);

    graphicsAllocation.setCoherent(true);
    EXPECT_TRUE(multiGraphicsAllocation.isCoherent());

    graphicsAllocation.setCoherent(false);
    EXPECT_FALSE(multiGraphicsAllocation.isCoherent());
}

TEST(MultiGraphicsAllocationTest, WhenCreatingMultiGraphicsAllocationWithoutGraphicsAllocationThenNoDefaultAllocationIsReturned) {
    MockMultiGraphicsAllocation multiGraphicsAllocation(1);
    EXPECT_EQ(nullptr, multiGraphicsAllocation.getDefaultGraphicsAllocation());
}

TEST(MultiGraphicsAllocationTest, givenMultiGraphicsAllocationwhenRemovingGraphicsAllocationThenTheAllocationIsNoLongerAvailable) {
    uint32_t rootDeviceIndex = 1u;
    GraphicsAllocation graphicsAllocation(rootDeviceIndex,
                                          GraphicsAllocation::AllocationType::BUFFER,
                                          nullptr, 0, 0, MemoryPool::System4KBPages, 0);

    MockMultiGraphicsAllocation multiGraphicsAllocation(rootDeviceIndex);
    EXPECT_EQ(2u, multiGraphicsAllocation.graphicsAllocations.size());

    multiGraphicsAllocation.addAllocation(&graphicsAllocation);

    EXPECT_EQ(&graphicsAllocation, multiGraphicsAllocation.getGraphicsAllocation(rootDeviceIndex));

    multiGraphicsAllocation.removeAllocation(rootDeviceIndex);

    EXPECT_EQ(nullptr, multiGraphicsAllocation.getGraphicsAllocation(rootDeviceIndex));
}