static partial void Test_WriteEvent_ArgsCornerCases_TestEtw(EventSourceTest log)
        {
            Guid guid = Guid.NewGuid();

            log.EventWithManyTypeArgs("Hello", 0, 0, 0, 'a', 0, 0, 0, 0, (float)10.0, (double)11.0, guid);
            Assert.Equal(25, LoudListener.LastEvent.EventId);
            Assert.Equal(12, LoudListener.LastEvent.Payload.Count);
            Assert.Equal("Hello", (string)LoudListener.LastEvent.Payload[0]);
            Assert.Equal(0, (long)LoudListener.LastEvent.Payload[1]);
            Assert.Equal((uint)0, (uint)LoudListener.LastEvent.Payload[2]);
            Assert.Equal((ulong)0, (ulong)LoudListener.LastEvent.Payload[3]);
            Assert.Equal('a', (char)LoudListener.LastEvent.Payload[4]);
            Assert.Equal((byte)0, (byte)LoudListener.LastEvent.Payload[5]);
            Assert.Equal((sbyte)0, (sbyte)LoudListener.LastEvent.Payload[6]);
            Assert.Equal((short)0, (short)LoudListener.LastEvent.Payload[7]);
            Assert.Equal((ushort)0, (ushort)LoudListener.LastEvent.Payload[8]);
            Assert.Equal((float)10.0, (float)LoudListener.LastEvent.Payload[9]);
            Assert.Equal((double)11.0, (double)LoudListener.LastEvent.Payload[10]);
            Assert.Equal(guid, (Guid)LoudListener.LastEvent.Payload[11]);

            log.EventWithWeirdArgs(IntPtr.Zero, true, MyLongEnum.LongVal1 /*, 9999999999999999999999999999m*/);
            Assert.Equal(30, LoudListener.LastEvent.EventId);
            Assert.Equal(3 /*4*/, LoudListener.LastEvent.Payload.Count);
            Assert.Equal(IntPtr.Zero, (IntPtr)LoudListener.LastEvent.Payload[0]);
            Assert.True((bool)LoudListener.LastEvent.Payload[1]);
            Assert.Equal(MyLongEnum.LongVal1, (MyLongEnum)LoudListener.LastEvent.Payload[2]);
            // Assert.Equal(9999999999999999999999999999m, (decimal)LoudListener.LastEvent.Payload[3]);
        }
예제 #2
0
        public void Test_WriteEvent_ArgsCornerCases()
        {
            TestUtilities.CheckNoEventSourcesRunning("Start");
            using (var log = new EventSourceTest())
            {
                using (var el = new LoudListener())
                {
                    // coverage for EventSource.SendCommand()
                    var options = new Dictionary <string, string>()
                    {
                        { "arg", "val" }
                    };
                    EventSource.SendCommand(log, EventCommand.SendManifest, options);

                    Guid guid = Guid.NewGuid();
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
                    log.EventWithManyTypeArgs("Hello", 0, 0, 0, 'a', 0, 0, 0, 0, (float)10.0, (double)11.0, guid);
                    Assert.Equal(25, LoudListener.LastEvent.EventId);
                    Assert.Equal(12, LoudListener.LastEvent.Payload.Count);
                    Assert.Equal("Hello", (string)LoudListener.LastEvent.Payload[0]);
                    Assert.Equal(0, (long)LoudListener.LastEvent.Payload[1]);
                    Assert.Equal((uint)0, (uint)LoudListener.LastEvent.Payload[2]);
                    Assert.Equal((ulong)0, (ulong)LoudListener.LastEvent.Payload[3]);
                    Assert.Equal('a', (char)LoudListener.LastEvent.Payload[4]);
                    Assert.Equal((byte)0, (byte)LoudListener.LastEvent.Payload[5]);
                    Assert.Equal((sbyte)0, (sbyte)LoudListener.LastEvent.Payload[6]);
                    Assert.Equal((short)0, (short)LoudListener.LastEvent.Payload[7]);
                    Assert.Equal((ushort)0, (ushort)LoudListener.LastEvent.Payload[8]);
                    Assert.Equal((float)10.0, (float)LoudListener.LastEvent.Payload[9]);
                    Assert.Equal((double)11.0, (double)LoudListener.LastEvent.Payload[10]);
                    Assert.Equal(guid, (Guid)LoudListener.LastEvent.Payload[11]);
#endif // USE_ETW
                    log.EventWith7Strings("s0", "s1", "s2", "s3", "s4", "s5", "s6");
                    Assert.Equal(26, LoudListener.LastEvent.EventId);
                    Assert.Equal(7, LoudListener.LastEvent.Payload.Count);
                    Assert.Equal("s0", (string)LoudListener.LastEvent.Payload[0]);
                    Assert.Equal("s6", (string)LoudListener.LastEvent.Payload[6]);

                    log.EventWith9Strings("s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8");
                    Assert.Equal(27, LoudListener.LastEvent.EventId);
                    Assert.Equal(9, LoudListener.LastEvent.Payload.Count);
                    Assert.Equal("s0", (string)LoudListener.LastEvent.Payload[0]);
                    Assert.Equal("s8", (string)LoudListener.LastEvent.Payload[8]);
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
                    log.EventWithWeirdArgs(IntPtr.Zero, true, MyLongEnum.LongVal1 /*, 9999999999999999999999999999m*/);
                    Assert.Equal(30, LoudListener.LastEvent.EventId);
                    Assert.Equal(3 /*4*/, LoudListener.LastEvent.Payload.Count);
                    Assert.Equal(IntPtr.Zero, (IntPtr)LoudListener.LastEvent.Payload[0]);
                    Assert.Equal(true, (bool)LoudListener.LastEvent.Payload[1]);
                    Assert.Equal(MyLongEnum.LongVal1, (MyLongEnum)LoudListener.LastEvent.Payload[2]);
                    // Assert.Equal(9999999999999999999999999999m, (decimal)LoudListener.LastEvent.Payload[3]);
#endif // USE_ETW
                }
            }
            TestUtilities.CheckNoEventSourcesRunning("Stop");
        }
        static partial void Test_WriteEvent_AddEtwTests(List <SubTest> tests, EventSourceTest logger)
        {
            if (!IsProcessElevated)
            {
                return;
            }

            tests.Add(new SubTest("Write/Basic/EventWithManyTypeArgs",
                                  delegate()
            {
                logger.EventWithManyTypeArgs("Hello", 1, 2, 3, 'a', 4, 5, 6, 7,
                                             (float)10.0, (double)11.0, logger.Guid);
            },
                                  delegate(Event evt)
            {
                Assert.Equal(logger.Name, evt.ProviderName);
                Assert.Equal("EventWithManyTypeArgs", evt.EventName);
                Assert.Equal("Hello", evt.PayloadValue(0, "msg"));
                Assert.Equal((float)10.0, evt.PayloadValue(9, "f"));
                Assert.Equal((double)11.0, evt.PayloadValue(10, "d"));
                Assert.Equal(logger.Guid, evt.PayloadValue(11, "guid"));
            }));

            tests.Add(new SubTest("Write/Activity/EventWithXferWeirdArgs",
                                  delegate()
            {
                var actid = Guid.NewGuid();
                logger.EventWithXferWeirdArgs(actid,
                                              (IntPtr)128,
                                              true,
                                              SdtEventSources.MyLongEnum.LongVal1);
            },
                                  delegate(Event evt)
            {
                Assert.Equal(logger.Name, evt.ProviderName);

                // We log EventWithXferWeirdArgs in one case and
                // WorkWeirdArgs/Send in the other
                Assert.Contains("WeirdArgs", evt.EventName);

                Assert.Equal("128", evt.PayloadValue(0, "iptr").ToString());
                Assert.True((bool)evt.PayloadValue(1, "b"));
                Assert.Equal((long)SdtEventSources.MyLongEnum.LongVal1, ((IConvertible)evt.PayloadValue(2, "le")).ToInt64(null));
            }));
        }