2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2021-05-17 02:51:16 +08:00
|
|
|
* Copyright (C) 2018-2021 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/device/device.h"
|
|
|
|
#include "shared/source/helpers/string.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-10-16 21:00:28 +08:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_cl_device.h"
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_program.h"
|
2018-08-06 22:36:12 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-08-06 22:36:12 +08:00
|
|
|
class ProcessSpirBinaryTests : public ::testing::Test {
|
|
|
|
public:
|
|
|
|
void SetUp() override {
|
2020-10-16 21:00:28 +08:00
|
|
|
device = std::make_unique<MockClDevice>(new MockDevice());
|
|
|
|
program = std::make_unique<MockProgram>(toClDeviceVector(*device));
|
2018-08-06 22:36:12 +08:00
|
|
|
}
|
|
|
|
|
2020-10-16 21:00:28 +08:00
|
|
|
std::unique_ptr<ClDevice> device;
|
2018-08-06 22:36:12 +08:00
|
|
|
std::unique_ptr<MockProgram> program;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
2020-07-20 17:16:58 +08:00
|
|
|
TEST_F(ProcessSpirBinaryTests, GivenNullBinaryWhenProcessingSpirBinaryThenSourceCodeIsEmpty) {
|
2018-08-06 22:36:12 +08:00
|
|
|
auto retVal = program->processSpirBinary(nullptr, 0, false);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
2018-08-06 22:36:12 +08:00
|
|
|
EXPECT_EQ(true, program->sourceCode.empty());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2020-07-20 17:16:58 +08:00
|
|
|
TEST_F(ProcessSpirBinaryTests, GivenInvalidSizeBinaryWhenProcessingSpirBinaryThenIrBinarSizeIsSetToPassedValue) {
|
2017-12-21 07:45:38 +08:00
|
|
|
char pBinary[] = "somebinary\0";
|
|
|
|
size_t binarySize = 1;
|
2018-08-06 22:36:12 +08:00
|
|
|
auto retVal = program->processSpirBinary(pBinary, binarySize, false);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
2019-10-20 20:22:34 +08:00
|
|
|
EXPECT_EQ(binarySize, program->irBinarySize);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2020-07-20 17:16:58 +08:00
|
|
|
TEST_F(ProcessSpirBinaryTests, WhenProcessingSpirBinaryThenIrBinaryIsSetCorrectly) {
|
2017-12-21 07:45:38 +08:00
|
|
|
char pBinary[] = "somebinary\0";
|
|
|
|
size_t binarySize = strnlen_s(pBinary, 11);
|
2018-08-06 22:36:12 +08:00
|
|
|
auto retVal = program->processSpirBinary(pBinary, binarySize, false);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
2019-10-20 20:22:34 +08:00
|
|
|
EXPECT_EQ(0, memcmp(pBinary, program->irBinary.get(), program->irBinarySize));
|
|
|
|
EXPECT_EQ(binarySize, program->irBinarySize);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
// Verify no built log is available
|
2020-08-24 19:07:06 +08:00
|
|
|
std::string buildLog = program->getBuildLog(0);
|
|
|
|
EXPECT_TRUE(buildLog.empty());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2020-07-20 17:16:58 +08:00
|
|
|
TEST_F(ProcessSpirBinaryTests, WhenProcessingSpirBinaryThenIsSpirvIsSetBasedonPassedValue) {
|
2017-12-21 07:45:38 +08:00
|
|
|
const uint32_t pBinary[2] = {0x03022307, 0x07230203};
|
|
|
|
size_t binarySize = sizeof(pBinary);
|
|
|
|
|
2018-08-06 22:36:12 +08:00
|
|
|
program->processSpirBinary(pBinary, binarySize, false);
|
|
|
|
EXPECT_FALSE(program->getIsSpirV());
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-08-06 22:36:12 +08:00
|
|
|
program->processSpirBinary(pBinary, binarySize, true);
|
|
|
|
EXPECT_TRUE(program->getIsSpirV());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|