Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testing for vk_enum_string_helper.h #63

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ endif()
if (VULKAN_HEADERS_INSTALL_DIR)
list(APPEND CMAKE_PREFIX_PATH ${VULKAN_HEADERS_INSTALL_DIR})
endif()
if (MAGIC_ENUM_INSTALL_DIR)
list(APPEND CMAKE_PREFIX_PATH ${MAGIC_ENUM_INSTALL_DIR})
endif()

if (CMAKE_CROSSCOMPILING)
set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${CMAKE_PREFIX_PATH} PARENT_SCOPE)
Expand Down
14 changes: 0 additions & 14 deletions scripts/generators/enum_string_helper_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@ def generate(self):
#include <vulkan/vulkan.h>
''')

# TODO - this should be moved into different generated util file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... can take action now to move this in VVL so it doesn't break when we switch over to VUL

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My initial thought is that VVL will use an internal only vk_enum_string_helper.hpp

Since I want to make vk_enum_string_helper.h C compatible.

out.append('\nstatic inline bool IsDuplicatePnext(VkStructureType input_value) {\n')
out.append(' switch (input_value) {\n')

for struct in [x for x in self.vk.structs.values() if x.allowDuplicate and x.sType is not None]:
# The sType will always be first member of struct
out.append(f' case {struct.sType}:\n')
out.append(' return true;\n')
out.append(' default:\n')
out.append(' return false;\n')
out.append(' }\n')
out.append('}\n')
out.append('\n')

# If there are no fields (empty enum) ignore
for enum in [x for x in self.vk.enums.values() if len(x.fields) > 0]:
groupType = enum.name if enum.bitWidth == 32 else 'uint64_t'
Expand Down
18 changes: 17 additions & 1 deletion scripts/known_good.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,26 @@
"optional": [
"tests"
]
},
{
"name": "magic_enum",
"url": "https://github.com/Neargye/magic_enum",
"sub_dir": "magic_enum",
"build_dir": "magic_enum/build",
"install_dir": "magic_enum/build/install",
"commit": "v0.9.3",
"cmake_options": [
"-DMAGIC_ENUM_OPT_BUILD_EXAMPLES=OFF",
"-DMAGIC_ENUM_OPT_BUILD_TESTS=OFF"
],
"optional": [
"tests"
]
}
],
"install_names": {
"Vulkan-Headers": "VULKAN_HEADERS_INSTALL_DIR",
"googletest": "GOOGLETEST_INSTALL_DIR"
"googletest": "GOOGLETEST_INSTALL_DIR",
"magic_enum": "MAGIC_ENUM_INSTALL_DIR"
}
}
17 changes: 16 additions & 1 deletion tests/generated/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
# Copyright 2023 LunarG, Inc.
#
# SPDX-License-Identifier: Apache-2.0
set(CMAKE_FOLDER "${CMAKE_FOLDER}/generated_code/tests")

find_package(magic_enum REQUIRED CONFIG)
find_package(GTest REQUIRED CONFIG)

include(GoogleTest)

if(${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)")
add_compile_options(-Wpedantic -Wall -Wextra -Werror)
endif()
Expand All @@ -14,4 +21,12 @@ endif()
# Test vk_enum_string_helper.h
add_executable(vk_enum_string_helper vk_enum_string_helper.cpp)
target_include_directories(vk_enum_string_helper PRIVATE ${VUL_SOURCE_DIR}/include)
target_link_libraries(vk_enum_string_helper PRIVATE Vulkan::Headers)
target_link_libraries(vk_enum_string_helper PRIVATE
Vulkan::Headers
GTest::gtest
GTest::gtest_main
magic_enum::magic_enum
)

gtest_discover_tests(vk_enum_string_helper)

71 changes: 69 additions & 2 deletions tests/generated/vk_enum_string_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,72 @@
// SPDX-License-Identifier: Apache-2.0
#include <vulkan/vk_enum_string_helper.h>

// TODO: Add actual testing
int main() {}
#include <magic_enum.hpp>

#include <gtest/gtest.h>

TEST(vk_enum_string_helper, string_VkResult) {
constexpr auto values = magic_enum::enum_values<VkResult>();
for (auto val : values) {
auto magic_str = magic_enum::enum_name(val);

auto str = string_VkResult(val);

EXPECT_STREQ(magic_str.data(), str);
}
Comment on lines +13 to +20
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/Neargye/magic_enum#examples

magic_enum makes testing these functions quite easy.

Note I didn't add testing for each enum possible. I just picked a few significant ones. Since we are mainly testing the code generation above anything else.

}

TEST(vk_enum_string_helper, string_VkStructureType) {
constexpr auto values = magic_enum::enum_values<VkStructureType>();
for (auto val : values) {
auto magic_str = magic_enum::enum_name(val);

auto str = string_VkStructureType(val);

EXPECT_STREQ(magic_str.data(), str);
}
}

TEST(vk_enum_string_helper, string_VkPipelineCacheHeaderVersion) {
constexpr auto values = magic_enum::enum_values<VkPipelineCacheHeaderVersion>();
for (auto val : values) {
auto magic_str = magic_enum::enum_name(val);

auto str = string_VkPipelineCacheHeaderVersion(val);

EXPECT_STREQ(magic_str.data(), str);
}
}

TEST(vk_enum_string_helper, string_VkImageLayout) {
constexpr auto values = magic_enum::enum_values<VkImageLayout>();
for (auto val : values) {
auto magic_str = magic_enum::enum_name(val);

auto str = string_VkImageLayout(val);

EXPECT_STREQ(magic_str.data(), str);
}
}

TEST(vk_enum_string_helper, string_VkObjectType) {
constexpr auto values = magic_enum::enum_values<VkObjectType>();
for (auto val : values) {
auto magic_str = magic_enum::enum_name(val);

auto str = string_VkObjectType(val);

EXPECT_STREQ(magic_str.data(), str);
}
}

TEST(vk_enum_string_helper, string_VkFormat) {
constexpr auto values = magic_enum::enum_values<VkFormat>();
for (auto val : values) {
auto magic_str = magic_enum::enum_name(val);

auto str = string_VkFormat(val);

EXPECT_STREQ(magic_str.data(), str);
}
}