コード例 #1
0
        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));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public IEnumerator CreateSwapChainRuntimeError()
        {
            MockRuntime.SetFunctionCallback("xrCreateSwapchain", (func) => XrResult.RuntimeFailure);

            InitializeAndStart();

            yield return(new WaitForLoaderShutdown());

            Assert.IsTrue(OpenXRLoader.Instance == null, "OpenXR should not be initialized");
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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");
        }
コード例 #7
0
        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);
        }
コード例 #8
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);
        }
コード例 #9
0
        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());
        }
コード例 #10
0
        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());
        }
コード例 #11
0
        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");
        }
コード例 #12
0
        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");
        }
コード例 #13
0
        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");
        }
コード例 #14
0
        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");
        }
コード例 #15
0
        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);
        }
コード例 #16
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));
        }
コード例 #17
0
        /// <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;
        }
コード例 #18
0
        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");
        }
コード例 #19
0
        /// 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}");
            }
        }
コード例 #20
0
        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;
            }
        }
コード例 #21
0
        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);
        }
コード例 #22
0
        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);
        }
コード例 #23
0
        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());
        }
コード例 #24
0
        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
        }
コード例 #25
0
        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);
        }
コード例 #26
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);
        }
コード例 #27
0
        /// 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();
                }
            }
        }