Skip to content

Commit

Permalink
Move urProgramGetInfo success test from a switch to individual tests.
Browse files Browse the repository at this point in the history
Replaced LogIsNullTerminated with SuccessLog.
  • Loading branch information
martygrant committed Jan 9, 2025
1 parent 9c652ff commit a5d3f36
Show file tree
Hide file tree
Showing 2 changed files with 211 additions and 158 deletions.
110 changes: 64 additions & 46 deletions test/conformance/program/urProgramGetBuildInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,76 @@

#include <uur/fixtures.h>

struct urProgramGetBuildInfoTest
: uur::urProgramTestWithParam<ur_program_build_info_t> {
struct urProgramGetBuildInfoTest : uur::urProgramTest {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(
urProgramTestWithParam<ur_program_build_info_t>::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<ur_program_build_info_t>);
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<char> 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<char> 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<char> 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) {
Expand Down Expand Up @@ -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<char> 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');
}
Loading

0 comments on commit a5d3f36

Please sign in to comment.