Skip to content

Commit f4c384d

Browse files
authored
Merge pull request #2536 from martygrant/martin/sampler-info-unswitch
Move urSamplerGetInfo success test from a switch to individual tests
2 parents 188e8a3 + 10ad30f commit f4c384d

File tree

2 files changed

+68
-53
lines changed

2 files changed

+68
-53
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
{{OPT}}urSamplerGetInfoTestWithParam.Success/*
1+
{{OPT}}urSamplerGetInfoTest.SuccessReferenceCount/*
2+
{{OPT}}urSamplerGetInfoTest.SuccessContext/*
3+
{{OPT}}urSamplerGetInfoTest.SuccessNormalizedCoords/*
4+
{{OPT}}urSamplerGetInfoTest.SuccessAddressingMode/*
5+
{{OPT}}urSamplerGetInfoTest.SuccessFilterMode/*
26
{{OPT}}urSamplerGetInfoTest.InvalidSizePropSizeSmall/*
37
{{OPT}}urSamplerReleaseTest.Success/*
48
{{OPT}}urSamplerRetainTest.Success/*

test/conformance/sampler/urSamplerGetInfo.cpp

Lines changed: 63 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,71 @@
55

66
#include <uur/fixtures.h>
77

8-
using urSamplerGetInfoTestWithParam =
9-
uur::urSamplerTestWithParam<ur_sampler_info_t>;
10-
UUR_TEST_SUITE_P(urSamplerGetInfoTestWithParam,
11-
::testing::Values(UR_SAMPLER_INFO_REFERENCE_COUNT,
12-
UR_SAMPLER_INFO_CONTEXT,
13-
UR_SAMPLER_INFO_NORMALIZED_COORDS,
14-
UR_SAMPLER_INFO_ADDRESSING_MODE,
15-
UR_SAMPLER_INFO_FILTER_MODE),
16-
uur::deviceTestWithParamPrinter<ur_sampler_info_t>);
17-
18-
TEST_P(urSamplerGetInfoTestWithParam, Success) {
8+
using urSamplerGetInfoTest = uur::urSamplerTest;
9+
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urSamplerGetInfoTest);
10+
11+
TEST_P(urSamplerGetInfoTest, SuccessReferenceCount) {
1912
size_t size = 0;
20-
ur_sampler_info_t info = getParam();
21-
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
22-
urSamplerGetInfo(sampler, info, 0, nullptr, &size), info);
23-
ASSERT_NE(size, 0);
24-
std::vector<uint8_t> infoData(size);
13+
auto infoType = UR_SAMPLER_INFO_REFERENCE_COUNT;
14+
ASSERT_SUCCESS(urSamplerGetInfo(sampler, infoType, 0, nullptr, &size));
15+
ASSERT_EQ(sizeof(uint32_t), size);
16+
17+
uint32_t returned_reference_count = 0;
18+
ASSERT_SUCCESS(urSamplerGetInfo(sampler, infoType, size,
19+
&returned_reference_count, nullptr));
20+
21+
ASSERT_GT(returned_reference_count, 0U);
22+
}
23+
24+
TEST_P(urSamplerGetInfoTest, SuccessContext) {
25+
size_t size = 0;
26+
auto infoType = UR_SAMPLER_INFO_CONTEXT;
27+
ASSERT_SUCCESS(urSamplerGetInfo(sampler, infoType, 0, nullptr, &size));
28+
ASSERT_EQ(sizeof(ur_context_handle_t), size);
29+
30+
ur_context_handle_t returned_context = nullptr;
2531
ASSERT_SUCCESS(
26-
urSamplerGetInfo(sampler, info, size, infoData.data(), nullptr));
27-
28-
switch (info) {
29-
case UR_SAMPLER_INFO_REFERENCE_COUNT: {
30-
auto *value = reinterpret_cast<uint32_t *>(infoData.data());
31-
ASSERT_TRUE(*value > 0);
32-
break;
33-
}
34-
case UR_SAMPLER_INFO_CONTEXT: {
35-
auto *value = reinterpret_cast<ur_context_handle_t *>(infoData.data());
36-
ASSERT_EQ(*value, this->context);
37-
break;
38-
}
39-
case UR_SAMPLER_INFO_NORMALIZED_COORDS: {
40-
auto *value = reinterpret_cast<ur_bool_t *>(infoData.data());
41-
ASSERT_EQ(*value, sampler_desc.normalizedCoords);
42-
break;
43-
}
44-
case UR_SAMPLER_INFO_ADDRESSING_MODE: {
45-
auto *value =
46-
reinterpret_cast<ur_sampler_addressing_mode_t *>(infoData.data());
47-
ASSERT_EQ(*value, sampler_desc.addressingMode);
48-
break;
49-
}
50-
case UR_SAMPLER_INFO_FILTER_MODE: {
51-
auto *value =
52-
reinterpret_cast<ur_sampler_filter_mode_t *>(infoData.data());
53-
ASSERT_EQ(*value, sampler_desc.filterMode);
54-
}
55-
default:
56-
break;
57-
}
32+
urSamplerGetInfo(sampler, infoType, size, &returned_context, nullptr));
33+
34+
ASSERT_EQ(returned_context, context);
5835
}
5936

60-
using urSamplerGetInfoTest = uur::urSamplerTest;
61-
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urSamplerGetInfoTest);
37+
TEST_P(urSamplerGetInfoTest, SuccessNormalizedCoords) {
38+
size_t size = 0;
39+
auto infoType = UR_SAMPLER_INFO_NORMALIZED_COORDS;
40+
ASSERT_SUCCESS(urSamplerGetInfo(sampler, infoType, 0, nullptr, &size));
41+
ASSERT_EQ(sizeof(ur_bool_t), size);
42+
}
43+
44+
TEST_P(urSamplerGetInfoTest, SuccessAddressingMode) {
45+
size_t size = 0;
46+
auto infoType = UR_SAMPLER_INFO_ADDRESSING_MODE;
47+
ASSERT_SUCCESS(urSamplerGetInfo(sampler, infoType, 0, nullptr, &size));
48+
ASSERT_EQ(sizeof(ur_sampler_addressing_mode_t), size);
49+
50+
ur_sampler_addressing_mode_t returned_mode =
51+
UR_SAMPLER_ADDRESSING_MODE_FORCE_UINT32;
52+
ASSERT_SUCCESS(
53+
urSamplerGetInfo(sampler, infoType, size, &returned_mode, nullptr));
54+
55+
ASSERT_GE(returned_mode, UR_SAMPLER_ADDRESSING_MODE_NONE);
56+
ASSERT_LT(returned_mode, UR_SAMPLER_ADDRESSING_MODE_FORCE_UINT32);
57+
}
58+
59+
TEST_P(urSamplerGetInfoTest, SuccessFilterMode) {
60+
size_t size = 0;
61+
auto infoType = UR_SAMPLER_INFO_FILTER_MODE;
62+
ASSERT_SUCCESS(urSamplerGetInfo(sampler, infoType, 0, nullptr, &size));
63+
ASSERT_EQ(sizeof(ur_sampler_filter_mode_t), size);
64+
65+
ur_sampler_filter_mode_t returned_mode =
66+
UR_SAMPLER_FILTER_MODE_FORCE_UINT32;
67+
ASSERT_SUCCESS(
68+
urSamplerGetInfo(sampler, infoType, size, &returned_mode, nullptr));
69+
70+
ASSERT_GE(returned_mode, UR_SAMPLER_FILTER_MODE_NEAREST);
71+
ASSERT_LT(returned_mode, UR_SAMPLER_FILTER_MODE_FORCE_UINT32);
72+
}
6273

6374
TEST_P(urSamplerGetInfoTest, InvalidNullHandleSampler) {
6475
uint32_t refcount = 0;
@@ -88,14 +99,14 @@ TEST_P(urSamplerGetInfoTest, InvalidNullPointerPropValue) {
8899
}
89100

90101
TEST_P(urSamplerGetInfoTest, InvalidSizePropSizeZero) {
91-
ur_sampler_addressing_mode_t mode;
102+
ur_sampler_addressing_mode_t mode = UR_SAMPLER_ADDRESSING_MODE_NONE;
92103
ASSERT_EQ_RESULT(urSamplerGetInfo(sampler, UR_SAMPLER_INFO_ADDRESSING_MODE,
93104
0, &mode, nullptr),
94105
UR_RESULT_ERROR_INVALID_SIZE);
95106
}
96107

97108
TEST_P(urSamplerGetInfoTest, InvalidSizePropSizeSmall) {
98-
ur_sampler_addressing_mode_t mode;
109+
ur_sampler_addressing_mode_t mode = UR_SAMPLER_ADDRESSING_MODE_NONE;
99110
ASSERT_EQ_RESULT(urSamplerGetInfo(sampler, UR_SAMPLER_INFO_ADDRESSING_MODE,
100111
sizeof(mode) - 1, &mode, nullptr),
101112
UR_RESULT_ERROR_INVALID_SIZE);

0 commit comments

Comments
 (0)