Skip to content

Commit 3bb0e8e

Browse files
committed
loader_test: Improve the dummy runtime so we can run more tests on it.
1 parent 00c1abc commit 3bb0e8e

File tree

1 file changed

+57
-61
lines changed

1 file changed

+57
-61
lines changed

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)