public bool DisconnectNetwork() { testLogger.LogComment("Disconnecting from WLAN"); try { using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); if (NetworkInterfaceDataPathTests.CheckWlanInterfaceCount(wlanApi) == false) { return(false); } var wlanInterface = wlanInterfaceList[0]; if (wlanInterface.State == WLAN_INTERFACE_STATE.wlan_interface_state_connected) { testLogger.LogComment("Disconnecting from WLAN network {0}", wlanInterface.Ssid); wlanApi.Disconnect(wlanInterface.Id, new TimeSpan(0, 0, 10)); } return(true); } } catch (Exception error) { testLogger.LogError("Error encountered while Disconnecting from the WLAN Network"); testLogger.LogError(error.ToString()); return(false); } }
private void SleepWakeAndScan(DateTime endTime, string profileName1) { testLogger.LogComment("SleepWakeAndScan"); using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); Verify.IsTrue(wlanInterfaceList.Count >= 1, string.Format(CultureInfo.InvariantCulture, "wlanInterfaceList.Count = {0}", wlanInterfaceList.Count)); var wlanInterface = wlanInterfaceList[0]; if (wlanInterface.State == WLAN_INTERFACE_STATE.wlan_interface_state_connected) { wlanApi.Disconnect(wlanInterface.Id, WlanStress.DisconnectWait); } } Verify.IsTrue(VerifyAPsAreInScanList(profileName1), "Verify APs are in Scan List"); while (DateTime.Now < endTime) { WakeHelper.StaticD2Sleep(new TimeSpan(0, 0, 30)); scanAfterSleepAttempts++; if (VerifyAPsAreInScanList(profileName1)) { scanAfterSleepSuccess++; } } }
private bool VerifyAPsAreInScanList(string ssid) { testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Verify SSID {0} is in scan list", ssid)); using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); Verify.IsTrue(wlanInterfaceList.Count >= 1, string.Format(CultureInfo.InvariantCulture, "wlanInterfaceList.Count = {0}", wlanInterfaceList.Count)); var wlanInterface = wlanInterfaceList[0]; wlanApi.TryScan(wlanInterface.Id, true, new TimeSpan(0, 0, 10)); Collection <WlanNetwork> list = wlanApi.GetAvailableNetworkList(wlanInterface.Id); bool found = false; foreach (var network in list) { if (String.Compare(network.Ssid, ssid, StringComparison.OrdinalIgnoreCase) == 0) { testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Found SSID {0}", ssid)); found = true; break; } } if (found == false) { testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Did not find SSID {0}", ssid)); } return(found); } }
public bool CreateProfile(string profile, string profileName) { try { using (Wlan wlanApi = new Wlan()) { testLogger.LogTrace("CreateProfile"); var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); if (NetworkInterfaceDataPathTests.CheckWlanInterfaceCount(wlanApi) == false) { return(false); } var wlanInterface = wlanInterfaceList[0]; testLogger.LogComment("Creating Profile {0}", profileName); wlanApi.CreateProfile(wlanInterface.Id, profile); return(true); } } catch (Exception error) { testLogger.LogError("Error encountered while Creating the Wlan Profile {0}", profileName); testLogger.LogError(error.ToString()); return(false); } }
private bool VerifyWeAreConnected(Wlan wlanApi) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); if (wlanInterfaceList[0].State == WLAN_INTERFACE_STATE.wlan_interface_state_connected) { return(true); } else { return(false); } }
public bool ConnectToNetwork(string ssid) { try { using (Wlan wlanApi = new Wlan()) { testLogger.LogComment("ConnectToNetwork"); var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); if (NetworkInterfaceDataPathTests.CheckWlanInterfaceCount(wlanApi) == false) { return(false); } var wlanInterface = wlanInterfaceList[0]; bool localConnectionNeeded = true; if (wlanInterface.State == WLAN_INTERFACE_STATE.wlan_interface_state_connected) { if (String.Compare(ssid, wlanInterface.Ssid, StringComparison.OrdinalIgnoreCase) == 0) { testLogger.LogComment("We already connected to the correct network."); localConnectionNeeded = false; } else { testLogger.LogComment("We already connected a different network. Disconnecting."); wlanApi.Disconnect(wlanInterface.Id, new TimeSpan(0, 0, 10)); Wlan.Sleep(1000); } } if (localConnectionNeeded) { testLogger.LogComment("Connecting to SSID {0}", ssid); wlanApi.TryScan(wlanInterface.Id, false, new TimeSpan(0, 0, 10)); wlanApi.ProfileConnect(wlanInterface.Id, ssid, new TimeSpan(0, 0, 30)); testLogger.LogComment("Connection Completed {0}", ssid); testLogger.LogComment("Waiting for DHCP to be stable"); Microsoft.Test.Networking.Kit.Helpers.WaitForWlanConnectivity(wlanInterface.Id, 1000 * 15, testLogger); } return(true); } } catch (Exception error) { testLogger.LogError("Error encountered while Connecting to the Wlan Profile {0}", ssid); testLogger.LogError(error.ToString()); return(false); } }
private bool IsConnected(Wlan wlanApi) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); // Verify.IsTrue(wlanInterfaceList.Count >= 1, string.Format(CultureInfo.InvariantCulture, "wlanInterfaceList.Count = {0}", wlanInterfaceList.Count)); if (wlanInterfaceList[0].State == WLAN_INTERFACE_STATE.wlan_interface_state_connected) { return(true); } else { return(false); } }
public void TestCleanup() { testLogger.LogComment("Entering: Suite Cleanup"); using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); // Verify.IsTrue(wlanInterfaceList.Count >= 1, string.Format(CultureInfo.InvariantCulture, "wlanInterfaceList.Count = {0}", wlanInterfaceList.Count)); var wlanInterface = wlanInterfaceList[0]; // Delete Profile if present DisconnectAndDeleteProfile(wlanApi); } testLogger.LogComment("Exiting:Suite Cleanup"); }
public void Configure(TestMode testMode, Guid localInterfaceGuid, string address, bool ipv6, UInt16 port) { this.ipv6Mode = ipv6; localPort = port; if (testMode == TestMode.Wlan) { localAddress = NetworkInterfaceDataPathTests.GetWirelessEndpoint(ipv6Mode); } else { localAddress = NetworkInterfaceDataPathTests.GetLanEndpoint(ipv6Mode, localInterfaceGuid); } this.identifier = String.Format(CultureInfo.InvariantCulture, "{0}:{1}", localAddress, localPort); testLogger.LogComment("MulticastReceiver[{0}] local address", this.identifier); testLogger.LogTrace("Creating Multicast Receive Socket"); if (ipv6Mode) { if (testMode == TestMode.Wlan) { using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); if (wlanInterfaceList.Count < 1) { throw new TestConfigException("No WLAN Interfaces were discovered. Ensure that WLAN interfaces are enabled, discoverable, and operational."); } var wlanInterface = wlanInterfaceList[0]; UInt32 wlanInterfaceIndex = NetworkInterfaceDataPathTests.GetNetworkIndex(wlanInterface.Id); listenSocket = sockets.CreateMulticastSocket(localAddress, localPort, address, port, wlanInterfaceIndex); } } else { UInt32 lanInterfaceIndex = NetworkInterfaceDataPathTests.GetNetworkIndex(localInterfaceGuid); listenSocket = sockets.CreateMulticastSocket(localAddress, localPort, address, port, lanInterfaceIndex); } } else { listenSocket = sockets.CreateMulticastSocket(localAddress, localPort, address, port); } }
public override void Run(string profileName1, string profileName2) { DateTime endTime = DateTime.Now.Add(new TimeSpan(0, 10, 0)); using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); Verify.IsTrue(wlanInterfaceList.Count >= 1, string.Format(CultureInfo.InvariantCulture, "wlanInterfaceList.Count = {0}", wlanInterfaceList.Count)); var wlanInterface = wlanInterfaceList[0]; if (wlanInterface.State == WLAN_INTERFACE_STATE.wlan_interface_state_connected) { wlanApi.Disconnect(wlanInterface.Id, WlanStress.DisconnectWait); } while (DateTime.Now < endTime) { testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Connecting to {0}", profileName1)); ConnectionAttempts++; var waiter1 = wlanApi.TryProfileConnect(wlanInterface.Id, profileName1, WlanStress.ConnectWait); if (waiter1 != null) { if (waiter1.WlanReasonCode == 0) { ConnectionSuccess++; testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Disconnecting from {0}", profileName1)); wlanApi.Disconnect(wlanInterface.Id, WlanStress.DisconnectWait); } } testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Connecting to {0}", profileName2)); ConnectionAttempts++; var waiter2 = wlanApi.TryProfileConnect(wlanInterface.Id, profileName2, WlanStress.ConnectWait); if (waiter2 != null) { if (waiter2.WlanReasonCode == 0) { ConnectionSuccess++; testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Disconnecting from {0}", profileName2)); wlanApi.Disconnect(wlanInterface.Id, WlanStress.DisconnectWait); } } } } }
public override void Run(string profileName1, string profileName2) { DateTime endTime = DateTime.Now.Add(new TimeSpan(0, 5, 0)); TimeSpan waiterTimeout = new TimeSpan(0, 0, 10); using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); Verify.IsTrue(wlanInterfaceList.Count >= 1, string.Format(CultureInfo.InvariantCulture, "wlanInterfaceList.Count = {0}", wlanInterfaceList.Count)); var wlanInterface = wlanInterfaceList[0]; while (DateTime.Now < endTime) { if (Random.Next(0, 2) == 1) { // Slow Scan testLogger.LogComment("Slow Scan"); int iterations = Random.Next(10); for (int toggleLooper = 0; toggleLooper < iterations; toggleLooper++) { testLogger.LogComment("Scanning..."); wlanApi.TryScan(wlanInterface.Id, false, WlanStress.ScanWait); testLogger.LogComment("Scanning...Complete"); SlowScans++; } } else { // Fast Scan testLogger.LogComment("Fast Scan"); int iterations = Random.Next(10); for (int toggleLooper = 0; toggleLooper < iterations; toggleLooper++) { testLogger.LogComment("Start Fast Scan"); wlanApi.TryScan(wlanInterface.Id, false); FastScans++; } testLogger.LogComment("Sleeping for a few seconds to allow the driver to calm down"); Wlan.Sleep(10000); } } } }
private void SleepWhileConnected(DateTime endTime, string profileName1) { testLogger.LogComment("SleepWhileConnected"); using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); Verify.IsTrue(wlanInterfaceList.Count >= 1, string.Format(CultureInfo.InvariantCulture, "wlanInterfaceList.Count = {0}", wlanInterfaceList.Count)); var wlanInterface = wlanInterfaceList[0]; if (wlanInterface.State != WLAN_INTERFACE_STATE.wlan_interface_state_connected) { testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Connecting to {0}", profileName1)); wlanApi.ProfileConnect(wlanInterface.Id, profileName1, WlanStress.ConnectWait); } while (DateTime.Now < endTime) { int sleepTime = Random.Next(1, 60); testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Sleeping for {0} seconds", sleepTime)); WakeHelper.StaticD2Sleep(new TimeSpan(0, 0, sleepTime)); testLogger.LogComment("Verify we are still connected"); connectedAfterSleepAttempts++; if (VerifyWeAreConnected(wlanApi)) { testLogger.LogComment("We are still connected"); connectedAfterSleepSuccess++; } else { testLogger.LogComment("We are not still connected"); } Wlan.Sleep(1000); } } }
private void DisconnectAndDeleteProfile(Wlan wlanApi) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); Verify.IsTrue(wlanInterfaceList.Count >= 1, string.Format(CultureInfo.InvariantCulture, "wlanInterfaceList.Count = {0}", wlanInterfaceList.Count)); if (wlanInterfaceList[0].State == WLAN_INTERFACE_STATE.wlan_interface_state_connected) { testLogger.LogComment("Disconnecting from AP"); wlanApi.Disconnect(wlanInterfaceList[0].Id); Wlan.Sleep(5000); } try { testLogger.LogComment("Deleting Profile"); wlanApi.DeleteProfile(wlanInterfaceList[0].Id, dot11wSSID); } catch (System.Runtime.InteropServices.COMException) { // The profile was not present to delete } }
private void SendThread(object obj) { CancellationToken token = (CancellationToken)obj; IntPtr socket = IntPtr.Zero; try { testLogger.LogComment("Multicast Sends from {0}:{1} to {2}:{3}", localAddress, localPort, remoteAddress, remotePort); if (ipv6Mode) { if (testMode == TestMode.Wlan) { using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); if (wlanInterfaceList.Count < 1) { throw new TestConfigException("No WLAN Interfaces were discovered. Ensure that WLAN interfaces are enabled, discoverable, and operational."); } var wlanInterface = wlanInterfaceList[0]; UInt32 wlanInterfaceIndex = NetworkInterfaceDataPathTests.GetNetworkIndex(wlanInterface.Id); socket = sockets.CreateMulticastSocket(localAddress, localPort, remoteAddress, remotePort, wlanInterfaceIndex); } } else { UInt32 lanInterfaceIndex = NetworkInterfaceDataPathTests.GetNetworkIndex(localInterfaceGuid); socket = sockets.CreateMulticastSocket(localAddress, localPort, remoteAddress, remotePort, lanInterfaceIndex); } } else { socket = sockets.CreateMulticastSocket(localAddress, localPort, remoteAddress, remotePort); } Byte[] sendData; while (!token.IsCancellationRequested) { sendData = NetworkInterfaceDataPathTests.GeneratePayload(100); testLogger.LogTrace("MulticastSender[{0}] Sending Packet", this.identifier); sockets.SendTo(socket, sendData, remoteAddress, remotePort, ipv6Mode); UnitsTransfered++; Wlan.Sleep(NetworkInterfaceDataPathTests.RandomWaitTime()); DateTime nextLogTime = DateTime.Now; if (DateTime.Now > nextLogTime) { testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Sending Multicast Data to {0}:{1}. Packets Sent {2}", remoteAddress, remotePort, UnitsTransfered)); nextLogTime = DateTime.Now.Add(logInterval); } testLogger.LogTrace("MulticastSender[{0}] Packets Sent {1}", this.identifier, UnitsTransfered); } testLogger.LogComment("Multicast Send Completed from {0}:{1} to {2}:{3}. Packet Count = {4}", localAddress, localPort, remoteAddress, remotePort, UnitsTransfered); } catch (Exception error) { testLogger.LogError(error.ToString()); throw; } finally { if (socket != IntPtr.Zero) { testLogger.LogTrace("MulticastSender[{0}] Closing Send Socket", this.identifier); sockets.CloseSocket(socket); } } }
private void ConnectForIntegrityCheck(ApConfigClient apConfigClient, int port, int streamBytes) { using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); Verify.IsTrue(wlanInterfaceList.Count >= 1, string.Format(CultureInfo.InvariantCulture, "wlanInterfaceList.Count = {0}", wlanInterfaceList.Count)); var wlanInterface = wlanInterfaceList[0]; if (wlanInterface.State == WLAN_INTERFACE_STATE.wlan_interface_state_connected) { return; } if (apConfigCreated == false) { var currentConfig1 = WlanAccessPointHelper.CreateWirelessAccessPoint(AuthenticationMethod.WPA2Personal, EncryptionMethod.AES, PhyType.n, "Password", AuthenticationMethod.WPA2Personal, EncryptionMethod.AES, PhyType.n, "Password"); var currentConfig2 = WlanAccessPointHelper.CreateWirelessAccessPoint(AuthenticationMethod.WPA2Personal, EncryptionMethod.AES, PhyType.n, "Password", AuthenticationMethod.WPA2Personal, EncryptionMethod.AES, PhyType.n, "Password"); ConfiguredSSIDs configuredSSID1 = new ConfiguredSSIDs("", ""); ConfiguredSSIDs configuredSSID2 = new ConfiguredSSIDs("", ""); if (apConfigClient.ApplyConfiguration(routers[0], currentConfig1, out configuredSSID1)) { currentConfig1.SSID_24GHZ = configuredSSID1.TwoPoint4GhzSSID; currentConfig1.SSID_5GHZ = configuredSSID1.FiveghzSSID; testLogger.LogComment("Successfully applied the Configuration to AP[0]"); } else { testLogger.LogError("Unable to apply the configuration to AP [0]"); } testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Applying AP Configuration to AP[1] {0}", currentConfig2.SSID_24GHZ)); if (apConfigClient.ApplyConfiguration(routers[1], currentConfig2, out configuredSSID2)) { currentConfig2.SSID_24GHZ = configuredSSID1.TwoPoint4GhzSSID; currentConfig2.SSID_5GHZ = configuredSSID1.FiveghzSSID; testLogger.LogComment("Successfully applied the Configuration to AP[2]"); } else { testLogger.LogError("Unable to apply the configuration to AP[2]"); } string profile1; string profile2; profile1 = currentConfig1.CreateProfile24ghz(ConnectionMode.Manual, false); profileName1 = currentConfig1.SSID_24GHZ; profile2 = currentConfig2.CreateProfile24ghz(ConnectionMode.Manual, false); profileName2 = currentConfig2.SSID_24GHZ; testLogger.LogComment(profile1); wlanApi.CreateProfile(wlanInterface.Id, profile1); wlanApi.CreateProfile(wlanInterface.Id, profile2); testLogger.LogComment("Wait to allow APs to beacon"); Wlan.Sleep(10000); apConfigCreated = true; } int retries = 3; while (retries > 0) { retries--; testLogger.LogComment("Scan"); wlanApi.TryScan(wlanInterface.Id, false, ScanWait); try { testLogger.LogComment(String.Format(CultureInfo.InvariantCulture, "Attempt to Connect to SSID : {0}", profileName1)); wlanApi.ProfileConnect(wlanInterface.Id, profileName1, ConnectWait); break; } catch (Exception) { testLogger.LogComment("Connect failed."); if (retries == 0) { testLogger.LogError(String.Format(CultureInfo.InvariantCulture, "Could not connect to SSID: {0}", profileName1)); return; } } } testLogger.LogComment("Wait for DHCP"); Microsoft.Test.Networking.Kit.Helpers.WaitForWlanConnectivity(wlanInterface.Id, 1000 * 15, testLogger); } }
private bool RunIntegrityCheck() { testLogger.LogComment("Running integrity check"); UInt16 port = 7777; UInt16 streamBytes = Convert.ToUInt16(random.Next(10, 2000)); nextIntegrityCheckTime = DateTime.Now.Add(integrityCheckInterval); using (ApConfigClient apConfigClient = new ApConfigClient(WlanStress.APServer)) { testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "WlanStress.APServer: {0}", WlanStress.APServer)); int retries = 3; bool connected = false; while (retries > 0) { retries--; testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Attempting to connect to AP machine. Retries remaining: {0}", retries)); bool connect = apConfigClient.Connect(); if (connect) { testLogger.LogComment("Connection to AP Server Succeeded"); connected = true; break; } else { testLogger.LogComment("Connection AP Server failed"); Wlan.Sleep(10000); } } if (connected == false) { testLogger.LogError("Giving up connecting to AP machine"); return(false); } apConfigClient.StartEchoServer(port, streamBytes, 1); ConnectForIntegrityCheck(apConfigClient, port, streamBytes); try { using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); Verify.IsTrue(wlanInterfaceList.Count >= 1, string.Format(CultureInfo.InvariantCulture, "wlanInterfaceList.Count = {0}", wlanInterfaceList.Count)); var wlanInterface = wlanInterfaceList[0]; using (Win32Sockets win32Sockets = new Win32Sockets()) { string localAddress = win32Sockets.FindIpAddress(wlanInterface.Id); testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "IPAddress: {0}", localAddress)); using (TCPEchoClient echoClient = new TCPEchoClient(localAddress, ServiceAPChannelAddress, port, streamBytes)) { echoClient.Connect(); echoClient.PerformEcho(); bool result = echoClient.IsResponseBufferValid(); testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Echo Client Success: {0}", result)); return(result); } } } } catch (Exception error) { testLogger.LogComment("TlukeTest: Exception hit"); testLogger.LogError(string.Format(CultureInfo.InvariantCulture, "Error While trying data path: {0}", error.ToString())); return(false); } finally { testLogger.LogComment("Cleaning Up Each Server"); apConfigClient.StopEchoServer(); using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); Verify.IsTrue(wlanInterfaceList.Count >= 1, string.Format(CultureInfo.InvariantCulture, "wlanInterfaceList.Count = {0}", wlanInterfaceList.Count)); var wlanInterface = wlanInterfaceList[0]; if (wlanInterface.State == WLAN_INTERFACE_STATE.wlan_interface_state_connected) { wlanApi.Disconnect(wlanInterface.Id, DisconnectWait); } } } } }
public void Stress() { // Populate Stress Modules StressModules = new List <StressModule>(); StressModules.Add(new ConnectDisconnectStress(random, routers, testLogger)); StressModules.Add(new AirplaneModeStress(random, routers, testLogger)); StressModules.Add(new ScanStress(random, routers, testLogger)); //StressModules.Add(new SleepStress(random, routers, testLogger)); apConfigCreated = false; testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Starting Stress at : {0}", DateTime.Now)); DateTime endTime = DateTime.Now.Add(new TimeSpan(0, TestDuration, 0)); testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Stress will end around : {0}", endTime)); bool testFailed = false; if (TestDuration < 50) { failForNotEnoughTime = true; testLogger.LogError("The test will fail because it is not scheduled to run long enough. Stress will still run but will ultimatly fail. To fix this inrease the stress run time."); } else { failForNotEnoughTime = false; } if (RunIntegrityCheck() == false) { testLogger.LogError("Ending test because of failed integrity check."); return; } while (DateTime.Now < endTime) { if (nextIntegrityCheckTime < DateTime.Now) { if (RunIntegrityCheck() == false) { testLogger.LogError("Ending test because of failed integrity check."); break; } else { continue; } } StressModule stressModule = null; try { stressModule = GetNextStressModule(); testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Starting test {0}", stressModule.Name)); stressModule.Run(profileName1, profileName2); // Wait a few seconds between stress run and next item Wlan.Sleep(5000); } catch (Exception error) { if (stressModule == null) { testLogger.LogError(string.Format(CultureInfo.InvariantCulture, "Exception when preparing test: {0}", error.ToString())); } else { testLogger.LogError(string.Format(CultureInfo.InvariantCulture, "Exception when running test: {0} {1}", stressModule.Name, error.ToString())); } testFailed = true; break; } } bool integrityCheck = true; if (RunIntegrityCheck() == false) { testLogger.LogError("Ending test because of failed integrity check."); integrityCheck = false; } using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); Verify.IsTrue(wlanInterfaceList.Count >= 1, string.Format(CultureInfo.InvariantCulture, "wlanInterfaceList.Count = {0}", wlanInterfaceList.Count)); var wlanInterface = wlanInterfaceList[0]; testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Deleting Profile {0}", profileName1)); wlanApi.TryDeleteProfile(wlanInterface.Id, profileName1); testLogger.LogComment(string.Format(CultureInfo.InvariantCulture, "Deleting Profile {0}", profileName2)); wlanApi.TryDeleteProfile(wlanInterface.Id, profileName2); } foreach (var stressModule in StressModules) { stressModule.PrintResults(); } Verify.IsTrue(testFailed == false); Verify.IsTrue(integrityCheck == true); if (failForNotEnoughTime == true) { testLogger.LogError("The stress test failed because it was not scheduled to run at a long enough duration. To fix this inrease the stress run time."); } Verify.IsTrue(failForNotEnoughTime == false); }
public override void Run(string profileName1, string profileName2) { DateTime endTime = DateTime.Now.Add(new TimeSpan(0, 5, 0)); TimeSpan waiterTimeout = new TimeSpan(0, 0, 10); using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); Verify.IsTrue(wlanInterfaceList.Count >= 1, string.Format(CultureInfo.InvariantCulture, "wlanInterfaceList.Count = {0}", wlanInterfaceList.Count)); var wlanInterface = wlanInterfaceList[0]; var radioStateList = wlanApi.GetRadioState(wlanInterface); if (radioStateList[0].SoftwareRadioState == RadioState.Off) { testLogger.LogComment("Turning Radio On"); WlanNotificationWaiter waiterOnSetup = wlanApi.CreateEventWaiter(WLAN_NOTIFICATION_MSM.wlan_notification_msm_radio_state_change); wlanApi.SetRadioState(wlanInterface, 0, true); waiterOnSetup.Wait(waiterTimeout); } try { while (DateTime.Now < endTime) { if (Random.Next(0, 2) == 1) { // Slow toggle testLogger.LogComment("Slow Toggle"); int iterations = Random.Next(10); for (int toggleLooper = 0; toggleLooper < iterations; toggleLooper++) { testLogger.LogComment("Turning Radio Off"); SlowToggles++; WlanNotificationWaiter waiterOff = wlanApi.CreateEventWaiter(WLAN_NOTIFICATION_MSM.wlan_notification_msm_radio_state_change); wlanApi.SetRadioState(wlanInterface, 0, false); waiterOff.Wait(waiterTimeout); testLogger.LogComment("Turning Radio On"); WlanNotificationWaiter waiterOn = wlanApi.CreateEventWaiter(WLAN_NOTIFICATION_MSM.wlan_notification_msm_radio_state_change); wlanApi.SetRadioState(wlanInterface, 0, true); waiterOn.Wait(waiterTimeout); } } else { // Fast Toggle testLogger.LogComment("Fast Toggle"); int iterations = Random.Next(10); for (int toggleLooper = 0; toggleLooper < iterations; toggleLooper++) { testLogger.LogComment("Turning Radio Off"); FastToggles++; wlanApi.SetRadioState(wlanInterface, 0, false); Wlan.Sleep(Random.Next(100, 750)); testLogger.LogComment("Turning Radio On"); wlanApi.SetRadioState(wlanInterface, 0, true); Wlan.Sleep(Random.Next(100, 750)); } testLogger.LogComment("Sleeping for a few seconds to allow the driver to calm down"); Wlan.Sleep(10000); } ScanAttempts++; testLogger.LogComment("Scanning"); wlanApi.TryScan(wlanInterface.Id, true, WlanStress.ScanWait); var list = wlanApi.GetAvailableNetworkList(wlanInterface.Id); if (list.Count > 0) { ScanSuccess++; } else { testLogger.LogComment("Scanning failed"); } } } finally { radioStateList = wlanApi.GetRadioState(wlanInterface); if (radioStateList[0].SoftwareRadioState == RadioState.Off) { testLogger.LogComment("Turning Radio On"); WlanNotificationWaiter waiterOnCleanup = wlanApi.CreateEventWaiter(WLAN_NOTIFICATION_MSM.wlan_notification_msm_radio_state_change); wlanApi.SetRadioState(wlanInterface, 0, true); waiterOnCleanup.Wait(waiterTimeout); } } } }
public void TestDot11wConnection() { Guid interfaceId; testLogger.LogComment("Testing 802.11w Connection to AP with SSID " + dot11wSSID + " and password " + dot11wPassword); using (Wlan wlanApi = new Wlan()) { var wlanInterfaceList = wlanApi.EnumWlanInterfaces(); Verify.IsTrue(wlanInterfaceList.Count >= 1, string.Format(CultureInfo.InvariantCulture, "wlanInterfaceList.Count = {0}", wlanInterfaceList.Count)); var wlanInterface = wlanInterfaceList[0]; interfaceId = wlanInterface.Id; // Delete Profile if present DisconnectAndDeleteProfile(wlanApi); // Scan testLogger.LogComment("Scan"); wlanApi.Scan(wlanInterface.Id, false, ScanWait); // Check to see if SSID is in scan list testLogger.LogComment("Check to see if SSID is in scan list"); var networkList = wlanApi.GetAvailableNetworkList(interfaceId); bool found = false; foreach (WlanNetwork network in networkList) { if (String.Compare(network.Ssid, dot11wSSID, StringComparison.Ordinal) == 0) { found = true; break; } } if (found == false) { testLogger.LogError("Could not find 11w router in scan list: " + dot11wSSID); testLogger.LogResult(TestResult.Failed); return; } else { testLogger.LogComment("Found the 11w router in the scan list: " + dot11wSSID); } // Create Profile string profile = GenerateProfile(); testLogger.LogComment("Creating Profile"); wlanApi.CreateProfile(interfaceId, profile); // Connect testLogger.LogComment("Connecting to AP"); wlanApi.ProfileConnect(interfaceId, dot11wSSID, new TimeSpan(0, 0, 30)); } // Check MFP Status bool mfpStatus = IsMfpNeogotiated(interfaceId); testLogger.LogComment("IsMfpNeogotiated == " + mfpStatus); if (mfpStatus == false) { testLogger.LogError("The device connected to the dot11w router but IsMfpNeogotiated == false"); testLogger.LogResult(TestResult.Failed); return; } if (enableSleepTest) { PowerManager powerManager; powerManager = new PowerManager(); // Wait for DHCP Stable testLogger.LogComment("Wait for DHCP to be stable"); Wlan.Sleep(1000 * 60 * 2); testLogger.LogComment("Going into Connected standby/Sleep for 1 minute"); powerManager.DeepestSleep(60); using (Wlan wlanApi = new Wlan()) { bool isConnected = IsConnected(wlanApi); if (isConnected == false) { testLogger.LogError("After waking from connected standby the device is no longer connected to the AP"); } else { testLogger.LogComment("After waking from connected standby the device is still connected to the AP"); } } // Check MFP Status mfpStatus = IsMfpNeogotiated(interfaceId); testLogger.LogComment("IsMfpNeogotiated == " + mfpStatus); if (mfpStatus == false) { testLogger.LogError("The device connected to the dot11w router but IsMfpNeogotiated == false"); return; } } }