コード例 #1
0
ファイル: Listeners.cs プロジェクト: ChuangYang/corefx
 internal void EnableTimer(EventSource eventSource, int pollingTime)
 {
     FilteringOptions options = new FilteringOptions();
     options.Args = new Dictionary<string, string>();
     options.Args.Add("EventCounterIntervalSec", pollingTime.ToString());
     EventSourceCommand(eventSource.Name, EventCommand.Enable, options);
 }
コード例 #2
0
ファイル: Listeners.cs プロジェクト: ChuangYang/corefx
 private void DoCommand(EventSource source, EventCommand command, FilteringOptions options)
 {
     if (command == EventCommand.Enable)
         _listener.EnableEvents(source, options.Level, options.Keywords, options.Args);
     else if (command == EventCommand.Disable)
         _listener.DisableEvents(source);
     else
         throw new NotImplementedException();
 }
コード例 #3
0
ファイル: Listeners.cs プロジェクト: ChuangYang/corefx
 public void EventSourceSynchronousEnable(EventSource eventSource, FilteringOptions options = null)
 {
     EventSourceCommand(eventSource.Name, EventCommand.Enable, options);
     WaitForEnable(eventSource);
 }
コード例 #4
0
ファイル: Listeners.cs プロジェクト: ChuangYang/corefx
 public override void EventSourceCommand(string eventSourceName, EventCommand command, FilteringOptions options = null)
 {
     if (options == null)
         options = new FilteringOptions();
     foreach (EventSource source in EventSource.GetSources())
     {
         if (source.Name == eventSourceName)
         {
             DoCommand(source, command, options);
             return;
         }
     }
     _onEventSourceCreated += delegate (EventSource sourceBeingCreated)
     {
         if (eventSourceName != null && eventSourceName == sourceBeingCreated.Name)
         {
             DoCommand(sourceBeingCreated, command, options);
             eventSourceName = null;         // so we only do it once.  
         }
     };
 }
コード例 #5
0
ファイル: Listeners.cs プロジェクト: ChuangYang/corefx
        public override void EventSourceCommand(string eventSourceName, EventCommand command, FilteringOptions options = null)
        {
            if (command == EventCommand.Enable)
            {
                if (options == null)
                    options = new FilteringOptions();

                _session.EnableProvider(eventSourceName, (TraceEventLevel)options.Level, (ulong)options.Keywords,
                    new TraceEventProviderOptions() { Arguments = options.Args });
            }
            else if (command == EventCommand.Disable)
            {
                _session.DisableProvider(TraceEventProviders.GetEventSourceGuidFromName(eventSourceName));
            }
            else
                throw new NotImplementedException();
            Thread.Sleep(200);          // Calls are async, give them time to work.  
        }
コード例 #6
0
ファイル: Listeners.cs プロジェクト: ChuangYang/corefx
 /// <summary>
 /// Send a command to an eventSource.   Be careful this is async.  You may wish to do a WaitForEnable 
 /// </summary>
 public abstract void EventSourceCommand(string eventSourceName, EventCommand command, FilteringOptions options = null);
コード例 #7
0
 public void EventSourceSynchronousEnable(EventSource eventSource, FilteringOptions options = null)
 {
     EventSourceCommand(eventSource.Name, EventCommand.Enable, options);
     WaitForEnable(eventSource);
 }
コード例 #8
0
 public override void EventSourceCommand(string eventSourceName, EventCommand command, FilteringOptions options = null)
 {
     if (options == null)
     {
         options = new FilteringOptions();
     }
     foreach (EventSource source in EventSource.GetSources())
     {
         if (source.Name == eventSourceName)
         {
             DoCommand(source, command, options);
             return;
         }
     }
     _onEventSourceCreated += delegate(EventSource sourceBeingCreated)
     {
         if (eventSourceName != null && eventSourceName == sourceBeingCreated.Name)
         {
             DoCommand(sourceBeingCreated, command, options);
             eventSourceName = null;         // so we only do it once.
         }
     };
 }
コード例 #9
0
 /// <summary>
 /// Send a command to an eventSource.   Be careful this is async.  You may wish to do a WaitForEnable
 /// </summary>
 public abstract void EventSourceCommand(string eventSourceName, EventCommand command, FilteringOptions options = null);
コード例 #10
0
        public override void EventSourceCommand(string eventSourceName, EventCommand command, FilteringOptions options = null)
        {
            if (command == EventCommand.Enable)
            {
                if (options == null)
                {
                    options = new FilteringOptions();
                }

                _session.EnableProvider(eventSourceName, (TraceEventLevel)options.Level, (ulong)options.Keywords,
                                        new TraceEventProviderOptions()
                {
                    Arguments = options.Args
                });
            }
            else if (command == EventCommand.Disable)
            {
                _session.DisableProvider(TraceEventProviders.GetEventSourceGuidFromName(eventSourceName));
            }
            else
            {
                throw new NotImplementedException();
            }
            Thread.Sleep(200);          // Calls are async, give them time to work.
        }
コード例 #11
0
        public override void EventSourceCommand(string eventSourceName, EventCommand command, FilteringOptions options = null)
        {
            EventTestHarness.LogWriteLine("Sending command {0} to EventSource {1} Options {2}", eventSourceName, command, options);

            if (options == null)
            {
                options = new FilteringOptions();
            }

            foreach (EventSource source in EventSource.GetSources())
            {
                if (source.Name == eventSourceName)
                {
                    DoCommand(source, command, options);
                    return;
                }
            }

            _onEventSourceCreated += delegate(EventSource sourceBeingCreated)
            {
                if (eventSourceName != null && eventSourceName == sourceBeingCreated.Name)
                {
                    DoCommand(sourceBeingCreated, command, options);
                    eventSourceName = null;         // so we only do it once.
                }
            };
        }
コード例 #12
0
        /// <summary>
        /// Runs a series of tests 'tests' using the listener (either an ETWListener or an EventListenerListener) on
        /// an EventSource 'source' passing it the filter parameters=options (by default source turn on completely
        ///
        /// Note that this routine calls Dispose on the listener, so it can't be used after that.
        /// </summary>
        public static void RunTests(List <SubTest> tests, Listener listener, EventSource source, FilteringOptions options = null)
        {
            int          expectedTestNumber = 0;
            SubTest      currentTest        = null;
            List <Event> replies            = new List <Event>(2);

            // Wire up the callback to handle the validation when the listener receives events.
            listener.OnEvent = delegate(Event data)
            {
                if (data.ProviderName == "TestHarnessEventSource")
                {
                    Assert.Equal(data.EventName, "StartTest");

                    int testNumber = (int)data.PayloadValue(1, "testNumber");
                    Assert.Equal(expectedTestNumber, testNumber);

                    // Validate that the events that came in during the test are correct.
                    if (currentTest != null)
                    {
                        // You can use the currentTest.Name to set a filter in the harness
                        // tests = tests.FindAll(test => Regex.IsMatch(test.Name, "Write/Basic/EventII")
                        // so the test only runs this one sub-test.   Then you can set
                        // breakpoints to watch the events be generated.
                        //
                        // All events from EventSource infrastructure should be coming from
                        // the ReportOutOfBand, so placing a breakpoint there is typically useful.
                        if (currentTest.EventListValidator != null)
                        {
                            currentTest.EventListValidator(replies);
                        }
                        else
                        {
                            // we only expect exactly one reply
                            Assert.Equal(replies.Count, 1);
                            currentTest.EventValidator(replies[0]);
                        }
                    }
                    replies.Clear();

                    if (testNumber < tests.Count)
                    {
                        currentTest = tests[testNumber];
                        Assert.Equal(currentTest.Name, data.PayloadValue(0, "name"));
                        expectedTestNumber++;
                        _log = new StringWriter();
                        LogWriteLine("STARTING Sub-Test {0}", currentTest.Name);
                    }
                    else
                    {
                        Assert.NotNull(currentTest);
                        Assert.Equal("", data.PayloadValue(0, "name"));
                        Assert.Equal(tests.Count, testNumber);
                        currentTest = null;
                    }
                }
                else
                {
                    LogWriteLine("Received Event {0}", data);
                    // If expectedTestNumber is 0 then this is before the first test
                    // If expectedTestNumber is count then it is after the last test
                    Assert.NotNull(currentTest);
                    replies.Add(data);
                }
            };

            // Run the tests. collecting and validating the results.
            try
            {
                using (TestHarnessEventSource testHarnessEventSource = new TestHarnessEventSource())
                {
                    // Turn on the test EventSource.
                    listener.EventSourceSynchronousEnable(source, options);
                    // And the harnesses's EventSource.
                    listener.EventSourceSynchronousEnable(testHarnessEventSource);

                    // Generate events for all the tests, surrounded by events that tell us we are starting a test.
                    int testNumber = 0;
                    foreach (var test in tests)
                    {
                        testHarnessEventSource.StartTest(test.Name, testNumber);
                        test.EventGenerator();
                        testNumber++;
                    }
                    testHarnessEventSource.StartTest("", testNumber);        // Empty test marks the end of testing.

                    // Disable the listeners.
                    listener.EventSourceCommand(source.Name, EventCommand.Disable);
                    listener.EventSourceCommand(testHarnessEventSource.Name, EventCommand.Disable);

                    // Send something that should be ignored.
                    testHarnessEventSource.IgnoreEvent();
                }
            }
            catch (Exception e)
            {
                if (e is EventSourceException)
                {
                    e = e.InnerException;
                }
                LogWriteLine("Exception thrown: {0}", e.Message);

                var exceptionText = new StringWriter();
                exceptionText.WriteLine("Error Detected in EventTestHarness.RunTest");
                if (currentTest != null)
                {
                    exceptionText.WriteLine("FAILURE IN SUBTEST: \"{0}\"", currentTest.Name);
                }

                exceptionText.WriteLine("************* EXCEPTION INFO ***************");
                exceptionText.WriteLine(e.ToString());
                exceptionText.WriteLine("*********** END EXCEPTION INFO *************");

                if (_log != null)
                {
                    exceptionText.WriteLine("************* LOGGING MESSAGES ***************");
                    exceptionText.WriteLine(_log.ToString());
                    exceptionText.WriteLine("*********** END LOGGING MESSAGES *************");
                }

                exceptionText.WriteLine("Version of Runtime {0}", Environment.Version);
                exceptionText.WriteLine("Version of OS {0}", Environment.OSVersion);
                exceptionText.WriteLine("**********************************************");
                throw new EventTestHarnessException(exceptionText.ToString(), e);
            }

            listener.Dispose();         // Indicate we are done listening.  For the ETW file based cases, we do all the processing here

            // expectedTetst number are the number of tests we successfully ran.
            Assert.Equal(expectedTestNumber, tests.Count);
        }
コード例 #13
0
        /// <summary>
        /// Runs a series of tests 'tests' using the listener (either an ETWListener or an EventListenerListener) on
        /// an EventSource 'source' passing it the filter parameters=options (by default source turn on completely
        ///
        /// Note that this routine calls Dispose on the listener, so it can't be used after that.
        /// </summary>
        public static void RunTests(List <SubTest> tests, Listener listener, EventSource source, FilteringOptions options = null)
        {
            int          expectedTestNumber = 0;
            SubTest      currentTest        = null;
            List <Event> replies            = new List <Event>(2);

            // Wire up the callback to handle the validation when the listener receives events.
            listener.OnEvent = delegate(Event data)
            {
                if (data.ProviderName == "TestHarnessEventSource")
                {
                    Assert.Equal(data.EventName, "StartTest");

                    int testNumber = (int)data.PayloadValue(1, "testNumber");
                    Assert.Equal(expectedTestNumber, testNumber);

                    // Validate that the events that came in during the test are correct.
                    if (currentTest != null)
                    {
                        // You can use the currentTest.Name to set a filter in the harness
                        // tests = tests.FindAll(test => Regex.IsMatch(test.Name, "Write/Basic/EventII")
                        // so the test only runs this one sub-test.   Then you can set
                        // breakpoints to watch the events be generated.
                        //
                        // All events from EventSource infrastructure should be coming from
                        // the ReportOutOfBand, so placing a breakpoint there is typically useful.
                        if (currentTest.EventListValidator != null)
                        {
                            currentTest.EventListValidator(replies);
                        }
                        else
                        {
                            // we only expect exactly one reply
                            Assert.Equal(replies.Count, 1);
                            currentTest.EventValidator(replies[0]);
                        }
                    }
                    replies.Clear();

                    if (testNumber < tests.Count)
                    {
                        currentTest = tests[testNumber];
                        Assert.Equal(currentTest.Name, data.PayloadValue(0, "name"));
                        expectedTestNumber++;
                    }
                    else
                    {
                        Assert.NotNull(currentTest);
                        Assert.Equal("", data.PayloadValue(0, "name"));
                        Assert.Equal(tests.Count, testNumber);
                        currentTest = null;
                    }
                }
                else
                {
                    // If expectedTestNumber is 0 then this is before the first test
                    // If expectedTestNumber is count then it is after the last test
                    Assert.NotNull(currentTest);
                    replies.Add(data);
                }
            };

            // Run the tests. collecting and validating the results.
            try
            {
                using (TestHarnessEventSource testHarnessEventSource = new TestHarnessEventSource())
                {
                    // Turn on the test EventSource.
                    listener.EventSourceSynchronousEnable(source, options);
                    // And the harnesses's EventSource.
                    listener.EventSourceSynchronousEnable(testHarnessEventSource);

                    // Generate events for all the tests, surrounded by events that tell us we are starting a test.
                    int testNumber = 0;
                    foreach (var test in tests)
                    {
                        Console.WriteLine("Starting Sub-Test {0}  thread: {1} time: {2:mm:ss.fff}",
                                          test.Name, System.Threading.Thread.CurrentThread.ManagedThreadId, DateTime.UtcNow);
                        testHarnessEventSource.StartTest(test.Name, testNumber);
                        test.EventGenerator();
                        testNumber++;
                    }
                    testHarnessEventSource.StartTest("", testNumber);        // Empty test marks the end of testing.

                    // Disable the listeners.
                    listener.EventSourceCommand(source.Name, EventCommand.Disable);
                    listener.EventSourceCommand(testHarnessEventSource.Name, EventCommand.Disable);

                    // Send something that should be ignored.
                    testHarnessEventSource.IgnoreEvent();
                }
            }
            finally
            {
                // Run the tests. collecting and validating the results.
                Console.WriteLine("Stopped running tests thread: {0} time: {1:mm:ss.fff}",
                                  System.Threading.Thread.CurrentThread.ManagedThreadId, DateTime.UtcNow);
            }

            listener.Dispose();         // Indicate we are done listening.  For the ETW file based cases, we do all the processing here

            // expectedTetst number are the number of tests we successfully ran.
            Assert.Equal(expectedTestNumber, tests.Count);
        }