Skip to content
Merged
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
30 changes: 23 additions & 7 deletions src/tests/tracing/userevents/common/UserEventsTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Tracing.UserEvents.Tests.Common
public class UserEventsTestRunner
{
private const int SIGINT = 2;
private const int DefaultTraceeExitTimeoutMs = 5000;
private const int DefaultTraceeExitTimeoutMs = 60000;
private const int DefaultRecordTraceExitTimeoutMs = 20000;

// Delay before starting the tracee to let record-trace finish setup. The
Expand Down Expand Up @@ -60,7 +60,9 @@ public static int Run(
enabledEvent.Set();
}

Console.WriteLine("Tracee waiting for EventSource to be enabled via IPC...");
enabledEvent.Wait();
Console.WriteLine("Tracee EventSource enabled, emitting events.");

traceeAction();
return 0;
Expand Down Expand Up @@ -122,6 +124,7 @@ private static int RunOrchestrator(
// As a workaround, deleting the temp file and allowing record-trace to create it works reliably.
File.Delete(traceFilePath);
traceFilePath = Path.ChangeExtension(traceFilePath, ".nettrace");
string recordTraceLogPath = Path.ChangeExtension(traceFilePath, ".log");

ProcessStartInfo recordTraceStartInfo = new();
recordTraceStartInfo.FileName = "sudo";
Expand All @@ -131,6 +134,8 @@ private static int RunOrchestrator(
recordTraceStartInfo.ArgumentList.Add(scriptFilePath);
recordTraceStartInfo.ArgumentList.Add("--out");
recordTraceStartInfo.ArgumentList.Add(traceFilePath);
recordTraceStartInfo.ArgumentList.Add("--log-path");
recordTraceStartInfo.ArgumentList.Add(recordTraceLogPath);
recordTraceStartInfo.WorkingDirectory = userEventsScenarioDir;
recordTraceStartInfo.UseShellExecute = false;
recordTraceStartInfo.RedirectStandardOutput = true;
Expand Down Expand Up @@ -243,14 +248,15 @@ private static int RunOrchestrator(
if (!File.Exists(traceFilePath))
{
Console.Error.WriteLine($"Expected trace file not found at `{traceFilePath}`");
UploadArtifactsFromHelixOnFailure(scenarioName, recordTraceLogPath);
return -1;
}

using EventPipeEventSource source = new EventPipeEventSource(traceFilePath);
if (!traceValidator(traceePid, source))
{
Console.Error.WriteLine($"Trace file `{traceFilePath}` does not contain expected events.");
UploadTraceFileFromHelix(traceFilePath, scenarioName);
UploadArtifactsFromHelixOnFailure(scenarioName, traceFilePath, recordTraceLogPath);
return -1;
}

Expand Down Expand Up @@ -345,14 +351,24 @@ private static void EnsureCleanDiagnosticPorts(string diagnosticPortDir)
}
}

private static void UploadTraceFileFromHelix(string traceFilePath, string scenarioName)
private static void UploadArtifactsFromHelixOnFailure(string scenarioName, params string[] filePaths)
{
var helixWorkItemDirectory = Environment.GetEnvironmentVariable("HELIX_WORKITEM_UPLOAD_ROOT");
if (helixWorkItemDirectory != null && Directory.Exists(helixWorkItemDirectory))
if (helixWorkItemDirectory is null || !Directory.Exists(helixWorkItemDirectory))
return;

foreach (string filePath in filePaths)
{
var destPath = Path.Combine(helixWorkItemDirectory, $"{scenarioName}.nettrace");
Console.WriteLine($"Uploading trace file to Helix work item directory: {destPath}");
File.Copy(traceFilePath, destPath, overwrite: true);
if (!File.Exists(filePath))
{
Console.WriteLine($"Artifact not found at `{filePath}`, skipping upload.");
continue;
}

string extension = Path.GetExtension(filePath);
string destPath = Path.Combine(helixWorkItemDirectory, $"{scenarioName}{extension}");
Console.WriteLine($"Uploading artifact to Helix work item directory: {destPath}");
File.Copy(filePath, destPath, overwrite: true);
}
}
}
Expand Down