Skip to content

Commit

Permalink
Add more CTS coverage for urKernelSetArgSampler
Browse files Browse the repository at this point in the history
  • Loading branch information
omarahmed1111 committed Apr 1, 2024
1 parent 0c0f48d commit e5f8d49
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 26 deletions.
64 changes: 60 additions & 4 deletions test/conformance/kernel/urKernelSetArgSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,65 @@

#include <uur/fixtures.h>

struct urKernelSetArgSamplerTestWithParam
: uur::urBaseKernelTestWithParam<uur::SamplerCreateParamTy> {
void SetUp() {
program_name = "image_copy";
UUR_RETURN_ON_FATAL_FAILURE(
uur::urBaseKernelTestWithParam<uur::SamplerCreateParamTy>::SetUp());
// Images and samplers are not available on AMD
ur_platform_backend_t backend;
ASSERT_SUCCESS(urPlatformGetInfo(platform, UR_PLATFORM_INFO_BACKEND,
sizeof(backend), &backend, nullptr));
if (backend == UR_PLATFORM_BACKEND_HIP) {
GTEST_SKIP() << "Sampler are not supported on hip.";
}
UUR_RETURN_ON_FATAL_FAILURE(
uur::urBaseKernelTestWithParam<uur::SamplerCreateParamTy>::Build());

const auto param = getParam();
const auto normalized = std::get<0>(param);
const auto addr_mode = std::get<1>(param);
const auto filter_mode = std::get<2>(param);

ur_sampler_desc_t sampler_desc = {
UR_STRUCTURE_TYPE_SAMPLER_DESC, /* sType */
nullptr, /* pNext */
normalized, /* normalizedCoords */
addr_mode, /* addressingMode */
filter_mode /* filterMode */
};
ASSERT_SUCCESS(urSamplerCreate(context, &sampler_desc, &sampler));
}

void TearDown() {
if (sampler) {
ASSERT_SUCCESS(urSamplerRelease(sampler));
}
UUR_RETURN_ON_FATAL_FAILURE(uur::urBaseKernelTestWithParam<
uur::SamplerCreateParamTy>::TearDown());
}

ur_sampler_handle_t sampler = nullptr;
};

UUR_TEST_SUITE_P(
urKernelSetArgSamplerTestWithParam,
::testing::Combine(
::testing::Values(true, false),
::testing::Values(UR_SAMPLER_ADDRESSING_MODE_NONE,
UR_SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE,
UR_SAMPLER_ADDRESSING_MODE_CLAMP,
UR_SAMPLER_ADDRESSING_MODE_REPEAT,
UR_SAMPLER_ADDRESSING_MODE_MIRRORED_REPEAT),
::testing::Values(UR_SAMPLER_FILTER_MODE_NEAREST,
UR_SAMPLER_FILTER_MODE_LINEAR)),
uur::deviceTestWithParamPrinter<uur::SamplerCreateParamTy>);

TEST_P(urKernelSetArgSamplerTestWithParam, Success) {
ASSERT_SUCCESS(urKernelSetArgSampler(kernel, 2, nullptr, sampler));
}

struct urKernelSetArgSamplerTest : uur::urBaseKernelTest {
void SetUp() {
program_name = "image_copy";
Expand Down Expand Up @@ -36,11 +95,8 @@ struct urKernelSetArgSamplerTest : uur::urBaseKernelTest {

ur_sampler_handle_t sampler = nullptr;
};
UUR_INSTANTIATE_KERNEL_TEST_SUITE_P(urKernelSetArgSamplerTest);

TEST_P(urKernelSetArgSamplerTest, Success) {
ASSERT_SUCCESS(urKernelSetArgSampler(kernel, 2, nullptr, sampler));
}
UUR_INSTANTIATE_KERNEL_TEST_SUITE_P(urKernelSetArgSamplerTest);

TEST_P(urKernelSetArgSamplerTest, InvalidNullHandleKernel) {
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
Expand Down
24 changes: 2 additions & 22 deletions test/conformance/sampler/urSamplerCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,9 @@
#include "uur/fixtures.h"
#include "uur/raii.h"

using SamplerCreateParamTy =
std::tuple<bool, ur_sampler_addressing_mode_t, ur_sampler_filter_mode_t>;

struct urSamplerCreateTestWithParam
: uur::urContextTestWithParam<SamplerCreateParamTy> {};

namespace uur {
template <>
std::string deviceTestWithParamPrinter(
const ::testing::TestParamInfo<
std::tuple<ur_device_handle_t, SamplerCreateParamTy>> &info) {
auto device = std::get<0>(info.param);
auto param = std::get<1>(info.param);
: uur::urContextTestWithParam<uur::SamplerCreateParamTy> {};

const auto normalized = std::get<0>(param);
const auto addr_mode = std::get<1>(param);
const auto filter_mode = std::get<2>(param);

std::stringstream ss;
ss << normalized << "_" << addr_mode << "_" << filter_mode;
return uur::GetPlatformAndDeviceName(device) + "__" + ss.str();
}
} // namespace uur
UUR_TEST_SUITE_P(
urSamplerCreateTestWithParam,
::testing::Combine(
Expand All @@ -40,7 +20,7 @@ UUR_TEST_SUITE_P(
UR_SAMPLER_ADDRESSING_MODE_MIRRORED_REPEAT),
::testing::Values(UR_SAMPLER_FILTER_MODE_NEAREST,
UR_SAMPLER_FILTER_MODE_LINEAR)),
uur::deviceTestWithParamPrinter<SamplerCreateParamTy>);
uur::deviceTestWithParamPrinter<uur::SamplerCreateParamTy>);

TEST_P(urSamplerCreateTestWithParam, Success) {

Expand Down
8 changes: 8 additions & 0 deletions test/conformance/testing/include/uur/fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,14 @@ std::string deviceTestWithParamPrinter<BoolTestParam>(
const ::testing::TestParamInfo<
std::tuple<ur_device_handle_t, BoolTestParam>> &info);

using SamplerCreateParamTy =
std::tuple<bool, ur_sampler_addressing_mode_t, ur_sampler_filter_mode_t>;

template <>
std::string deviceTestWithParamPrinter<SamplerCreateParamTy>(
const ::testing::TestParamInfo<
std::tuple<ur_device_handle_t, SamplerCreateParamTy>> &info);

struct urProgramTest : urQueueTest {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(urQueueTest::SetUp());
Expand Down
16 changes: 16 additions & 0 deletions test/conformance/testing/source/fixtures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,20 @@ std::string deviceTestWithParamPrinter<BoolTestParam>(
ss << param.name << (param.value ? "Enabled" : "Disabled");
return uur::GetPlatformAndDeviceName(device) + "__" + ss.str();
}

template <>
std::string deviceTestWithParamPrinter<SamplerCreateParamTy>(
const ::testing::TestParamInfo<
std::tuple<ur_device_handle_t, uur::SamplerCreateParamTy>> &info) {
auto device = std::get<0>(info.param);
auto param = std::get<1>(info.param);

const auto normalized = std::get<0>(param);
const auto addr_mode = std::get<1>(param);
const auto filter_mode = std::get<2>(param);

std::stringstream ss;
ss << normalized << "_" << addr_mode << "_" << filter_mode;
return uur::GetPlatformAndDeviceName(device) + "__" + ss.str();
}
} // namespace uur

0 comments on commit e5f8d49

Please sign in to comment.