public IEnumerator BeginSessionFailure() { var states = new List <XrSessionState>(); MockRuntime.Instance.TestCallback = (methodName, param) => { if (methodName == nameof(OpenXRFeature.OnSessionStateChange)) { var newState = (XrSessionState)((MockRuntime.XrSessionStateChangedParams)param).NewState; states.Add(newState); } return(true); }; MockRuntime.SetFunctionCallback("xrBeginSession", (name) => XrResult.RuntimeFailure); InitializeAndStart(); yield return(null); Assert.IsTrue(base.IsRunning <XRDisplaySubsystem>()); Assert.IsTrue(states.Contains(XrSessionState.Ready)); Assert.IsFalse(states.Contains(XrSessionState.Synchronized)); Assert.IsFalse(states.Contains(XrSessionState.Visible)); Assert.IsFalse(states.Contains(XrSessionState.Focused)); }
public IEnumerator UserPresence() { List <InputDevice> hmdDevices = new List <InputDevice>(); InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HeadMounted, hmdDevices); Assert.That(hmdDevices.Count == 0, Is.True); InitializeAndStart(); // Wait two frames to let the input catch up with the renderer yield return(new WaitForXrFrame(2)); InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HeadMounted, hmdDevices); Assert.That(hmdDevices.Count > 0, Is.True); bool hasValue = hmdDevices[0].TryGetFeatureValue(CommonUsages.userPresence, out bool isUserPresent); Assert.That(hasValue, Is.True); Assert.That(isUserPresent, Is.True); MockRuntime.TransitionToState(XrSessionState.Visible, true); // State transition doesnt happen immediately so make doubly sure it has happened before we try to get the new feature value yield return(new WaitForXrFrame(2)); hasValue = hmdDevices[0].TryGetFeatureValue(CommonUsages.userPresence, out isUserPresent); Assert.That(hasValue, Is.True); Assert.That(isUserPresent, Is.False); }
public IEnumerator LossPendingCausesRestart() { bool lossPendingReceived = false; MockRuntime.Instance.TestCallback = (methodName, param) => { switch (methodName) { case nameof(OpenXRFeature.OnSessionLossPending): lossPendingReceived = true; break; } return(true); }; InitializeAndStart(); yield return(new WaitForXrFrame(1)); Assert.IsTrue(MockRuntime.TransitionToState(XrSessionState.LossPending, true), "Failed to transition to loss pending state"); yield return(new WaitForLoaderRestart()); Assert.IsTrue(lossPendingReceived); }
public IEnumerator CreateSwapChainRuntimeError() { MockRuntime.SetFunctionCallback("xrCreateSwapchain", (func) => XrResult.RuntimeFailure); InitializeAndStart(); yield return(new WaitForLoaderShutdown()); Assert.IsTrue(OpenXRLoader.Instance == null, "OpenXR should not be initialized"); }
public IEnumerator TransitionToState() { InitializeAndStart(); yield return(new WaitForXrFrame()); Assert.AreEqual(MockRuntime.sessionState, XrSessionState.Focused, "MockRuntime must be in focused state for this test to work correctly"); Assert.IsTrue(MockRuntime.TransitionToState(XrSessionState.Visible, false), "Failed to transition to visible state"); Assert.AreEqual(MockRuntime.sessionState, XrSessionState.Visible); }
public IEnumerator CreateSessionRuntimeError() { MockRuntime.SetFunctionCallback("xrCreateSession", (func) => XrResult.RuntimeFailure); InitializeAndStart(); yield return(null); Assert.IsTrue(DoesDiagnosticReportContain(new System.Text.RegularExpressions.Regex(@"xrCreateSession: XR_ERROR_RUNTIME_FAILURE"))); Assert.IsTrue(OpenXRLoader.Instance.currentLoaderState == OpenXRLoaderBase.LoaderState.Stopped, "OpenXR should be stopped"); }
public IEnumerator FirstPersonObserverRestartWhileActive() { base.InitializeAndStart(); MockRuntime.ActivateSecondaryView(XrViewConfigurationType.SecondaryMonoFirstPersonObserver, true); yield return(new WaitForXrFrame(1)); MockRuntime.GetEndFrameStats(out var primaryLayerCount, out var secondaryLayerCount); Assert.IsTrue(secondaryLayerCount == 1); // Transition to ready, which was causing a crash. MockRuntime.TransitionToState(XrSessionState.Visible, false); yield return(null); MockRuntime.TransitionToState(XrSessionState.Synchronized, false); yield return(null); MockRuntime.TransitionToState(XrSessionState.Stopping, false); yield return(null); MockRuntime.TransitionToState(XrSessionState.Idle, false); yield return(null); MockRuntime.TransitionToState(XrSessionState.Ready, false); yield return(null); // Check that secondary layer is still there MockRuntime.GetEndFrameStats(out primaryLayerCount, out secondaryLayerCount); Assert.IsTrue(secondaryLayerCount == 1); // Transition back to focused MockRuntime.TransitionToState(XrSessionState.Synchronized, false); yield return(null); MockRuntime.TransitionToState(XrSessionState.Visible, false); yield return(null); MockRuntime.TransitionToState(XrSessionState.Focused, false); yield return(null); yield return(new WaitForXrFrame(2)); // Verify secondary layer is still up and running MockRuntime.GetEndFrameStats(out primaryLayerCount, out secondaryLayerCount); Assert.IsTrue(secondaryLayerCount == 1); // Make sure we can turn it off MockRuntime.ActivateSecondaryView(XrViewConfigurationType.SecondaryMonoFirstPersonObserver, false); yield return(new WaitForXrFrame(2)); MockRuntime.GetEndFrameStats(out primaryLayerCount, out secondaryLayerCount); Assert.IsTrue(secondaryLayerCount == 0); }
public IEnumerator TransitionToStateForced() { InitializeAndStart(); yield return(new WaitForXrFrame()); Assert.IsFalse(MockRuntime.TransitionToState(XrSessionState.Synchronized, false), "Synchronized state must be an invalid transition for this test to be valid"); Assert.IsTrue(MockRuntime.TransitionToState(XrSessionState.Synchronized, true), "Force state transition should not return false"); yield return(new WaitForXrFrame()); Assert.IsTrue(MockRuntime.sessionState == XrSessionState.Synchronized); }
public IEnumerator RequestExitSession() { InitializeAndStart(); // Wait for a single XrFrame to make sure OpenXR is up and running yield return(new WaitForXrFrame()); // Request the session exit which should shutdown OpenXR MockRuntime.RequestExitSession(); // Wait for OpenXR to shutdown yield return(new WaitForLoaderShutdown()); }
public IEnumerator WantsToRestartFalse() { OpenXRRuntime.wantsToRestart += () => true; OpenXRRuntime.wantsToRestart += () => false; OpenXRRuntime.wantsToRestart += () => true; InitializeAndStart(); yield return(new WaitForXrFrame(2)); MockRuntime.TransitionToState(XrSessionState.LossPending, true); yield return(new WaitForLoaderShutdown()); }
public IEnumerator CallbacksClearedOnLoaderShutdown() { MockRuntime.SetFunctionCallback("xrBeginSession", (func) => XrResult.Success); InitializeAndStart(); yield return(new WaitForXrFrame(1)); StopAndShutdown(); Assert.IsTrue(OpenXRLoader.Instance == null, "OpenXR should not be running"); Assert.IsNull(MockRuntime.GetBeforeFunctionCallback("xrBeginSession"), "Callback should have been cleared when loader shut down"); }
public IEnumerator BeforeFunctionCallbackSuccess() { var createInstanceCalled = false; MockRuntime.SetFunctionCallback("xrCreateInstance", (name) => { createInstanceCalled = true; return(XrResult.Success); }); InitializeAndStart(); yield return(new WaitForXrFrame(1)); Assert.IsTrue(createInstanceCalled, "xrCreateInstance callback was not called"); }
public void BeforeFunctionCallbackError() { var createInstanceCalled = false; MockRuntime.SetFunctionCallback("xrCreateInstance", (name) => { createInstanceCalled = true; return(XrResult.RuntimeFailure); }); LogAssert.ignoreFailingMessages = true; InitializeAndStart(); LogAssert.ignoreFailingMessages = false; Assert.IsTrue(OpenXRLoaderBase.Instance == null, "OpenXR instance should have failed to initialize"); Assert.IsTrue(createInstanceCalled, "xrCreateInstance callback was not called"); }
public IEnumerator AfterFunctionCallback( ) { var createInstanceCalled = false; var createInstanceSuccess = false; MockRuntime.SetFunctionCallback("xrCreateInstance", (name, result) => { createInstanceCalled = true; createInstanceSuccess = result == XrResult.Success; }); InitializeAndStart(); yield return(new WaitForXrFrame(1)); Assert.IsTrue(createInstanceCalled, "xrCreateInstance callback was not called"); Assert.IsTrue(createInstanceSuccess, "xrCreateInstance result was not XR_SUCCESS"); }
public IEnumerator FirstPersonObserver() { base.InitializeAndStart(); MockRuntime.ActivateSecondaryView(XrViewConfigurationType.SecondaryMonoFirstPersonObserver, true); yield return(new WaitForXrFrame(2)); MockRuntime.GetEndFrameStats(out var primaryLayerCount, out var secondaryLayerCount); Assert.IsTrue(secondaryLayerCount == 1); MockRuntime.ActivateSecondaryView(XrViewConfigurationType.SecondaryMonoFirstPersonObserver, false); yield return(new WaitForXrFrame(2)); MockRuntime.GetEndFrameStats(out primaryLayerCount, out secondaryLayerCount); Assert.IsTrue(secondaryLayerCount == 0); }
public IEnumerator BoundaryPoints() { AddExtension(MockRuntime.XR_UNITY_mock_test); base.InitializeAndStart(); yield return(null); Assert.IsTrue(base.IsRunning <XRInputSubsystem>(), "Input subsystem failed to properly start!"); MockRuntime.SetReferenceSpaceBounds(XrReferenceSpaceType.Stage, new Vector2 { x = 1.0f, y = 3.0f }); yield return(null); var input = Loader.GetLoadedSubsystem <XRInputSubsystem>(); Assert.That(() => input, Is.Not.Null); input.TrySetTrackingOriginMode(TrackingOriginModeFlags.Floor); yield return(null); var points = new List <Vector3>(); Assert.IsTrue(input.TryGetBoundaryPoints(points), "Failed to get boundary points!"); Assert.That(() => points.Count, Is.EqualTo(4), "Incorrect number of boundary points received!"); var comparer = new Vector3EqualityComparer(10e-6f); Assert.That(points[0], Is.EqualTo(new Vector3 { x = -1.0f, y = 0.0f, z = -3.0f }).Using(comparer)); Assert.That(points[1], Is.EqualTo(new Vector3 { x = -1.0f, y = 0.0f, z = 3.0f }).Using(comparer)); Assert.That(points[2], Is.EqualTo(new Vector3 { x = 1.0f, y = 0.0f, z = 3.0f }).Using(comparer)); Assert.That(points[3], Is.EqualTo(new Vector3 { x = 1.0f, y = 0.0f, z = -3.0f }).Using(comparer)); }
/// <summary> /// A hard-coded Game, using Earth and the player as Babylonian. /// </summary> protected TestsBase() { rs = new RuntimeSettings(); rs.InitialSeed = 23905; runtime = new MockRuntime(rs); // Load Earth map var foo = Map.Instance; foo.LoadMap(); do { Thread.Sleep(5); } while (!foo.Ready); // Start with Babylonians at King level Game.CreateGame(3, 2, Common.Civilizations.First(x => x.Name == "Babylonian")); playa = Game.Instance.HumanPlayer; }
public IEnumerator WantsToQuitFalse() { var onQuit = false; OpenXRRuntime.wantsToQuit += () => true; OpenXRRuntime.wantsToQuit += () => false; OpenXRRuntime.wantsToQuit += () => true; OpenXRRestarter.Instance.onQuit += () => onQuit = true; InitializeAndStart(); yield return(new WaitForXrFrame(2)); MockRuntime.CauseInstanceLoss(); yield return(new WaitForLoaderShutdown()); Assert.IsTrue(OpenXRLoader.Instance == null, "OpenXR should not be running"); Assert.IsFalse(onQuit, "Quit was not called"); }
/// Program entry point static void Main(string[] args) { // Add all /var/lang/bin/shared/*/* directories to the search path foreach (var di in new DirectoryInfo("/var/lang/bin/shared").EnumerateDirectories().SelectMany(di => di.EnumerateDirectories().Select(di2 => di2))) { assemblyDirs.Add(di.FullName); } AssemblyLoadContext.Default.Resolving += OnAssemblyResolving; try { var shouldWaitForDebugger = GetShouldWaitForDebuggerFlag(args, out var positionalArgs); var handler = GetFunctionHandler(positionalArgs); var body = GetEventBody(positionalArgs); if (shouldWaitForDebugger) { Console.Error.WriteLine("Waiting for the debugger to attach..."); if (!DebuggerExtensions.TryWaitForAttaching( _debuggerStatusQueryInterval, _debuggerStatusQueryTimeout)) { Console.Error.WriteLine("Timeout. Proceeding without debugger."); } } var lambdaRuntime = new MockRuntime(handler, body); LambdaBootstrap lambdaBootstrap = new LambdaBootstrap(lambdaRuntime, InternalLogger.NO_OP_LOGGER); UnhandledExceptionLogger.Register(); lambdaBootstrap.Initialize(); lambdaBootstrap.Invoke(); } // Catch all unhandled exceptions from runtime, to prevent user from hanging on them while debugging catch (Exception ex) { Console.Error.WriteLine($"\nUnhandled exception occured in runner:\n{ex}"); } }
public IEnumerator BeginSessionSuccessWithValues([ValueSource("beginSessionSuccessResults")] XrResult successResult) { var states = new List <XrSessionState>(); MockRuntime.Instance.TestCallback = (methodName, param) => { if (methodName == nameof(OpenXRFeature.OnSessionStateChange)) { var newState = (XrSessionState)((MockRuntime.XrSessionStateChangedParams)param).NewState; states.Add(newState); } return(true); }; MockRuntime.SetFunctionCallback("xrBeginSession", (name) => successResult); base.InitializeAndStart(); yield return(null); Assert.IsTrue(base.IsRunning <XRDisplaySubsystem>()); switch (successResult) { case XrResult.Success: Assert.IsTrue(states.Contains(XrSessionState.Ready)); Assert.IsTrue(states.Contains(XrSessionState.Synchronized)); Assert.IsTrue(states.Contains(XrSessionState.Visible)); Assert.IsTrue(states.Contains(XrSessionState.Focused)); break; case XrResult.LossPending: Assert.IsTrue(states.Contains(XrSessionState.Ready)); Assert.IsFalse(states.Contains(XrSessionState.Synchronized)); Assert.IsFalse(states.Contains(XrSessionState.Visible)); Assert.IsFalse(states.Contains(XrSessionState.Focused)); break; } }
public IEnumerator CreateSessionFailure() { bool sawCreateSession = false; MockRuntime.Instance.TestCallback = (methodName, param) => { if (methodName == nameof(OpenXRFeature.OnSessionCreate)) { sawCreateSession = true; } return(true); }; MockRuntime.SetFunctionCallback("xrCreateSession", (name) => XrResult.RuntimeFailure); base.InitializeAndStart(); yield return(null); Assert.IsFalse(sawCreateSession); }
public IEnumerator DisplayTransparent() { AddExtension(MockRuntime.XR_UNITY_mock_test); MockRuntime.Instance.TestCallback = (methodName, param) => { if (methodName == nameof(OpenXRFeature.OnInstanceCreate)) { MockRuntime.SetEnvironmentBlendMode(XrEnvironmentBlendMode.Additive); } return(true); }; base.InitializeAndStart(); yield return(null); var displays = new List <XRDisplaySubsystem>(); SubsystemManager.GetInstances(displays); Assert.AreEqual(false, displays[0].displayOpaque); }
public IEnumerator CheckDisplayRestartAfterStopSendRestartEvent() { // Initialize and make sure the frame loop is running InitializeAndStart(); yield return(new WaitForXrFrame()); // Stop the session and make sure xrEndSession is called var endSessionCalled = false; MockRuntime.SetFunctionCallback("xrEndSession", (func, result) => endSessionCalled = true); Stop(); Assert.IsTrue(endSessionCalled); // Restart the display subsystem which should force a restart loader.displaySubsystem.Start(); // Wait for the restart to finish and then wait for a single Xr Frame, if things restarted // properly then the frame loop should be back up and running yield return(new WaitForLoaderRestart()); yield return(new WaitForXrFrame()); }
public virtual void BeforeTest() { // Make sure we are not running if (OpenXRLoaderBase.Instance != null) { StopAndShutdown(); } // Cache off the features before we start savedFeatures = (OpenXRFeature[])OpenXRSettings.Instance.features.Clone(); // Disable all features to make sure the feature list is clean before tests start. DisableAllFeatures(); // Enable the mock runtime and reset it back to default state Assert.IsTrue(EnableMockRuntime()); MockRuntime.ResetDefaults(); OpenXRRuntime.ClearEvents(); OpenXRRestarter.Instance.ResetCallbacks(); #pragma warning disable CS0618 loader = XRGeneralSettings.Instance?.Manager?.loaders[0] as OpenXRLoader; #pragma warning restore CS0618 }
public IEnumerator InvalidLocateSpace() { MockRuntime.Instance.TestCallback = (methodName, param) => { switch (methodName) { case nameof(OpenXRFeature.OnInstanceCreate): // Set the location space to invalid data MockRuntime.SetSpace(XrReferenceSpaceType.View, Vector3.zero, Quaternion.identity, XrSpaceLocationFlags.None); MockRuntime.SetViewState(XrViewConfigurationType.PrimaryStereo, XrViewStateFlags.None); break; } return(true); }; base.InitializeAndStart(); // Wait a few frames to let the input catch up with the renderer yield return(new WaitForXrFrame(2)); MockRuntime.GetEndFrameStats(out var primaryLayerCount, out var secondaryLayerCount); Assert.IsTrue(primaryLayerCount == 0); }
public IEnumerator CauseInstanceLoss() { bool instanceLost = false; MockRuntime.Instance.TestCallback = (methodName, param) => { if (methodName == nameof(OpenXRFeature.OnInstanceLossPending)) { instanceLost = true; } return(true); }; InitializeAndStart(); yield return(null); MockRuntime.CauseInstanceLoss(); yield return(new WaitForLoaderShutdown()); Assert.IsTrue(instanceLost); }
/// Program entry point static void Main(string[] args) { // Add all /var/lang/bin/shared/*/* directories to the search path foreach (var di in new DirectoryInfo("/var/lang/bin/shared").EnumerateDirectories().SelectMany(di => di.EnumerateDirectories().Select(di2 => di2))) { assemblyDirs.Add(di.FullName); } AssemblyLoadContext.Default.Resolving += OnAssemblyResolving; //Console.CancelKeyPress += delegate { // // call methods to clean up //}; Process mockServer = null; try { var shouldWaitForDebugger = GetShouldWaitForDebuggerFlag(args, out var positionalArgs); var handler = GetFunctionHandler(positionalArgs); var body = GetEventBody(positionalArgs); var lambdaRuntime = new MockRuntime(handler, body); mockServer = new Process(); mockServer.StartInfo.FileName = "/var/runtime/mockserver"; mockServer.StartInfo.CreateNoWindow = true; mockServer.StartInfo.RedirectStandardInput = true; mockServer.StartInfo.Environment["DOCKER_LAMBDA_NO_BOOTSTRAP"] = "1"; mockServer.StartInfo.Environment["DOCKER_LAMBDA_USE_STDIN"] = "1"; mockServer.Start(); mockServer.StandardInput.Write(body); mockServer.StandardInput.Close(); if (shouldWaitForDebugger) { Console.Error.WriteLine("Waiting for the debugger to attach..."); if (!DebuggerExtensions.TryWaitForAttaching( _debuggerStatusQueryInterval, _debuggerStatusQueryTimeout)) { Console.Error.WriteLine("Timeout. Proceeding without debugger."); } } var lambdaBootstrap = new LambdaBootstrap(lambdaRuntime, InternalLogger.NO_OP_LOGGER); UnhandledExceptionLogger.Register(); lambdaBootstrap.Initialize(); lambdaBootstrap.Invoke(); } // Catch all unhandled exceptions from runtime, to prevent user from hanging on them while debugging catch (Exception ex) { Console.Error.WriteLine($"\nUnhandled exception occured in runner:\n{ex}"); } finally { if (mockServer != null) { mockServer.Dispose(); } } }