|
10 | 10 | #include "shared/test/common/helpers/debug_manager_state_restore.h"
|
11 | 11 | #include "shared/test/common/helpers/default_hw_info.h"
|
12 | 12 | #include "shared/test/common/libult/linux/drm_mock.h"
|
| 13 | +#include "shared/test/common/mocks/linux/mock_drm_allocation.h" |
13 | 14 | #include "shared/test/common/test_macros/test.h"
|
14 | 15 |
|
15 | 16 | using namespace NEO;
|
@@ -194,3 +195,65 @@ TEST(IoctlHelperTestsPrelim, givenPrelimsWhenGetHwConfigIoctlValThenCorrectValue
|
194 | 195 | uint32_t ioctlVal = (1 << 16) | 6;
|
195 | 196 | EXPECT_EQ(ioctlVal, IoctlHelper::get(drm.get())->getHwConfigIoctlVal());
|
196 | 197 | }
|
| 198 | + |
| 199 | +TEST(IoctlHelperTestsPrelim, givenDrmAllocationWhenSetMemAdviseFailsThenDontUpdateMemAdviceFlags) { |
| 200 | + auto executionEnvironment = std::make_unique<ExecutionEnvironment>(); |
| 201 | + executionEnvironment->prepareRootDeviceEnvironments(1); |
| 202 | + |
| 203 | + DrmPrelimMock drm(*executionEnvironment->rootDeviceEnvironments[0]); |
| 204 | + drm.ioctlRetVal = -1; |
| 205 | + |
| 206 | + MockBufferObject bo(&drm, 0, 0, 1); |
| 207 | + MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::LocalMemory); |
| 208 | + allocation.bufferObjects[0] = &bo; |
| 209 | + |
| 210 | + MemAdviseFlags memAdviseFlags{}; |
| 211 | + memAdviseFlags.non_atomic = 1; |
| 212 | + |
| 213 | + allocation.setMemAdvise(&drm, memAdviseFlags); |
| 214 | + |
| 215 | + EXPECT_EQ(1u, drm.ioctlCallsCount); |
| 216 | + EXPECT_NE(memAdviseFlags.memadvise_flags, allocation.enabledMemAdviseFlags.memadvise_flags); |
| 217 | +} |
| 218 | + |
| 219 | +TEST(IoctlHelperTestsPrelim, givenDrmAllocationWhenSetMemAdviseWithNonAtomicIsCalledThenUpdateTheCorrespondingVmAdviceForBufferObject) { |
| 220 | + auto executionEnvironment = std::make_unique<ExecutionEnvironment>(); |
| 221 | + executionEnvironment->prepareRootDeviceEnvironments(1); |
| 222 | + |
| 223 | + DrmPrelimMock drm(*executionEnvironment->rootDeviceEnvironments[0]); |
| 224 | + |
| 225 | + MockBufferObject bo(&drm, 0, 0, 1); |
| 226 | + MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::LocalMemory); |
| 227 | + allocation.bufferObjects[0] = &bo; |
| 228 | + |
| 229 | + MemAdviseFlags memAdviseFlags{}; |
| 230 | + |
| 231 | + for (auto nonAtomic : {true, false}) { |
| 232 | + memAdviseFlags.non_atomic = nonAtomic; |
| 233 | + |
| 234 | + EXPECT_TRUE(allocation.setMemAdvise(&drm, memAdviseFlags)); |
| 235 | + EXPECT_EQ(memAdviseFlags.memadvise_flags, allocation.enabledMemAdviseFlags.memadvise_flags); |
| 236 | + } |
| 237 | + EXPECT_EQ(2u, drm.ioctlCallsCount); |
| 238 | +} |
| 239 | + |
| 240 | +TEST(IoctlHelperTestsPrelim, givenDrmAllocationWhenSetMemAdviseWithDevicePreferredLocationIsCalledThenUpdateTheCorrespondingVmAdviceForBufferObject) { |
| 241 | + auto executionEnvironment = std::make_unique<ExecutionEnvironment>(); |
| 242 | + executionEnvironment->prepareRootDeviceEnvironments(1); |
| 243 | + |
| 244 | + DrmPrelimMock drm(*executionEnvironment->rootDeviceEnvironments[0]); |
| 245 | + |
| 246 | + MockBufferObject bo(&drm, 0, 0, 1); |
| 247 | + MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::LocalMemory); |
| 248 | + allocation.bufferObjects[0] = &bo; |
| 249 | + |
| 250 | + MemAdviseFlags memAdviseFlags{}; |
| 251 | + |
| 252 | + for (auto devicePreferredLocation : {true, false}) { |
| 253 | + memAdviseFlags.device_preferred_location = devicePreferredLocation; |
| 254 | + |
| 255 | + EXPECT_TRUE(allocation.setMemAdvise(&drm, memAdviseFlags)); |
| 256 | + EXPECT_EQ(memAdviseFlags.memadvise_flags, allocation.enabledMemAdviseFlags.memadvise_flags); |
| 257 | + } |
| 258 | + EXPECT_EQ(2u, drm.ioctlCallsCount); |
| 259 | +} |
0 commit comments