public async Task TestEventStreamCleanup() { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { throw new SkipTestException("Test debugee sigfaults for OSX/Linux"); } Stream eventStream = null; using var cancellationTokenSource = new CancellationTokenSource(); await using (var testExecution = StartTraceeProcess("TestEventStreamCleanup")) { //TestRunner should account for start delay to make sure that the diagnostic pipe is available. var client = new DiagnosticsClient(testExecution.TestRunner.Pid); var settings = new EventTracePipelineSettings() { Duration = Timeout.InfiniteTimeSpan, Configuration = new CpuProfileConfiguration() }; await using var pipeline = new EventTracePipeline(client, settings, (s, token) => { eventStream = s; //Clients should not do this. cancellationTokenSource.Cancel(); token.ThrowIfCancellationRequested(); return(Task.CompletedTask); }); await Assert.ThrowsAsync <OperationCanceledException>(async() => await PipelineTestUtilities.ExecutePipelineWithDebugee(pipeline, testExecution, cancellationTokenSource.Token)); } //Validate that the stream is only valid for the lifetime of the callback in the trace pipeline. Assert.Throws <ObjectDisposedException>(() => eventStream.Read(new byte[4], 0, 4)); }
public async Task TestTraceStopAsync() { Stream eventStream = null; await using (var testExecution = StartTraceeProcess("TraceStopTest")) { //TestRunner should account for start delay to make sure that the diagnostic pipe is available. var client = new DiagnosticsClient(testExecution.TestRunner.Pid); var settings = new EventTracePipelineSettings() { Duration = Timeout.InfiniteTimeSpan, Configuration = new CpuProfileConfiguration() }; var foundProviderSource = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously); await using var pipeline = new EventTracePipeline(client, settings, async(s, token) => { eventStream = s; using var eventSource = new EventPipeEventSource(s); // Dispose event source when cancelled. using var _ = token.Register(() => eventSource.Dispose()); eventSource.Dynamic.All += (TraceEvent obj) => { if (string.Equals(obj.ProviderName, MonitoringSourceConfiguration.SampleProfilerProviderName, StringComparison.OrdinalIgnoreCase)) { foundProviderSource.TrySetResult(null); } }; await Task.Run(() => Assert.True(eventSource.Process()), token); }); await PipelineTestUtilities.ExecutePipelineWithDebugee( _output, pipeline, testExecution, foundProviderSource); } //Validate that the stream is only valid for the lifetime of the callback in the trace pipeline. Assert.Throws <ObjectDisposedException>(() => eventStream.Read(new byte[4], 0, 4)); }
public async Task TestTraceStopAsync() { using var buffer = new MemoryStream(); Stream eventStream = null; await using (var testExecution = StartTraceeProcess("TraceStopTest")) { //TestRunner should account for start delay to make sure that the diagnostic pipe is available. var client = new DiagnosticsClient(testExecution.TestRunner.Pid); var settings = new EventTracePipelineSettings() { Duration = Timeout.InfiniteTimeSpan, Configuration = new CpuProfileConfiguration() }; await using var pipeline = new EventTracePipeline(client, settings, async(s, token) => { await s.CopyToAsync(buffer); eventStream = s; }); await PipelineTestUtilities.ExecutePipelineWithDebugee(pipeline, testExecution); } //Validate that the stream is only valid for the lifetime of the callback in the trace pipeline. Assert.Throws <ObjectDisposedException>(() => eventStream.Read(new byte[4], 0, 4)); Assert.True(buffer.Length > 0); var eventSource = new EventPipeEventSource(buffer); bool foundCpuProvider = false; eventSource.Dynamic.All += (TraceEvent obj) => { if (string.Equals(obj.ProviderName, MonitoringSourceConfiguration.SampleProfilerProviderName, StringComparison.OrdinalIgnoreCase)) { foundCpuProvider = true; } }; Assert.True(eventSource.Process()); Assert.True(foundCpuProvider); }
public async Task TestTraceStopAsync() { using var buffer = new MemoryStream(); await using (var testExecution = StartTraceeProcess("TraceStopTest")) { //TestRunner should account for start delay to make sure that the diagnostic pipe is available. var client = new DiagnosticsClient(testExecution.TestRunner.Pid); var settings = new EventTracePipelineSettings() { Duration = Timeout.InfiniteTimeSpan, Configuration = new CpuProfileConfiguration() }; await using var pipeline = new EventTracePipeline(client, settings, async(s, token) => { //The buffer must be read in order to not hang. The Stop message will not be processed otherwise. await s.CopyToAsync(buffer); }); await PipelineTestUtilities.ExecutePipelineWithDebugee(pipeline, testExecution); } Assert.True(buffer.Length > 0); var eventSource = new EventPipeEventSource(buffer); bool foundCpuProvider = false; eventSource.Dynamic.All += (TraceEvent obj) => { if (string.Equals(obj.ProviderName, MonitoringSourceConfiguration.SampleProfilerProviderName, StringComparison.OrdinalIgnoreCase)) { foundCpuProvider = true; } }; Assert.True(eventSource.Process()); Assert.True(foundCpuProvider); }