Commit 5870eb3e authored by David Kline's avatar David Kline Committed by GitHub
Browse files

Merge pull request #213 from CBaud/master

Issue #31: ETW APIs are unimplemented
parents 6d23ead9 42c7ed84
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -40,8 +40,11 @@ namespace MockDataGenerator
            new Endpoint(HttpMethods.Get, DevicePortal.IpConfigApi),
            new Endpoint(HttpMethods.Get, DevicePortal.SystemPerfApi),
            new Endpoint(HttpMethods.Get, DevicePortal.RunningProcessApi),
            new Endpoint(HttpMethods.Get, DevicePortal.CustomEtwProvidersApi),
            new Endpoint(HttpMethods.Get, DevicePortal.EtwProvidersApi),
            new Endpoint(HttpMethods.WebSocket, DevicePortal.SystemPerfApi),
            new Endpoint(HttpMethods.WebSocket, DevicePortal.RunningProcessApi),
            new Endpoint(HttpMethods.WebSocket, DevicePortal.RealtimeEtwSessionApi),

            // HoloLens specific endpoints
            new Endpoint(HttpMethods.Get, DevicePortal.HolographicIpdApi),
+112 −0
Original line number Diff line number Diff line
//----------------------------------------------------------------------------------------------
// <copyright file="EtwTests.cs" company="Microsoft Corporation">
//     Licensed under the MIT License. See LICENSE.TXT in the project root license information.
// </copyright>
//----------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static Microsoft.Tools.WindowsDevicePortal.DevicePortal;

namespace Microsoft.Tools.WindowsDevicePortal.Tests.Core
{
    /// <summary>
    /// Test class for ETW APIs.
    /// </summary>
    [TestClass]
    public class EtwTests : BaseTests
    {
        /// <summary>
        /// Basic test of GET method for getting a list of custom registered ETW providers.
        /// </summary>
        [TestMethod]
        public void GetCustomEtwProvidersTest()
        {
            TestHelpers.MockHttpResponder.AddMockResponse(DevicePortal.CustomEtwProvidersApi, HttpMethods.Get);

            Task<EtwProviders> getCustomEtwProvidersTask = TestHelpers.Portal.GetCustomEtwProvidersAsync();
            getCustomEtwProvidersTask.Wait();

            Assert.AreEqual(TaskStatus.RanToCompletion, getCustomEtwProvidersTask.Status);

            ValidateEtwProviders(getCustomEtwProvidersTask.Result);
        }

        /// <summary>
        /// Basic test of GET method for getting a list of registered ETW providers.
        /// </summary>
        [TestMethod]
        public void GetEtwProvidersTest()
        {
            TestHelpers.MockHttpResponder.AddMockResponse(DevicePortal.EtwProvidersApi, HttpMethods.Get);

            Task<EtwProviders> getEtwProvidersTask = TestHelpers.Portal.GetEtwProvidersAsync();
            getEtwProvidersTask.Wait();

            Assert.AreEqual(TaskStatus.RanToCompletion, getEtwProvidersTask.Status);

            ValidateEtwProviders(getEtwProvidersTask.Result);
        }

        [TestMethod]
        public void GetEtwEventsTest()
        {
            TestHelpers.MockHttpResponder.AddMockResponse(DevicePortal.RealtimeEtwSessionApi, HttpMethods.WebSocket);

            ManualResetEvent etwEventsReceived = new ManualResetEvent(false);
            EtwEvents etwEvents = null;

            WindowsDevicePortal.WebSocketMessageReceivedEventHandler<EtwEvents> etwEventsReceivedHandler =
                delegate (DevicePortal sender, WebSocketMessageReceivedEventArgs<EtwEvents> args)
                {
                    if (args.Message != null)
                    {
                        etwEvents = args.Message;
                        etwEventsReceived.Set();
                    }
                };

            TestHelpers.Portal.RealtimeEventsMessageReceived += etwEventsReceivedHandler;

            Task startListeningForEtwEventsTask = TestHelpers.Portal.StartListeningForEtwEventsAsync();
            startListeningForEtwEventsTask.Wait();
            Assert.AreEqual(TaskStatus.RanToCompletion, startListeningForEtwEventsTask.Status);

            etwEventsReceived.WaitOne();

            Task stopListeningForEtwEventsTask = TestHelpers.Portal.StopListeningForEtwEventsAsync();
            stopListeningForEtwEventsTask.Wait();
            Assert.AreEqual(TaskStatus.RanToCompletion, stopListeningForEtwEventsTask.Status);

            TestHelpers.Portal.RealtimeEventsMessageReceived -= etwEventsReceivedHandler;

            ValidateEtwEvents(etwEvents);
        }

        /// <summary>
        /// Validate the <see cref="EtwEvents"/>  returned from the tests.
        /// </summary>
        /// <param name="etwEvents">The <see cref="EtwEvents"/> to validate.</param>
        private static void ValidateEtwEvents(EtwEvents etwEvents)
        {
            Assert.IsNotNull(etwEvents);
        }
        
        /// <summary>
        /// Validate the <see cref="EtwProviders"/> returned from the tests. 
        /// </summary>
        /// <param name="etw">The <see cref="EtwProviders"/> to validate.</param>
        private static void ValidateEtwProviders(EtwProviders etw)
        {
            Guid result;
            Assert.IsTrue(etw.Providers.Count > 0);
            Assert.IsTrue(etw.Providers.All(etwProvider => 
                Guid.TryParse(etwProvider.GUID, out result) &&
                !string.IsNullOrEmpty(etwProvider.Name)));
        }
    }
}
+1 −0
Original line number Diff line number Diff line
{  }
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
{"Providers" : [{"GUID" : "3A43D90E-530E-41E5-A897-B555516070E2", "Name" : "Provider.One"},{"GUID" : "52B1715B-5AB6-4B48-A61A-A93EE8D4B5CD", "Name" : "Provider-Two"},{"GUID" : "698F02FF-2B63-4CBB-AB06-FEB88011347E", "Name" : "Provider.Three"}]}
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
{"Providers" : [{"GUID" : "3A43D90E-530E-41E5-A897-B555516070E2", "Name" : "Provider.One"},{"GUID" : "52B1715B-5AB6-4B48-A61A-A93EE8D4B5CD", "Name" : "Provider-Two"},{"GUID" : "698F02FF-2B63-4CBB-AB06-FEB88011347E", "Name" : "Provider.Three"}]}
 No newline at end of file
Loading