Skip to content

Commit fe08231

Browse files
authored
Merge pull request #168 from rpavlik/fix-loader-test
Fix loader test
2 parents 1664460 + 7c5291f commit fe08231

File tree

4 files changed

+80
-73
lines changed

4 files changed

+80
-73
lines changed

src/scripts/generate_runtime_manifest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ def main(argv):
4545
elif opt in ("-b", "--bad"):
4646
generate_badjson_jsons = True
4747

48+
file_text = '{\n'
49+
file_text += ' "file_format_version": "%s",\n' % cur_runtime_json_version
50+
file_text += ' "runtime": {\n'
51+
file_text += ' "library_path": "%s",\n' % library_location
52+
file_text += ' "functions": {\n'
53+
file_text += ' "xrNegotiateLoaderRuntimeInterface":\n'
54+
file_text += ' "xrNegotiateLoaderRuntimeInterface"\n'
55+
file_text += ' }\n'
56+
file_text += ' }\n'
57+
file_text += '}\n'
58+
with open(output_file, 'w') as f:
59+
f.write(file_text)
60+
4861
if generate_badjson_jsons:
4962
# Bad File format versions
5063
####################################

src/tests/loader_test/loader_test.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ void TestEnumLayers(uint32_t& total, uint32_t& passed, uint32_t& skipped, uint32
130130
#endif
131131
try {
132132
XrResult test_result = XR_SUCCESS;
133-
uint32_t num_before_explicit = 0;
134133
std::vector<XrApiLayerProperties> layer_props;
135134

136135
#if FILTER_OUT_LOADER_ERRORS == 1
@@ -186,9 +185,8 @@ void TestEnumLayers(uint32_t& total, uint32_t& passed, uint32_t& skipped, uint32
186185
}
187186
}
188187
}
189-
num_before_explicit = out_layer_value;
190188

191-
// Tests with some explicit layers added
189+
// Tests with some explicit layers instead
192190
in_layer_value = 0;
193191
out_layer_value = 0;
194192
subtest_name = "Simple explicit layers";
@@ -206,9 +204,8 @@ void TestEnumLayers(uint32_t& total, uint32_t& passed, uint32_t& skipped, uint32
206204
cout << "Failed with return " << std::to_string(test_result) << endl;
207205
local_failed++;
208206
} else {
209-
if (out_layer_value != num_before_explicit + num_valid_jsons) {
210-
cout << "Failed, expected count " << (num_before_explicit + num_valid_jsons) << " (" << num_before_explicit
211-
<< " seen earlier plus " << num_valid_jsons << " we added), got " << std::to_string(out_layer_value) << endl;
207+
if (out_layer_value != num_valid_jsons) {
208+
cout << "Failed, expected count " << num_valid_jsons << ", got " << std::to_string(out_layer_value) << endl;
212209
local_failed++;
213210
} else {
214211
local_passed++;
@@ -463,6 +460,11 @@ void TestEnumInstanceExtensions(uint32_t& total, uint32_t& passed, uint32_t& ski
463460
}
464461
}
465462
}
463+
} catch (std::exception const& e) {
464+
cout << "Exception triggered during test (" << e.what() << "), automatic failure" << endl;
465+
local_failed++;
466+
local_total++;
467+
466468
} catch (...) {
467469
cout << "Exception triggered during test, automatic failure" << endl;
468470
local_failed++;

src/tests/loader_test/test_runtimes/CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ set_target_properties(test_runtime PROPERTIES FOLDER ${TESTS_FOLDER})
3434
add_dependencies(test_runtime
3535
xr_global_generated_files
3636
generate_openxr_header
37-
generated_rt_json_files
3837
)
3938
target_include_directories(test_runtime
4039
PRIVATE ${PROJECT_SOURCE_DIR}/src
@@ -85,8 +84,5 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
8584
)
8685
endif()
8786

88-
add_custom_target(generated_rt_json_files DEPENDS
89-
${PROJECT_BINARY_DIR}/src/tests/loader_test/resources/runtimes/test_runtime.json
90-
)
91-
set_target_properties(generated_rt_json_files PROPERTIES FOLDER ${CODEGEN_FOLDER})
92-
87+
# Add generated file to our sources so we depend on it, and thus trigger geenration.
88+
target_sources(test_runtime PRIVATE ${PROJECT_BINARY_DIR}/src/tests/loader_test/resources/runtimes/test_runtime.json)

src/tests/loader_test/test_runtimes/runtime_test.cpp

Lines changed: 57 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,17 @@
3535

3636
extern "C" {
3737

38-
XrResult RuntimeTestXrCreateInstance(const XrInstanceCreateInfo *info, XrInstance *instance) { return XR_SUCCESS; }
38+
XRAPI_ATTR XrResult XRAPI_CALL RuntimeTestXrCreateInstance(const XrInstanceCreateInfo *info, XrInstance *instance) {
39+
*instance = (XrInstance)1;
40+
return XR_SUCCESS;
41+
}
3942

40-
XrResult RuntimeTestXrDestroyInstance(XrInstance instance) { return XR_SUCCESS; }
43+
XRAPI_ATTR XrResult XRAPI_CALL RuntimeTestXrDestroyInstance(XrInstance instance) { return XR_SUCCESS; }
4144

42-
XrResult RuntimeTestXrEnumerateInstanceExtensionProperties(const char *layerName, uint32_t propertyCapacityInput,
43-
uint32_t *propertyCountOutput, XrExtensionProperties *properties) {
45+
XRAPI_ATTR XrResult XRAPI_CALL RuntimeTestXrEnumerateInstanceExtensionProperties(const char *layerName,
46+
uint32_t propertyCapacityInput,
47+
uint32_t *propertyCountOutput,
48+
XrExtensionProperties *properties) {
4449
if (nullptr != layerName) {
4550
return XR_ERROR_API_LAYER_NOT_PRESENT;
4651
}
@@ -55,7 +60,27 @@ XrResult RuntimeTestXrEnumerateInstanceExtensionProperties(const char *layerName
5560
return XR_SUCCESS;
5661
}
5762

58-
XrResult RuntimeTestXrGetInstanceProcAddr(XrInstance instance, const char *name, PFN_xrVoidFunction *function) {
63+
XRAPI_ATTR XrResult XRAPI_CALL RuntimeTestXrGetSystem(XrInstance instance, const XrSystemGetInfo *getInfo, XrSystemId *systemId) {
64+
*systemId = 1;
65+
return XR_SUCCESS;
66+
}
67+
68+
XRAPI_ATTR XrResult XRAPI_CALL RuntimeTestXrGetSystemProperties(XrInstance instance, XrSystemId systemId,
69+
XrSystemProperties *properties) {
70+
if (systemId != 1) {
71+
return XR_ERROR_SYSTEM_INVALID;
72+
}
73+
properties->graphicsProperties.maxLayerCount = 1;
74+
properties->graphicsProperties.maxSwapchainImageHeight = 1;
75+
properties->graphicsProperties.maxSwapchainImageWidth = 1;
76+
properties->systemId = systemId;
77+
strcpy(properties->systemName, "Dummy system");
78+
properties->vendorId = 0x0;
79+
return XR_SUCCESS;
80+
}
81+
82+
XRAPI_ATTR XrResult XRAPI_CALL RuntimeTestXrGetInstanceProcAddr(XrInstance instance, const char *name,
83+
PFN_xrVoidFunction *function) {
5984
if (0 == strcmp(name, "xrGetInstanceProcAddr")) {
6085
*function = reinterpret_cast<PFN_xrVoidFunction>(RuntimeTestXrGetInstanceProcAddr);
6186
} else if (0 == strcmp(name, "xrEnumerateInstanceExtensionProperties")) {
@@ -64,6 +89,10 @@ XrResult RuntimeTestXrGetInstanceProcAddr(XrInstance instance, const char *name,
6489
*function = reinterpret_cast<PFN_xrVoidFunction>(RuntimeTestXrCreateInstance);
6590
} else if (0 == strcmp(name, "xrDestroyInstance")) {
6691
*function = reinterpret_cast<PFN_xrVoidFunction>(RuntimeTestXrDestroyInstance);
92+
} else if (0 == strcmp(name, "xrGetSystem")) {
93+
*function = reinterpret_cast<PFN_xrVoidFunction>(RuntimeTestXrGetSystem);
94+
} else if (0 == strcmp(name, "xrGetSystemProperties")) {
95+
*function = reinterpret_cast<PFN_xrVoidFunction>(RuntimeTestXrGetSystemProperties);
6796
} else {
6897
*function = nullptr;
6998
}
@@ -72,8 +101,8 @@ XrResult RuntimeTestXrGetInstanceProcAddr(XrInstance instance, const char *name,
72101
}
73102

74103
// Function used to negotiate an interface betewen the loader and a runtime.
75-
RUNTIME_EXPORT XrResult xrNegotiateLoaderRuntimeInterface(const XrNegotiateLoaderInfo *loaderInfo,
76-
XrNegotiateRuntimeRequest *runtimeRequest) {
104+
RUNTIME_EXPORT XRAPI_ATTR XrResult XRAPI_CALL xrNegotiateLoaderRuntimeInterface(const XrNegotiateLoaderInfo *loaderInfo,
105+
XrNegotiateRuntimeRequest *runtimeRequest) {
77106
if (nullptr == loaderInfo || nullptr == runtimeRequest || loaderInfo->structType != XR_LOADER_INTERFACE_STRUCT_LOADER_INFO ||
78107
loaderInfo->structVersion != XR_LOADER_INFO_STRUCT_VERSION || loaderInfo->structSize != sizeof(XrNegotiateLoaderInfo) ||
79108
runtimeRequest->structType != XR_LOADER_INTERFACE_STRUCT_RUNTIME_REQUEST ||
@@ -87,82 +116,49 @@ RUNTIME_EXPORT XrResult xrNegotiateLoaderRuntimeInterface(const XrNegotiateLoade
87116
}
88117

89118
runtimeRequest->runtimeInterfaceVersion = XR_CURRENT_LOADER_RUNTIME_VERSION;
90-
runtimeRequest->runtimeApiVersion = XR_MAKE_VERSION(0, 1, 0);
119+
runtimeRequest->runtimeApiVersion = XR_CURRENT_API_VERSION;
91120
runtimeRequest->getInstanceProcAddr = reinterpret_cast<PFN_xrGetInstanceProcAddr>(RuntimeTestXrGetInstanceProcAddr);
92121

93122
return XR_SUCCESS;
94123
}
95124

96125
// Always fail
97-
RUNTIME_EXPORT XrResult TestRuntimeAlwaysFailNegotiateLoaderRuntimeInterface(const XrNegotiateLoaderInfo *loaderInfo,
98-
XrNegotiateRuntimeRequest *runtimeRequest) {
126+
RUNTIME_EXPORT XRAPI_ATTR XrResult XRAPI_CALL TestRuntimeAlwaysFailNegotiateLoaderRuntimeInterface(
127+
const XrNegotiateLoaderInfo *loaderInfo, XrNegotiateRuntimeRequest *runtimeRequest) {
99128
return XR_ERROR_INITIALIZATION_FAILED;
100129
}
101130

102131
// Pass, but return NULL for the runtime's xrGetInstanceProcAddr
103-
RUNTIME_EXPORT XrResult TestRuntimeNullGipaNegotiateLoaderRuntimeInterface(const XrNegotiateLoaderInfo *loaderInfo,
104-
XrNegotiateRuntimeRequest *runtimeRequest) {
105-
if (nullptr == loaderInfo || nullptr == runtimeRequest || loaderInfo->structType != XR_LOADER_INTERFACE_STRUCT_LOADER_INFO ||
106-
loaderInfo->structVersion != XR_LOADER_INFO_STRUCT_VERSION || loaderInfo->structSize != sizeof(XrNegotiateLoaderInfo) ||
107-
runtimeRequest->structType != XR_LOADER_INTERFACE_STRUCT_RUNTIME_REQUEST ||
108-
runtimeRequest->structVersion != XR_RUNTIME_INFO_STRUCT_VERSION ||
109-
runtimeRequest->structSize != sizeof(XrNegotiateRuntimeRequest) ||
110-
loaderInfo->minInterfaceVersion > XR_CURRENT_LOADER_RUNTIME_VERSION ||
111-
loaderInfo->maxInterfaceVersion < XR_CURRENT_LOADER_RUNTIME_VERSION ||
112-
loaderInfo->maxInterfaceVersion > XR_CURRENT_LOADER_RUNTIME_VERSION ||
113-
loaderInfo->minApiVersion < XR_MAKE_VERSION(0, 1, 0) || loaderInfo->minApiVersion >= XR_MAKE_VERSION(1, 1, 0)) {
114-
return XR_ERROR_INITIALIZATION_FAILED;
132+
RUNTIME_EXPORT XRAPI_ATTR XrResult XRAPI_CALL TestRuntimeNullGipaNegotiateLoaderRuntimeInterface(
133+
const XrNegotiateLoaderInfo *loaderInfo, XrNegotiateRuntimeRequest *runtimeRequest) {
134+
auto result = xrNegotiateLoaderRuntimeInterface(loaderInfo, runtimeRequest);
135+
if (result == XR_SUCCESS) {
136+
runtimeRequest->getInstanceProcAddr = nullptr;
115137
}
116138

117-
runtimeRequest->runtimeInterfaceVersion = XR_CURRENT_LOADER_RUNTIME_VERSION;
118-
runtimeRequest->runtimeApiVersion = XR_MAKE_VERSION(0, 1, 0);
119-
runtimeRequest->getInstanceProcAddr = nullptr;
120-
121-
return XR_SUCCESS;
139+
return result;
122140
}
123141

124142
// Pass, but return invalid interface version
125-
RUNTIME_EXPORT XrResult TestRuntimeInvalidInterfaceNegotiateLoaderRuntimeInterface(const XrNegotiateLoaderInfo *loaderInfo,
126-
XrNegotiateRuntimeRequest *runtimeRequest) {
127-
if (nullptr == loaderInfo || nullptr == runtimeRequest || loaderInfo->structType != XR_LOADER_INTERFACE_STRUCT_LOADER_INFO ||
128-
loaderInfo->structVersion != XR_LOADER_INFO_STRUCT_VERSION || loaderInfo->structSize != sizeof(XrNegotiateLoaderInfo) ||
129-
runtimeRequest->structType != XR_LOADER_INTERFACE_STRUCT_RUNTIME_REQUEST ||
130-
runtimeRequest->structVersion != XR_RUNTIME_INFO_STRUCT_VERSION ||
131-
runtimeRequest->structSize != sizeof(XrNegotiateRuntimeRequest) ||
132-
loaderInfo->minInterfaceVersion > XR_CURRENT_LOADER_RUNTIME_VERSION ||
133-
loaderInfo->maxInterfaceVersion < XR_CURRENT_LOADER_RUNTIME_VERSION ||
134-
loaderInfo->maxInterfaceVersion > XR_CURRENT_LOADER_RUNTIME_VERSION ||
135-
loaderInfo->minApiVersion < XR_MAKE_VERSION(0, 1, 0) || loaderInfo->minApiVersion >= XR_MAKE_VERSION(1, 1, 0)) {
136-
return XR_ERROR_INITIALIZATION_FAILED;
143+
RUNTIME_EXPORT XRAPI_ATTR XrResult XRAPI_CALL TestRuntimeInvalidInterfaceNegotiateLoaderRuntimeInterface(
144+
const XrNegotiateLoaderInfo *loaderInfo, XrNegotiateRuntimeRequest *runtimeRequest) {
145+
auto result = xrNegotiateLoaderRuntimeInterface(loaderInfo, runtimeRequest);
146+
if (result == XR_SUCCESS) {
147+
runtimeRequest->runtimeInterfaceVersion = 0;
137148
}
138149

139-
runtimeRequest->runtimeInterfaceVersion = 0;
140-
runtimeRequest->runtimeApiVersion = XR_MAKE_VERSION(0, 1, 0);
141-
runtimeRequest->getInstanceProcAddr = reinterpret_cast<PFN_xrGetInstanceProcAddr>(RuntimeTestXrGetInstanceProcAddr);
142-
143-
return XR_SUCCESS;
150+
return result;
144151
}
145152

146153
// Pass, but return invalid API version
147-
RUNTIME_EXPORT XrResult TestRuntimeInvalidApiNegotiateLoaderRuntimeInterface(const XrNegotiateLoaderInfo *loaderInfo,
148-
XrNegotiateRuntimeRequest *runtimeRequest) {
149-
if (nullptr == loaderInfo || nullptr == runtimeRequest || loaderInfo->structType != XR_LOADER_INTERFACE_STRUCT_LOADER_INFO ||
150-
loaderInfo->structVersion != XR_LOADER_INFO_STRUCT_VERSION || loaderInfo->structSize != sizeof(XrNegotiateLoaderInfo) ||
151-
runtimeRequest->structType != XR_LOADER_INTERFACE_STRUCT_RUNTIME_REQUEST ||
152-
runtimeRequest->structVersion != XR_RUNTIME_INFO_STRUCT_VERSION ||
153-
runtimeRequest->structSize != sizeof(XrNegotiateRuntimeRequest) ||
154-
loaderInfo->minInterfaceVersion > XR_CURRENT_LOADER_RUNTIME_VERSION ||
155-
loaderInfo->maxInterfaceVersion < XR_CURRENT_LOADER_RUNTIME_VERSION ||
156-
loaderInfo->maxInterfaceVersion > XR_CURRENT_LOADER_RUNTIME_VERSION ||
157-
loaderInfo->minApiVersion < XR_MAKE_VERSION(0, 1, 0) || loaderInfo->minApiVersion >= XR_MAKE_VERSION(1, 1, 0)) {
158-
return XR_ERROR_INITIALIZATION_FAILED;
154+
RUNTIME_EXPORT XRAPI_ATTR XrResult XRAPI_CALL TestRuntimeInvalidApiNegotiateLoaderRuntimeInterface(
155+
const XrNegotiateLoaderInfo *loaderInfo, XrNegotiateRuntimeRequest *runtimeRequest) {
156+
auto result = xrNegotiateLoaderRuntimeInterface(loaderInfo, runtimeRequest);
157+
if (result == XR_SUCCESS) {
158+
runtimeRequest->runtimeApiVersion = 0;
159159
}
160160

161-
runtimeRequest->runtimeInterfaceVersion = XR_CURRENT_LOADER_RUNTIME_VERSION;
162-
runtimeRequest->runtimeApiVersion = 0;
163-
runtimeRequest->getInstanceProcAddr = reinterpret_cast<PFN_xrGetInstanceProcAddr>(RuntimeTestXrGetInstanceProcAddr);
164-
165-
return XR_SUCCESS;
161+
return result;
166162
}
167163

168164
} // extern "C"

0 commit comments

Comments
 (0)