Skip to content

Commit 7cfd4c0

Browse files
Add extra properties for test results in dotnet test (#44109)
1 parent 8ed29ab commit 7cfd4c0

File tree

7 files changed

+154
-72
lines changed

7 files changed

+154
-72
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
#nullable enable
55

66
namespace Microsoft.DotNet.Tools.Test
77
{
8-
internal sealed record SuccessfulTestResultMessage(string? Uid, string? DisplayName, byte? State, string? Reason, string? SessionUid);
8+
internal sealed record SuccessfulTestResultMessage(string? Uid, string? DisplayName, byte? State, long? Duration, string? Reason, string? StandardOutput, string? ErrorOutput, string? SessionUid);
99

10-
internal sealed record FailedTestResultMessage(string? Uid, string? DisplayName, byte? State, string? Reason, string? ErrorMessage, string? ErrorStackTrace, string? SessionUid);
10+
internal sealed record FailedTestResultMessage(string? Uid, string? DisplayName, byte? State, long? Duration, string? Reason, string? ErrorMessage, string? ErrorStackTrace, string? StandardOutput, string? ErrorOutput, string? SessionUid);
1111

1212
internal sealed record TestResultMessages(string? ExecutionId, SuccessfulTestResultMessage[] SuccessfulTestMessages, FailedTestResultMessage[] FailedTestMessages) : IRequest;
1313
}

src/Cli/dotnet/commands/dotnet-test/IPC/ObjectFieldIds.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,25 @@ internal static class SuccessfulTestResultMessageFieldsId
7171
public const ushort Uid = 1;
7272
public const ushort DisplayName = 2;
7373
public const ushort State = 3;
74-
public const ushort Reason = 4;
75-
public const ushort SessionUid = 5;
74+
public const ushort Duration = 4;
75+
public const ushort Reason = 5;
76+
public const ushort StandardOutput = 6;
77+
public const ushort ErrorOutput = 7;
78+
public const ushort SessionUid = 8;
7679
}
7780

7881
internal static class FailedTestResultMessageFieldsId
7982
{
8083
public const ushort Uid = 1;
8184
public const ushort DisplayName = 2;
8285
public const ushort State = 3;
83-
public const ushort Reason = 4;
84-
public const ushort ErrorMessage = 5;
85-
public const ushort ErrorStackTrace = 6;
86-
public const ushort SessionUid = 7;
86+
public const ushort Duration = 4;
87+
public const ushort Reason = 5;
88+
public const ushort ErrorMessage = 6;
89+
public const ushort ErrorStackTrace = 7;
90+
public const ushort StandardOutput = 8;
91+
public const ushort ErrorOutput = 9;
92+
public const ushort SessionUid = 10;
8793
}
8894

8995
internal static class FileArtifactMessagesFieldsId

src/Cli/dotnet/commands/dotnet-test/IPC/Serializers/BaseSerializer.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,18 @@ protected static void WriteField(Stream stream, ushort id, string? value)
279279
WriteStringValue(stream, value);
280280
}
281281

282+
protected static void WriteField(Stream stream, ushort id, long? value)
283+
{
284+
if (value is null)
285+
{
286+
return;
287+
}
288+
289+
WriteShort(stream, id);
290+
WriteSize<long>(stream);
291+
WriteLong(stream, value.Value);
292+
}
293+
282294
protected static void WriteField(Stream stream, string? value)
283295
{
284296
if (value is null)

src/Cli/dotnet/commands/dotnet-test/IPC/Serializers/TestResultMessagesSerializer.cs

Lines changed: 118 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,74 +10,98 @@
1010
namespace Microsoft.DotNet.Tools.Test
1111
{
1212
/*
13-
|---FieldCount---| 2 bytes
13+
|---FieldCount---| 2 bytes
1414
15-
|---ExecutionId Id---| (2 bytes)
16-
|---ExecutionId Size---| (4 bytes)
17-
|---ExecutionId Value---| (n bytes)
15+
|---ExecutionId Id---| (2 bytes)
16+
|---ExecutionId Size---| (4 bytes)
17+
|---ExecutionId Value---| (n bytes)
1818
19-
|---SuccessfulTestMessageList Id---| (2 bytes)
20-
|---SuccessfulTestMessageList Size---| (4 bytes)
21-
|---SuccessfulTestMessageList Value---| (n bytes)
22-
|---SuccessfulTestMessageList Length---| (4 bytes)
19+
|---SuccessfulTestMessageList Id---| (2 bytes)
20+
|---SuccessfulTestMessageList Size---| (4 bytes)
21+
|---SuccessfulTestMessageList Value---| (n bytes)
22+
|---SuccessfulTestMessageList Length---| (4 bytes)
2323
24-
|---SuccessfulTestMessageList[0] FieldCount---| 2 bytes
24+
|---SuccessfulTestMessageList[0] FieldCount---| 2 bytes
2525
26-
|---SuccessfulTestMessageList[0].Uid Id---| (2 bytes)
27-
|---SuccessfulTestMessageList[0].Uid Size---| (4 bytes)
28-
|---SuccessfulTestMessageList[0].Uid Value---| (n bytes)
26+
|---SuccessfulTestMessageList[0].Uid Id---| (2 bytes)
27+
|---SuccessfulTestMessageList[0].Uid Size---| (4 bytes)
28+
|---SuccessfulTestMessageList[0].Uid Value---| (n bytes)
2929
30-
|---SuccessfulTestMessageList[0].DisplayName Id---| (2 bytes)
31-
|---SuccessfulTestMessageList[0].DisplayName Size---| (4 bytes)
32-
|---SuccessfulTestMessageList[0].DisplayName Value---| (n bytes)
30+
|---SuccessfulTestMessageList[0].DisplayName Id---| (2 bytes)
31+
|---SuccessfulTestMessageList[0].DisplayName Size---| (4 bytes)
32+
|---SuccessfulTestMessageList[0].DisplayName Value---| (n bytes)
3333
34-
|---SuccessfulTestMessageList[0].State Id---| (2 bytes)
35-
|---SuccessfulTestMessageList[0].State Size---| (4 bytes)
36-
|---SuccessfulTestMessageList[0].State Value---| (n bytes)
34+
|---SuccessfulTestMessageList[0].State Id---| (2 bytes)
35+
|---SuccessfulTestMessageList[0].State Size---| (1 byte)
36+
|---SuccessfulTestMessageList[0].State Value---| (n bytes)
3737
38-
|---SuccessfulTestMessageList[0].Reason Id---| (2 bytes)
39-
|---SuccessfulTestMessageList[0].Reason Size---| (4 bytes)
40-
|---SuccessfulTestMessageList[0].Reason Value---| (n bytes)
38+
|---SuccessfulTestMessageList[0].Duration Id---| (2 bytes)
39+
|---SuccessfulTestMessageList[0].Duration Size---| (8 bytes)
40+
|---SuccessfulTestMessageList[0].Duration Value---| (n bytes)
4141
42-
|---SuccessfulTestMessageList[0].SessionUid Id---| (2 bytes)
43-
|---SuccessfulTestMessageList[0].SessionUid Size---| (4 bytes)
44-
|---SuccessfulTestMessageList[0].SessionUid Value---| (n bytes)
42+
|---SuccessfulTestMessageList[0].Reason Id---| (2 bytes)
43+
|---SuccessfulTestMessageList[0].Reason Size---| (4 bytes)
44+
|---SuccessfulTestMessageList[0].Reason Value---| (n bytes)
4545
46-
|---FailedTestMessageList Id---| (2 bytes)
47-
|---FailedTestMessageList Size---| (4 bytes)
48-
|---FailedTestMessageList Value---| (n bytes)
49-
|---FailedTestMessageList Length---| (4 bytes)
46+
|---SuccessfulTestMessageList[0].StandardOutput Id---| (2 bytes)
47+
|---SuccessfulTestMessageList[0].StandardOutput Size---| (4 bytes)
48+
|---SuccessfulTestMessageList[0].StandardOutput Value---| (n bytes)
5049
51-
|---FailedTestMessageList[0] FieldCount---| 2 bytes
50+
|---SuccessfulTestMessageList[0].StandardError Id---| (2 bytes)
51+
|---SuccessfulTestMessageList[0].StandardError Size---| (4 bytes)
52+
|---SuccessfulTestMessageList[0].StandardError Value---| (n bytes)
5253
53-
|---FailedTestMessageList[0].Uid Id---| (2 bytes)
54-
|---FailedTestMessageList[0].Uid Size---| (4 bytes)
55-
|---FailedTestMessageList[0].Uid Value---| (n bytes)
54+
|---SuccessfulTestMessageList[0].SessionUid Id---| (2 bytes)
55+
|---SuccessfulTestMessageList[0].SessionUid Size---| (4 bytes)
56+
|---SuccessfulTestMessageList[0].SessionUid Value---| (n bytes)
5657
57-
|---FailedTestMessageList[0].DisplayName Id---| (2 bytes)
58-
|---FailedTestMessageList[0].DisplayName Size---| (4 bytes)
59-
|---FailedTestMessageList[0].DisplayName Value---| (n bytes)
58+
|---FailedTestMessageList Id---| (2 bytes)
59+
|---FailedTestMessageList Size---| (4 bytes)
60+
|---FailedTestMessageList Value---| (n bytes)
61+
|---FailedTestMessageList Length---| (4 bytes)
6062
61-
|---FailedTestMessageList[0].State Id---| (2 bytes)
62-
|---FailedTestMessageList[0].State Size---| (4 bytes)
63-
|---FailedTestMessageList[0].State Value---| (n bytes)
63+
|---FailedTestMessageList[0] FieldCount---| 2 bytes
6464
65-
|---FailedTestMessageList[0].Reason Id---| (2 bytes)
66-
|---FailedTestMessageList[0].Reason Size---| (4 bytes)
67-
|---FailedTestMessageList[0].Reason Value---| (n bytes)
65+
|---FailedTestMessageList[0].Uid Id---| (2 bytes)
66+
|---FailedTestMessageList[0].Uid Size---| (4 bytes)
67+
|---FailedTestMessageList[0].Uid Value---| (n bytes)
6868
69-
|---FailedTestMessageList[0].ErrorMessage Id---| (2 bytes)
70-
|---FailedTestMessageList[0].ErrorMessage Size---| (4 bytes)
71-
|---FailedTestMessageList[0].ErrorMessage Value---| (n bytes)
69+
|---FailedTestMessageList[0].DisplayName Id---| (2 bytes)
70+
|---FailedTestMessageList[0].DisplayName Size---| (4 bytes)
71+
|---FailedTestMessageList[0].DisplayName Value---| (n bytes)
7272
73-
|---FailedTestMessageList[0].ErrorStackTrace Id---| (2 bytes)
74-
|---FailedTestMessageList[0].ErrorStackTrace Size---| (4 bytes)
75-
|---FailedTestMessageList[0].ErrorStackTrace Value---| (n bytes)
73+
|---FailedTestMessageList[0].State Id---| (2 bytes)
74+
|---FailedTestMessageList[0].State Size---| (1 byte)
75+
|---FailedTestMessageList[0].State Value---| (n bytes)
7676
77-
|---FailedTestMessageList[0].SessionUid Id---| (2 bytes)
78-
|---FailedTestMessageList[0].SessionUid Size---| (4 bytes)
79-
|---FailedTestMessageList[0].SessionUid Value---| (n bytes)
80-
*/
77+
|---SuccessfulTestMessageList[0].Duration Id---| (2 bytes)
78+
|---SuccessfulTestMessageList[0].Duration Size---| (8 bytes)
79+
|---SuccessfulTestMessageList[0].Duration Value---| (n bytes)
80+
81+
|---FailedTestMessageList[0].Reason Id---| (2 bytes)
82+
|---FailedTestMessageList[0].Reason Size---| (4 bytes)
83+
|---FailedTestMessageList[0].Reason Value---| (n bytes)
84+
85+
|---FailedTestMessageList[0].ErrorMessage Id---| (2 bytes)
86+
|---FailedTestMessageList[0].ErrorMessage Size---| (4 bytes)
87+
|---FailedTestMessageList[0].ErrorMessage Value---| (n bytes)
88+
89+
|---FailedTestMessageList[0].ErrorStackTrace Id---| (2 bytes)
90+
|---FailedTestMessageList[0].ErrorStackTrace Size---| (4 bytes)
91+
|---FailedTestMessageList[0].ErrorStackTrace Value---| (n bytes)
92+
93+
|---SuccessfulTestMessageList[0].StandardOutput Id---| (2 bytes)
94+
|---SuccessfulTestMessageList[0].StandardOutput Size---| (4 bytes)
95+
|---SuccessfulTestMessageList[0].StandardOutput Value---| (n bytes)
96+
97+
|---SuccessfulTestMessageList[0].StandardError Id---| (2 bytes)
98+
|---SuccessfulTestMessageList[0].StandardError Size---| (4 bytes)
99+
|---SuccessfulTestMessageList[0].StandardError Value---| (n bytes)
100+
101+
|---FailedTestMessageList[0].SessionUid Id---| (2 bytes)
102+
|---FailedTestMessageList[0].SessionUid Size---| (4 bytes)
103+
|---FailedTestMessageList[0].SessionUid Value---| (n bytes)
104+
*/
81105

82106
internal sealed class TestResultMessagesSerializer : BaseSerializer, INamedPipeSerializer
83107
{
@@ -130,8 +154,9 @@ private static List<SuccessfulTestResultMessage> ReadSuccessfulTestMessagesPaylo
130154
int length = ReadInt(stream);
131155
for (int i = 0; i < length; i++)
132156
{
133-
string? uid = null, displayName = null, reason = null, sessionUid = null;
157+
string? uid = null, displayName = null, reason = null, standardOutput = null, errorOutput = null, sessionUid = null;
134158
byte? state = null;
159+
long? duration = null;
135160

136161
int fieldCount = ReadShort(stream);
137162

@@ -154,10 +179,22 @@ private static List<SuccessfulTestResultMessage> ReadSuccessfulTestMessagesPaylo
154179
state = ReadByte(stream);
155180
break;
156181

182+
case SuccessfulTestResultMessageFieldsId.Duration:
183+
duration = ReadLong(stream);
184+
break;
185+
157186
case SuccessfulTestResultMessageFieldsId.Reason:
158187
reason = ReadStringValue(stream, fieldSize);
159188
break;
160189

190+
case SuccessfulTestResultMessageFieldsId.StandardOutput:
191+
standardOutput = ReadStringValue(stream, fieldSize);
192+
break;
193+
194+
case SuccessfulTestResultMessageFieldsId.ErrorOutput:
195+
errorOutput = ReadStringValue(stream, fieldSize);
196+
break;
197+
161198
case SuccessfulTestResultMessageFieldsId.SessionUid:
162199
sessionUid = ReadStringValue(stream, fieldSize);
163200
break;
@@ -168,7 +205,7 @@ private static List<SuccessfulTestResultMessage> ReadSuccessfulTestMessagesPaylo
168205
}
169206
}
170207

171-
successfulTestResultMessages.Add(new SuccessfulTestResultMessage(uid, displayName, state, reason, sessionUid));
208+
successfulTestResultMessages.Add(new SuccessfulTestResultMessage(uid, displayName, state, duration, reason, standardOutput, errorOutput, sessionUid));
172209
}
173210

174211
return successfulTestResultMessages;
@@ -181,8 +218,10 @@ private static List<FailedTestResultMessage> ReadFailedTestMessagesPayload(Strea
181218
int length = ReadInt(stream);
182219
for (int i = 0; i < length; i++)
183220
{
184-
string? uid = null, displayName = null, reason = null, sessionUid = null, errorMessage = null, errorStackTrace = null;
221+
string? uid = null, displayName = null, reason = null, sessionUid = null,
222+
errorMessage = null, errorStackTrace = null, standardOutput = null, errorOutput = null;
185223
byte? state = null;
224+
long? duration = null;
186225

187226
int fieldCount = ReadShort(stream);
188227

@@ -205,6 +244,10 @@ private static List<FailedTestResultMessage> ReadFailedTestMessagesPayload(Strea
205244
state = ReadByte(stream);
206245
break;
207246

247+
case FailedTestResultMessageFieldsId.Duration:
248+
duration = ReadLong(stream);
249+
break;
250+
208251
case FailedTestResultMessageFieldsId.Reason:
209252
reason = ReadStringValue(stream, fieldSize);
210253
break;
@@ -217,6 +260,14 @@ private static List<FailedTestResultMessage> ReadFailedTestMessagesPayload(Strea
217260
errorStackTrace = ReadStringValue(stream, fieldSize);
218261
break;
219262

263+
case FailedTestResultMessageFieldsId.StandardOutput:
264+
standardOutput = ReadStringValue(stream, fieldSize);
265+
break;
266+
267+
case FailedTestResultMessageFieldsId.ErrorOutput:
268+
errorOutput = ReadStringValue(stream, fieldSize);
269+
break;
270+
220271
case FailedTestResultMessageFieldsId.SessionUid:
221272
sessionUid = ReadStringValue(stream, fieldSize);
222273
break;
@@ -227,7 +278,7 @@ private static List<FailedTestResultMessage> ReadFailedTestMessagesPayload(Strea
227278
}
228279
}
229280

230-
failedTestResultMessages.Add(new FailedTestResultMessage(uid, displayName, state, reason, errorMessage, errorStackTrace, sessionUid));
281+
failedTestResultMessages.Add(new FailedTestResultMessage(uid, displayName, state, duration, reason, errorMessage, errorStackTrace, standardOutput, errorOutput, sessionUid));
231282
}
232283

233284
return failedTestResultMessages;
@@ -268,7 +319,10 @@ private static void WriteSuccessfulTestMessagesPayload(Stream stream, Successful
268319
WriteField(stream, SuccessfulTestResultMessageFieldsId.Uid, successfulTestResultMessage.Uid);
269320
WriteField(stream, SuccessfulTestResultMessageFieldsId.DisplayName, successfulTestResultMessage.DisplayName);
270321
WriteField(stream, SuccessfulTestResultMessageFieldsId.State, successfulTestResultMessage.State);
322+
WriteField(stream, SuccessfulTestResultMessageFieldsId.Duration, successfulTestResultMessage.Duration);
271323
WriteField(stream, SuccessfulTestResultMessageFieldsId.Reason, successfulTestResultMessage.Reason);
324+
WriteField(stream, SuccessfulTestResultMessageFieldsId.StandardOutput, successfulTestResultMessage.StandardOutput);
325+
WriteField(stream, SuccessfulTestResultMessageFieldsId.ErrorOutput, successfulTestResultMessage.ErrorOutput);
272326
WriteField(stream, SuccessfulTestResultMessageFieldsId.SessionUid, successfulTestResultMessage.SessionUid);
273327
}
274328

@@ -299,9 +353,12 @@ private static void WriteFailedTestMessagesPayload(Stream stream, FailedTestResu
299353
WriteField(stream, FailedTestResultMessageFieldsId.Uid, failedTestResultMessage.Uid);
300354
WriteField(stream, FailedTestResultMessageFieldsId.DisplayName, failedTestResultMessage.DisplayName);
301355
WriteField(stream, FailedTestResultMessageFieldsId.State, failedTestResultMessage.State);
356+
WriteField(stream, FailedTestResultMessageFieldsId.Duration, failedTestResultMessage.Duration);
302357
WriteField(stream, FailedTestResultMessageFieldsId.Reason, failedTestResultMessage.Reason);
303358
WriteField(stream, FailedTestResultMessageFieldsId.ErrorMessage, failedTestResultMessage.ErrorMessage);
304359
WriteField(stream, FailedTestResultMessageFieldsId.ErrorStackTrace, failedTestResultMessage.ErrorStackTrace);
360+
WriteField(stream, FailedTestResultMessageFieldsId.StandardOutput, failedTestResultMessage.StandardOutput);
361+
WriteField(stream, FailedTestResultMessageFieldsId.ErrorOutput, failedTestResultMessage.ErrorOutput);
305362
WriteField(stream, FailedTestResultMessageFieldsId.SessionUid, failedTestResultMessage.SessionUid);
306363
}
307364

@@ -319,16 +376,22 @@ private static ushort GetFieldCount(SuccessfulTestResultMessage successfulTestRe
319376
(ushort)((successfulTestResultMessage.Uid is null ? 0 : 1) +
320377
(successfulTestResultMessage.DisplayName is null ? 0 : 1) +
321378
(successfulTestResultMessage.State is null ? 0 : 1) +
379+
(successfulTestResultMessage.Duration is null ? 0 : 1) +
322380
(successfulTestResultMessage.Reason is null ? 0 : 1) +
381+
(successfulTestResultMessage.StandardOutput is null ? 0 : 1) +
382+
(successfulTestResultMessage.ErrorOutput is null ? 0 : 1) +
323383
(successfulTestResultMessage.SessionUid is null ? 0 : 1));
324384

325385
private static ushort GetFieldCount(FailedTestResultMessage failedTestResultMessage) =>
326386
(ushort)((failedTestResultMessage.Uid is null ? 0 : 1) +
327387
(failedTestResultMessage.DisplayName is null ? 0 : 1) +
328388
(failedTestResultMessage.State is null ? 0 : 1) +
389+
(failedTestResultMessage.Duration is null ? 0 : 1) +
329390
(failedTestResultMessage.Reason is null ? 0 : 1) +
330391
(failedTestResultMessage.ErrorMessage is null ? 0 : 1) +
331392
(failedTestResultMessage.ErrorStackTrace is null ? 0 : 1) +
393+
(failedTestResultMessage.StandardOutput is null ? 0 : 1) +
394+
(failedTestResultMessage.ErrorOutput is null ? 0 : 1) +
332395
(failedTestResultMessage.SessionUid is null ? 0 : 1));
333396
}
334397
}

0 commit comments

Comments
 (0)