Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve VSTEST_DUMP_PROCDUMPARGUMENTS usage for BlameDataCollector #3957

Merged
merged 5 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TestPlatform.sln
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ Global
src\Microsoft.TestPlatform.Execution.Shared\Microsoft.TestPlatform.Execution.Shared.projitems*{27dfbd04-64b2-4f1b-82b2-006620cca6f8}*SharedItemsImports = 5
src\Microsoft.TestPlatform.Execution.Shared\Microsoft.TestPlatform.Execution.Shared.projitems*{2c7ce1f8-e73e-4987-8023-b5a0ebac86e8}*SharedItemsImports = 5
src\Microsoft.TestPlatform.Execution.Shared\Microsoft.TestPlatform.Execution.Shared.projitems*{71cb42ff-e750-4a3b-9c3a-ac938853cc89}*SharedItemsImports = 5
src\Microsoft.TestPlatform.Execution.Shared\Microsoft.TestPlatform.Execution.Shared.projitems*{76d4bb7e-d981-42d5-be96-6fad8def9a4a}*SharedItemsImports = 5
src\Microsoft.TestPlatform.Execution.Shared\Microsoft.TestPlatform.Execution.Shared.projitems*{7f26eda3-c8c4-4b7f-a9b6-d278c2f40a13}*SharedItemsImports = 13
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
[assembly: InternalsVisibleTo("Microsoft.TestPlatform.CrossPlatEngine, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("vstest.console.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("Microsoft.TestPlatform.Extensions.BlameDataCollector, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("Microsoft.TestPlatform.Extensions.BlameDataCollector.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]

#if !NETSTANDARD1_0
// The following GUID is for the ID of the typelib if this project is exposed to COM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)DebuggerBreakpoint.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UILanguageOverride.cs" />
<Compile Include="$(MSBuildThisFileDirectory)WellKnownDebugEnvironmentVariables.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.VisualStudio.TestPlatform.Execution;

internal static class WellKnownDebugEnvironmentVariables
{
public const string VSTEST_BLAMEDATACOLLECTOR_DEBUG = nameof(VSTEST_BLAMEDATACOLLECTOR_DEBUG);
public const string VSTEST_DATACOLLECTOR_DEBUG = nameof(VSTEST_DATACOLLECTOR_DEBUG);
public const string VSTEST_HOST_DEBUG = nameof(VSTEST_HOST_DEBUG);
public const string VSTEST_RUNNER_DEBUG = nameof(VSTEST_RUNNER_DEBUG);
public const string VSTEST_DATACOLLECTOR_DEBUG_ATTACHVS = nameof(VSTEST_DATACOLLECTOR_DEBUG_ATTACHVS);
public const string VSTEST_HOST_DEBUG_ATTACHVS = nameof(VSTEST_HOST_DEBUG_ATTACHVS);
public const string VSTEST_RUNNER_DEBUG_ATTACHVS = nameof(VSTEST_RUNNER_DEBUG_ATTACHVS);
public const string VSTEST_HOST_NATIVE_DEBUG = nameof(VSTEST_HOST_NATIVE_DEBUG);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Linq;
using System.Xml;

using Microsoft.VisualStudio.TestPlatform.Execution;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
using Microsoft.VisualStudio.TestPlatform.Utilities;
Expand Down Expand Up @@ -118,6 +119,8 @@ public override void Initialize(
DataCollectionLogger logger,
DataCollectionEnvironmentContext? environmentContext)
{
DebuggerBreakpoint.WaitForDebugger(WellKnownDebugEnvironmentVariables.VSTEST_BLAMEDATACOLLECTOR_DEBUG);

_events = events;
_dataCollectionSink = dataSink;
_context = environmentContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<MSBuildWarningsAsMessages>$(MSBuildWarningsAsMessages);MSB3270;MSB3276</MSBuildWarningsAsMessages>
<TestPlatformRoot Condition="$(TestPlatformRoot) == ''">..\..\</TestPlatformRoot>
</PropertyGroup>
<Import Project="$(TestPlatformRoot)src\Microsoft.TestPlatform.Execution.Shared\Microsoft.TestPlatform.Execution.Shared.projitems" Label="Shared" />
<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" />
<PropertyGroup Label="Configuration">
<RootNamespace>Microsoft.TestPlatform.Extensions.BlameDataCollector</RootNamespace>
Expand All @@ -27,7 +28,6 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(TestPlatformRoot)src\Microsoft.TestPlatform.TestHostProvider\Properties\TestExtensionTypesAttribute.cs" Link="Properties\TestExtensionTypesAttribute.cs" />
<Compile Include="..\..\shared\NullableAttributes.cs" Link="NullableAttributes.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Resources.resx" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,22 @@
using System.Collections.Generic;
using System.Text;

using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;

namespace Microsoft.TestPlatform.Extensions.BlameDataCollector;

public class ProcDumpArgsBuilder : IProcDumpArgsBuilder
{
private readonly IEnvironmentVariableHelper _environmentVariableHelper;

public ProcDumpArgsBuilder() : this(new EnvironmentVariableHelper()) { }

internal ProcDumpArgsBuilder(IEnvironmentVariableHelper environmentVariableHelper)
{
_environmentVariableHelper = environmentVariableHelper ?? throw new ArgumentNullException(nameof(environmentVariableHelper));
}

/// <inheritdoc />
public string BuildTriggerBasedProcDumpArgs(int processId, string filename, IEnumerable<string> procDumpExceptionsList, bool isFullDump)
{
Expand All @@ -26,10 +38,10 @@ public string BuildTriggerBasedProcDumpArgs(int processId, string filename, IEnu
// Filter the first chance exceptions only to those that are most likely to kill the whole process.

// Fully override parameters to procdump
var procdumpArgumentsFromEnv = Environment.GetEnvironmentVariable("VSTEST_DUMP_PROCDUMPARGUMENTS")?.Trim();
var procdumpArgumentsFromEnv = _environmentVariableHelper.GetEnvironmentVariable("VSTEST_DUMP_PROCDUMPARGUMENTS")?.Trim();

// Useful additional arguments are -n 100, to collect all dumps that you can, or -o to overwrite dump, or -f EXCEPTION_NAME to add exception to filter list
var procdumpAdditonalArgumentsFromEnv = Environment.GetEnvironmentVariable("VSTEST_DUMP_PROCDUMPADDITIONALARGUMENTS")?.Trim();
var procdumpAdditonalArgumentsFromEnv = _environmentVariableHelper.GetEnvironmentVariable("VSTEST_DUMP_PROCDUMPADDITIONALARGUMENTS")?.Trim();
StringBuilder procDumpArgument = new($"-accepteula -e 1 -g -t {procdumpAdditonalArgumentsFromEnv}");
if (isFullDump)
{
Expand All @@ -42,7 +54,10 @@ public string BuildTriggerBasedProcDumpArgs(int processId, string filename, IEnu
}

procDumpArgument.Append($"{processId} {filename}.dmp");
var argument = procdumpArgumentsFromEnv.IsNullOrWhiteSpace() ? procDumpArgument.ToString() : procdumpArgumentsFromEnv;
var argument = procdumpArgumentsFromEnv.IsNullOrWhiteSpace()
MarcoRossignoli marked this conversation as resolved.
Show resolved Hide resolved
? procDumpArgument.ToString()
: $"-accepteula {procdumpArgumentsFromEnv} {processId} {filename}.dmp";

if (!argument.ToUpperInvariant().Contains("-accepteula".ToUpperInvariant()))
{
argument = $"-accepteula {argument}";
Expand Down
4 changes: 2 additions & 2 deletions src/datacollector/DataCollectorMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ internal DataCollectorMain(IProcessHelper processHelper, IEnvironment environmen

public void Run(string[]? args)
{
DebuggerBreakpoint.AttachVisualStudioDebugger("VSTEST_DATACOLLECTOR_DEBUG_ATTACHVS");
DebuggerBreakpoint.WaitForDebugger("VSTEST_DATACOLLECTOR_DEBUG");
DebuggerBreakpoint.AttachVisualStudioDebugger(WellKnownDebugEnvironmentVariables.VSTEST_DATACOLLECTOR_DEBUG_ATTACHVS);
DebuggerBreakpoint.WaitForDebugger(WellKnownDebugEnvironmentVariables.VSTEST_DATACOLLECTOR_DEBUG);

var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args);

Expand Down
6 changes: 3 additions & 3 deletions src/testhost.x86/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public static void Main(string[]? args)

internal static void Run(string[]? args, UiLanguageOverride uiLanguageOverride)
{
DebuggerBreakpoint.AttachVisualStudioDebugger("VSTEST_HOST_DEBUG_ATTACHVS");
DebuggerBreakpoint.WaitForNativeDebugger("VSTEST_HOST_NATIVE_DEBUG");
DebuggerBreakpoint.WaitForDebugger("VSTEST_HOST_DEBUG");
DebuggerBreakpoint.AttachVisualStudioDebugger(WellKnownDebugEnvironmentVariables.VSTEST_HOST_DEBUG_ATTACHVS);
DebuggerBreakpoint.WaitForNativeDebugger(WellKnownDebugEnvironmentVariables.VSTEST_HOST_NATIVE_DEBUG);
DebuggerBreakpoint.WaitForDebugger(WellKnownDebugEnvironmentVariables.VSTEST_HOST_DEBUG);
uiLanguageOverride.SetCultureSpecifiedByUser();
var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args);

Expand Down
4 changes: 2 additions & 2 deletions src/vstest.console/CommandLine/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ internal class Executor

internal Executor(IOutput output, ITestPlatformEventSource testPlatformEventSource, IProcessHelper processHelper, IEnvironment environment)
{
DebuggerBreakpoint.AttachVisualStudioDebugger("VSTEST_RUNNER_DEBUG_ATTACHVS");
DebuggerBreakpoint.WaitForDebugger("VSTEST_RUNNER_DEBUG");
DebuggerBreakpoint.AttachVisualStudioDebugger(WellKnownDebugEnvironmentVariables.VSTEST_RUNNER_DEBUG_ATTACHVS);
DebuggerBreakpoint.WaitForDebugger(WellKnownDebugEnvironmentVariables.VSTEST_RUNNER_DEBUG);

Output = output;
_testPlatformEventSource = testPlatformEventSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

using System.Collections.Generic;

using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Moq;

namespace Microsoft.TestPlatform.Extensions.BlameDataCollector.UnitTests;

[TestClass]
Expand Down Expand Up @@ -54,4 +57,15 @@ public void BuildTriggerProcDumpArgsWithAlwaysCollectShouldCreateCorrectArgStrin
// adds -t for collect on every process exit
Assert.AreEqual("-accepteula -e 1 -g -t -ma -f a -f b 1234 dump.dmp", argString);
}

[TestMethod]
public void BuildTriggerProcDumpArgsWith_VSTEST_DUMP_PROCDUMPARGUMENTS_EnvironmentVariable()
{
Mock<IEnvironmentVariableHelper> environmentVariableHelper = new();
environmentVariableHelper.Setup(e => e.GetEnvironmentVariable("VSTEST_DUMP_PROCDUMPARGUMENTS")).Returns("-e 1 -g -t -ma");

var procDumpArgsBuilder = new ProcDumpArgsBuilder(environmentVariableHelper.Object);
var argString = procDumpArgsBuilder.BuildTriggerBasedProcDumpArgs(_defaultProcId, _defaultDumpFileName, new List<string> { "a", "b" }, true);
Assert.AreEqual("-accepteula -e 1 -g -t -ma 1234 dump.dmp", argString);
}
}