From a5bf178b3883f67d57cc4f067a1881c590fe3c07 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 6 Mar 2023 19:19:25 +0900 Subject: [PATCH] Mode env variables to FrameworkEnvironment --- osu.Framework/FrameworkEnvironment.cs | 22 +++++++++++++++++++ osu.Framework/Platform/HeadlessGameHost.cs | 6 ++--- .../Drawables/Steps/UntilStepButton.cs | 2 +- osu.Framework/Testing/TestScene.cs | 2 +- 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 osu.Framework/FrameworkEnvironment.cs diff --git a/osu.Framework/FrameworkEnvironment.cs b/osu.Framework/FrameworkEnvironment.cs new file mode 100644 index 000000000..e94a38819 --- /dev/null +++ b/osu.Framework/FrameworkEnvironment.cs @@ -0,0 +1,22 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using osu.Framework.Platform; + +namespace osu.Framework +{ + public static class FrameworkEnvironment + { + public static readonly ExecutionMode? STARTUP_EXECUTION_MODE; + public static readonly bool NO_TEST_TIMEOUT; + public static readonly bool FORCE_TEST_GC; + + static FrameworkEnvironment() + { + STARTUP_EXECUTION_MODE = Enum.TryParse(Environment.GetEnvironmentVariable("OSU_EXECUTION_MODE"), true, out var mode) ? mode : null; + NO_TEST_TIMEOUT = Environment.GetEnvironmentVariable("OSU_TESTS_NO_TIMEOUT") == "1"; + FORCE_TEST_GC = Environment.GetEnvironmentVariable("OSU_TESTS_FORCED_GC") == "1"; + } + } +} diff --git a/osu.Framework/Platform/HeadlessGameHost.cs b/osu.Framework/Platform/HeadlessGameHost.cs index 49c41ceec..6a0f7b675 100644 --- a/osu.Framework/Platform/HeadlessGameHost.cs +++ b/osu.Framework/Platform/HeadlessGameHost.cs @@ -52,10 +52,10 @@ namespace osu.Framework.Platform base.SetupConfig(defaultOverrides); - if (Enum.TryParse(Environment.GetEnvironmentVariable("OSU_EXECUTION_MODE"), out var mode)) + if (FrameworkEnvironment.STARTUP_EXECUTION_MODE != null) { - Config.SetValue(FrameworkSetting.ExecutionMode, mode); - Logger.Log($"Startup execution mode set to {mode} from envvar"); + Config.SetValue(FrameworkSetting.ExecutionMode, FrameworkEnvironment.STARTUP_EXECUTION_MODE); + Logger.Log($"Startup execution mode set to {FrameworkEnvironment.STARTUP_EXECUTION_MODE} from envvar"); } } diff --git a/osu.Framework/Testing/Drawables/Steps/UntilStepButton.cs b/osu.Framework/Testing/Drawables/Steps/UntilStepButton.cs index eb26a39cb..9048ce06d 100644 --- a/osu.Framework/Testing/Drawables/Steps/UntilStepButton.cs +++ b/osu.Framework/Testing/Drawables/Steps/UntilStepButton.cs @@ -17,7 +17,7 @@ namespace osu.Framework.Testing.Drawables.Steps private int invocations; - private static readonly int max_attempt_milliseconds = Environment.GetEnvironmentVariable("OSU_TESTS_NO_TIMEOUT") == "1" ? int.MaxValue : 10000; + private static readonly int max_attempt_milliseconds = FrameworkEnvironment.NO_TEST_TIMEOUT ? int.MaxValue : 10000; public override int RequiredRepetitions => success ? 0 : int.MaxValue; diff --git a/osu.Framework/Testing/TestScene.cs b/osu.Framework/Testing/TestScene.cs index 74ce7c6e2..10a615633 100644 --- a/osu.Framework/Testing/TestScene.cs +++ b/osu.Framework/Testing/TestScene.cs @@ -470,7 +470,7 @@ namespace osu.Framework.Testing runner.RunTestBlocking(this); checkForErrors(); - if (Environment.GetEnvironmentVariable("OSU_TESTS_FORCED_GC") == "1") + if (FrameworkEnvironment.FORCE_TEST_GC) { // Force any unobserved exceptions to fire against the current test run. // Without this they could be delayed until a future test scene is running, making tracking down the cause difficult.