Skip to content

Commit

Permalink
Move GetInfo queries into separate tests rather than being done in a …
Browse files Browse the repository at this point in the history
…switch statement in one test.
  • Loading branch information
martygrant committed Nov 14, 2024
1 parent 8e8adb5 commit 1c3d756
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 117 deletions.
14 changes: 14 additions & 0 deletions bisect.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
echo "###################### NEW RUN #################"
cd build-cl
ninja

if ./bin/test-context; then
# If the command succeeds, there's no regression
echo "###################### END OF RUN #################"
exit 0
else
# If the command fails, the regression is present
echo "###################### END OF RUN #################"
exit 1
fi
11 changes: 5 additions & 6 deletions test/conformance/queue/queue_adapter_native_cpu.match
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ urQueueCreateTest.CheckContext/*
urQueueCreateWithParamTest.SuccessWithProperties/*
urQueueCreateWithParamTest.MatchingDeviceHandles/*
urQueueFlushTest.Success/*
urQueueGetInfoTestWithInfoParam.Success/*__UR_QUEUE_INFO_CONTEXT
urQueueGetInfoTestWithInfoParam.Success/*__UR_QUEUE_INFO_DEVICE
urQueueGetInfoTestWithInfoParam.Success/*__UR_QUEUE_INFO_FLAGS
urQueueGetInfoTestWithInfoParam.Success/*__UR_QUEUE_INFO_REFERENCE_COUNT
urQueueGetInfoTestWithInfoParam.Success/*__UR_QUEUE_INFO_EMPTY
urQueueGetInfoDeviceQueueTestWithInfoParam.Success/*
urQueueGetInfoTest.Success/*__UR_QUEUE_INFO_CONTEXT
urQueueGetInfoTest.Success/*__UR_QUEUE_INFO_DEVICE
urQueueGetInfoTest.Success/*__UR_QUEUE_INFO_FLAGS
urQueueGetInfoTest.Success/*__UR_QUEUE_INFO_REFERENCE_COUNT
urQueueGetInfoTest.Success/*__UR_QUEUE_INFO_EMPTY
urQueueGetInfoTest.InvalidSizeSmall/*
urQueueRetainTest.Success/*
urQueueReleaseTest.Success/*
195 changes: 85 additions & 110 deletions test/conformance/queue/urQueueGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,120 +5,95 @@
#include <map>
#include <uur/fixtures.h>

std::unordered_map<ur_queue_info_t, size_t> queue_info_size_map = {
{UR_QUEUE_INFO_CONTEXT, sizeof(ur_context_handle_t)},
{UR_QUEUE_INFO_DEVICE, sizeof(ur_device_handle_t)},
{UR_QUEUE_INFO_DEVICE_DEFAULT, sizeof(ur_queue_handle_t)},
{UR_QUEUE_INFO_FLAGS, sizeof(ur_queue_flags_t)},
{UR_QUEUE_INFO_REFERENCE_COUNT, sizeof(uint32_t)},
{UR_QUEUE_INFO_SIZE, sizeof(uint32_t)},
{UR_QUEUE_INFO_EMPTY, sizeof(ur_bool_t)},
};

using urQueueGetInfoTestWithInfoParam =
uur::urQueueTestWithParam<ur_queue_info_t>;

UUR_TEST_SUITE_P(urQueueGetInfoTestWithInfoParam,
::testing::Values(UR_QUEUE_INFO_CONTEXT, UR_QUEUE_INFO_DEVICE,
UR_QUEUE_INFO_FLAGS,
UR_QUEUE_INFO_REFERENCE_COUNT,
UR_QUEUE_INFO_EMPTY),
uur::deviceTestWithParamPrinter<ur_queue_info_t>);

TEST_P(urQueueGetInfoTestWithInfoParam, Success) {
ur_queue_info_t info_type = getParam();
using urQueueGetInfoTest = uur::urQueueTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urQueueGetInfoTest);

TEST_P(urQueueGetInfoTest, Context) {
size_t size = 0;
auto result = urQueueGetInfo(queue, info_type, 0, nullptr, &size);

if (result == UR_RESULT_SUCCESS) {
ASSERT_NE(size, 0);

if (const auto expected_size = queue_info_size_map.find(info_type);
expected_size != queue_info_size_map.end()) {
ASSERT_EQ(expected_size->second, size);
}

std::vector<uint8_t> data(size);
ASSERT_SUCCESS(
urQueueGetInfo(queue, info_type, size, data.data(), nullptr));

switch (info_type) {
case UR_QUEUE_INFO_CONTEXT: {
auto returned_context =
reinterpret_cast<ur_context_handle_t *>(data.data());
ASSERT_EQ(context, *returned_context);
break;
}
case UR_QUEUE_INFO_DEVICE: {
auto returned_device =
reinterpret_cast<ur_device_handle_t *>(data.data());
ASSERT_EQ(*returned_device, device);
break;
}
case UR_QUEUE_INFO_DEVICE_DEFAULT: {
auto returned_default_queue =
reinterpret_cast<ur_queue_handle_t *>(data.data());
ASSERT_EQ(*returned_default_queue, queue);
break;
}
case UR_QUEUE_INFO_FLAGS: {
auto returned_flags =
reinterpret_cast<ur_queue_flags_t *>(data.data());
EXPECT_EQ(*returned_flags, *returned_flags & UR_QUEUE_FLAGS_MASK);
break;
}
case UR_QUEUE_INFO_REFERENCE_COUNT: {
auto returned_reference_count =
reinterpret_cast<uint32_t *>(data.data());
ASSERT_GT(*returned_reference_count, 0U);
break;
}
case UR_QUEUE_INFO_EMPTY: {
auto returned_empty_queue =
reinterpret_cast<ur_bool_t *>(data.data());
ASSERT_TRUE(returned_empty_queue);
break;
}
default:
break;
}
} else {
ASSERT_EQ_RESULT(result, UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION);
}
auto infoType = UR_QUEUE_INFO_CONTEXT;
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, 0, nullptr, &size));
ASSERT_NE(size, 0);
ASSERT_EQ(sizeof(ur_context_handle_t), size);

std::vector<uint8_t> data(size);
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, size, data.data(), nullptr));

auto returned_context =
reinterpret_cast<ur_context_handle_t *>(data.data());
ASSERT_EQ(context, *returned_context);
}

struct urQueueGetInfoDeviceQueueTestWithInfoParam
: public uur::urContextTestWithParam<ur_queue_info_t> {
void SetUp() {
urContextTestWithParam<ur_queue_info_t>::SetUp();
ur_queue_flags_t deviceQueueCapabilities;
ASSERT_SUCCESS(
urDeviceGetInfo(device, UR_DEVICE_INFO_QUEUE_ON_DEVICE_PROPERTIES,
sizeof(deviceQueueCapabilities),
&deviceQueueCapabilities, nullptr));
if (!deviceQueueCapabilities) {
GTEST_SKIP() << "Queue on device is not supported.";
}
ASSERT_SUCCESS(
urQueueCreate(context, device, &queueProperties, &queue));
}

void TearDown() {
if (queue) {
ASSERT_SUCCESS(urQueueRelease(queue));
}
urContextTestWithParam<ur_queue_info_t>::TearDown();
}

ur_queue_handle_t queue = nullptr;
ur_queue_properties_t queueProperties = {
UR_STRUCTURE_TYPE_QUEUE_PROPERTIES, nullptr,
UR_QUEUE_FLAG_ON_DEVICE | UR_QUEUE_FLAG_ON_DEVICE_DEFAULT |
UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE};
};
TEST_P(urQueueGetInfoTest, Device) {
size_t size = 0;
auto infoType = UR_QUEUE_INFO_DEVICE;
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, 0, nullptr, &size));
ASSERT_NE(size, 0);
ASSERT_EQ(sizeof(ur_device_handle_t), size);

using urQueueGetInfoTest = uur::urQueueTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urQueueGetInfoTest);
std::vector<uint8_t> data(size);
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, size, data.data(), nullptr));

auto returned_device = reinterpret_cast<ur_device_handle_t *>(data.data());
ASSERT_EQ(device, *returned_device);
}

TEST_P(urQueueGetInfoTest, DeviceDefault) {
size_t size = 0;
auto infoType = UR_QUEUE_INFO_DEVICE_DEFAULT;
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, 0, nullptr, &size));
ASSERT_NE(size, 0);
ASSERT_EQ(sizeof(ur_queue_handle_t), size);

std::vector<uint8_t> data(size);
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, size, data.data(), nullptr));

auto returned_default_queue =
reinterpret_cast<ur_queue_handle_t *>(data.data());
ASSERT_EQ(queue, *returned_default_queue);
}

TEST_P(urQueueGetInfoTest, Flags) {
size_t size = 0;
auto infoType = UR_QUEUE_INFO_FLAGS;
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, 0, nullptr, &size));
ASSERT_NE(size, 0);
ASSERT_EQ(sizeof(ur_queue_flags_t), size);

std::vector<uint8_t> data(size);
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, size, data.data(), nullptr));

auto returned_flags = reinterpret_cast<ur_queue_flags_t *>(data.data());
EXPECT_EQ(*returned_flags, queue_properties.flags);
}

TEST_P(urQueueGetInfoTest, ReferenceCount) {
size_t size = 0;
auto infoType = UR_QUEUE_INFO_REFERENCE_COUNT;
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, 0, nullptr, &size));
ASSERT_NE(size, 0);
ASSERT_EQ(sizeof(uint32_t), size);

std::vector<uint8_t> data(size);
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, size, data.data(), nullptr));

auto returned_reference_count = reinterpret_cast<uint32_t *>(data.data());
ASSERT_GT(*returned_reference_count, 0U);
}

TEST_P(urQueueGetInfoTest, EmptyQueue) {
size_t size = 0;
auto infoType = UR_QUEUE_INFO_EMPTY;
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
urQueueGetInfo(queue, infoType, 0, nullptr, &size));
ASSERT_NE(size, 0);
ASSERT_EQ(sizeof(ur_bool_t), size);

std::vector<uint8_t> data(size);
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, size, data.data(), nullptr));

auto returned_empty_queue = reinterpret_cast<ur_bool_t *>(data.data());
ASSERT_TRUE(returned_empty_queue);
}

TEST_P(urQueueGetInfoTest, InvalidNullHandleQueue) {
ur_context_handle_t context = nullptr;
Expand Down
4 changes: 3 additions & 1 deletion test/conformance/testing/include/uur/fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,9 @@ struct urQueueTest : urContextTest {
}

ur_queue_properties_t queue_properties = {
UR_STRUCTURE_TYPE_QUEUE_PROPERTIES, nullptr, 0};
UR_STRUCTURE_TYPE_QUEUE_PROPERTIES, nullptr,
UR_QUEUE_FLAG_ON_DEVICE | UR_QUEUE_FLAG_ON_DEVICE_DEFAULT |
UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE};
ur_queue_handle_t queue = nullptr;
};

Expand Down

0 comments on commit 1c3d756

Please sign in to comment.