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 integration testing #1423

Merged
merged 1 commit into from
Dec 27, 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
5 changes: 0 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ jobs:
- run: cmake --build build
- run: ctest --output-on-failure --test-dir build/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI @ncesario-lunarg who is looking to do similar work in glslang.

ctest now handles the find_package integration testing. Making it require little to no CI effort.

- run: cmake --install build --prefix /tmp
# NOTE: This check is NOT sufficient to ensure vulkan.pc is actually valid
- name: Check vulkan.pc exists and validate it
run: |
cat /tmp/lib/pkgconfig/vulkan.pc
pkg-config --validate /tmp/lib/pkgconfig/vulkan.pc
Comment on lines -73 to -77
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The logic is now tested by ctest


codegen:
runs-on: ubuntu-latest
Expand Down
29 changes: 29 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,32 @@ if(NOT CMAKE_CROSSCOMPILING)
else()
gtest_add_tests(TARGET test_regression)
endif()

# When APPLE_STATIC_LOADER is ON installation is disabled
if (APPLE_STATIC_LOADER)
return()
endif()

# Test installation
set(test_install_dir "${CMAKE_CURRENT_BINARY_DIR}/install")
add_test(NAME integration.install
COMMAND ${CMAKE_COMMAND} --install ${PROJECT_BINARY_DIR} --prefix ${test_install_dir} --config $<CONFIG>
)
Comment on lines +94 to +98
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NOTE: You can go 1 step further and test the BOM (build of materials).

See https://cmake.org/cmake/help/latest/prop_test/PASS_REGULAR_EXPRESSION.html

The CMake book covers this fairly well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also I have an example in VVL:

find_program(GNU_NM NAMES nm)
if (GNU_NM)
    # Ensure ANativeActivity_onCreate is being exported
    add_test(NAME ANativeActivity_onCreate COMMAND ${GNU_NM} --dynamic $<TARGET_FILE:vk_layer_validation_tests>)
    set_tests_properties(ANativeActivity_onCreate
        PROPERTIES PASS_REGULAR_EXPRESSION "T ANativeActivity_onCreate"
    )

    # Ensure compatibility with older Android loaders
    add_test(NAME vkEnumerateDeviceExtensionProperties COMMAND ${GNU_NM} --dynamic $<TARGET_FILE:vvl>)
    set_tests_properties(vkEnumerateDeviceExtensionProperties
        PROPERTIES PASS_REGULAR_EXPRESSION "T vkEnumerateDeviceExtensionProperties"
    )

    # Ensure compatibility with older Android loaders
    add_test(NAME vkEnumerateDeviceLayerProperties COMMAND ${GNU_NM} --dynamic $<TARGET_FILE:vvl>)
    set_tests_properties(vkEnumerateDeviceLayerProperties
        PROPERTIES PASS_REGULAR_EXPRESSION "T vkEnumerateDeviceLayerProperties"
    )
endif()


# find_package testing currently doesn't work well under cross-compilation scenarios.
if (CMAKE_CROSSCOMPILING OR
NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This 1 line was added to make 32 bit builds work without issue. I'm not a fan and it could potentially be handled more elegantly.

return()
endif()

# Test find_package suppport
add_test(NAME integration.find_package
COMMAND ${CMAKE_CTEST_COMMAND}
--build-and-test ${CMAKE_CURRENT_LIST_DIR}/integration
${CMAKE_CURRENT_BINARY_DIR}/find_package
--build-generator ${CMAKE_GENERATOR}
--build-options -DCMAKE_PREFIX_PATH=${test_install_dir}
)

# Installing comes before testing
set_tests_properties(integration.find_package PROPERTIES DEPENDS integration.install)
39 changes: 39 additions & 0 deletions tests/integration/CMakeLists.txt
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NOTE: The testing here is SUPER minimal.

glslang would need more of course.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# ~~~
# Copyright (c) 2023 Valve Corporation
# Copyright (c) 2023 LunarG, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ~~~
cmake_minimum_required(VERSION 3.17.2)

project(INTEGRATION LANGUAGES C)

find_package(VulkanLoader REQUIRED CONFIG)

# The intent is ensuring we don't accidentally change the names of these
# targets. Since it would break downstream users.
if (NOT TARGET Vulkan::Loader)
message(FATAL_ERROR "Vulkan::Loader target not defined!")
endif()

if (NOT DEFINED VulkanLoader_VERSION)
message(FATAL_ERROR "VulkanLoader_VERSION not defined!")
endif()
message(STATUS "VulkanLoader_VERSION = ${VulkanLoader_VERSION}")

# NOTE: This check is NOT sufficient to ensure vulkan.pc is actually valid
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
find_file(VULKAN_PC vulkan.pc PATH_SUFFIXES lib/pkgconfig REQUIRED)
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --validate ${VULKAN_PC})
endif()