Exemplo n.º 1
0
 def _start_advertisements_thread(self, ad, beacon_count, restart=False):
     d, e = ad.droid, ad.ed
     if restart:
         try:
             reset_bluetooth([ad])
         except Exception:
             self.log.debug("Failed resetting Bluetooth, continuing...")
             return
     try:
         for _ in range(beacon_count):
             d.bleSetAdvertiseDataIncludeDeviceName(True)
             d.bleSetAdvertiseSettingsAdvertiseMode(
                 AdvertiseSettingsAdvertiseMode.ADVERTISE_MODE_LOW_LATENCY.
                 value)
             advertise_callback, advertise_data, advertise_settings = (
                 generate_ble_advertise_objects(d))
             d.bleStartBleAdvertising(advertise_callback, advertise_data,
                                      advertise_settings)
             try:
                 e.pop_event(adv_succ.format(advertise_callback),
                             self.default_timeout)
                 self.beacon_swarm_count += 1
                 local_bt_name = d.bluetoothGetLocalName()
                 if local_bt_name not in self.advertising_device_name_list:
                     self.advertising_device_name_list.append(
                         d.bluetoothGetLocalName())
             except Exception as e:
                 self.log.info("Advertising failed due to " + str(e))
             self.log.info("Beacons active: {}".format(
                 self.beacon_swarm_count))
     except Exception:
         self.log.debug(
             "Something went wrong in starting advertisements, continuing.")
     return
 def setup_test(self):
     super().setup_test()
     self.log.info("Setting up advertisements")
     reset_bluetooth(self.android_devices)
     try:
         self.advertise_callback_list = setup_n_advertisements(
             self.adv_ad, self.max_advertisements)
     except BtTestUtilsError:
         return False
     return True
    def test_restart_advertise_callback_after_bt_toggle(self):
        """Test starting an advertisement on a cleared out callback.

        Test that a single device resets its callbacks when the bluetooth state
        is reset.

        Steps:
        1. Setup the scanning android device.
        2. Setup the advertiser android device.
        3. Call start ble advertising.
        4. Toggle bluetooth on and off.
        5. Call start ble advertising on the same callback.

        Expected Result:
        Starting an advertisement on a callback id after toggling bluetooth
        should fail.

        Returns:
          Pass if True
          Fail if False

        TAGS: LE, Advertising, Concurrency
        Priority: 1
        """
        test_result = True
        advertise_callback, advertise_data, advertise_settings = (
            generate_ble_advertise_objects(self.adv_ad.droid))
        self.adv_ad.droid.bleStartBleAdvertising(advertise_callback,
                                                 advertise_data,
                                                 advertise_settings)
        try:
            self.adv_ad.ed.pop_event(adv_succ.format(advertise_callback),
                                     self.default_timeout)
        except Empty as error:
            self.log.error("Test failed with Empty error: {}".format(error))
            test_result = False
        except concurrent.futures._base.TimeoutError as error:
            self.log.debug(
                "Test failed, filtering callback onSuccess never occurred: {}".
                format(error))
        test_result = reset_bluetooth([self.android_devices[1]])
        if not test_result:
            return test_result
        self.adv_ad.droid.bleStartBleAdvertising(advertise_callback,
                                                 advertise_data,
                                                 advertise_settings)
        try:
            self.adv_ad.ed.pop_event(adv_succ.format(advertise_callback),
                                     self.default_timeout)
        except Empty as error:
            self.log.error("Test failed with Empty error: {}".format(error))
            test_result = False
        except concurrent.futures._base.TimeoutError as error:
            self.log.debug(
                "Test failed, filtering callback onSuccess never occurred: {}".
                format(error))
        return test_result
Exemplo n.º 4
0
 def on_fail(self, test_name, begin_time):
     self.log.debug(
         "Test {} failed. Gathering bugreport and btsnoop logs".format(
             test_name))
     take_btsnoop_logs(self.android_devices, self, test_name)
     self._take_bug_report(test_name, begin_time)
     for _ in range(5):
         if reset_bluetooth(self.android_devices):
             break
         else:
             self.log.error("Failed to reset Bluetooth... retrying.")
     return
    def test_max_advertisements_defaults(self):
        """Test scan integrity after BT state is reset

        This test is to verify that LE devices are found
        successfully after the Bluetooth stack is
        reset. This is repeated multiple times in order
        to verify that LE devices are not lost in scanning
        when the stack is brought back up.

        Steps:
        1. Pre-Condition: Max advertisements are active
        2. With the DUT android device, scan for all advertisements
        and verify that all expected advertisements are found.
        3. Reset Bluetooth on DUT.
        4. Repeat steps 2-3 for defined iterations

        Expected Result:
        All expected advertisements should be found on all iterations.

        Returns:
          Pass if True
          Fail if False

        TAGS: LE, Advertising, Concurrency, Scanning
        Priority: 2
        """
        filter_list = self.scn_ad.droid.bleGenFilterList()
        self.scn_ad.droid.bleBuildScanFilter(filter_list)
        self.scn_ad.droid.bleSetScanSettingsCallbackType(
            ble_scan_settings_callback_types['all_matches'])
        self.scn_ad.droid.bleSetScanSettingsScanMode(
            ble_scan_settings_modes['low_latency'])
        iterations = 20
        for _ in range(iterations):
            self.log.info("Verify all advertisements found")
            try:
                if not scan_and_verify_n_advertisements(
                        self.scn_ad, self.max_advertisements):
                    self.log.error("Failed to find all advertisements")
                    return False
            except BtTestUtilsError:
                return False
            if not reset_bluetooth([self.scn_ad]):
                self.log.error("Failed to reset Bluetooth state")
                return False
        return True
Exemplo n.º 6
0
 def on_fail(self, test_name, begin_time):
     take_btsnoop_logs(self.android_devices, self, test_name)
     reset_bluetooth([self.scn_ad])
Exemplo n.º 7
0
 def cleanup_class(self):
     return reset_bluetooth(self.android_devices)
Exemplo n.º 8
0
 def teardown_test(self):
     reset_bluetooth([self.android_devices[0]])
     return True
Exemplo n.º 9
0
 def on_exception(self, test_name, begin_time):
     reset_bluetooth(self.android_devices)
 def setup_test(self):
     super().setup_test()
     return reset_bluetooth(self.android_devices)
    def test_toggle_advertiser_bt_state(self):
        """Test forcing stopping advertisements.

        Test that a single device resets its callbacks when the bluetooth state is
        reset. There should be no advertisements.

        Steps:
        1. Setup the scanning android device.
        2. Setup the advertiser android device.
        3. Call start ble advertising.
        4. Toggle bluetooth on and off.
        5. Scan for any advertisements.

        Expected Result:
        No advertisements should be found after toggling Bluetooth on the
        advertising device.

        Returns:
          Pass if True
          Fail if False

        TAGS: LE, Advertising, Concurrency
        Priority: 2
        """
        test_result = True
        self.adv_ad.droid.bleSetAdvertiseDataIncludeDeviceName(True)
        advertise_callback, advertise_data, advertise_settings = (
            generate_ble_advertise_objects(self.adv_ad.droid))
        self.adv_ad.droid.bleStartBleAdvertising(advertise_callback,
                                                 advertise_data,
                                                 advertise_settings)
        try:
            self.adv_ad.ed.pop_event(adv_succ.format(advertise_callback),
                                     self.default_timeout)
        except Empty as error:
            self.log.error("Test failed with Empty error: {}".format(error))
            return False
        except concurrent.futures._base.TimeoutError as error:
            self.log.error(
                "Test failed, filtering callback onSuccess never occurred: {}".
                format(error))
        self.scn_ad.droid.bleSetScanSettingsScanMode(
            ble_scan_settings_modes['low_latency'])
        self.scn_ad.droid.bleSetScanFilterDeviceName(
            self.adv_ad.droid.bluetoothGetLocalName())
        filter_list, scan_settings, scan_callback = generate_ble_scan_objects(
            self.scn_ad.droid)
        self.scn_ad.droid.bleBuildScanFilter(filter_list)
        self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
                                          scan_callback)
        try:
            self.scn_ad.ed.pop_event(scan_result.format(scan_callback),
                                     self.default_timeout)
        except Empty as error:
            self.log.error("Test failed with: {}".format(error))
            return False
        self.scn_ad.droid.bleStopBleScan(scan_callback)
        test_result = reset_bluetooth([self.android_devices[1]])
        self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings,
                                          scan_callback)
        if not test_result:
            return False
        try:
            expected_event = scan_result.format(scan_callback)
            event = self.scn_ad.ed.pop_event(expected_event,
                                             self.default_timeout)
            self.log.error("Event {} not expected. Found: {}".format(
                expected_event, event))
            return False
        except Empty as error:
            self.log.debug("Test passed with: {}".format(error))
        self.scn_ad.droid.bleStopBleScan(scan_callback)
        self.adv_ad.droid.bleStopBleAdvertising(advertise_callback)
        return True
Exemplo n.º 12
0
 def setup_test(self):
     return reset_bluetooth(self.android_devices)
Exemplo n.º 13
0
 def on_fail(self, test_name, begin_time):
     self.log.debug("Test {} failed. Gathering bugreport and btsnoop logs."
                    .format(test_name))
     take_btsnoop_logs(self.android_devices, self, test_name)
     reset_bluetooth(self.android_devices)
Exemplo n.º 14
0
 def test_bt_toggle(self):
     """
     Test that simply toggle bluetooth
     :return:
     """
     return reset_bluetooth([self.android_devices[0]])