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 15, 2024
1 parent 6513abc commit 5b6689a
Show file tree
Hide file tree
Showing 8 changed files with 302 additions and 82 deletions.
39 changes: 39 additions & 0 deletions test/conformance/enqueue/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,45 @@ 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();
}

} // 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{8, 16, 32, 64, 128, 256, 512, 1024};

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
1 change: 1 addition & 0 deletions test/conformance/enqueue/urEnqueueMemBufferFill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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 {
Expand Down
92 changes: 70 additions & 22 deletions test/conformance/enqueue/urEnqueueMemBufferMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,52 @@
// 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{
{8, UR_MEM_FLAG_READ_WRITE},
{16, UR_MEM_FLAG_READ_WRITE},
{32, UR_MEM_FLAG_READ_WRITE},
{64, UR_MEM_FLAG_READ_WRITE},
{128, UR_MEM_FLAG_READ_WRITE},
{256, UR_MEM_FLAG_READ_WRITE},
{512, UR_MEM_FLAG_READ_WRITE},
{1024, UR_MEM_FLAG_READ_WRITE},
{8, UR_MEM_FLAG_WRITE_ONLY},
{16, UR_MEM_FLAG_WRITE_ONLY},
{32, UR_MEM_FLAG_WRITE_ONLY},
{64, UR_MEM_FLAG_WRITE_ONLY},
{128, UR_MEM_FLAG_WRITE_ONLY},
{256, UR_MEM_FLAG_WRITE_ONLY},
{512, UR_MEM_FLAG_WRITE_ONLY},
{1024, UR_MEM_FLAG_WRITE_ONLY},
{8, UR_MEM_FLAG_READ_ONLY},
{16, UR_MEM_FLAG_READ_ONLY},
{32, UR_MEM_FLAG_READ_ONLY},
{64, UR_MEM_FLAG_READ_ONLY},
{128, UR_MEM_FLAG_READ_ONLY},
{256, UR_MEM_FLAG_READ_ONLY},
{512, UR_MEM_FLAG_READ_ONLY},
{1024, UR_MEM_FLAG_READ_ONLY},
{8, UR_MEM_FLAG_ALLOC_HOST_POINTER},
{16, UR_MEM_FLAG_ALLOC_HOST_POINTER},
{32, UR_MEM_FLAG_ALLOC_HOST_POINTER},
{64, UR_MEM_FLAG_ALLOC_HOST_POINTER},
{128, UR_MEM_FLAG_ALLOC_HOST_POINTER},
{256, UR_MEM_FLAG_ALLOC_HOST_POINTER},
{512, UR_MEM_FLAG_ALLOC_HOST_POINTER},
{1024, 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 +61,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 +97,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 +126,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 +154,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 +178,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 +205,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 +246,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 +303,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 5b6689a

Please sign in to comment.