Skip to content

Commit

Permalink
Add OpenXR CTS test for API layer pre-create operations
Browse files Browse the repository at this point in the history
OpenXR API Layers may need to query other layers or the runtime before
the instance has been created - add an explicit test for this case.
  • Loading branch information
johnkearney committed Aug 6, 2024
1 parent 477fae4 commit 8f3b9d9
Show file tree
Hide file tree
Showing 15 changed files with 486 additions and 3 deletions.
5 changes: 5 additions & 0 deletions changes/conformance/mr.3415.gl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- mr.3415.gl
- issues.2333.gl
---
Add conformance test to validate xrCreateInstance patterns required by API layers.
1 change: 1 addition & 0 deletions src/conformance/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ set_target_properties(
add_subdirectory(conformance_layer)
add_subdirectory(utilities)
add_subdirectory(framework)
add_subdirectory(test_layer)
add_subdirectory(conformance_test)
if(NOT ANDROID)
add_subdirectory(conformance_cli)
Expand Down
2 changes: 1 addition & 1 deletion src/conformance/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ android {
'-DBUILD_LOADER=ON',
'-DBUILD_CONFORMANCE_TESTS=ON',
'-DBUILD_ALL_EXTENSIONS=ON'
targets 'conformance_test', 'openxr_loader', 'XrApiLayer_runtime_conformance'
targets 'conformance_test', 'openxr_loader', 'XrApiLayer_runtime_conformance', 'XrApiLayer_conformance_test_layer'
}
}
preBuild.dependsOn(copyAssets)
Expand Down
12 changes: 11 additions & 1 deletion src/conformance/conformance_layer/Negotiate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
#include "ConformanceHooks.h"
#include "gen_dispatch.h"

#include <cstring>

namespace
{
static const char* LAYER_NAME = "XR_APILAYER_KHRONOS_runtime_conformance";

XRAPI_ATTR XrResult XRAPI_CALL ConformanceLayer_RegisterInstance(const XrInstanceCreateInfo* createInfo,
const XrApiLayerCreateInfo* apiLayerInfo, XrInstance* instance)
{
Expand Down Expand Up @@ -68,7 +72,7 @@ namespace
// Function used to negotiate an interface betewen the loader and an API layer. Each library exposing one or
// more API layers needs to expose at least this function.
extern "C" LAYER_EXPORT XRAPI_ATTR XrResult XRAPI_CALL xrNegotiateLoaderApiLayerInterface(const XrNegotiateLoaderInfo* loaderInfo,
const char* /*apiLayerName*/,
const char* apiLayerName,
XrNegotiateApiLayerRequest* apiLayerRequest)
{
if (loaderInfo == nullptr || loaderInfo->structType != XR_LOADER_INTERFACE_STRUCT_LOADER_INFO ||
Expand All @@ -91,6 +95,12 @@ extern "C" LAYER_EXPORT XRAPI_ATTR XrResult XRAPI_CALL xrNegotiateLoaderApiLayer
return XR_ERROR_INITIALIZATION_FAILED;
}

if (strcmp(apiLayerName, LAYER_NAME) != 0) {
// TODO: Log reason somehow.
// LogPlatformUtilsError("loader layer name does not match expected name");
return XR_ERROR_INITIALIZATION_FAILED;
}

if (apiLayerRequest == nullptr || apiLayerRequest->structType != XR_LOADER_INTERFACE_STRUCT_API_LAYER_REQUEST ||
apiLayerRequest->structVersion != XR_API_LAYER_INFO_STRUCT_VERSION ||
apiLayerRequest->structSize != sizeof(XrNegotiateApiLayerRequest)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"file_format_version": "1.0.0",
"api_layer": {
"name": "XR_APILAYER_KHRONOS_conformance_test_layer",
"library_path": "libXrApiLayer_conformance_test_layer.so",
"api_version": "1.1",
"implementation_version": "1",
"description": "API Layer to validate OpenXR runtime conformance",
"disable_environment": "KHRONOS_conformance_test_layer_disabled"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2019-2024, The Khronos Group Inc.

SPDX-License-Identifier: Apache-2.0
68 changes: 68 additions & 0 deletions src/conformance/conformance_test/test_apiLayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) 2019-2024, The Khronos Group Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// 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.

#include "conformance_framework.h"
#include "conformance_utils.h"
#include "utilities/types_and_constants.h"
#include "utilities/utils.h"

#include <catch2/catch_test_macros.hpp>
#include <openxr/openxr.h>

#include <cstring>
#include <string>
#include <thread>

namespace Conformance
{
TEST_CASE("validApiLayer", "")
{
GlobalData& globalData = GetGlobalData();

// Layer for run-time conformance (and anything else global)
StringVec enabledApiLayers = globalData.enabledAPILayerNames;
// plus our test layer
enabledApiLayers.push_back("XR_APILAYER_KHRONOS_conformance_test_layer");

// Enable only the required platform extensions by default
auto enabledExtensions = StringVec(globalData.requiredPlatformInstanceExtensions);

XrInstance instance = XR_NULL_HANDLE_CPP;
CleanupInstanceOnScopeExit cleanup(instance);

XrInstanceCreateInfo createInfo{XR_TYPE_INSTANCE_CREATE_INFO};

strcpy(createInfo.applicationInfo.applicationName, "conformance test");
createInfo.applicationInfo.applicationVersion = 1;
// Leave engineName and engineVersion empty, which is valid usage.
createInfo.applicationInfo.apiVersion = globalData.options.desiredApiVersionValue;

if (globalData.requiredPlatformInstanceCreateStruct) {
createInfo.next = globalData.requiredPlatformInstanceCreateStruct;
}

createInfo.enabledApiLayerCount = (uint32_t)enabledApiLayers.size();
createInfo.enabledApiLayerNames = enabledApiLayers.data();
createInfo.enabledExtensionCount = (uint32_t)enabledExtensions.size();
createInfo.enabledExtensionNames = enabledExtensions.data();

SECTION("XR_SUCCESS, only platform-required extensions enabled")
{
REQUIRE(XR_SUCCESS == xrCreateInstance(&createInfo, &instance));
}
}

} // namespace Conformance
3 changes: 2 additions & 1 deletion src/conformance/conformance_test/test_xrCreateInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ namespace Conformance
// Leave engineName and engineVersion empty, which is valid usage.
createInfo.applicationInfo.apiVersion = globalData.options.desiredApiVersionValue;

if (globalData.requiredPlatformInstanceCreateStruct)
if (globalData.requiredPlatformInstanceCreateStruct) {
createInfo.next = globalData.requiredPlatformInstanceCreateStruct;
}

// Layers enabled at least for run-time conformance
StringVec enabledApiLayers = globalData.enabledAPILayerNames;
Expand Down
129 changes: 129 additions & 0 deletions src/conformance/test_layer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Copyright (c) 2019-2024, The Khronos Group Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# 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.

file(
GLOB
LOCAL_HEADERS
CONFIGURE_DEPENDS
"*.h"
)
file(
GLOB
LOCAL_SOURCE
CONFIGURE_DEPENDS
"*.cpp"
)

configure_file(
conformance_test_layer.json
${CMAKE_CURRENT_BINARY_DIR}/XrApiLayer_conformance_test_layer.json @ONLY
)

add_library(
XrApiLayer_conformance_test_layer MODULE
${LOCAL_SOURCE}
${LOCAL_HEADERS}
)
target_link_libraries(
XrApiLayer_conformance_test_layer PRIVATE OpenXR::headers
)

source_group("Headers" FILES ${LOCAL_HEADERS})

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_compile_options(XrApiLayer_conformance_test_layer PRIVATE -Wall)
target_link_libraries(XrApiLayer_conformance_test_layer PRIVATE m)
endif()

if(ANDROID)
target_link_libraries(
XrApiLayer_conformance_test_layer PRIVATE ${ANDROID_LOG_LIBRARY}
)
endif()

# Dynamic Library:
# - Make build depend on the module definition/version script/export map
# - Add the linker flag (except windows)
if(WIN32)
target_sources(
XrApiLayer_conformance_test_layer
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/XrApiLayer_conformance_test_layer.def"
)
elseif(APPLE)
set_target_properties(
XrApiLayer_conformance_test_layer
PROPERTIES
LINK_FLAGS
"-Wl,-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/XrApiLayer_conformance_test_layer.expsym"
)
target_sources(
XrApiLayer_conformance_test_layer
PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/XrApiLayer_conformance_test_layer.expsym"
)
else()
set_target_properties(
XrApiLayer_conformance_test_layer
PROPERTIES
LINK_FLAGS
"-Wl,--version-script=\"${CMAKE_CURRENT_SOURCE_DIR}/XrApiLayer_conformance_test_layer.map\""
)
target_sources(
XrApiLayer_conformance_test_layer
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/XrApiLayer_conformance_test_layer.map"
)
endif()

if(BUILD_CONFORMANCE_CLI)
# Copy conformance layer files to conformance_cli binary folder
add_custom_command(
TARGET XrApiLayer_conformance_test_layer
POST_BUILD
COMMAND
${CMAKE_COMMAND} -E copy
$<TARGET_FILE:XrApiLayer_conformance_test_layer>
$<TARGET_PROPERTY:conformance_cli,BINARY_DIR>
COMMAND
${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/XrApiLayer_conformance_test_layer.json
$<TARGET_PROPERTY:conformance_cli,BINARY_DIR>
)
endif()

set_target_properties(
XrApiLayer_conformance_test_layer PROPERTIES FOLDER
${CONFORMANCE_TESTS_FOLDER}
)

install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/XrApiLayer_conformance_test_layer.json
DESTINATION conformance
)

install(
TARGETS XrApiLayer_conformance_test_layer
LIBRARY DESTINATION conformance
ARCHIVE DESTINATION conformance
RUNTIME DESTINATION conformance
)

if(MSVC)
install(
FILES $<TARGET_PDB_FILE:XrApiLayer_conformance_test_layer>
DESTINATION conformance
OPTIONAL
)
endif()
Loading

0 comments on commit 8f3b9d9

Please sign in to comment.