From 07e417a7b8f2ba9290623af90db47a1db28f5a98 Mon Sep 17 00:00:00 2001 From: Gregg Miskelly Date: Mon, 13 Jul 2026 22:28:31 -0700 Subject: [PATCH 1/2] Support environment variables in config.xml This PR adds support for an `Environment` dictionary in config.xml to make it easy to configure cygwin tests on Windows. --- .../OpenDebug/CrossPlatCpp/DebuggerRunner.cs | 3 ++- .../TestConfigurations/config_msys_gdb.xml | 8 ++++-- .../Attribution/DebuggerSettings.cs | 6 ++++- .../Attribution/TestSettings.cs | 5 ++-- .../Attribution/TestSettingsHelper.cs | 25 +++++++++++++++++-- test/DebuggerTesting/IDebuggerSettings.cs | 2 ++ 6 files changed, 41 insertions(+), 8 deletions(-) diff --git a/test/CppTests/OpenDebug/CrossPlatCpp/DebuggerRunner.cs b/test/CppTests/OpenDebug/CrossPlatCpp/DebuggerRunner.cs index 0ae05f008..adacc6632 100644 --- a/test/CppTests/OpenDebug/CrossPlatCpp/DebuggerRunner.cs +++ b/test/CppTests/OpenDebug/CrossPlatCpp/DebuggerRunner.cs @@ -62,7 +62,8 @@ private DebuggerRunner(ILoggingComponent logger, ITestSettings testSettings, IEn pauseForDebugger: false, isVsDbg: this.DebuggerSettings.DebuggerType == SupportedDebugger.VsDbg, isNative: true, - responseTimeout: 5000); + responseTimeout: 5000, + additionalEnvironmentVariables: this.DebuggerSettings.EnvironmentVariables); if (callbackHandlers != null) { diff --git a/test/CppTests/TestConfigurations/config_msys_gdb.xml b/test/CppTests/TestConfigurations/config_msys_gdb.xml index 695f520f7..d6ee086ad 100644 --- a/test/CppTests/TestConfigurations/config_msys_gdb.xml +++ b/test/CppTests/TestConfigurations/config_msys_gdb.xml @@ -17,7 +17,11 @@ Name="GdbMingw64" Type="Gdb_MinGW" Path="D:\a\_temp\msys64\mingw64\bin\gdb.exe" - AdapterPath="OpenDebugAD7.exe" - /> + AdapterPath="OpenDebugAD7.exe"> + + + + + \ No newline at end of file diff --git a/test/DebuggerTesting/Attribution/DebuggerSettings.cs b/test/DebuggerTesting/Attribution/DebuggerSettings.cs index 3e1c9036b..50fdf2a79 100644 --- a/test/DebuggerTesting/Attribution/DebuggerSettings.cs +++ b/test/DebuggerTesting/Attribution/DebuggerSettings.cs @@ -20,7 +20,8 @@ public DebuggerSettings( string debuggerAdapterPath, string miMode, SupportedArchitecture debuggeeArchitecture, - IDictionary debuggerProperties) + IDictionary debuggerProperties, + IDictionary environmentVariables = null) { this.DebuggeeArchitecture = debuggeeArchitecture; this.DebuggerName = debuggerName; @@ -30,6 +31,7 @@ public DebuggerSettings( if (!string.IsNullOrWhiteSpace(miMode)) this.MIMode = miMode; this.Properties = debuggerProperties ?? new Dictionary(StringComparer.Ordinal); + this.EnvironmentVariables = environmentVariables ?? new Dictionary(StringComparer.OrdinalIgnoreCase); } #endregion @@ -119,6 +121,8 @@ public override string ToString() public IDictionary Properties { get; private set; } + public IDictionary EnvironmentVariables { get; private set; } + #endregion } } diff --git a/test/DebuggerTesting/Attribution/TestSettings.cs b/test/DebuggerTesting/Attribution/TestSettings.cs index e393f1f08..37476de75 100644 --- a/test/DebuggerTesting/Attribution/TestSettings.cs +++ b/test/DebuggerTesting/Attribution/TestSettings.cs @@ -24,10 +24,11 @@ internal TestSettings( string debuggerPath, string debuggerAdapterPath, string miMode, - IDictionary debuggerProperties) + IDictionary debuggerProperties, + IDictionary environmentVariables = null) { this.CompilerSettings = new CompilerSettings(compilerName, compilerType, compilerPath, debuggeeArchitecture, compilerProperties); - this.DebuggerSettings = new DebuggerSettings(debuggerName, debuggerType, debuggerPath, debuggerAdapterPath, miMode, debuggeeArchitecture, debuggerProperties); + this.DebuggerSettings = new DebuggerSettings(debuggerName, debuggerType, debuggerPath, debuggerAdapterPath, miMode, debuggeeArchitecture, debuggerProperties, environmentVariables); } private TestSettings(ITestSettings original, string name) diff --git a/test/DebuggerTesting/Attribution/TestSettingsHelper.cs b/test/DebuggerTesting/Attribution/TestSettingsHelper.cs index 7ca8db5c9..371341469 100644 --- a/test/DebuggerTesting/Attribution/TestSettingsHelper.cs +++ b/test/DebuggerTesting/Attribution/TestSettingsHelper.cs @@ -158,7 +158,8 @@ public static IEnumerable LoadSettingsFromConfig(string configPat Path = x.GetAttributeValue("Path"), AdapterPath = x.GetAttributeValue("AdapterPath"), MIMode = x.GetAttributeValue("MIMode"), - Properties = x.GetPropertiesDictionary() + Properties = x.GetPropertiesDictionary(), + EnvironmentVariables = x.GetEnvironmentDictionary() }); Assert.True(null != debuggers && debuggers.Count != 0, "Object loaded from '{0}' is not a TestMachineConfiguration. Missing Debuggers.".FormatInvariantWithArgs(configPath)); @@ -197,7 +198,8 @@ into config SafeExpandEnvironmentVariables(config.Debugger.Path), SafeExpandEnvironmentVariables(config.Debugger.AdapterPath), config.Debugger.MIMode, - config.Debugger.Properties); + config.Debugger.Properties, + config.Debugger.EnvironmentVariables); // Force evaluation return testSettings.ToArray(); @@ -215,6 +217,25 @@ private static IDictionary GetPropertiesDictionary(this XElement ?.ToDictionary(p => p.GetAttributeValue("Name"), p => SafeExpandEnvironmentVariables(p.Value), StringComparer.Ordinal); } + /// + /// Reads the Environment element and returns its child element names and values as a dictionary. + /// For example: value yields {"Path": "value"} + /// + private static IDictionary GetEnvironmentDictionary(this XElement element) + { + var envElement = element.Element("Environment"); + if (envElement == null) + return null; + + var result = new Dictionary(StringComparer.OrdinalIgnoreCase); + foreach (var child in envElement.Elements()) + { + result[child.Name.LocalName] = SafeExpandEnvironmentVariables(child.Value); + } + + return result.Count > 0 ? result : null; + } + private static bool Matches(this IEnumerable compilers, ICompilerSettings settings) { return compilers.Any(ca => ca.Compiler.HasFlag(settings.CompilerType) && ca.Architecture.HasFlag(settings.DebuggeeArchitecture)); diff --git a/test/DebuggerTesting/IDebuggerSettings.cs b/test/DebuggerTesting/IDebuggerSettings.cs index 0117f3579..d9a4e3079 100644 --- a/test/DebuggerTesting/IDebuggerSettings.cs +++ b/test/DebuggerTesting/IDebuggerSettings.cs @@ -26,6 +26,8 @@ public interface IDebuggerSettings IDictionary Properties { get; } + IDictionary EnvironmentVariables { get; } + #endregion } } From a19eb63bdb0504fa180af21cc27ebfe696881862 Mon Sep 17 00:00:00 2001 From: Gregg Miskelly Date: Tue, 14 Jul 2026 08:05:12 -0700 Subject: [PATCH 2/2] Address Copilot suggestion Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- test/DebuggerTesting/Attribution/TestSettingsHelper.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/DebuggerTesting/Attribution/TestSettingsHelper.cs b/test/DebuggerTesting/Attribution/TestSettingsHelper.cs index 371341469..bda80b539 100644 --- a/test/DebuggerTesting/Attribution/TestSettingsHelper.cs +++ b/test/DebuggerTesting/Attribution/TestSettingsHelper.cs @@ -227,11 +227,9 @@ private static IDictionary GetEnvironmentDictionary(this XElemen if (envElement == null) return null; - var result = new Dictionary(StringComparer.OrdinalIgnoreCase); - foreach (var child in envElement.Elements()) - { - result[child.Name.LocalName] = SafeExpandEnvironmentVariables(child.Value); - } + Dictionary result = envElement + .Elements() + .ToDictionary(e => e.Name.LocalName, e => SafeExpandEnvironmentVariables(e.Value), StringComparer.OrdinalIgnoreCase); return result.Count > 0 ? result : null; }