Files
compute-runtime/unit_tests/helpers/mem_properties_parser_helper_tests.cpp
Krzysztof Gibala b5020eac81 Create helper for memory properties
-Move logics from  mem_obj_helper

Related-To: NEO-3374
Change-Id: I167cdcc8fcb08cb1fa6d19640fd266f0004f4c6b
Signed-off-by: Krzysztof Gibala <krzysztof.gibala@intel.com>
2019-07-23 11:31:49 +02:00

70 lines
3.1 KiB
C++

/*
* Copyright (C) 2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "runtime/helpers/mem_properties_parser_helper.h"
#include "gtest/gtest.h"
using namespace NEO;
TEST(MemoryPropertiesParser, givenNullPropertiesWhenParsingMemoryPropertiesThenTrueIsReturned) {
MemoryProperties propertiesStruct;
EXPECT_TRUE(MemoryPropertiesParser::parseMemoryProperties(nullptr, propertiesStruct));
}
TEST(MemoryPropertiesParser, givenEmptyPropertiesWhenParsingMemoryPropertiesThenTrueIsReturned) {
cl_mem_properties_intel properties[] = {0};
MemoryProperties propertiesStruct;
EXPECT_TRUE(MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct));
}
TEST(MemoryPropertiesParser, givenValidPropertiesWhenParsingMemoryPropertiesThenTrueIsReturned) {
cl_mem_properties_intel properties[] = {
CL_MEM_FLAGS,
CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR |
CL_MEM_USE_HOST_PTR | CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS,
CL_MEM_FLAGS_INTEL,
CL_MEM_LOCALLY_UNCACHED_RESOURCE,
0};
MemoryProperties propertiesStruct;
EXPECT_TRUE(MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct));
}
TEST(MemoryPropertiesParser, givenInvalidPropertiesWhenParsingMemoryPropertiesThenFalseIsReturned) {
cl_mem_properties_intel properties[] = {
(1 << 30), CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR,
0};
MemoryProperties propertiesStruct;
EXPECT_FALSE(MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct));
}
TEST(MemoryPropertiesParser, givenDifferentParametersWhenCallingFillCachePolicyInPropertiesThenFlushL3FlagsAreCorrectlySet) {
AllocationProperties allocationProperties{0, GraphicsAllocation::AllocationType::BUFFER};
for (auto uncached : ::testing::Bool()) {
for (auto readOnly : ::testing::Bool()) {
for (auto deviceOnlyVisibilty : ::testing::Bool()) {
if (uncached || readOnly || deviceOnlyVisibilty) {
allocationProperties.flags.flushL3RequiredForRead = true;
allocationProperties.flags.flushL3RequiredForWrite = true;
MemoryPropertiesParser::fillCachePolicyInProperties(allocationProperties, uncached, readOnly, deviceOnlyVisibilty);
EXPECT_FALSE(allocationProperties.flags.flushL3RequiredForRead);
EXPECT_FALSE(allocationProperties.flags.flushL3RequiredForWrite);
} else {
allocationProperties.flags.flushL3RequiredForRead = false;
allocationProperties.flags.flushL3RequiredForWrite = false;
MemoryPropertiesParser::fillCachePolicyInProperties(allocationProperties, uncached, readOnly, deviceOnlyVisibilty);
EXPECT_TRUE(allocationProperties.flags.flushL3RequiredForRead);
EXPECT_TRUE(allocationProperties.flags.flushL3RequiredForWrite);
}
}
}
}
}