2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-02-06 16:58:57 +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/command_queue/command_queue.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "runtime/context/context.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/helpers/surface_formats.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 clEnqueueReadImageTests;
|
|
|
|
|
|
|
|
namespace ULT {
|
|
|
|
|
|
|
|
struct clEnqueueReadImageTests : public api_fixture,
|
|
|
|
public ::testing::Test {
|
|
|
|
void SetUp() override {
|
|
|
|
api_fixture::SetUp();
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
imageFormat.image_channel_order = CL_YUYV_INTEL;
|
|
|
|
imageFormat.image_channel_data_type = CL_UNORM_INT8;
|
|
|
|
|
|
|
|
imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
|
|
|
|
imageDesc.image_width = 32;
|
|
|
|
imageDesc.image_height = 32;
|
|
|
|
imageDesc.image_depth = 1;
|
|
|
|
imageDesc.image_array_size = 1;
|
|
|
|
imageDesc.image_row_pitch = 0;
|
|
|
|
imageDesc.image_slice_pitch = 0;
|
|
|
|
imageDesc.num_mip_levels = 0;
|
|
|
|
imageDesc.num_samples = 0;
|
|
|
|
imageDesc.mem_object = nullptr;
|
|
|
|
// clang-format on
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
api_fixture::TearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
cl_image_format imageFormat;
|
|
|
|
cl_image_desc imageDesc;
|
|
|
|
};
|
|
|
|
|
2019-02-06 16:58:57 +08:00
|
|
|
TEST_F(clEnqueueReadImageTests, GivenNullCommandQueueWhenReadingImageThenInvalidCommandQueueErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
auto retVal = clEnqueueReadImage(
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
false,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
nullptr,
|
|
|
|
0,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
EXPECT_EQ(CL_INVALID_COMMAND_QUEUE, retVal);
|
|
|
|
}
|
|
|
|
|
2019-02-06 16:58:57 +08:00
|
|
|
TEST_F(clEnqueueReadImageTests, GivenNullImageWhenReadingImageThenInvalidMemObjectErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
auto retVal = clEnqueueReadImage(
|
|
|
|
pCommandQueue,
|
|
|
|
nullptr,
|
|
|
|
false,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
nullptr,
|
|
|
|
0,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
EXPECT_EQ(CL_INVALID_MEM_OBJECT, retVal);
|
|
|
|
}
|
|
|
|
|
2019-02-06 16:58:57 +08:00
|
|
|
TEST_F(clEnqueueReadImageTests, GivenValidParametersWhenReadinImagesThenSuccessIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
imageFormat.image_channel_order = CL_RGBA;
|
|
|
|
auto image = clCreateImage(
|
|
|
|
pContext,
|
|
|
|
CL_MEM_READ_WRITE,
|
|
|
|
&imageFormat,
|
|
|
|
&imageDesc,
|
|
|
|
nullptr,
|
|
|
|
&retVal);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_NE(nullptr, image);
|
|
|
|
const size_t origin[] = {2, 2, 0};
|
2018-03-08 18:11:27 +08:00
|
|
|
const size_t region[] = {2, 2, 1};
|
2017-12-21 07:45:38 +08:00
|
|
|
auto retVal = clEnqueueReadImage(
|
|
|
|
pCommandQueue,
|
|
|
|
image,
|
|
|
|
false,
|
|
|
|
origin,
|
|
|
|
region,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
nullptr,
|
|
|
|
0,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
retVal = clReleaseMemObject(image);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
|
2019-02-06 16:58:57 +08:00
|
|
|
typedef clEnqueueReadImageTests clEnqueueReadImageYuv;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-02-06 16:58:57 +08:00
|
|
|
TEST_F(clEnqueueReadImageYuv, GivenValidYuvImageWhenReadingImageThenSuccessIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
auto image = clCreateImage(
|
|
|
|
pContext,
|
|
|
|
CL_MEM_READ_ONLY,
|
|
|
|
&imageFormat,
|
|
|
|
&imageDesc,
|
|
|
|
nullptr,
|
|
|
|
&retVal);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_NE(nullptr, image);
|
|
|
|
const size_t origin[] = {2, 2, 0};
|
2018-03-08 18:11:27 +08:00
|
|
|
const size_t region[] = {2, 2, 1};
|
2017-12-21 07:45:38 +08:00
|
|
|
auto retVal = clEnqueueReadImage(
|
|
|
|
pCommandQueue,
|
|
|
|
image,
|
|
|
|
false,
|
|
|
|
origin,
|
|
|
|
region,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
nullptr,
|
|
|
|
0,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
retVal = clReleaseMemObject(image);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
|
2019-02-06 16:58:57 +08:00
|
|
|
TEST_F(clEnqueueReadImageYuv, GivenInvalidOriginWhenReadingYuvImageThenInvalidValueErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
auto image = clCreateImage(
|
|
|
|
pContext,
|
|
|
|
CL_MEM_READ_ONLY,
|
|
|
|
&imageFormat,
|
|
|
|
&imageDesc,
|
|
|
|
nullptr,
|
|
|
|
&retVal);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_NE(nullptr, image);
|
|
|
|
const size_t origin[] = {1, 2, 0};
|
|
|
|
const size_t region[] = {2, 2, 0};
|
|
|
|
auto retVal = clEnqueueReadImage(
|
|
|
|
pCommandQueue,
|
|
|
|
image,
|
|
|
|
false,
|
|
|
|
origin,
|
|
|
|
region,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
nullptr,
|
|
|
|
0,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
|
|
|
retVal = clReleaseMemObject(image);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
|
2019-02-06 16:58:57 +08:00
|
|
|
TEST_F(clEnqueueReadImageYuv, GivenInvalidRegionWhenReadingYuvImageThenInvalidValueErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
auto image = clCreateImage(
|
|
|
|
pContext,
|
|
|
|
CL_MEM_READ_ONLY,
|
|
|
|
&imageFormat,
|
|
|
|
&imageDesc,
|
|
|
|
nullptr,
|
|
|
|
&retVal);
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_NE(nullptr, image);
|
|
|
|
const size_t origin[] = {2, 2, 0};
|
|
|
|
const size_t region[] = {1, 2, 0};
|
|
|
|
auto retVal = clEnqueueReadImage(
|
|
|
|
pCommandQueue,
|
|
|
|
image,
|
|
|
|
false,
|
|
|
|
origin,
|
|
|
|
region,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
nullptr,
|
|
|
|
0,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
|
|
|
retVal = clReleaseMemObject(image);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
} // namespace ULT
|