2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-02-27 18:39:32 +08:00
|
|
|
* Copyright (C) 2017-2019 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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "runtime/context/context.h"
|
|
|
|
#include "runtime/device/device.h"
|
|
|
|
#include "runtime/helpers/base_object.h"
|
|
|
|
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "cl_api_tests.h"
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
typedef api_tests clCreatePipeTests;
|
|
|
|
|
2018-08-09 16:57:53 +08:00
|
|
|
namespace ClCreatePipeTests {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
class clCreatePipeWithParamTests : public api_fixture, public testing::TestWithParam<uint64_t> {
|
|
|
|
void SetUp() override {
|
|
|
|
api_fixture::SetUp();
|
|
|
|
}
|
|
|
|
void TearDown() override {
|
|
|
|
api_fixture::TearDown();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class clCreatePipeWithParamNegativeTests : public api_fixture, public testing::TestWithParam<uint64_t> {
|
|
|
|
void SetUp() override {
|
|
|
|
api_fixture::SetUp();
|
|
|
|
}
|
|
|
|
void TearDown() override {
|
|
|
|
api_fixture::TearDown();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-27 21:42:35 +08:00
|
|
|
TEST_P(clCreatePipeWithParamTests, GivenValidFlagsWhenCreatingPipeThenPipeIsCreatedAndSuccessIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_mem_flags flags = GetParam();
|
|
|
|
|
|
|
|
auto pipe = clCreatePipe(pContext, flags, 1, 20, nullptr, &retVal);
|
|
|
|
EXPECT_NE(nullptr, pipe);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
clReleaseMemObject(pipe);
|
|
|
|
}
|
|
|
|
|
2018-09-27 21:42:35 +08:00
|
|
|
TEST_P(clCreatePipeWithParamNegativeTests, GivenInalidFlagsWhenCreatingPipeThenInvalidValueErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_mem_flags flags = GetParam();
|
|
|
|
|
|
|
|
auto pipe = clCreatePipe(pContext, flags, 1, 20, nullptr, &retVal);
|
|
|
|
EXPECT_EQ(nullptr, pipe);
|
|
|
|
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
|
|
|
|
|
|
|
clReleaseMemObject(pipe);
|
|
|
|
}
|
|
|
|
|
|
|
|
static cl_mem_flags validFlags[] = {
|
|
|
|
0,
|
|
|
|
CL_MEM_READ_WRITE,
|
|
|
|
CL_MEM_HOST_NO_ACCESS,
|
|
|
|
CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS,
|
|
|
|
};
|
|
|
|
|
|
|
|
static cl_mem_flags invalidFlags[] = {
|
|
|
|
CL_MEM_READ_WRITE | CL_MEM_HOST_READ_ONLY,
|
|
|
|
CL_MEM_WRITE_ONLY,
|
|
|
|
CL_MEM_READ_ONLY | CL_MEM_HOST_WRITE_ONLY,
|
|
|
|
CL_MEM_HOST_READ_ONLY,
|
|
|
|
CL_MEM_HOST_WRITE_ONLY,
|
|
|
|
CL_MEM_USE_HOST_PTR,
|
|
|
|
CL_MEM_USE_HOST_PTR | CL_MEM_READ_WRITE,
|
|
|
|
CL_MEM_COPY_HOST_PTR,
|
|
|
|
CL_MEM_ALLOC_HOST_PTR,
|
|
|
|
CL_MEM_COPY_HOST_PTR | CL_MEM_ALLOC_HOST_PTR,
|
|
|
|
CL_MEM_READ_ONLY | CL_MEM_WRITE_ONLY,
|
|
|
|
CL_MEM_READ_WRITE | CL_MEM_READ_ONLY,
|
|
|
|
CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY,
|
|
|
|
CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS,
|
|
|
|
CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_WRITE_ONLY,
|
|
|
|
CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS,
|
|
|
|
CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR,
|
|
|
|
CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR,
|
|
|
|
};
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(
|
|
|
|
CreatePipeCheckFlags,
|
|
|
|
clCreatePipeWithParamTests,
|
|
|
|
testing::ValuesIn(validFlags));
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(
|
|
|
|
CreatePipeCheckFlagsNegative,
|
|
|
|
clCreatePipeWithParamNegativeTests,
|
|
|
|
testing::ValuesIn(invalidFlags));
|
|
|
|
|
2018-09-27 21:42:35 +08:00
|
|
|
TEST_F(clCreatePipeTests, GivenValidFlagsAndNullReturnWhenCreatingPipeThenPipeIsCreated) {
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_mem_flags flags = CL_MEM_READ_WRITE;
|
|
|
|
auto pipe = clCreatePipe(pContext, flags, 1, 20, nullptr, nullptr);
|
|
|
|
|
|
|
|
EXPECT_NE(nullptr, pipe);
|
|
|
|
|
|
|
|
clReleaseMemObject(pipe);
|
|
|
|
}
|
|
|
|
|
2018-09-27 21:42:35 +08:00
|
|
|
TEST_F(clCreatePipeTests, GivenPipePacketSizeZeroWhenCreatingPipeThenInvalidPipeSizeErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_mem_flags flags = CL_MEM_READ_WRITE;
|
|
|
|
auto pipe = clCreatePipe(pContext, flags, 0, 20, nullptr, &retVal);
|
|
|
|
|
|
|
|
EXPECT_EQ(nullptr, pipe);
|
|
|
|
EXPECT_EQ(CL_INVALID_PIPE_SIZE, retVal);
|
|
|
|
|
|
|
|
clReleaseMemObject(pipe);
|
|
|
|
}
|
|
|
|
|
2018-09-27 21:42:35 +08:00
|
|
|
TEST_F(clCreatePipeTests, GivenPipeMaxSizeZeroWhenCreatingPipeThenInvalidPipeSizeErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_mem_flags flags = CL_MEM_READ_WRITE;
|
|
|
|
auto pipe = clCreatePipe(pContext, flags, 1, 0, nullptr, &retVal);
|
|
|
|
|
|
|
|
EXPECT_EQ(nullptr, pipe);
|
|
|
|
EXPECT_EQ(CL_INVALID_PIPE_SIZE, retVal);
|
|
|
|
|
|
|
|
clReleaseMemObject(pipe);
|
|
|
|
}
|
|
|
|
|
2018-09-27 21:42:35 +08:00
|
|
|
TEST_F(clCreatePipeTests, GivenPipePropertiesNotNullWhenCreatingPipeThenInvalidValueErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_mem_flags flags = CL_MEM_READ_WRITE;
|
|
|
|
cl_pipe_properties properties = {0};
|
|
|
|
auto pipe = clCreatePipe(pContext, flags, 1, 20, &properties, &retVal);
|
|
|
|
|
|
|
|
EXPECT_EQ(nullptr, pipe);
|
|
|
|
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
|
|
|
|
|
|
|
clReleaseMemObject(pipe);
|
|
|
|
}
|
|
|
|
|
2018-09-27 21:42:35 +08:00
|
|
|
TEST_F(clCreatePipeTests, GivenPipePacketSizeGreaterThanAllowedWhenCreatingPipeThenInvalidPipeSizeErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_uint packetSize = pContext->getDevice(0)->getDeviceInfo().pipeMaxPacketSize;
|
|
|
|
cl_mem_flags flags = CL_MEM_READ_WRITE;
|
|
|
|
|
|
|
|
auto pipe = clCreatePipe(pContext, flags, packetSize, 20, nullptr, &retVal);
|
|
|
|
EXPECT_NE(nullptr, pipe);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
clReleaseMemObject(pipe);
|
|
|
|
|
|
|
|
packetSize += 1;
|
|
|
|
pipe = clCreatePipe(pContext, flags, packetSize, 20, nullptr, &retVal);
|
|
|
|
|
|
|
|
EXPECT_EQ(nullptr, pipe);
|
|
|
|
EXPECT_EQ(CL_INVALID_PIPE_SIZE, retVal);
|
|
|
|
|
|
|
|
clReleaseMemObject(pipe);
|
|
|
|
}
|
|
|
|
|
2018-09-27 21:42:35 +08:00
|
|
|
TEST_F(clCreatePipeTests, GivenNullContextWhenCreatingPipeThenInvalidContextErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
auto pipe = clCreatePipe(nullptr, 0, 1, 20, nullptr, &retVal);
|
|
|
|
|
|
|
|
EXPECT_EQ(nullptr, pipe);
|
|
|
|
EXPECT_EQ(CL_INVALID_CONTEXT, retVal);
|
|
|
|
|
2018-09-27 21:42:35 +08:00
|
|
|
clReleaseMemObject(pipe);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2018-08-09 16:57:53 +08:00
|
|
|
} // namespace ClCreatePipeTests
|