Exemplo n.º 1
0
        /// <summary>
        /// Test for the method overload: public EventPipeSession StartEventPipeSession(EventPipeProvider provider, bool requestRundown=true, int circularBufferMB=256)
        /// </summary>
        private async Task StartEventPipeSessionWithSingleProviderTestCore(bool useAsync)
        {
            using TestRunner runner = new TestRunner(CommonHelper.GetTraceePathWithArgs(), output);
            runner.Start(timeoutInMSPipeCreation: 15_000, testProcessTimeout: 60_000);
            DiagnosticsClientApiShim clientShim = new DiagnosticsClientApiShim(new DiagnosticsClient(runner.Pid), useAsync);

            using (var session = await clientShim.StartEventPipeSession(new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Informational)))
            {
                Assert.True(session.EventStream != null);
            }
            runner.Stop();
        }
        public void StartEventPipeSessionWithSingleProviderTest()
        {
            using TestRunner runner = new TestRunner(CommonHelper.GetTraceePathWithArgs(), output);
            runner.Start(timeoutInMSPipeCreation: 3000);
            DiagnosticsClient client = new DiagnosticsClient(runner.Pid);

            using (var session = client.StartEventPipeSession(new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Informational)))
            {
                Assert.True(session.EventStream != null);
            }
            runner.Stop();
        }
        public void PublishedProcessTest1()
        {
            TestRunner runner = new TestRunner(CommonHelper.GetTraceePath(), output);

            runner.Start(3000);
            List <int> publishedProcesses = new List <int>(DiagnosticsClient.GetPublishedProcesses());

            foreach (int p in publishedProcesses)
            {
                output.WriteLine($"[{DateTime.Now.ToString()}] Saw published process {p}");
            }
            Assert.Contains(publishedProcesses, p => p == runner.Pid);
            runner.Stop();
        }
        public void CheckSpecificProcessTest()
        {
            TestRunner runner = new TestRunner(CommonHelper.GetTraceePath(), output);

            runner.Start(3000);
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Thread.Sleep(5000);
            }

            var client = new DiagnosticsClient(runner.Pid);

            Assert.True(client.CheckTransport(), $"Unable to verify diagnostics transport for test process {runner.Pid}.");

            runner.Stop();
        }
Exemplo n.º 5
0
        public void BasicEventPipeSessionTest()
        {
            TestRunner runner = new TestRunner(CommonHelper.GetTraceePath(), output);

            runner.Start(3000);
            DiagnosticsClient client = new DiagnosticsClient(runner.Pid);

            using (var session = client.StartEventPipeSession(new List <EventPipeProvider>()
            {
                new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Informational)
            }))
            {
                Assert.True(session.EventStream != null);
            }
            runner.Stop();
        }
        public void BasicEnvTest()
        {
            // as the attribute says, this test requires 5.0-rc1 or newer.  This has been tested locally on
            // an rc1 build and passes.  It is equivalent to the dotnet/runtime version of this test.
            TestRunner runner  = new TestRunner(CommonHelper.GetTraceePathWithArgs(targetFramework: "net5.0"), output);
            string     testKey = "FOO";
            string     testVal = "BAR";

            runner.AddEnvVar(testKey, testVal);
            runner.Start(3000);
            DiagnosticsClient           client = new DiagnosticsClient(runner.Pid);
            Dictionary <string, string> env    = client.GetProcessEnvironment();

            Assert.True(env.ContainsKey(testKey) && env[testKey].Equals(testVal));

            runner.Stop();
        }
        /// <summary>
        /// A simple test that collects process environment.
        /// </summary>
        private async Task BasicEnvTestCore(bool useAsync)
        {
            // as the attribute says, this test requires 5.0-rc1 or newer.  This has been tested locally on
            // an rc1 build and passes.  It is equivalent to the dotnet/runtime version of this test.
            using TestRunner runner = new TestRunner(CommonHelper.GetTraceePathWithArgs(targetFramework: "net5.0"), output);
            string testKey = "FOO";
            string testVal = "BAR";

            runner.AddEnvVar(testKey, testVal);
            runner.Start(timeoutInMSPipeCreation: 3000);
            var clientShim = new DiagnosticsClientApiShim(new DiagnosticsClient(runner.Pid), useAsync);
            Dictionary <string, string> env = await clientShim.GetProcessEnvironment();

            Assert.True(env.ContainsKey(testKey) && env[testKey].Equals(testVal));

            runner.Stop();
        }
Exemplo n.º 8
0
        public void EventPipeSessionStreamTest()
        {
            TestRunner runner = new TestRunner(CommonHelper.GetTraceePathWithArgs(), output);

            runner.Start(3000);
            DiagnosticsClient client = new DiagnosticsClient(runner.Pid);

            runner.PrintStatus();
            output.WriteLine($"[{DateTime.Now.ToString()}] Trying to start an EventPipe session on process {runner.Pid}");
            using (var session = client.StartEventPipeSession(new List <EventPipeProvider>()
            {
                new EventPipeProvider("System.Runtime", EventLevel.Informational, 0, new Dictionary <string, string>()
                {
                    { "EventCounterIntervalSec", "1" }
                })
            }))
            {
                var evntCnt = 0;

                Task streamTask = Task.Run(() => {
                    var source          = new EventPipeEventSource(session.EventStream);
                    source.Dynamic.All += (TraceEvent obj) => {
                        output.WriteLine("Got an event");
                        evntCnt += 1;
                    };
                    try
                    {
                        source.Process();
                    }
                    catch (Exception e)
                    {
                        // This exception can happen if the target process exits while EventPipeEventSource is in the middle of reading from the pipe.
                        Console.WriteLine("Error encountered while processing events");
                        Console.WriteLine(e.ToString());
                    }
                    finally
                    {
                        runner.Stop();
                    }
                });
                output.WriteLine("Waiting for stream Task");
                streamTask.Wait(10000);
                output.WriteLine("Done waiting for stream Task");
                Assert.True(evntCnt > 0);
            }
        }
Exemplo n.º 9
0
        public async Task ReversedServerSingleTargetExitsClientInviableTest()
        {
            await using var server = CreateReversedServer(out string transportName);
            server.Start();

            TestRunner      runner = null;
            IpcEndpointInfo info;

            try
            {
                // Start client pointing to diagnostics server
                runner = StartTracee(transportName);

                // Get client connection
                info = await AcceptAsync(server);

                await VerifyEndpointInfo(runner, info);

                // There should not be any new endpoint infos
                await VerifyNoNewEndpointInfos(server);

                ResumeRuntime(info);

                await VerifyWaitForConnection(info);
            }
            finally
            {
                _outputHelper.WriteLine("Stopping tracee.");
                runner?.Stop();
            }

            // Wait some time for the process to exit
            await Task.Delay(TimeSpan.FromSeconds(1));

            // Process exited so the endpoint should not have a valid transport anymore.
            await VerifyWaitForConnection(info, expectValid : false);

            Assert.True(server.RemoveConnection(info.RuntimeInstanceCookie), "Expected to be able to remove connection from server.");

            // There should not be any more endpoint infos
            await VerifyNoNewEndpointInfos(server);
        }
        public void PublishedProcessTest1()
        {
            using TestRunner runner = new TestRunner(CommonHelper.GetTraceePathWithArgs(), output);
            runner.Start(timeoutInMSPipeCreation: 3000);
            // On Windows, runner.Start will not wait for named pipe creation since for other tests, NamedPipeClientStream will
            // just wait until the named pipe is created.
            // For these tests, we need to sleep an arbitrary time before pipe is created.
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Thread.Sleep(5000);
            }
            List <int> publishedProcesses = new List <int>(DiagnosticsClient.GetPublishedProcesses());

            foreach (int p in publishedProcesses)
            {
                output.WriteLine($"[{DateTime.Now.ToString()}] Saw published process {p}");
            }
            Assert.Contains(publishedProcesses, p => p == runner.Pid);
            runner.Stop();
        }
Exemplo n.º 11
0
        public void WriteAllDumpTypesTest()
        {
            var normalDumpPath = "./myDump-normal.dmp";
            var heapDumpPath   = "./myDump-heap.dmp";
            var triageDumpPath = "./myDump-triage.dmp";
            var fullDumpPath   = "./myDump-full.dmp";

            using TestRunner runner = new TestRunner(CommonHelper.GetTraceePathWithArgs(), output);
            runner.Start(3000);
            DiagnosticsClient client = new DiagnosticsClient(runner.Pid);

            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                Assert.Throws <PlatformNotSupportedException>(() => client.WriteDump(DumpType.Normal, normalDumpPath));
                Assert.Throws <PlatformNotSupportedException>(() => client.WriteDump(DumpType.WithHeap, heapDumpPath));
                Assert.Throws <PlatformNotSupportedException>(() => client.WriteDump(DumpType.Triage, triageDumpPath));
                Assert.Throws <PlatformNotSupportedException>(() => client.WriteDump(DumpType.Full, fullDumpPath));
            }
            else
            {
                // Write each type of dump
                output.WriteLine($"Requesting dump at {DateTime.Now.ToString()}");
                client.WriteDump(DumpType.Normal, normalDumpPath);
                client.WriteDump(DumpType.WithHeap, heapDumpPath);
                client.WriteDump(DumpType.Triage, triageDumpPath);
                client.WriteDump(DumpType.Full, fullDumpPath);

                // Check they were all created
                Assert.True(File.Exists(normalDumpPath));
                Assert.True(File.Exists(heapDumpPath));
                Assert.True(File.Exists(triageDumpPath));
                Assert.True(File.Exists(fullDumpPath));

                // Remove them
                File.Delete(normalDumpPath);
                File.Delete(heapDumpPath);
                File.Delete(triageDumpPath);
                File.Delete(fullDumpPath);
            }
            runner.Stop();
        }
Exemplo n.º 12
0
        public async Task ReversedServerNoCreateTransportAfterDispose()
        {
            var transportCallback = new IpcServerTransportCallback();

            int        transportVersion = 0;
            TestRunner runner           = null;

            try
            {
                await using var server   = CreateReversedServer(out string transportName);
                server.TransportCallback = transportCallback;
                server.Start();

                // Start client pointing to diagnostics server
                runner = StartTracee(transportName);

                // Get client connection
                IpcEndpointInfo info = await AcceptEndpointInfo(server, useAsync : true);

                await VerifyEndpointInfo(runner, info, useAsync : true);

                // There should not be any new endpoint infos
                await VerifyNoNewEndpointInfos(server, useAsync : true);

                ResumeRuntime(info);

                await VerifyWaitForConnection(info, useAsync : true);

                transportVersion = await transportCallback.GetStableTransportVersion();

                // Server will be disposed
            }
            finally
            {
                _outputHelper.WriteLine("Stopping tracee.");
                runner?.Stop();
            }

            // Check that the reversed server did not create a new server transport upon disposal.
            Assert.Equal(transportVersion, await transportCallback.GetStableTransportVersion());
        }
Exemplo n.º 13
0
        public void BasicWriteDumpTest()
        {
            var        dumpPath = "./myDump.dmp";
            TestRunner runner   = new TestRunner(CommonHelper.GetTraceePath(), output);

            runner.Start(3000);
            DiagnosticsClient client = new DiagnosticsClient(runner.Pid);

            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                Assert.Throws <PlatformNotSupportedException>(() => client.WriteDump(DumpType.Normal, dumpPath));
            }
            else
            {
                output.WriteLine($"Requesting dump at {DateTime.Now.ToString()}");
                client.WriteDump(DumpType.Normal, dumpPath);
                Assert.True(File.Exists(dumpPath));
                File.Delete(dumpPath);
            }
            runner.Stop();
        }
        public async Task WaitForConnectionTest()
        {
            using TestRunner runner = new TestRunner(CommonHelper.GetTraceePathWithArgs(), output);
            runner.Start(timeoutInMSPipeCreation: 3000);
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Thread.Sleep(5000);
            }

            var client = new DiagnosticsClient(runner.Pid);

            using var timeoutSource = new CancellationTokenSource(TimeSpan.FromMilliseconds(250));
            try
            {
                await client.WaitForConnectionAsync(timeoutSource.Token);
            }
            finally
            {
                runner.Stop();
            }
        }
Exemplo n.º 15
0
        public void BasicWriteDumpTest()
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                var dumpPath = "./myDump.dmp";
                using TestRunner runner = new TestRunner(CommonHelper.GetTraceePathWithArgs(), output);
                runner.Start(timeoutInMSPipeCreation: 3000);
                DiagnosticsClient client = new DiagnosticsClient(runner.Pid);

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Environment.Version.ToString().StartsWith("3"))
                {
                    Assert.Throws <UnsupportedCommandException>(() => client.WriteDump(DumpType.Normal, dumpPath));
                }
                else
                {
                    output.WriteLine($"Requesting dump at {DateTime.Now.ToString()}");
                    client.WriteDump(DumpType.Normal, dumpPath);
                    Assert.True(File.Exists(dumpPath));
                    File.Delete(dumpPath);
                }

                runner.Stop();
            }
        }