예제 #1
0
파일: EtwTests.cs 프로젝트: johnhhm/corefx
        public void TestEtw()
        {
            using (var listener = new TestEventListener("System.Threading.Tasks.Parallel.EventSource", EventLevel.Verbose))
            {
                var events = new ConcurrentQueue<int>();
                listener.RunWithCallback(ev => events.Enqueue(ev.EventId), () => {
                    Parallel.For(0, 10000, i => { });

                    var barrier = new Barrier(2);
                    Parallel.Invoke(
                        () => barrier.SignalAndWait(),
                        () => barrier.SignalAndWait());
                });

                const int BeginLoopEventId = 1;
                const int BeginInvokeEventId = 3;
                Assert.Equal(expected: 1, actual: events.Count(i => i == BeginLoopEventId));
                Assert.Equal(expected: 1, actual: events.Count(i => i == BeginInvokeEventId));

                const int EndLoopEventId = 2;
                const int EndInvokeEventId = 4;
                Assert.Equal(expected: 1, actual: events.Count(i => i == EndLoopEventId));
                Assert.Equal(expected: 1, actual: events.Count(i => i == EndInvokeEventId));

                const int ForkEventId = 5;
                const int JoinEventId = 6;
                Assert.True(events.Count(i => i == ForkEventId) >= 1);
                Assert.Equal(events.Count(i => i == ForkEventId), events.Count(i => i == JoinEventId));
            }
        }
예제 #2
0
 public void EventSource_EventsRaisedAsExpected()
 {
     RemoteInvoke(() =>
     {
         using (var listener = new TestEventListener("Microsoft-System-Net-Primitives", EventLevel.Verbose))
         {
             var events = new ConcurrentQueue<EventWrittenEventArgs>();
             listener.RunWithCallback(events.Enqueue, () =>
             {
                 // Invoke a test that'll cause some events to be generated
                 CredentialCacheTest.Add_HostPortAuthenticationTypeCredential_Success();
             });
             Assert.DoesNotContain(events, ev => ev.EventId == 0); // errors from the EventSource itself
             Assert.InRange(events.Count, 1, int.MaxValue);
         }
         return SuccessExitCode;
     }).Dispose();
 }
예제 #3
0
 public void EventSource_EventsRaisedAsExpected()
 {
     RemoteInvoke(() =>
     {
         using (var listener = new TestEventListener("Microsoft-System-Net-Mail", EventLevel.Verbose))
         {
             var events = new ConcurrentQueue<EventWrittenEventArgs>();
             listener.RunWithCallback(events.Enqueue, () =>
             {
                 // Invoke a test that'll cause some events to be generated
                 new SmtpClientTest().TestMailDelivery();
             });
             Assert.DoesNotContain(events, ev => ev.EventId == 0); // errors from the EventSource itself
             Assert.InRange(events.Count, 1, int.MaxValue);
         }
         return SuccessExitCode;
     }).Dispose();
 }
예제 #4
0
 public void EventSource_EventsRaisedAsExpected()
 {
     RemoteInvoke(() =>
     {
         using (var listener = new TestEventListener("Microsoft-System-Net-Sockets", EventLevel.Verbose))
         {
             var events = new ConcurrentQueue<EventWrittenEventArgs>();
             listener.RunWithCallback(events.Enqueue, () =>
             {
                 // Invoke a test that'll cause some events to be generated
                 new NetworkStreamTest().CopyToAsync_AllDataCopied(4096).GetAwaiter().GetResult();
             });
             Assert.DoesNotContain(events, ev => ev.EventId == 0); // errors from the EventSource itself
             Assert.InRange(events.Count, 1, int.MaxValue);
         }
         return SuccessExitCode;
     }).Dispose();
 }
예제 #5
0
 public void EventSource_EventsRaisedAsExpected()
 {
     RemoteInvoke(() =>
     {
         using (var listener = new TestEventListener("Microsoft-System-Net-Security", EventLevel.Verbose))
         {
             var events = new ConcurrentQueue<EventWrittenEventArgs>();
             listener.RunWithCallback(events.Enqueue, () =>
             {
                 // Invoke tests that'll cause some events to be generated
                 var test = new SslStreamStreamToStreamTest_Async();
                 test.SslStream_StreamToStream_Authentication_Success();
                 test.SslStream_StreamToStream_Successive_ClientWrite_Sync_Success();
             });
             Assert.DoesNotContain(events, ev => ev.EventId == 0); // errors from the EventSource itself
             Assert.InRange(events.Count, 1, int.MaxValue);
         }
         return SuccessExitCode;
     }).Dispose();
 }
예제 #6
0
 public void TestEtw()
 {
     using (var listener = new TestEventListener("System.Threading.SynchronizationEventSource", EventLevel.Verbose))
     {
         const int BarrierPhaseFinishedId = 3;
         const int ExpectedInvocations = 5;
         int eventsRaised = 0;
         int delegateInvocations = 0;
         listener.RunWithCallback(ev => {
                 Assert.Equal(expected: BarrierPhaseFinishedId, actual: ev.EventId);
                 eventsRaised++;
             },
             () => {
                 Barrier b = new Barrier(1, _ => delegateInvocations++);
                 for (int i = 0; i < ExpectedInvocations; i++)
                     b.SignalAndWait();
             });
         Assert.Equal(ExpectedInvocations, delegateInvocations);
         Assert.Equal(ExpectedInvocations, eventsRaised);
     }
 }
예제 #7
0
        public void TestEtw()
        {
            using (var listener = new TestEventListener(new Guid("159eeeec-4a14-4418-a8fe-faabcd987887"), EventLevel.Verbose))
            {
                var events = new ConcurrentQueue<int>();
                listener.RunWithCallback(ev => events.Enqueue(ev.EventId), () => {
                    Enumerable.Range(0, 10000).AsParallel().Select(i => i).ToArray();
                });

                const int BeginEventId = 1;
                Assert.Equal(expected: 1, actual: events.Count(i => i == BeginEventId));

                const int EndEventId = 2;
                Assert.Equal(expected: 1, actual: events.Count(i => i == EndEventId));

                const int ForkEventId = 3;
                const int JoinEventId = 4;
                Assert.True(events.Count(i => i == ForkEventId) > 0);
                Assert.Equal(events.Count(i => i == ForkEventId), events.Count(i => i == JoinEventId));
            }
        }
예제 #8
0
        public void InvokeCodeThatShouldFirEvents_EnsureEventsFired()
        {
            using (var listener = new TestEventListener("System.Data.DataCommonEventSource", EventLevel.Verbose))
            {
                var events = new ConcurrentQueue<EventWrittenEventArgs>();
                listener.RunWithCallback(events.Enqueue, () =>
                {
                    var dt = new DataTable("Players");
                    dt.Columns.Add(new DataColumn("Name", typeof(string)));
                    dt.Columns.Add(new DataColumn("Weight", typeof(int)));

                    var ds = new DataSet();
                    ds.Tables.Add(dt);

                    dt.Rows.Add("John", 150);
                    dt.Rows.Add("Jane", 120);

                    DataRow[] results = dt.Select("Weight < 140");
                    Assert.Equal(1, results.Length);
                });
                Assert.InRange(events.Count, 1, int.MaxValue);
            }
        }
예제 #9
0
파일: EtwTests.cs 프로젝트: SGuyGe/corefx
        public void TestEtw()
        {
            using (var listener = new TestEventListener(new Guid("16F53577-E41D-43D4-B47E-C17025BF4025"), EventLevel.Verbose))
            {
                ActionBlock<int> ab = null;
                BufferBlock<int> bb = null;
                int remaining = 0;
                CountdownEvent ce = new CountdownEvent(0);

                // Check that block creation events fire
                const int DataflowBlockCreatedId = 1;
                remaining = 2;
                listener.RunWithCallback(ev => {
                        Assert.Equal(expected: DataflowBlockCreatedId, actual: ev.EventId);
                        remaining--;
                    },
                    () => {
                        ab = new ActionBlock<int>(i => { });
                        bb = new BufferBlock<int>(); // trigger block creation event
                        Assert.Equal(expected: 0, actual: remaining);
                    });

                // Check that linking events fire
                const int BlockLinkedId = 4;
                remaining = 1;
                IDisposable link = null;
                listener.RunWithCallback(ev => {
                        Assert.Equal(expected: BlockLinkedId, actual: ev.EventId);
                        remaining--;
                    },
                    () => {
                        link = bb.LinkTo(ab);
                        Assert.Equal(expected: 0, actual: remaining);
                    });

                // Check that unlinking events fire
                const int BlockUnlinkedId = 5;
                remaining = 1;
                listener.RunWithCallback(ev => {
                        Assert.Equal(expected: BlockUnlinkedId, actual: ev.EventId);
                        remaining--;
                    },
                    () => {
                        link.Dispose();
                        Assert.Equal(expected: 0, actual: remaining);
                    });

                // Check that task launched events fire
                const int TaskLaunchedId = 2;
                ce.Reset(1);
                listener.RunWithCallback(ev => {
                        Assert.Equal(expected: TaskLaunchedId, actual: ev.EventId);
                        ce.Signal();
                    },
                    () => {
                        ab.Post(42);
                        ce.Wait();
                        Assert.Equal(expected: 0, actual: ce.CurrentCount);
                    });

                // Check that completion events fire
                const int BlockCompletedId = 3;
                ce.Reset(2);
                listener.RunWithCallback(ev => {
                        Assert.Equal(expected: BlockCompletedId, actual: ev.EventId);
                        ce.Signal();
                    },
                    () => {
                        ab.Complete();
                        bb.Complete();
                        ce.Wait();
                        Assert.Equal(expected: 0, actual: ce.CurrentCount);
                    });

            }
        }
예제 #10
0
 private static void ActionFiresSpecificEvent(Action body, int eventId, AutoResetEvent are)
 {
     using (TestEventListener listener = new TestEventListener("System.Buffers.BufferPoolEventSource", EventLevel.Verbose))
     {
         listener.RunWithCallback((EventWrittenEventArgs e) =>
         {
             if (e.EventId == eventId)
                 are.Set();
         }, body);
     }
 }
예제 #11
0
파일: UnitTests.cs 프로젝트: dotnet/corefx
 private static int RunWithListener(Action body, EventLevel level, Action<EventWrittenEventArgs> callback)
 {
     using (TestEventListener listener = new TestEventListener("System.Buffers.ArrayPoolEventSource", level))
     {
         int count = 0;
         listener.RunWithCallback(e =>
         {
             Interlocked.Increment(ref count);
             callback(e);
         }, body);
         return count;
     }
 }
예제 #12
0
파일: EtwTests.cs 프로젝트: noahfalk/corefx
        public void TestEtw()
        {
            using (var listener = new TestEventListener(new Guid("16F53577-E41D-43D4-B47E-C17025BF4025"), EventLevel.Verbose))
            {
                ActionBlock<int> ab = null;
                BufferBlock<int> bb = null;
                int remaining = 0;
                CountdownEvent ce = new CountdownEvent(0);

                // Check that block creation events fire
                const int DataflowBlockCreatedId = 1;
                remaining = 2;
                listener.RunWithCallback(ev => {
                        Assert.Equal(expected: DataflowBlockCreatedId, actual: ev.EventId);
                        remaining--;
                    },
                    () => {
                        ab = new ActionBlock<int>(i => { });
                        bb = new BufferBlock<int>(); // trigger block creation event
                        Assert.Equal(expected: 0, actual: remaining);
                    });

                // Check that linking events fire
                const int BlockLinkedId = 4;
                remaining = 1;
                IDisposable link = null;
                listener.RunWithCallback(ev => {
                        Assert.Equal(expected: BlockLinkedId, actual: ev.EventId);
                        remaining--;
                    },
                    () => {
                        link = bb.LinkTo(ab);
                        Assert.Equal(expected: 0, actual: remaining);
                    });

                // Check that unlinking events fire
                const int BlockUnlinkedId = 5;
                remaining = 1;
                listener.RunWithCallback(ev => {
                        Assert.Equal(expected: BlockUnlinkedId, actual: ev.EventId);
                        remaining--;
                    },
                    () => {
                        link.Dispose();
                        Assert.Equal(expected: 0, actual: remaining);
                    });

                // Bug: It appears that private reflection problems are causing events with enum arguments
                //      to fail to fire on .NET Core.  Needs further investigation.  The following
                //      two tests are disabled as a result.

                //// Check that task launched events fire
                //const int TaskLaunchedId = 2;
                //ce.Reset(1);
                //listener.RunWithCallback(ev => {
                //        Assert.Equal(expected: TaskLaunchedId, actual: ev.EventId);
                //        ce.Signal();
                //    },
                //    () => {
                //        ab.Post(42);
                //        ce.Wait();
                //        Assert.Equal(expected: 0, actual: ce.CurrentCount);
                //    });

                //// Check that completion events fire
                //const int BlockCompletedId = 3;
                //ce.Reset(2);
                //listener.RunWithCallback(ev => {
                //        Assert.Equal(expected: BlockCompletedId, actual: ev.EventId);
                //        ce.Signal();
                //    },
                //    () => {
                //        ab.Complete();
                //        bb.Complete();
                //        ce.Wait();
                //        Assert.Equal(expected: 0, actual: ce.CurrentCount);
                //    });

            }
        }