Skip to content

Commit

Permalink
[CTS] Modify various urEnqueueMemBuffer* conformance tests to use par…
Browse files Browse the repository at this point in the history
…ameterized fixtures.
  • Loading branch information
martygrant committed Mar 21, 2024
1 parent c98fdbc commit 6a44b93
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 96 deletions.
52 changes: 52 additions & 0 deletions test/conformance/enqueue/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,58 @@ print2DTestString(const testing::TestParamInfo<typename T::ParamType> &info) {
return test_name.str();
}

struct mem_buffer_test_parameters_t {
size_t count;
ur_mem_flag_t mem_flag;
};

struct mem_buffer_map_write_test_parameters_t {
size_t count;
ur_mem_flag_t mem_flag;
ur_map_flag_t map_flag;
};

template <typename T>
inline std::string printMemBufferTestString(
const testing::TestParamInfo<typename T::ParamType> &info) {
// ParamType will be std::tuple<ur_device_handle_t, test_parameters_t>
const auto device_handle = std::get<0>(info.param);
const auto platform_device_name = GetPlatformAndDeviceName(device_handle);

std::stringstream ss;
ss << std::get<1>(info.param).count;
ss << "_";
ss << std::get<1>(info.param).mem_flag;

return platform_device_name + "__" + ss.str();
}

template <typename T>
inline std::string printMemBufferMapWriteTestString(
const testing::TestParamInfo<typename T::ParamType> &info) {
// ParamType will be std::tuple<ur_device_handle_t, mem_buffer_map_write_test_parameters_t>
const auto device_handle = std::get<0>(info.param);
const auto platform_device_name = GetPlatformAndDeviceName(device_handle);

std::stringstream ss;
ss << std::get<1>(info.param).map_flag;

return platform_device_name + "__" + ss.str();
}

template <typename T>
inline std::string
printFillTestString(const testing::TestParamInfo<typename T::ParamType> &info) {
const auto device_handle = std::get<0>(info.param);
const auto platform_device_name =
uur::GetPlatformAndDeviceName(device_handle);
std::stringstream test_name;
test_name << platform_device_name << "__size__"
<< std::get<1>(info.param).size << "__patternSize__"
<< std::get<1>(info.param).pattern_size;
return test_name.str();
}

} // namespace uur

#endif // UUR_ENQUEUE_RECT_HELPERS_H_INCLUDED
28 changes: 17 additions & 11 deletions test/conformance/enqueue/urEnqueueMemBufferCopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "helpers.h"
#include <uur/fixtures.h>

struct urEnqueueMemBufferCopyTest : uur::urQueueTest {
struct urEnqueueMemBufferCopyTestWithParam : uur::urQueueTestWithParam<size_t> {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(urQueueTest::SetUp());
UUR_RETURN_ON_FATAL_FAILURE(urQueueTestWithParam::SetUp());
ASSERT_SUCCESS(urMemBufferCreate(context, UR_MEM_FLAG_WRITE_ONLY, size,
nullptr, &src_buffer));
ASSERT_SUCCESS(urMemBufferCreate(context, UR_MEM_FLAG_READ_ONLY, size,
Expand All @@ -25,18 +26,23 @@ struct urEnqueueMemBufferCopyTest : uur::urQueueTest {
if (src_buffer) {
EXPECT_SUCCESS(urMemRelease(dst_buffer));
}
urQueueTest::TearDown();
urQueueTestWithParam::TearDown();
}

const size_t count = 1024;
const size_t count = std::get<1>(this->GetParam());
const size_t size = sizeof(uint32_t) * count;
ur_mem_handle_t src_buffer = nullptr;
ur_mem_handle_t dst_buffer = nullptr;
std::vector<uint32_t> input;
};
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urEnqueueMemBufferCopyTest);

TEST_P(urEnqueueMemBufferCopyTest, Success) {
static std::vector<size_t> test_parameters{1024, 2500, 4096, 6000};

UUR_TEST_SUITE_P(urEnqueueMemBufferCopyTestWithParam,
::testing::ValuesIn(test_parameters),
uur::deviceTestWithParamPrinter<size_t>);

TEST_P(urEnqueueMemBufferCopyTestWithParam, Success) {
ASSERT_SUCCESS(urEnqueueMemBufferCopy(queue, src_buffer, dst_buffer, 0, 0,
size, 0, nullptr, nullptr));
std::vector<uint32_t> output(count, 1);
Expand All @@ -45,25 +51,25 @@ TEST_P(urEnqueueMemBufferCopyTest, Success) {
ASSERT_EQ(input, output);
}

TEST_P(urEnqueueMemBufferCopyTest, InvalidNullHandleQueue) {
TEST_P(urEnqueueMemBufferCopyTestWithParam, InvalidNullHandleQueue) {
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urEnqueueMemBufferCopy(nullptr, src_buffer, dst_buffer, 0,
0, size, 0, nullptr, nullptr));
}

TEST_P(urEnqueueMemBufferCopyTest, InvalidNullHandleBufferSrc) {
TEST_P(urEnqueueMemBufferCopyTestWithParam, InvalidNullHandleBufferSrc) {
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urEnqueueMemBufferCopy(queue, nullptr, dst_buffer, 0, 0,
size, 0, nullptr, nullptr));
}

TEST_P(urEnqueueMemBufferCopyTest, InvalidNullHandleBufferDst) {
TEST_P(urEnqueueMemBufferCopyTestWithParam, InvalidNullHandleBufferDst) {
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urEnqueueMemBufferCopy(queue, src_buffer, nullptr, 0, 0,
size, 0, nullptr, nullptr));
}

TEST_P(urEnqueueMemBufferCopyTest, InvalidNullPtrEventWaitList) {
TEST_P(urEnqueueMemBufferCopyTestWithParam, InvalidNullPtrEventWaitList) {
ASSERT_EQ_RESULT(urEnqueueMemBufferCopy(queue, src_buffer, dst_buffer, 0, 0,
size, 1, nullptr, nullptr),
UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST);
Expand All @@ -83,7 +89,7 @@ TEST_P(urEnqueueMemBufferCopyTest, InvalidNullPtrEventWaitList) {
ASSERT_SUCCESS(urEventRelease(validEvent));
}

TEST_P(urEnqueueMemBufferCopyTest, InvalidSize) {
TEST_P(urEnqueueMemBufferCopyTestWithParam, InvalidSize) {
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urEnqueueMemBufferCopy(queue, src_buffer, dst_buffer, 1, 0,
size, 0, nullptr, nullptr));
Expand Down
16 changes: 2 additions & 14 deletions test/conformance/enqueue/urEnqueueMemBufferFill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,14 @@
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "helpers.h"
#include <uur/fixtures.h>

struct testParametersFill {
size_t size;
size_t pattern_size;
};

template <typename T>
inline std::string
printFillTestString(const testing::TestParamInfo<typename T::ParamType> &info) {
const auto device_handle = std::get<0>(info.param);
const auto platform_device_name =
uur::GetPlatformAndDeviceName(device_handle);
std::stringstream test_name;
test_name << platform_device_name << "__size__"
<< std::get<1>(info.param).size << "__patternSize__"
<< std::get<1>(info.param).pattern_size;
return test_name.str();
}

struct urEnqueueMemBufferFillTest
: uur::urQueueTestWithParam<testParametersFill> {
void SetUp() override {
Expand Down Expand Up @@ -76,7 +64,7 @@ static std::vector<testParametersFill> test_cases{
{256, 32}};

UUR_TEST_SUITE_P(urEnqueueMemBufferFillTest, testing::ValuesIn(test_cases),
printFillTestString<urEnqueueMemBufferFillTest>);
uur::printFillTestString<urEnqueueMemBufferFillTest>);

TEST_P(urEnqueueMemBufferFillTest, Success) {
ASSERT_SUCCESS(urEnqueueMemBufferFill(queue, buffer, pattern.data(),
Expand Down
76 changes: 54 additions & 22 deletions test/conformance/enqueue/urEnqueueMemBufferMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,36 @@
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "helpers.h"
#include <uur/fixtures.h>

using urEnqueueMemBufferMapTest = uur::urMemBufferQueueTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urEnqueueMemBufferMapTest);

TEST_P(urEnqueueMemBufferMapTest, SuccessRead) {
using urEnqueueMemBufferMapTestWithParam =
uur::urMemBufferQueueTestWithParam<uur::mem_buffer_test_parameters_t>;

static std::vector<uur::mem_buffer_test_parameters_t> test_parameters{
{1024, UR_MEM_FLAG_READ_WRITE},
{2500, UR_MEM_FLAG_READ_WRITE},
{4096, UR_MEM_FLAG_READ_WRITE},
{6000, UR_MEM_FLAG_READ_WRITE},
{1024, UR_MEM_FLAG_WRITE_ONLY},
{2500, UR_MEM_FLAG_WRITE_ONLY},
{4096, UR_MEM_FLAG_WRITE_ONLY},
{6000, UR_MEM_FLAG_WRITE_ONLY},
{1024, UR_MEM_FLAG_READ_ONLY},
{2500, UR_MEM_FLAG_READ_ONLY},
{4096, UR_MEM_FLAG_READ_ONLY},
{6000, UR_MEM_FLAG_READ_ONLY},
{1024, UR_MEM_FLAG_ALLOC_HOST_POINTER},
{2500, UR_MEM_FLAG_ALLOC_HOST_POINTER},
{4096, UR_MEM_FLAG_ALLOC_HOST_POINTER},
{6000, UR_MEM_FLAG_ALLOC_HOST_POINTER},
};

UUR_TEST_SUITE_P(
urEnqueueMemBufferMapTestWithParam, ::testing::ValuesIn(test_parameters),
uur::printMemBufferTestString<urEnqueueMemBufferMapTestWithParam>);

TEST_P(urEnqueueMemBufferMapTestWithParam, SuccessRead) {
const std::vector<uint32_t> input(count, 42);
ASSERT_SUCCESS(urEnqueueMemBufferWrite(queue, buffer, true, 0, size,
input.data(), 0, nullptr, nullptr));
Expand All @@ -21,22 +45,30 @@ TEST_P(urEnqueueMemBufferMapTest, SuccessRead) {
}
}

static std::vector<uur::mem_buffer_map_write_test_parameters_t>
map_write_test_parameters{
{8, UR_MEM_FLAG_READ_WRITE, UR_MAP_FLAG_WRITE},
{8, UR_MEM_FLAG_READ_WRITE, UR_MAP_FLAG_WRITE_INVALIDATE_REGION},
};

using urEnqueueMemBufferMapTestWithWriteFlagParam =
uur::urMemBufferQueueTestWithParam<ur_map_flag_t>;
uur::urMemBufferQueueTestWithParam<
uur::mem_buffer_map_write_test_parameters_t>;

UUR_TEST_SUITE_P(urEnqueueMemBufferMapTestWithWriteFlagParam,
::testing::Values(UR_MAP_FLAG_WRITE,
UR_MAP_FLAG_WRITE_INVALIDATE_REGION),
uur::deviceTestWithParamPrinter<ur_map_flag_t>);
::testing::ValuesIn(map_write_test_parameters),
uur::printMemBufferMapWriteTestString<
urEnqueueMemBufferMapTestWithWriteFlagParam>);

TEST_P(urEnqueueMemBufferMapTestWithWriteFlagParam, SuccessWrite) {
const std::vector<uint32_t> input(count, 0);
ASSERT_SUCCESS(urEnqueueMemBufferWrite(queue, buffer, true, 0, size,
input.data(), 0, nullptr, nullptr));

uint32_t *map = nullptr;
ASSERT_SUCCESS(urEnqueueMemBufferMap(queue, buffer, true, getParam(), 0,
size, 0, nullptr, nullptr,
(void **)&map));
ASSERT_SUCCESS(urEnqueueMemBufferMap(queue, buffer, true,
getParam().map_flag, 0, size, 0,
nullptr, nullptr, (void **)&map));
for (unsigned i = 0; i < count; ++i) {
map[i] = 42;
}
Expand All @@ -49,7 +81,7 @@ TEST_P(urEnqueueMemBufferMapTestWithWriteFlagParam, SuccessWrite) {
}
}

TEST_P(urEnqueueMemBufferMapTest, SuccessOffset) {
TEST_P(urEnqueueMemBufferMapTestWithParam, SuccessOffset) {
const std::vector<uint32_t> input(count, 0);
ASSERT_SUCCESS(urEnqueueMemBufferWrite(queue, buffer, true, 0, size,
input.data(), 0, nullptr, nullptr));
Expand Down Expand Up @@ -78,7 +110,7 @@ TEST_P(urEnqueueMemBufferMapTest, SuccessOffset) {
}
}

TEST_P(urEnqueueMemBufferMapTest, SuccessPartialMap) {
TEST_P(urEnqueueMemBufferMapTestWithParam, SuccessPartialMap) {
const std::vector<uint32_t> input(count, 0);
ASSERT_SUCCESS(urEnqueueMemBufferWrite(queue, buffer, true, 0, size,
input.data(), 0, nullptr, nullptr));
Expand Down Expand Up @@ -106,7 +138,7 @@ TEST_P(urEnqueueMemBufferMapTest, SuccessPartialMap) {
}
}

TEST_P(urEnqueueMemBufferMapTest, SuccesPinnedRead) {
TEST_P(urEnqueueMemBufferMapTestWithParam, SuccesPinnedRead) {
const size_t memSize = sizeof(int);
const int value = 20;

Expand All @@ -130,7 +162,7 @@ TEST_P(urEnqueueMemBufferMapTest, SuccesPinnedRead) {
ASSERT_SUCCESS(urMemRelease(memObj));
}

TEST_P(urEnqueueMemBufferMapTest, SuccesPinnedWrite) {
TEST_P(urEnqueueMemBufferMapTestWithParam, SuccesPinnedWrite) {
const size_t memSize = sizeof(int);
const int value = 30;

Expand All @@ -157,7 +189,7 @@ TEST_P(urEnqueueMemBufferMapTest, SuccesPinnedWrite) {
ASSERT_SUCCESS(urMemRelease(memObj));
}

TEST_P(urEnqueueMemBufferMapTest, SuccessMultiMaps) {
TEST_P(urEnqueueMemBufferMapTestWithParam, SuccessMultiMaps) {
const std::vector<uint32_t> input(count, 0);
ASSERT_SUCCESS(urEnqueueMemBufferWrite(queue, buffer, true, 0, size,
input.data(), 0, nullptr, nullptr));
Expand Down Expand Up @@ -198,39 +230,39 @@ TEST_P(urEnqueueMemBufferMapTest, SuccessMultiMaps) {
}
}

TEST_P(urEnqueueMemBufferMapTest, InvalidNullHandleQueue) {
TEST_P(urEnqueueMemBufferMapTestWithParam, InvalidNullHandleQueue) {
void *map = nullptr;
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urEnqueueMemBufferMap(nullptr, buffer, true,
UR_MAP_FLAG_READ | UR_MAP_FLAG_WRITE,
0, size, 0, nullptr, nullptr, &map));
}

TEST_P(urEnqueueMemBufferMapTest, InvalidNullHandleBuffer) {
TEST_P(urEnqueueMemBufferMapTestWithParam, InvalidNullHandleBuffer) {
void *map = nullptr;
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urEnqueueMemBufferMap(queue, nullptr, true,
UR_MAP_FLAG_READ | UR_MAP_FLAG_WRITE,
0, size, 0, nullptr, nullptr, &map));
}

TEST_P(urEnqueueMemBufferMapTest, InvalidEnumerationMapFlags) {
TEST_P(urEnqueueMemBufferMapTestWithParam, InvalidEnumerationMapFlags) {
void *map = nullptr;
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_ENUMERATION,
urEnqueueMemBufferMap(queue, buffer, true,
UR_MAP_FLAG_FORCE_UINT32, 0, size, 0,
nullptr, nullptr, &map));
}

TEST_P(urEnqueueMemBufferMapTest, InvalidNullPointerRetMap) {
TEST_P(urEnqueueMemBufferMapTestWithParam, InvalidNullPointerRetMap) {
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_POINTER,
urEnqueueMemBufferMap(queue, buffer, true,
UR_MAP_FLAG_READ | UR_MAP_FLAG_WRITE,
0, size, 0, nullptr, nullptr,
nullptr));
}

TEST_P(urEnqueueMemBufferMapTest, InvalidNullPtrEventWaitList) {
TEST_P(urEnqueueMemBufferMapTestWithParam, InvalidNullPtrEventWaitList) {
void *map;
ASSERT_EQ_RESULT(urEnqueueMemBufferMap(queue, buffer, true,
UR_MAP_FLAG_READ | UR_MAP_FLAG_WRITE,
Expand All @@ -255,7 +287,7 @@ TEST_P(urEnqueueMemBufferMapTest, InvalidNullPtrEventWaitList) {
ASSERT_SUCCESS(urEventRelease(validEvent));
}

TEST_P(urEnqueueMemBufferMapTest, InvalidSize) {
TEST_P(urEnqueueMemBufferMapTestWithParam, InvalidSize) {
void *map = nullptr;
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urEnqueueMemBufferMap(queue, buffer, true, 0, 1, size, 0,
Expand Down
Loading

0 comments on commit 6a44b93

Please sign in to comment.