public void Scan() { Log("Scan Test Configuration Parameters: "); Log(m_AP1Config24GHz.GetTestParameter()); Log(m_AP1Config5GHz.GetTestParameter()); Log(m_AP2Config24GHz.GetTestParameter()); Log(m_AP2Config5GHz.GetTestParameter()); SetupRouters(); // Turn on all Radios Log("Turning on all radios"); AC.SetRadio24GHzState(routers[0], true); AC.SetRadio24GHzState(routers[1], true); AC.SetRadio5GHzState(routers[0], true); AC.SetRadio5GHzState(routers[1], true); LogMajor("Turning on Airplane Mode"); Api.SetRadioState(TestInterface, false); EventHandler <EventArrivedEventArgs> ETWCallback = null; ETWCallback = (object sender, EventArrivedEventArgs properties) => { LogEtwEvent(properties); }; var wlanEtwWatcher = new WlanEtwWatcher(); wlanEtwWatcher.EventArrived += ETWCallback; Log("Start ETW Tracing"); wlanEtwWatcher.Start(); bool Radio_0_24Ghz_Found = false; bool Radio_1_24Ghz_Found = false; bool Radio_0_5Ghz_Found = false; bool Radio_1_5Ghz_Found = false; string Reason_Radio_0_24Ghz_Found = null; string Reason_Radio_1_24Ghz_Found = null; string Reason_Radio_0_5Ghz_Found = null; string Reason_Radio_1_5Ghz_Found = null; try { Log("Sleeping for a second"); Wlan.Sleep(1 * 1000); // 1s LogMajor("Turning off Airplane Mode"); Api.SetRadioState(TestInterface, true); for (int i = 0; i < 4; i++) { Log("Scan Iteration " + i); if (i == 0) { // First scan is always with a flush so that we dont get old data LogMajor("Calling (public) scan with flush"); Api.Scan(TestInterface.Id, true, new TimeSpan(0, 0, 10)); } else if (ScanningConfiguration.IssueMulitpleScans == true) { // Additional scans are without flush LogMajor("Calling (internal) scan without flush"); Api.Scan(TestInterface.Id, false, new TimeSpan(0, 0, 10)); } // If any network is marked hidden, we need to specifically search for those for (int j = 0; j < 2; j++) { if (APConfigs[j].BeaconEnabled_24GHZ == false) { LogMajor("Calling (public) scan for " + APConfigs[j].SSID_24GHZ); Api.Scan(TestInterface.Id, false, APConfigs[j].SSID_24GHZ, new TimeSpan(0, 0, 10)); } if (APConfigs[j].BeaconEnabled_5GHZ == false) { LogMajor("Calling (public) scan for " + APConfigs[j].SSID_5GHZ); Api.Scan(TestInterface.Id, false, APConfigs[j].SSID_5GHZ, new TimeSpan(0, 0, 10)); } } if (!Radio_0_24Ghz_Found) { LogMajor("Scan : Locating " + APConfigs[0].SSID_24GHZ + " in bssid list"); if (Helpers.ValidateNetworkVisible(Api, APConfigs[0], false, out Reason_Radio_0_24Ghz_Found)) { LogMajor(APConfigs[0].SSID_24GHZ + "found in scan list "); Radio_0_24Ghz_Found = true; } else { LogMajor("ValidateNetworkVisible failed for " + APConfigs[0].SSID_24GHZ); } } if (!Radio_1_24Ghz_Found) { LogMajor("Scan : Locating " + APConfigs[1].SSID_24GHZ + " in bssid list"); if (Helpers.ValidateNetworkVisible(Api, APConfigs[1], false, out Reason_Radio_1_24Ghz_Found)) { LogMajor(APConfigs[1].SSID_24GHZ + "found in scan list "); Radio_1_24Ghz_Found = true; } else { LogMajor("ValidateNetworkVisible failed for " + APConfigs[1].SSID_24GHZ); } } if (!ScanningConfiguration.DeviceSupports5Ghz) { if (Radio_0_24Ghz_Found && Radio_1_24Ghz_Found) { LogMajor("Scan: Located all routers"); return; } else { LogMajor("Scan: Not yet located all routers "); LogMajor("Router 0 2.4Ghz Found =" + Radio_0_24Ghz_Found); LogMajor("Router 1 2.4Ghz Found =" + Radio_1_24Ghz_Found); continue; // skip 5Ghz } } if (!Radio_0_5Ghz_Found) { LogMajor("Scan : Locating " + APConfigs[0].SSID_5GHZ + " in bssid list"); if (Helpers.ValidateNetworkVisible(Api, APConfigs[0], true, out Reason_Radio_0_5Ghz_Found)) { LogMajor(APConfigs[0].SSID_5GHZ + " found in scan list"); Radio_0_5Ghz_Found = true; } else { LogMajor("ValidateNetworkVisible failed for " + APConfigs[0].SSID_5GHZ); } } if (!Radio_1_5Ghz_Found) { LogMajor("Scan : Locating " + APConfigs[1].SSID_5GHZ + " in bssid list"); if (Helpers.ValidateNetworkVisible(Api, APConfigs[1], true, out Reason_Radio_1_5Ghz_Found)) { LogMajor(APConfigs[1].SSID_5GHZ + " found in scan list"); Radio_1_5Ghz_Found = true; } else { LogMajor("ValidateNetworkVisible failed for " + APConfigs[1].SSID_5GHZ); } } if (Radio_0_24Ghz_Found && Radio_1_24Ghz_Found && Radio_0_5Ghz_Found && Radio_1_5Ghz_Found) { LogMajor("Scan: Located all routers"); return; } LogMajor("Scan: Not yet located all routers "); LogMajor("Router 0 2.4Ghz Found =" + Radio_0_24Ghz_Found); LogMajor("Router 1 2.4Ghz Found =" + Radio_1_24Ghz_Found); LogMajor("Router 0 5Ghz Found =" + Radio_0_5Ghz_Found); LogMajor("Router 1 5Ghz Found =" + Radio_1_5Ghz_Found); } } catch (Exception error) { LogMajor(error.ToString()); throw; } finally { wlanEtwWatcher.Dispose(); } LogMajor("Error locating all routers"); if (!Radio_0_24Ghz_Found) { LogMajor("Scanning - " + Reason_Radio_0_24Ghz_Found); throw new Exception(Reason_Radio_0_24Ghz_Found); } if (!Radio_1_24Ghz_Found) { LogMajor("Scanning - " + Reason_Radio_1_24Ghz_Found); throw new Exception(Reason_Radio_1_24Ghz_Found); } if (ScanningConfiguration.DeviceSupports5Ghz) { if (!Radio_0_5Ghz_Found) { LogMajor("Scanning - " + Reason_Radio_0_5Ghz_Found); throw new Exception(Reason_Radio_0_5Ghz_Found); } if (!Radio_1_5Ghz_Found) { LogMajor("Scanning - " + Reason_Radio_1_5Ghz_Found); throw new Exception(Reason_Radio_1_5Ghz_Found); } } }
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); } } } }