Skip to content

Commit

Permalink
Redo various urXGetInfo query tests so the first call uses the ASSERT…
Browse files Browse the repository at this point in the history
…_SUCCESS_OR_OPTIONAL_QUERY macro.

Rework urVirtualMemGranularityGetInfoTest into separate tests.
Various tidying up of the urXGetInfo tests for better consistency.
  • Loading branch information
martygrant committed Jan 16, 2025
1 parent c3d1510 commit cc0aa40
Show file tree
Hide file tree
Showing 14 changed files with 759 additions and 577 deletions.
58 changes: 34 additions & 24 deletions test/conformance/adapter/urAdapterGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,65 @@ using urAdapterGetInfoTest = uur::urAdapterTest;
UUR_INSTANTIATE_ADAPTER_TEST_SUITE_P(urAdapterGetInfoTest);

TEST_P(urAdapterGetInfoTest, SuccessBackend) {
auto info_type = UR_ADAPTER_INFO_BACKEND;
size_t size = 0;
ASSERT_SUCCESS(urAdapterGetInfo(adapter, info_type, 0, nullptr, &size));
ASSERT_EQ(size, sizeof(ur_adapter_backend_t));
ur_adapter_info_t property_name = UR_ADAPTER_INFO_BACKEND;
size_t property_size = 0;

ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urAdapterGetInfo(adapter, property_name, 0, nullptr, &property_size),
property_name);
ASSERT_EQ(property_size, sizeof(ur_adapter_backend_t));

ur_adapter_backend_t backend = UR_ADAPTER_BACKEND_UNKNOWN;
ASSERT_SUCCESS(
urAdapterGetInfo(adapter, info_type, size, &backend, nullptr));
ASSERT_SUCCESS(urAdapterGetInfo(adapter, property_name, property_size,
&backend, nullptr));

ASSERT_TRUE(backend >= UR_ADAPTER_BACKEND_LEVEL_ZERO &&
backend <= UR_ADAPTER_BACKEND_NATIVE_CPU);
}

TEST_P(urAdapterGetInfoTest, SuccessReferenceCount) {
auto info_type = UR_ADAPTER_INFO_REFERENCE_COUNT;
size_t size = 0;
ASSERT_SUCCESS(urAdapterGetInfo(adapter, info_type, 0, nullptr, &size));
ASSERT_EQ(size, sizeof(uint32_t));
ur_adapter_info_t property_name = UR_ADAPTER_INFO_REFERENCE_COUNT;
size_t property_size = 0;

ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urAdapterGetInfo(adapter, property_name, 0, nullptr, &property_size),
property_name);
ASSERT_EQ(property_size, sizeof(uint32_t));

uint32_t reference_count = 0;
ASSERT_SUCCESS(
urAdapterGetInfo(adapter, info_type, size, &reference_count, nullptr));
ASSERT_SUCCESS(urAdapterGetInfo(adapter, property_name, property_size,
&reference_count, nullptr));
ASSERT_GE(reference_count, 0);
}

TEST_P(urAdapterGetInfoTest, SuccessVersion) {
auto info_type = UR_ADAPTER_INFO_VERSION;
size_t size = 0;
ASSERT_SUCCESS(urAdapterGetInfo(adapter, info_type, 0, nullptr, &size));
ASSERT_EQ(size, sizeof(uint32_t));
ur_adapter_info_t property_name = UR_ADAPTER_INFO_VERSION;
size_t property_size = 0;

ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urAdapterGetInfo(adapter, property_name, 0, nullptr, &property_size),
property_name);
ASSERT_EQ(property_size, sizeof(uint32_t));

uint32_t returned_version = 46;
ASSERT_SUCCESS(
urAdapterGetInfo(adapter, info_type, size, &returned_version, nullptr));
ASSERT_SUCCESS(urAdapterGetInfo(adapter, property_name, property_size,
&returned_version, nullptr));
ASSERT_NE(42, returned_version);
}

TEST_P(urAdapterGetInfoTest, InvalidNullHandleAdapter) {
size_t size = 0;
ASSERT_EQ_RESULT(
UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urAdapterGetInfo(nullptr, UR_ADAPTER_INFO_BACKEND, 0, nullptr, &size));
size_t property_size = 0;
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urAdapterGetInfo(nullptr, UR_ADAPTER_INFO_BACKEND, 0,
nullptr, &property_size));
}

TEST_P(urAdapterGetInfoTest, InvalidEnumerationAdapterInfoType) {
size_t size = 0;
size_t property_size = 0;

ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_ENUMERATION,
urAdapterGetInfo(adapter, UR_ADAPTER_INFO_FORCE_UINT32, 0,
nullptr, &size));
nullptr, &property_size));
}

TEST_P(urAdapterGetInfoTest, InvalidSizeZero) {
Expand Down
112 changes: 65 additions & 47 deletions test/conformance/context/urContextGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,120 +8,138 @@ using urContextGetInfoTest = uur::urContextTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urContextGetInfoTest);

TEST_P(urContextGetInfoTest, SuccessNumDevices) {
ur_context_info_t info_type = UR_CONTEXT_INFO_NUM_DEVICES;
size_t size = 0;
ur_context_info_t property_name = UR_CONTEXT_INFO_NUM_DEVICES;
size_t property_size = 0;

ASSERT_SUCCESS(urContextGetInfo(context, info_type, 0, nullptr, &size));
ASSERT_EQ(size, sizeof(uint32_t));
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urContextGetInfo(context, property_name, 0, nullptr, &property_size),
property_name);
ASSERT_EQ(property_size, sizeof(uint32_t));

uint32_t nDevices = 0;
ASSERT_SUCCESS(
urContextGetInfo(context, info_type, size, &nDevices, nullptr));
ASSERT_SUCCESS(urContextGetInfo(context, property_name, property_size,
&nDevices, nullptr));

ASSERT_EQ(nDevices, 1);
}

TEST_P(urContextGetInfoTest, SuccessDevices) {
ur_context_info_t info_type = UR_CONTEXT_INFO_DEVICES;
size_t size = 0;
ur_context_info_t property_name = UR_CONTEXT_INFO_DEVICES;
size_t property_size = 0;

ASSERT_SUCCESS(urContextGetInfo(context, info_type, 0, nullptr, &size));
ASSERT_NE(size, 0);
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urContextGetInfo(context, property_name, 0, nullptr, &property_size),
property_name);
ASSERT_NE(property_size, 0);

ur_device_handle_t queried_device = nullptr;
ASSERT_SUCCESS(
urContextGetInfo(context, info_type, size, &queried_device, nullptr));
ASSERT_SUCCESS(urContextGetInfo(context, property_name, property_size,
&queried_device, nullptr));

size_t devices_count = size / sizeof(ur_device_handle_t);
size_t devices_count = property_size / sizeof(ur_device_handle_t);
ASSERT_EQ(devices_count, 1);
ASSERT_EQ(queried_device, device);
}

TEST_P(urContextGetInfoTest, SuccessUSMMemCpy2DSupport) {
ur_context_info_t info_type = UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT;
size_t size = 0;
ur_context_info_t property_name = UR_CONTEXT_INFO_USM_MEMCPY2D_SUPPORT;
size_t property_size = 0;

ASSERT_SUCCESS(urContextGetInfo(context, info_type, 0, nullptr, &size));
ASSERT_EQ(size, sizeof(ur_bool_t));
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urContextGetInfo(context, property_name, 0, nullptr, &property_size),
property_name);
ASSERT_EQ(property_size, sizeof(ur_bool_t));
}

TEST_P(urContextGetInfoTest, SuccessUSMFill2DSupport) {
ur_context_info_t info_type = UR_CONTEXT_INFO_USM_FILL2D_SUPPORT;
size_t size = 0;
ur_context_info_t property_name = UR_CONTEXT_INFO_USM_FILL2D_SUPPORT;
size_t property_size = 0;

ASSERT_SUCCESS(urContextGetInfo(context, info_type, 0, nullptr, &size));
ASSERT_EQ(size, sizeof(ur_bool_t));
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urContextGetInfo(context, property_name, 0, nullptr, &property_size),
property_name);
ASSERT_EQ(property_size, sizeof(ur_bool_t));
}

TEST_P(urContextGetInfoTest, SuccessReferenceCount) {
ur_context_info_t info_type = UR_CONTEXT_INFO_REFERENCE_COUNT;
size_t size = 0;
ur_context_info_t property_name = UR_CONTEXT_INFO_REFERENCE_COUNT;
size_t property_size = 0;

ASSERT_SUCCESS(urContextGetInfo(context, info_type, 0, nullptr, &size));
ASSERT_EQ(size, sizeof(uint32_t));
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urContextGetInfo(context, property_name, 0, nullptr, &property_size),
property_name);
ASSERT_EQ(property_size, sizeof(uint32_t));

uint32_t reference_count = 0;
ASSERT_SUCCESS(
urContextGetInfo(context, info_type, size, &reference_count, nullptr));
ASSERT_SUCCESS(urContextGetInfo(context, property_name, property_size,
&reference_count, nullptr));
ASSERT_GT(reference_count, 0U);
}

TEST_P(urContextGetInfoTest, SuccessAtomicMemoryOrderCapabilities) {
ur_context_info_t info_type =
ur_context_info_t property_name =
UR_CONTEXT_INFO_ATOMIC_MEMORY_ORDER_CAPABILITIES;
size_t size = 0;
size_t property_size = 0;

ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urContextGetInfo(context, info_type, 0, nullptr, &size), info_type);
ASSERT_EQ(size, sizeof(ur_memory_order_capability_flags_t));
urContextGetInfo(context, property_name, 0, nullptr, &property_size),
property_name);
ASSERT_EQ(property_size, sizeof(ur_memory_order_capability_flags_t));

ur_memory_order_capability_flags_t flags = 0;
ASSERT_SUCCESS(urContextGetInfo(context, info_type, size, &flags, nullptr));
ASSERT_SUCCESS(urContextGetInfo(context, property_name, property_size,
&flags, nullptr));

ASSERT_EQ(flags & UR_MEMORY_ORDER_CAPABILITY_FLAGS_MASK, 0);
}

TEST_P(urContextGetInfoTest, SuccessAtomicMemoryScopeCapabilities) {
ur_context_info_t info_type =
ur_context_info_t property_name =
UR_CONTEXT_INFO_ATOMIC_MEMORY_SCOPE_CAPABILITIES;
size_t size = 0;
size_t property_size = 0;

ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urContextGetInfo(context, info_type, 0, nullptr, &size), info_type);
ASSERT_EQ(size, sizeof(ur_memory_scope_capability_flags_t));
urContextGetInfo(context, property_name, 0, nullptr, &property_size),
property_name);
ASSERT_EQ(property_size, sizeof(ur_memory_scope_capability_flags_t));

ur_memory_scope_capability_flags_t flags = 0;
ASSERT_SUCCESS(urContextGetInfo(context, info_type, size, &flags, nullptr));
ASSERT_SUCCESS(urContextGetInfo(context, property_name, property_size,
&flags, nullptr));

ASSERT_EQ(flags & UR_MEMORY_SCOPE_CAPABILITY_FLAGS_MASK, 0);
}

TEST_P(urContextGetInfoTest, SuccessAtomicFenceOrderCapabilities) {
ur_context_info_t info_type =
ur_context_info_t property_name =
UR_CONTEXT_INFO_ATOMIC_FENCE_ORDER_CAPABILITIES;
size_t size = 0;
size_t property_size = 0;

ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urContextGetInfo(context, info_type, 0, nullptr, &size), info_type);
ASSERT_EQ(size, sizeof(ur_memory_order_capability_flags_t));
urContextGetInfo(context, property_name, 0, nullptr, &property_size),
property_name);
ASSERT_EQ(property_size, sizeof(ur_memory_order_capability_flags_t));

ur_memory_order_capability_flags_t flags = 0;
ASSERT_SUCCESS(urContextGetInfo(context, info_type, size, &flags, nullptr));
ASSERT_SUCCESS(urContextGetInfo(context, property_name, property_size,
&flags, nullptr));

ASSERT_EQ(flags & UR_MEMORY_ORDER_CAPABILITY_FLAGS_MASK, 0);
}

TEST_P(urContextGetInfoTest, SuccessAtomicFenceScopeCapabilities) {
ur_context_info_t info_type =
ur_context_info_t property_name =
UR_CONTEXT_INFO_ATOMIC_FENCE_SCOPE_CAPABILITIES;
size_t size = 0;
size_t property_size = 0;

ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urContextGetInfo(context, info_type, 0, nullptr, &size), info_type);
ASSERT_EQ(size, sizeof(ur_memory_scope_capability_flags_t));
urContextGetInfo(context, property_name, 0, nullptr, &property_size),
property_name);
ASSERT_EQ(property_size, sizeof(ur_memory_scope_capability_flags_t));

ur_memory_scope_capability_flags_t flags = 0;
ASSERT_SUCCESS(urContextGetInfo(context, info_type, size, &flags, nullptr));
ASSERT_SUCCESS(urContextGetInfo(context, property_name, property_size,
&flags, nullptr));

ASSERT_EQ(flags & UR_MEMORY_SCOPE_CAPABILITY_FLAGS_MASK, 0);
}
Expand Down
Loading

0 comments on commit cc0aa40

Please sign in to comment.