From a5d3f362fd3d3e3fc3e8469fc078aac99f9b3ba5 Mon Sep 17 00:00:00 2001 From: Martin Morrison-Grant Date: Wed, 8 Jan 2025 11:55:17 +0000 Subject: [PATCH] Move urProgramGetInfo success test from a switch to individual tests. Replaced LogIsNullTerminated with SuccessLog. --- .../program/urProgramGetBuildInfo.cpp | 110 ++++---- test/conformance/program/urProgramGetInfo.cpp | 259 ++++++++++-------- 2 files changed, 211 insertions(+), 158 deletions(-) diff --git a/test/conformance/program/urProgramGetBuildInfo.cpp b/test/conformance/program/urProgramGetBuildInfo.cpp index df46467197..5aef40139a 100644 --- a/test/conformance/program/urProgramGetBuildInfo.cpp +++ b/test/conformance/program/urProgramGetBuildInfo.cpp @@ -5,42 +5,76 @@ #include -struct urProgramGetBuildInfoTest - : uur::urProgramTestWithParam { +struct urProgramGetBuildInfoTest : uur::urProgramTest { void SetUp() override { - UUR_RETURN_ON_FATAL_FAILURE( - urProgramTestWithParam::SetUp()); + UUR_RETURN_ON_FATAL_FAILURE(urProgramTest::SetUp()); ASSERT_SUCCESS(urProgramBuild(this->context, program, nullptr)); } }; +UUR_INSTANTIATE_KERNEL_TEST_SUITE_P(urProgramGetBuildInfoTest); -UUR_TEST_SUITE_P(urProgramGetBuildInfoTest, - ::testing::Values(UR_PROGRAM_BUILD_INFO_STATUS, - UR_PROGRAM_BUILD_INFO_OPTIONS, - UR_PROGRAM_BUILD_INFO_LOG, - UR_PROGRAM_BUILD_INFO_BINARY_TYPE), - uur::deviceTestWithParamPrinter); +TEST_P(urProgramGetBuildInfoTest, SuccessStatus) { + size_t size = 0; + auto info_type = UR_PROGRAM_BUILD_INFO_STATUS; + ASSERT_SUCCESS( + urProgramGetBuildInfo(program, device, info_type, 0, nullptr, &size)); + ASSERT_EQ(sizeof(ur_program_build_status_t), size); -struct urProgramGetBuildInfoSingleTest : uur::urProgramTest { - void SetUp() override { - UUR_RETURN_ON_FATAL_FAILURE(urProgramTest::SetUp()); - ASSERT_SUCCESS(urProgramBuild(this->context, program, nullptr)); - } -}; -UUR_INSTANTIATE_KERNEL_TEST_SUITE_P(urProgramGetBuildInfoSingleTest); - -TEST_P(urProgramGetBuildInfoTest, Success) { - auto property_name = getParam(); - size_t property_size = 0; - std::vector property_value; - ASSERT_SUCCESS_OR_OPTIONAL_QUERY( - urProgramGetBuildInfo(program, device, property_name, 0, nullptr, - &property_size), - property_name); - property_value.resize(property_size); - ASSERT_SUCCESS(urProgramGetBuildInfo(program, device, property_name, - property_size, property_value.data(), - nullptr)); + ur_program_build_status_t returned_status = + UR_PROGRAM_BUILD_STATUS_FORCE_UINT32; + ASSERT_SUCCESS(urProgramGetBuildInfo(program, device, info_type, size, + &returned_status, nullptr)); + + ASSERT_GE(returned_status, UR_PROGRAM_BUILD_STATUS_NONE); + ASSERT_LE(returned_status, UR_PROGRAM_BUILD_STATUS_IN_PROGRESS); +} + +TEST_P(urProgramGetBuildInfoTest, SuccessOptions) { + size_t size = 0; + auto info_type = UR_PROGRAM_BUILD_INFO_OPTIONS; + ASSERT_SUCCESS( + urProgramGetBuildInfo(program, device, info_type, 0, nullptr, &size)); + ASSERT_GT(size, 0); + + std::vector returned_options(size); + returned_options[size - 1] = 'x'; + ASSERT_SUCCESS(urProgramGetBuildInfo(program, device, info_type, size, + returned_options.data(), nullptr)); + + ASSERT_EQ(size, returned_options.size()); + ASSERT_EQ(returned_options[size - 1], '\0'); +} + +TEST_P(urProgramGetBuildInfoTest, SuccessLog) { + size_t size = 0; + auto info_type = UR_PROGRAM_BUILD_INFO_LOG; + ASSERT_SUCCESS( + urProgramGetBuildInfo(program, device, info_type, 0, nullptr, &size)); + ASSERT_GT(size, 0); + + std::vector returned_log(size); + returned_log[size - 1] = 'x'; + ASSERT_SUCCESS(urProgramGetBuildInfo(program, device, info_type, size, + returned_log.data(), nullptr)); + + ASSERT_EQ(size, returned_log.size()); + ASSERT_EQ(returned_log[size - 1], '\0'); +} + +TEST_P(urProgramGetBuildInfoTest, SuccessBinaryType) { + size_t size = 0; + auto info_type = UR_PROGRAM_BUILD_INFO_BINARY_TYPE; + ASSERT_SUCCESS( + urProgramGetBuildInfo(program, device, info_type, 0, nullptr, &size)); + ASSERT_EQ(sizeof(ur_program_binary_type_t), size); + + ur_program_binary_type_t returned_binary_type = + UR_PROGRAM_BINARY_TYPE_FORCE_UINT32; + ASSERT_SUCCESS(urProgramGetBuildInfo(program, device, info_type, size, + &returned_binary_type, nullptr)); + + ASSERT_GE(returned_binary_type, UR_PROGRAM_BINARY_TYPE_NONE); + ASSERT_LE(returned_binary_type, UR_PROGRAM_BINARY_TYPE_EXECUTABLE); } TEST_P(urProgramGetBuildInfoTest, InvalidNullHandleProgram) { @@ -70,19 +104,3 @@ TEST_P(urProgramGetBuildInfoTest, InvalidEnumeration) { UR_PROGRAM_BUILD_INFO_FORCE_UINT32, 0, nullptr, &propSizeOut)); } - -TEST_P(urProgramGetBuildInfoSingleTest, LogIsNullTerminated) { - size_t logSize; - std::vector log; - - ASSERT_SUCCESS(urProgramGetBuildInfo( - program, device, UR_PROGRAM_BUILD_INFO_LOG, 0, nullptr, &logSize)); - // The size should always include the null terminator. - ASSERT_GT(logSize, 0); - log.resize(logSize); - log[logSize - 1] = 'x'; - ASSERT_SUCCESS(urProgramGetBuildInfo(program, device, - UR_PROGRAM_BUILD_INFO_LOG, logSize, - log.data(), nullptr)); - ASSERT_EQ(log[logSize - 1], '\0'); -} diff --git a/test/conformance/program/urProgramGetInfo.cpp b/test/conformance/program/urProgramGetInfo.cpp index 176a278583..4658c5c700 100644 --- a/test/conformance/program/urProgramGetInfo.cpp +++ b/test/conformance/program/urProgramGetInfo.cpp @@ -5,124 +5,159 @@ #include -struct urProgramGetInfoTest : uur::urProgramTestWithParam { +struct urProgramGetInfoTest : uur::urProgramTest { void SetUp() override { - UUR_RETURN_ON_FATAL_FAILURE( - urProgramTestWithParam::SetUp()); + UUR_RETURN_ON_FATAL_FAILURE(urProgramTest::SetUp()); // Some queries need the program to be built. ASSERT_SUCCESS(urProgramBuild(this->context, program, nullptr)); } }; -UUR_TEST_SUITE_P( - urProgramGetInfoTest, - ::testing::Values(UR_PROGRAM_INFO_REFERENCE_COUNT, UR_PROGRAM_INFO_CONTEXT, - UR_PROGRAM_INFO_NUM_DEVICES, UR_PROGRAM_INFO_DEVICES, - UR_PROGRAM_INFO_IL, UR_PROGRAM_INFO_BINARY_SIZES, - UR_PROGRAM_INFO_BINARIES, UR_PROGRAM_INFO_NUM_KERNELS, - UR_PROGRAM_INFO_KERNEL_NAMES), - uur::deviceTestWithParamPrinter); +UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urProgramGetInfoTest); -struct urProgramGetInfoSingleTest : uur::urProgramTest { - void SetUp() override { - UUR_RETURN_ON_FATAL_FAILURE(urProgramTest::SetUp()); - ASSERT_SUCCESS(urProgramBuild(this->context, program, nullptr)); +TEST_P(urProgramGetInfoTest, SuccessReferenceCount) { + size_t size = 0; + auto info_type = UR_PROGRAM_INFO_REFERENCE_COUNT; + ASSERT_SUCCESS(urProgramGetInfo(program, info_type, 0, nullptr, &size)); + ASSERT_EQ(size, sizeof(uint32_t)); + + uint32_t returned_reference_count = 0; + ASSERT_SUCCESS(urProgramGetInfo(program, info_type, size, + &returned_reference_count, nullptr)); + + ASSERT_GT(returned_reference_count, 0U); +} + +TEST_P(urProgramGetInfoTest, SuccessContext) { + size_t size = 0; + auto info_type = UR_PROGRAM_INFO_CONTEXT; + ASSERT_SUCCESS(urProgramGetInfo(program, info_type, 0, nullptr, &size)); + ASSERT_EQ(size, sizeof(ur_context_handle_t)); + + ur_context_handle_t returned_context = nullptr; + ASSERT_SUCCESS( + urProgramGetInfo(program, info_type, size, &returned_context, nullptr)); + + ASSERT_EQ(returned_context, context); +} + +TEST_P(urProgramGetInfoTest, SuccessNumDevices) { + size_t size = 0; + auto info_type = UR_PROGRAM_INFO_NUM_DEVICES; + ASSERT_SUCCESS(urProgramGetInfo(program, info_type, 0, nullptr, &size)); + ASSERT_EQ(size, sizeof(uint32_t)); + + uint32_t returned_num_devices = 0; + ASSERT_SUCCESS(urProgramGetInfo(program, info_type, size, + &returned_num_devices, nullptr)); + + ASSERT_GE(uur::DevicesEnvironment::instance->devices.size(), + returned_num_devices); +} + +TEST_P(urProgramGetInfoTest, SuccessDevices) { + size_t size = 0; + auto info_type = UR_PROGRAM_INFO_DEVICES; + ASSERT_SUCCESS(urProgramGetInfo(program, info_type, 0, nullptr, &size)); + ASSERT_EQ(size, sizeof(ur_context_handle_t)); + + std::vector returned_devices(size); + ASSERT_SUCCESS(urProgramGetInfo(program, info_type, size, + returned_devices.data(), nullptr)); + + size_t devices_count = size / sizeof(ur_device_handle_t); + + ASSERT_GT(devices_count, 0); + for (uint32_t i = 0; i < devices_count; i++) { + auto &devices = uur::DevicesEnvironment::instance->devices; + auto queried_device = + std::find(devices.begin(), devices.end(), returned_devices[i]); + EXPECT_TRUE(queried_device != devices.end()); } -}; -UUR_INSTANTIATE_KERNEL_TEST_SUITE_P(urProgramGetInfoSingleTest); +} -TEST_P(urProgramGetInfoTest, Success) { - auto property_name = getParam(); - std::vector property_value; - size_t property_size = 0; - if (property_name == UR_PROGRAM_INFO_BINARIES) { - size_t binary_sizes_len = 0; - ASSERT_SUCCESS(urProgramGetInfo(program, UR_PROGRAM_INFO_BINARY_SIZES, - 0, nullptr, &binary_sizes_len)); - // Due to how the fixtures + env are set up we should only have one - // device associated with program, so one binary. - ASSERT_EQ(binary_sizes_len / sizeof(size_t), 1); - size_t binary_sizes[1] = {binary_sizes_len}; - ASSERT_SUCCESS(urProgramGetInfo(program, UR_PROGRAM_INFO_BINARY_SIZES, - binary_sizes_len, binary_sizes, - nullptr)); - property_value.resize(binary_sizes[0]); - char *binaries[1] = {property_value.data()}; - ASSERT_SUCCESS(urProgramGetInfo(program, UR_PROGRAM_INFO_BINARIES, - sizeof(binaries[0]), binaries, - nullptr)); +TEST_P(urProgramGetInfoTest, SuccessIL) { + size_t size = 0; + auto info_type = UR_PROGRAM_INFO_IL; + ASSERT_SUCCESS(urProgramGetInfo(program, info_type, 0, nullptr, &size)); + ASSERT_GE(size, 0); + + std::vector returned_il(size); + // Some adapters only support ProgramCreateWithBinary, in those cases we + // expect a return size of 0 and an empty return value for INFO_IL. + if (size > 0) { + ASSERT_SUCCESS(urProgramGetInfo(program, UR_PROGRAM_INFO_IL, size, + returned_il.data(), nullptr)); + ASSERT_EQ(returned_il, *il_binary.get()); } else { - ASSERT_SUCCESS_OR_OPTIONAL_QUERY( - urProgramGetInfo(program, property_name, 0, nullptr, - &property_size), - property_name); - if (property_size) { - property_value.resize(property_size); - ASSERT_SUCCESS(urProgramGetInfo(program, property_name, - property_size, - property_value.data(), nullptr)); - } else { - ASSERT_EQ(property_name, UR_PROGRAM_INFO_IL); - } + ASSERT_TRUE(returned_il.empty()); } - switch (property_name) { - case UR_PROGRAM_INFO_REFERENCE_COUNT: { - auto returned_reference_count = - reinterpret_cast(property_value.data()); - ASSERT_GT(*returned_reference_count, 0U); - break; - } - case UR_PROGRAM_INFO_CONTEXT: { - auto returned_context = - reinterpret_cast(property_value.data()); - ASSERT_EQ(context, *returned_context); - break; - } - case UR_PROGRAM_INFO_NUM_DEVICES: { - auto returned_num_of_devices = - reinterpret_cast(property_value.data()); - ASSERT_GE(uur::DevicesEnvironment::instance->devices.size(), - *returned_num_of_devices); - break; - } - case UR_PROGRAM_INFO_DEVICES: { - auto returned_devices = - reinterpret_cast(property_value.data()); - size_t devices_count = property_size / sizeof(ur_device_handle_t); - ASSERT_GT(devices_count, 0); - for (uint32_t i = 0; i < devices_count; i++) { - auto &devices = uur::DevicesEnvironment::instance->devices; - auto queried_device = - std::find(devices.begin(), devices.end(), returned_devices[i]); - EXPECT_TRUE(queried_device != devices.end()); - } - break; - } - case UR_PROGRAM_INFO_NUM_KERNELS: { - auto returned_num_of_kernels = - reinterpret_cast(property_value.data()); - ASSERT_GT(*returned_num_of_kernels, 0U); - break; - } - case UR_PROGRAM_INFO_KERNEL_NAMES: { - auto returned_kernel_names = - reinterpret_cast(property_value.data()); - ASSERT_STRNE(returned_kernel_names, ""); - break; - } - case UR_PROGRAM_INFO_IL: { - // Some adapters only support ProgramCreateWithBinary, in those cases we - // expect a return size of 0 and an empty return value for INFO_IL. - if (!property_value.empty()) { - ASSERT_EQ(property_value, *il_binary.get()); - } - break; - } - default: - break; +} + +TEST_P(urProgramGetInfoTest, SuccessBinarySizes) { + size_t size = 0; + auto info_type = UR_PROGRAM_INFO_BINARY_SIZES; + ASSERT_SUCCESS(urProgramGetInfo(program, info_type, 0, nullptr, &size)); + ASSERT_NE(size, 0); + + std::vector binary_sizes(size / sizeof(size_t)); + ASSERT_SUCCESS(urProgramGetInfo(program, UR_PROGRAM_INFO_BINARY_SIZES, size, + binary_sizes.data(), nullptr)); + + for (const auto &binary_size : binary_sizes) { + ASSERT_GT(binary_size, 0); } } +TEST_P(urProgramGetInfoTest, SuccessBinaries) { + size_t binary_sizes_len = 0; + std::vector property_value; + auto info_type = UR_PROGRAM_INFO_BINARIES; + ASSERT_SUCCESS( + urProgramGetInfo(program, info_type, 0, nullptr, &binary_sizes_len)); + // Due to how the fixtures + env are set up we should only have one + // device associated with program, so one binary. + ASSERT_EQ(binary_sizes_len / sizeof(size_t), 1); + + size_t binary_sizes[1] = {binary_sizes_len}; + ASSERT_SUCCESS(urProgramGetInfo(program, UR_PROGRAM_INFO_BINARY_SIZES, + binary_sizes_len, binary_sizes, nullptr)); + property_value.resize(binary_sizes[0]); + char *binaries[1] = {property_value.data()}; + ASSERT_SUCCESS(urProgramGetInfo(program, UR_PROGRAM_INFO_BINARIES, + sizeof(binaries[0]), binaries, nullptr)); +} + +TEST_P(urProgramGetInfoTest, SuccessNumKernels) { + size_t size = 0; + auto info_type = UR_PROGRAM_INFO_NUM_KERNELS; + ASSERT_SUCCESS_OR_OPTIONAL_QUERY( + urProgramGetInfo(program, info_type, 0, nullptr, &size), info_type); + ASSERT_EQ(size, sizeof(size_t)); + + size_t returned_num_kernels = 0; + ASSERT_SUCCESS(urProgramGetInfo(program, info_type, size, + &returned_num_kernels, nullptr)); + + ASSERT_GT(returned_num_kernels, 0U); +} + +TEST_P(urProgramGetInfoTest, SuccessKernelNames) { + size_t size = 0; + auto info_type = UR_PROGRAM_INFO_KERNEL_NAMES; + ASSERT_SUCCESS_OR_OPTIONAL_QUERY( + urProgramGetInfo(program, info_type, 0, nullptr, &size), info_type); + ASSERT_GT(size, 0); + + std::vector returned_kernel_names(size); + returned_kernel_names[size - 1] = 'x'; + ASSERT_SUCCESS(urProgramGetInfo(program, info_type, size, + returned_kernel_names.data(), nullptr)); + + ASSERT_EQ(size, returned_kernel_names.size()); + ASSERT_EQ(returned_kernel_names[size - 1], '\0'); +} + TEST_P(urProgramGetInfoTest, InvalidNullHandleProgram) { uint32_t ref_count = 0; ASSERT_EQ_RESULT(urProgramGetInfo(nullptr, UR_PROGRAM_INFO_REFERENCE_COUNT, @@ -164,32 +199,32 @@ TEST_P(urProgramGetInfoTest, InvalidNullPointerPropValueRet) { UR_RESULT_ERROR_INVALID_NULL_POINTER); } -TEST_P(urProgramGetInfoSingleTest, NumDevicesIsNonzero) { - uint32_t count; +TEST_P(urProgramGetInfoTest, NumDevicesIsNonzero) { + uint32_t count = 0; ASSERT_SUCCESS(urProgramGetInfo(program, UR_PROGRAM_INFO_NUM_DEVICES, sizeof(uint32_t), &count, nullptr)); ASSERT_GE(count, 1); } -TEST_P(urProgramGetInfoSingleTest, NumDevicesMatchesDeviceArray) { - uint32_t count; +TEST_P(urProgramGetInfoTest, NumDevicesMatchesDeviceArray) { + uint32_t count = 0; ASSERT_SUCCESS(urProgramGetInfo(program, UR_PROGRAM_INFO_NUM_DEVICES, sizeof(uint32_t), &count, nullptr)); - size_t info_devices_size; + size_t info_devices_size = 0; ASSERT_SUCCESS(urProgramGetInfo(program, UR_PROGRAM_INFO_DEVICES, 0, nullptr, &info_devices_size)); ASSERT_EQ(count, info_devices_size / sizeof(ur_device_handle_t)); } -TEST_P(urProgramGetInfoSingleTest, NumDevicesMatchesContextNumDevices) { - uint32_t count; +TEST_P(urProgramGetInfoTest, NumDevicesMatchesContextNumDevices) { + uint32_t count = 0; ASSERT_SUCCESS(urProgramGetInfo(program, UR_PROGRAM_INFO_NUM_DEVICES, sizeof(uint32_t), &count, nullptr)); // The device count either matches the number of devices in the context or // is 1, depending on how it was built - uint32_t info_context_devices_count; + uint32_t info_context_devices_count = 0; ASSERT_SUCCESS(urContextGetInfo(context, UR_CONTEXT_INFO_NUM_DEVICES, sizeof(uint32_t), &info_context_devices_count, nullptr));