Skip to content

Commit

Permalink
Binder tracing tests: print more info on missing start event (#38048)
Browse files Browse the repository at this point in the history
  • Loading branch information
elinor-fung authored Jun 18, 2020
1 parent c85db66 commit 5a0fdae
Showing 1 changed file with 49 additions and 19 deletions.
68 changes: 49 additions & 19 deletions src/coreclr/tests/src/Loader/binding/tracing/BinderEventListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,7 @@ public BindOperation[] WaitAndGetEventsForAssembly(AssemblyName assemblyName)
if (timeWaitedInMs > waitTimeoutInMs)
{
var msg = new System.Text.StringBuilder($"Timed out waiting for bind events for {assemblyName}");
msg.AppendLine("Received events:");
lock (eventsLock)
{
foreach (BindOperation op in bindOperations.Values)
{
msg.AppendLine($"{op.AssemblyName}");
msg.AppendLine($" Completed: {op.Completed}");
msg.AppendLine($" Nested: {op.Nested}");
}
}

msg.AppendLine(GetReceivedEventsAsString());
throw new TimeoutException(msg.ToString());
}
}
Expand Down Expand Up @@ -249,12 +239,15 @@ object GetData(string name)
}
case "AssemblyLoadStop":
{
bool success = (bool)GetData("Success");
string resultName = GetDataString("ResultAssemblyName");
lock (eventsLock)
{
Assert.IsTrue(bindOperations.ContainsKey(data.ActivityId), $"{data.EventName} should have a matching AssemblyBindStart");
if (!bindOperations.ContainsKey(data.ActivityId))
Assert.Fail(GetMisssingAssemblyBindStartMessage(data, $"Success={success}, Name={resultName}"));

BindOperation bind = bindOperations[data.ActivityId];
bind.Success = (bool)GetData("Success");
string resultName = GetDataString("ResultAssemblyName");
bind.Success = success;
if (!string.IsNullOrEmpty(resultName))
{
bind.ResultAssemblyName = new AssemblyName(resultName);
Expand All @@ -270,7 +263,9 @@ object GetData(string name)
ResolutionAttempt attempt = ParseResolutionAttemptedEvent(GetData, GetDataString);
lock (eventsLock)
{
Assert.IsTrue(bindOperations.ContainsKey(data.ActivityId), $"{data.EventName} should have a matching AssemblyBindStart");
if (!bindOperations.ContainsKey(data.ActivityId))
Assert.Fail(GetMisssingAssemblyBindStartMessage(data, attempt.ToString()));

BindOperation bind = bindOperations[data.ActivityId];
bind.ResolutionAttempts.Add(attempt);
}
Expand All @@ -281,7 +276,9 @@ object GetData(string name)
HandlerInvocation handlerInvocation = ParseHandlerInvokedEvent(GetDataString);
lock (eventsLock)
{
Assert.IsTrue(bindOperations.ContainsKey(data.ActivityId), $"{data.EventName} should have a matching AssemblyBindStart");
if (!bindOperations.ContainsKey(data.ActivityId))
Assert.Fail(GetMisssingAssemblyBindStartMessage(data, handlerInvocation.ToString()));

BindOperation bind = bindOperations[data.ActivityId];
bind.AssemblyLoadContextResolvingHandlers.Add(handlerInvocation);
}
Expand All @@ -292,7 +289,9 @@ object GetData(string name)
HandlerInvocation handlerInvocation = ParseHandlerInvokedEvent(GetDataString);
lock (eventsLock)
{
Assert.IsTrue(bindOperations.ContainsKey(data.ActivityId), $"{data.EventName} should have a matching AssemblyBindStart");
if (!bindOperations.ContainsKey(data.ActivityId))
Assert.Fail(GetMisssingAssemblyBindStartMessage(data, handlerInvocation.ToString()));

BindOperation bind = bindOperations[data.ActivityId];
bind.AppDomainAssemblyResolveHandlers.Add(handlerInvocation);
}
Expand All @@ -303,7 +302,9 @@ object GetData(string name)
LoadFromHandlerInvocation loadFrom = ParseLoadFromHandlerInvokedEvent(GetData, GetDataString);
lock (eventsLock)
{
Assert.IsTrue(bindOperations.ContainsKey(data.ActivityId), $"{data.EventName} should have a matching AssemblyBindStart");
if (!bindOperations.ContainsKey(data.ActivityId))
Assert.Fail(GetMisssingAssemblyBindStartMessage(data, loadFrom.ToString()));

BindOperation bind = bindOperations[data.ActivityId];
bind.AssemblyLoadFromHandler = loadFrom;
}
Expand All @@ -314,7 +315,9 @@ object GetData(string name)
ProbedPath probedPath = ParseKnownPathProbedEvent(GetData, GetDataString);
lock (eventsLock)
{
Assert.IsTrue(bindOperations.ContainsKey(data.ActivityId), $"{data.EventName} should have a matching AssemblyBindStart");
if (!bindOperations.ContainsKey(data.ActivityId))
Assert.Fail(GetMisssingAssemblyBindStartMessage(data, probedPath.ToString()));

BindOperation bind = bindOperations[data.ActivityId];
bind.ProbedPaths.Add(probedPath);
}
Expand All @@ -323,6 +326,33 @@ object GetData(string name)
}
}

private string GetMisssingAssemblyBindStartMessage(EventWrittenEventArgs data, string parsedEventAsString)
{
var msg = new System.Text.StringBuilder();
msg.AppendLine($"{data.EventName} (ActivityId: {data.ActivityId}) should have a matching AssemblyBindStart");
msg.AppendLine($"Parsed event: {parsedEventAsString}");
msg.AppendLine(GetReceivedEventsAsString());
return msg.ToString();
}

private string GetReceivedEventsAsString()
{
var msg = new System.Text.StringBuilder();
msg.AppendLine("Received events:");
lock (eventsLock)
{
foreach (BindOperation op in bindOperations.Values)
{
msg.AppendLine(op.ToString());
msg.AppendLine($" - ActivityId: {op.ActivityId}");
msg.AppendLine($" - Completed: {op.Completed}");
msg.AppendLine($" - Nested: {op.Nested}");
}
}

return msg.ToString();
}

private BindOperation ParseAssemblyLoadStartEvent(EventWrittenEventArgs data, Func<string, string> getDataString)
{
var bindOperation = new BindOperation()
Expand Down

0 comments on commit 5a0fdae

Please sign in to comment.