forked from microsoft/vstest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestHostManagerCallbacks.cs
72 lines (61 loc) · 2.64 KB
/
TestHostManagerCallbacks.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Extensions;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host;
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces;
namespace Microsoft.TestPlatform.TestHostProvider.Hosting;
internal class TestHostManagerCallbacks
{
private const int E_HANDLE = unchecked((int)0x80070006);
public static void ErrorReceivedCallback(StringBuilder testHostProcessStdError, string? data)
{
// Log all standard error message because on too much data we ignore starting part.
// This is helpful in abnormal failure of testhost.
EqtTrace.Warning("TestHostManagerCallbacks.ErrorReceivedCallback Test host standard error line: {0}", data);
testHostProcessStdError.AppendSafeWithNewLine(data);
}
public static void ExitCallBack(
IProcessHelper processHelper,
object? process,
StringBuilder testHostProcessStdError,
Action<HostProviderEventArgs> onHostExited)
{
EqtTrace.Verbose("TestHostProvider.ExitCallBack: Host exited starting callback.");
var testHostProcessStdErrorStr = testHostProcessStdError.ToString();
int exitCode = -1;
try
{
processHelper.TryGetExitCode(process, out exitCode);
}
catch (COMException ex) when (ex.HResult == E_HANDLE)
{
EqtTrace.Error("TestHostProvider.ExitCallBack: Invalid process handle we cannot get the error code, error {0}.", ex);
}
int procId = -1;
try
{
if (process is Process p)
{
procId = p.Id;
}
}
catch (InvalidOperationException ex)
{
EqtTrace.Error("TestHostProvider.ExitCallBack: could not get proccess id from process, error: {0}.", ex);
}
if (exitCode != 0)
{
EqtTrace.Error("TestHostManagerCallbacks.ExitCallBack: Testhost processId: {0} exited with exitcode: {1} error: '{2}'", procId, exitCode, testHostProcessStdErrorStr);
}
else
{
EqtTrace.Info("TestHostManagerCallbacks.ExitCallBack: Testhost processId: {0} exited with exitcode: 0 error: '{1}'", procId, testHostProcessStdErrorStr);
}
onHostExited(new HostProviderEventArgs(testHostProcessStdErrorStr, exitCode, procId));
}
}