2019-10-22 12:09:08 +02:00
|
|
|
/*
|
2020-02-22 22:21:06 +01:00
|
|
|
* Copyright (C) 2017-2020 Intel Corporation
|
2019-10-22 12:09:08 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/compiler_interface/compiler_interface.h"
|
|
|
|
|
#include "shared/source/compiler_interface/compiler_interface.inl"
|
|
|
|
|
#include "shared/source/helpers/file_io.h"
|
|
|
|
|
#include "shared/source/helpers/hw_info.h"
|
2020-02-24 01:01:38 +01:00
|
|
|
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
|
2020-02-24 10:22:30 +01:00
|
|
|
|
2020-02-23 15:20:22 +01:00
|
|
|
#include "opencl/test/unit_test/fixtures/device_fixture.h"
|
|
|
|
|
#include "opencl/test/unit_test/global_environment.h"
|
|
|
|
|
#include "opencl/test/unit_test/helpers/test_files.h"
|
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_cif.h"
|
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_compilers.h"
|
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_program.h"
|
2019-10-22 12:09:08 +02:00
|
|
|
|
|
|
|
|
#include "gmock/gmock.h"
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
using namespace NEO;
|
|
|
|
|
|
|
|
|
|
struct UpdateSpecConstantsTest : public ::testing::Test {
|
|
|
|
|
void SetUp() override {
|
|
|
|
|
mockProgram.reset(new MockProgram(executionEnvironment));
|
|
|
|
|
|
|
|
|
|
mockProgram->specConstantsIds.reset(new MockCIFBuffer());
|
|
|
|
|
mockProgram->specConstantsSizes.reset(new MockCIFBuffer());
|
|
|
|
|
mockProgram->specConstantsValues.reset(new MockCIFBuffer());
|
|
|
|
|
|
2020-03-04 09:20:09 +01:00
|
|
|
uint32_t id1 = 1u, id2 = 2u, id3 = 3u;
|
|
|
|
|
mockProgram->specConstantsIds->PushBackRawCopy(id1);
|
|
|
|
|
mockProgram->specConstantsIds->PushBackRawCopy(id2);
|
|
|
|
|
mockProgram->specConstantsIds->PushBackRawCopy(id3);
|
2019-10-22 12:09:08 +02:00
|
|
|
|
2020-03-04 09:20:09 +01:00
|
|
|
uint32_t size1 = sizeof(char), size2 = sizeof(uint16_t), size3 = sizeof(int);
|
|
|
|
|
mockProgram->specConstantsSizes->PushBackRawCopy(size1);
|
|
|
|
|
mockProgram->specConstantsSizes->PushBackRawCopy(size2);
|
|
|
|
|
mockProgram->specConstantsSizes->PushBackRawCopy(size3);
|
2019-10-22 12:09:08 +02:00
|
|
|
|
2020-03-04 09:20:09 +01:00
|
|
|
val1 = new char;
|
|
|
|
|
val2 = new uint16_t;
|
2019-10-22 12:09:08 +02:00
|
|
|
|
2020-03-04 09:20:09 +01:00
|
|
|
*val1 = 5;
|
|
|
|
|
*val2 = 50;
|
2019-10-22 12:09:08 +02:00
|
|
|
|
2020-03-04 09:20:09 +01:00
|
|
|
mockProgram->specConstantsValues->PushBackRawCopy(val1);
|
|
|
|
|
mockProgram->specConstantsValues->PushBackRawCopy(val2);
|
|
|
|
|
mockProgram->specConstantsValues->PushBackRawCopy(val3);
|
|
|
|
|
|
|
|
|
|
values = mockProgram->specConstantsValues->GetMemoryWriteable<void *>();
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(val1, reinterpret_cast<char *>(values[0]));
|
|
|
|
|
EXPECT_EQ(val2, reinterpret_cast<uint16_t *>(values[1]));
|
|
|
|
|
EXPECT_EQ(val3, reinterpret_cast<int *>(values[2]));
|
2019-10-22 12:09:08 +02:00
|
|
|
}
|
|
|
|
|
ExecutionEnvironment executionEnvironment;
|
|
|
|
|
std::unique_ptr<MockProgram> mockProgram;
|
|
|
|
|
|
2020-03-04 09:20:09 +01:00
|
|
|
char *val1 = nullptr;
|
|
|
|
|
uint16_t *val2 = nullptr;
|
|
|
|
|
int *val3 = nullptr;
|
|
|
|
|
void **values;
|
2019-10-22 12:09:08 +02:00
|
|
|
};
|
|
|
|
|
|
2020-03-04 09:20:09 +01:00
|
|
|
TEST_F(UpdateSpecConstantsTest, givenNewSpecConstValueWhenUpdateSpecializationConstantThenProperValueIsCopiedAndUpdated) {
|
2019-10-22 12:09:08 +02:00
|
|
|
int newSpecConstVal3 = 5000;
|
|
|
|
|
|
|
|
|
|
auto ret = mockProgram->updateSpecializationConstant(3, sizeof(int), &newSpecConstVal3);
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(CL_SUCCESS, ret);
|
2020-03-04 09:20:09 +01:00
|
|
|
EXPECT_EQ(val1, reinterpret_cast<char *>(values[0]));
|
|
|
|
|
EXPECT_EQ(val2, reinterpret_cast<uint16_t *>(values[1]));
|
|
|
|
|
EXPECT_EQ(newSpecConstVal3, *reinterpret_cast<int *>(values[2]));
|
|
|
|
|
EXPECT_NE(&newSpecConstVal3, values[2]);
|
|
|
|
|
EXPECT_NE(val3, values[2]);
|
|
|
|
|
|
|
|
|
|
newSpecConstVal3 = 50000;
|
|
|
|
|
EXPECT_NE(newSpecConstVal3, *reinterpret_cast<int *>(values[2]));
|
|
|
|
|
|
|
|
|
|
ret = mockProgram->updateSpecializationConstant(3, sizeof(int), &newSpecConstVal3);
|
|
|
|
|
EXPECT_EQ(CL_SUCCESS, ret);
|
|
|
|
|
EXPECT_EQ(newSpecConstVal3, *reinterpret_cast<int *>(values[2]));
|
2019-10-22 12:09:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(UpdateSpecConstantsTest, givenNewSpecConstValueWithUnproperSizeWhenUpdateSpecializationConstantThenErrorIsReturned) {
|
|
|
|
|
int newSpecConstVal3 = 5000;
|
|
|
|
|
|
|
|
|
|
auto ret = mockProgram->updateSpecializationConstant(3, 10 * sizeof(int), &newSpecConstVal3);
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(CL_INVALID_VALUE, ret);
|
2020-03-04 09:20:09 +01:00
|
|
|
EXPECT_EQ(val1, reinterpret_cast<char *>(values[0]));
|
|
|
|
|
EXPECT_EQ(val2, reinterpret_cast<uint16_t *>(values[1]));
|
|
|
|
|
EXPECT_EQ(val3, reinterpret_cast<int *>(values[2]));
|
2019-10-22 12:09:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(UpdateSpecConstantsTest, givenNewSpecConstValueWithUnproperIdAndSizeWhenUpdateSpecializationConstantThenErrorIsReturned) {
|
|
|
|
|
int newSpecConstVal3 = 5000;
|
|
|
|
|
|
|
|
|
|
auto ret = mockProgram->updateSpecializationConstant(4, sizeof(int), &newSpecConstVal3);
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(CL_INVALID_SPEC_ID, ret);
|
2020-03-04 09:20:09 +01:00
|
|
|
EXPECT_EQ(val1, reinterpret_cast<char *>(values[0]));
|
|
|
|
|
EXPECT_EQ(val2, reinterpret_cast<uint16_t *>(values[1]));
|
|
|
|
|
EXPECT_EQ(val3, reinterpret_cast<int *>(values[2]));
|
2019-10-22 12:09:08 +02:00
|
|
|
}
|