Esempio n. 1
0
        private static byte[] Serialize(MessageHeader header, TestSessionConfiguration configuration, Stream stream)
        {
            using (var bw = new BinaryWriter(stream))
            {
                bw.Write((uint)header.RequestType);
                bw.Write(header.Pid);

                bw.Write(configuration.CircularBufferSizeInMB);

                bw.WriteString(null);

                if (configuration.Providers == null)
                {
                    bw.Write(0);
                }
                else
                {
                    bw.Write(configuration.Providers.Count());
                    foreach (var provider in configuration.Providers)
                    {
                        bw.Write(provider.Keywords);
                        bw.Write((uint)provider.EventLevel);

                        bw.WriteString(provider.Name);
                        bw.WriteString(provider.FilterData);
                    }
                }

                bw.Flush();
                stream.Position = 0;

                var bytes = new byte[stream.Length];
                stream.Read(bytes, 0, bytes.Length);
                return(bytes);
            }
        }
Esempio n. 2
0
        private static void SendInvalidInputData()
        {
            var configs = new TestSessionConfiguration[] {
                new TestSessionConfiguration {
                    CircularBufferSizeInMB = 0,
                    TestName  = "0 size circular buffer",
                    Providers = new TestProvider[] {
                        new TestProvider {
                            Name = "Microsoft-Windows-DotNETRuntime"
                        },
                    },
                },
                new TestSessionConfiguration {
                    CircularBufferSizeInMB = 64,
                    TestName  = "null providers",
                    Providers = null,
                },
                new TestSessionConfiguration {
                    CircularBufferSizeInMB = 64,
                    TestName  = "no providers",
                    Providers = new TestProvider[] { },
                },
                new TestSessionConfiguration {
                    CircularBufferSizeInMB = 64,
                    TestName  = "null provider name",
                    Providers = new TestProvider[] { new TestProvider {
                                                         Name = null,
                                                     }, },
                },
                new TestSessionConfiguration {
                    CircularBufferSizeInMB = 64,
                    TestName  = "empty provider name",
                    Providers = new TestProvider[] { new TestProvider {
                                                         Name = string.Empty,
                                                     }, },
                },
                new TestSessionConfiguration {
                    CircularBufferSizeInMB = 64,
                    TestName  = "white space provider name",
                    Providers = new TestProvider[] { new TestProvider {
                                                         Name = " ",
                                                     }, },
                },
            };

            foreach (var config in configs)
            {
                ulong sessionId = 0;

                try
                {
                    var header = new MessageHeader {
                        RequestType = DiagnosticsMessageType.CollectEventPipeTracing,
                        Pid         = (uint)Process.GetCurrentProcess().Id,
                    };

                    byte[] bytes;
                    using (var stream = new MemoryStream())
                        bytes = Serialize(header, config, stream);

                    Console.WriteLine($"Test: {config.TestName}");
                    sessionId = EventPipeClient.SendCommand(ThisProcess.Id, bytes);

                    // Check that a session was created.
                    Assert.Equal("EventPipe Session Id", sessionId, (ulong)0);
                }
                catch (EndOfStreamException)
                {
                    Assert.Equal("EventPipe Session Id", sessionId, (ulong)0);
                }
                catch
                {
                    Assert.True("Send command threw unexpected exception", false);
                }
            }
        }