Bug 1175057 - Fix the problem of the script timeout by ensuring it associates to the right ap. r=hchang
authorTim Huang <tihuang@mozilla.com>
Thu, 03 Sep 2015 19:29:00 +0200
changeset 261164 7d271e866fa2bcbfdbc58a200e4136376c1bd1cb
parent 261163 eba9f42f0c414251da7c6f1bc02cdc6ac584b782
child 261165 bee2b0164ec464771fadf08b3e07a098ecb3626d
push id17353
push usercbook@mozilla.com
push dateTue, 08 Sep 2015 06:44:59 +0000
treeherderb2g-inbound@7d271e866fa2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershchang
bugs1175057
milestone43.0a1
Bug 1175057 - Fix the problem of the script timeout by ensuring it associates to the right ap. r=hchang
dom/wifi/test/marionette/head.js
dom/wifi/test/marionette/test_wifi_static_ip.js
--- a/dom/wifi/test/marionette/head.js
+++ b/dom/wifi/test/marionette/head.js
@@ -771,17 +771,22 @@ let gTestSuite = (function() {
     }
 
     function startOneHostapd(aIndex) {
       let configFileName = HOSTAPD_CONFIG_PATH + 'ap' + aIndex + '.conf';
       return writeHostapdConfFile(configFileName, createConfigFromCommon(aIndex))
         .then(() => runEmulatorShellSafe(['hostapd', '-B', configFileName]))
         .then(function (reply) {
           // It may fail at the first time due to the previous ungracefully terminated one.
-          if (reply[0] === 'bind(PF_UNIX): Address already in use') {
+          if (reply.length === 0) {
+            // The hostapd starts successfully
+            return;
+          }
+
+          if (reply[0].indexOf('bind(PF_UNIX): Address already in use') !== -1) {
             return startOneHostapd(aIndex);
           }
         });
     }
 
     return Promise.all(aConfigList.map(function(aConfig, aIndex) {
       return startOneHostapd(aIndex);
     }));
--- a/dom/wifi/test/marionette/test_wifi_static_ip.js
+++ b/dom/wifi/test/marionette/test_wifi_static_ip.js
@@ -9,16 +9,18 @@ const STATIC_IP_CONFIG = {
   ipaddr: "192.168.111.222",
   proxy: "",
   maskLength: 24,
   gateway: "192.168.111.1",
   dns1: "8.8.8.8",
   dns2: "8.8.4.4",
 };
 
+const TESTING_HOSTAPD = [{ ssid: 'ap0' }];
+
 function testAssociateWithStaticIp(aNetwork, aStaticIpConfig) {
   return gTestSuite.setStaticIpMode(aNetwork, aStaticIpConfig)
     .then(() => gTestSuite.testAssociate(aNetwork))
     // Check ip address and prefix.
     .then(() => gTestSuite.exeAndParseNetcfg())
     .then((aResult) => {
       is(aResult["wlan0"].ip, aStaticIpConfig.ipaddr, "Check ip address");
       is(aResult["wlan0"].prefix, aStaticIpConfig.maskLength, "Check prefix");
@@ -27,15 +29,37 @@ function testAssociateWithStaticIp(aNetw
     .then(() => gTestSuite.exeAndParseIpRoute())
     .then((aResult) => {
       is(aResult["wlan0"].src, aStaticIpConfig.ipaddr, "Check ip address");
       is(aResult["wlan0"].default, true, "Check default route");
       is(aResult["wlan0"].gateway, aStaticIpConfig.gateway, "Check gateway");
     });
 }
 
+function findDesireNetwork(aNetworks) {
+  let i = gTestSuite.getFirstIndexBySsid(TESTING_HOSTAPD[0].ssid, aNetworks);
+
+  if (-1 !== i) {
+    return aNetworks[i];
+  }
+
+  return aNetworks[0];
+}
+
 // Start test.
-gTestSuite.doTest(function() {
+gTestSuite.doTestWithoutStockAp(function() {
   return gTestSuite.ensureWifiEnabled(true)
+
+    // Start custom hostapd for testing.
+    .then(() => gTestSuite.startHostapds(TESTING_HOSTAPD))
+    .then(() => gTestSuite.verifyNumOfProcesses('hostapd',
+                                                TESTING_HOSTAPD.length))
+
+    // Perform a wifi scan, and then run the static ip test
     .then(() => gTestSuite.requestWifiScan())
-    .then((aNetworks) => testAssociateWithStaticIp(aNetworks[0],
-                                                   STATIC_IP_CONFIG));
+    .then((aNetworks) => findDesireNetwork(aNetworks))
+    .then((aNetwork) => testAssociateWithStaticIp(aNetwork,
+                                                   STATIC_IP_CONFIG))
+
+    // Kill running hostapd.
+    .then(gTestSuite.killAllHostapd)
+    .then(() => gTestSuite.verifyNumOfProcesses('hostapd', 0));
 });