def test_nmi_randomization_on_interval(self):
        """Validate randomization of the NMI (NAN management interface) on a set
    interval. Default value is 30 minutes - change to a small value to allow
    testing in real-time"""
        RANDOM_INTERVAL = 120  # minimal value in current implementation

        dut = self.android_devices[0]

        # set randomization interval to 120 seconds
        autils.configure_mac_random_interval(dut, RANDOM_INTERVAL)

        # attach and wait for first identity
        id = dut.droid.wifiAwareAttach(True)
        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)
        ident_event = autils.wait_for_event(
            dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
        mac1 = ident_event["data"]["mac"]

        # wait for second identity callback
        # Note: exact randomization interval is not critical, just approximate,
        # hence giving a few more seconds.
        ident_event = autils.wait_for_event(
            dut,
            aconsts.EVENT_CB_ON_IDENTITY_CHANGED,
            timeout=RANDOM_INTERVAL + 5)
        mac2 = ident_event["data"]["mac"]

        # validate MAC address is randomized
        asserts.assert_false(
            mac1 == mac2,
            "Randomized MAC addresses (%s, %s) should be different" %
            (mac1, mac2))

        # clean-up
        dut.droid.wifiAwareDestroy(id)
Пример #2
0
    def start_discovery_session(self, dut, session_id, is_publish, dtype,
                                service_name, expect_success):
        """Start a discovery session

    Args:
      dut: Device under test
      session_id: ID of the Aware session in which to start discovery
      is_publish: True for a publish session, False for subscribe session
      dtype: Type of the discovery session
      service_name: Service name to use for the discovery session
      expect_success: True if expect session to be created, False otherwise

    Returns:
      Discovery session ID.
    """
        config = {}
        config[aconsts.DISCOVERY_KEY_DISCOVERY_TYPE] = dtype
        config[aconsts.DISCOVERY_KEY_SERVICE_NAME] = service_name

        if is_publish:
            disc_id = dut.droid.wifiAwarePublish(session_id, config)
            event_name = aconsts.SESSION_CB_ON_PUBLISH_STARTED
        else:
            disc_id = dut.droid.wifiAwareSubscribe(session_id, config)
            event_name = aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED

        if expect_success:
            autils.wait_for_event(dut, event_name)
        else:
            autils.wait_for_event(dut,
                                  aconsts.SESSION_CB_ON_SESSION_CONFIG_FAILED)

        return disc_id
    def setup_test(self):
        required_params = ("aware_default_power_mode", )
        self.unpack_userparams(required_params)

        for ad in self.android_devices:
            asserts.skip_if(
                not ad.droid.doesDeviceSupportWifiAwareFeature(),
                "Device under test does not support Wi-Fi Aware - skipping test"
            )
            wutils.wifi_toggle_state(ad, True)
            ad.droid.wifiP2pClose()
            utils.set_location_service(ad, True)
            aware_avail = ad.droid.wifiIsAwareAvailable()
            if not aware_avail:
                self.log.info('Aware not available. Waiting ...')
                autils.wait_for_event(ad,
                                      aconsts.BROADCAST_WIFI_AWARE_AVAILABLE)
            ad.ed.clear_all_events()
            ad.aware_capabilities = autils.get_aware_capabilities(ad)
            self.reset_device_parameters(ad)
            self.reset_device_statistics(ad)
            self.set_power_mode_parameters(ad)
            wutils.set_wifi_country_code(ad, wutils.WifiEnums.CountryCode.US)
            autils.configure_ndp_allow_any_override(ad, True)
            # set randomization interval to 0 (disable) to reduce likelihood of
            # interference in tests
            autils.configure_mac_random_interval(ad, 0)
    def run_aware_then_incompat_service(self, is_p2p):
        """Run test to validate that a running Aware session terminates when an
    Aware-incompatible service is started.

    Args:
      is_p2p: True for p2p, False for SoftAP
    """
        dut = self.android_devices[0]

        # start Aware
        id = dut.droid.wifiAwareAttach()
        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)

        # start other service
        if is_p2p:
            dut.droid.wifiP2pInitialize()
        else:
            wutils.start_wifi_tethering(dut, self.TETHER_SSID, password=None)

        # expect an announcement about Aware non-availability
        autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_NOT_AVAILABLE)

        # local clean-up
        if not is_p2p:
            wutils.stop_wifi_tethering(dut)
    def run_rtt_oob_discovery_set(self, do_both_directions, iter_count,
                                  time_between_iterations, time_between_roles):
        """Perform a set of RTT measurements, using out-of-band discovery.

        Args:
              do_both_directions: False - perform all measurements in one direction,
                                  True - perform 2 measurements one in both directions.
              iter_count: Number of measurements to perform.
              time_between_iterations: Number of seconds to wait between iterations.
              time_between_roles: Number of seconds to wait when switching between
                                  Initiator and Responder roles (only matters if
                                  do_both_directions=True).
              enable_ranging: True to enable Ranging, False to disable.

        Returns: a list of the events containing the RTT results (or None for a
        failed measurement). If both directions are tested then returns a list of
        2 elements: one set for each direction.
        """
        dut0 = self.android_devices[0]
        dut1 = self.android_devices[1]

        id0, mac0 = autils.attach_with_identity(dut0)
        id1, mac1 = autils.attach_with_identity(dut1)

        # wait for for devices to synchronize with each other - there are no other
        # mechanisms to make sure this happens for OOB discovery (except retrying
        # to execute the data-path request)
        time.sleep(autils.WAIT_FOR_CLUSTER)

        # start publisher(s) on the Responder(s) with ranging enabled
        p_config = autils.add_ranging_to_pub(autils.create_discovery_config(
            self.SERVICE_NAME, aconsts.PUBLISH_TYPE_UNSOLICITED),
                                             enable_ranging=True)
        dut1.droid.wifiAwarePublish(id1, p_config)
        autils.wait_for_event(dut1, aconsts.SESSION_CB_ON_PUBLISH_STARTED)
        if do_both_directions:
            dut0.droid.wifiAwarePublish(id0, p_config)
            autils.wait_for_event(dut0, aconsts.SESSION_CB_ON_PUBLISH_STARTED)

        results01 = []
        results10 = []
        for i in range(iter_count):
            if i != 0 and time_between_iterations != 0:
                time.sleep(time_between_iterations)

            # perform RTT from dut0 -> dut1
            results01.append(self.run_rtt_discovery(dut0, resp_mac=mac1))

            if do_both_directions:
                if time_between_roles != 0:
                    time.sleep(time_between_roles)

                # perform RTT from dut1 -> dut0
                results10.append(self.run_rtt_discovery(dut1, resp_mac=mac0))

        return results01 if not do_both_directions else [results01, results10]
    def test_attach_with_identity(self):
        """Functional test case / Attach test cases / attach with identity callback

    Validates that attaching to the Wi-Fi Aware service works (receive
    the expected callbacks).
    """
        dut = self.android_devices[0]
        dut.droid.wifiAwareAttach(True)
        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)
        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
Пример #7
0
    def run_message_no_queue(self, payload_size):
        """Validate L2 message exchange between publisher & subscriber with no
    queueing - i.e. wait for an ACK on each message before sending the next
    message.

    Args:
      payload_size: min, typical, or max (PAYLOAD_SIZE_xx).
    """
        discovery_info = self.prep_message_exchange()
        p_dut = discovery_info["p_dut"]
        s_dut = discovery_info["s_dut"]
        p_disc_id = discovery_info["p_disc_id"]
        s_disc_id = discovery_info["s_disc_id"]
        peer_id_on_sub = discovery_info["peer_id_on_sub"]

        for i in range(self.NUM_MSGS_NO_QUEUE):
            msg = self.create_msg(s_dut.aware_capabilities, payload_size, i)
            msg_id = self.get_next_msg_id()
            s_dut.droid.wifiAwareSendMessage(s_disc_id, peer_id_on_sub, msg_id,
                                             msg, 0)
            tx_event = autils.wait_for_event(
                s_dut, aconsts.SESSION_CB_ON_MESSAGE_SENT)
            rx_event = autils.wait_for_event(
                p_dut, aconsts.SESSION_CB_ON_MESSAGE_RECEIVED)
            asserts.assert_equal(
                msg_id, tx_event["data"][aconsts.SESSION_CB_KEY_MESSAGE_ID],
                "Subscriber -> Publisher message ID corrupted")
            autils.assert_equal_strings(
                msg,
                rx_event["data"][aconsts.SESSION_CB_KEY_MESSAGE_AS_STRING],
                "Subscriber -> Publisher message %d corrupted" % i)

        peer_id_on_pub = rx_event["data"][aconsts.SESSION_CB_KEY_PEER_ID]
        for i in range(self.NUM_MSGS_NO_QUEUE):
            msg = self.create_msg(s_dut.aware_capabilities, payload_size,
                                  1000 + i)
            msg_id = self.get_next_msg_id()
            p_dut.droid.wifiAwareSendMessage(p_disc_id, peer_id_on_pub, msg_id,
                                             msg, 0)
            tx_event = autils.wait_for_event(
                p_dut, aconsts.SESSION_CB_ON_MESSAGE_SENT)
            rx_event = autils.wait_for_event(
                s_dut, aconsts.SESSION_CB_ON_MESSAGE_RECEIVED)
            asserts.assert_equal(
                msg_id, tx_event["data"][aconsts.SESSION_CB_KEY_MESSAGE_ID],
                "Publisher -> Subscriber message ID corrupted")
            autils.assert_equal_strings(
                msg,
                rx_event["data"][aconsts.SESSION_CB_KEY_MESSAGE_AS_STRING],
                "Publisher -> Subscriber message %d corrupted" % i)

        # verify there are no more events
        time.sleep(autils.EVENT_TIMEOUT)
        autils.verify_no_more_events(p_dut, timeout=0)
        autils.verify_no_more_events(s_dut, timeout=0)
    def test_attach_with_no_wifi(self):
        """Function test case / Attach test cases / attempt to attach with wifi off

    Validates that if trying to attach with Wi-Fi disabled will receive the
    expected failure callback. As a side-effect also validates that the broadcast
    for Aware unavailable is received.
    """
        dut = self.android_devices[0]
        wutils.wifi_toggle_state(dut, False)
        autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_NOT_AVAILABLE)
        dut.droid.wifiAwareAttach()
        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACH_FAILED)
    def test_nmi_ndi_randomization_on_enable(self):
        """Validate randomization of the NMI (NAN management interface) and all NDIs
    (NAN data-interface) on each enable/disable cycle"""
        dut = self.android_devices[0]

        # re-enable randomization interval (since if disabled it may also disable
        # the 'randomize on enable' feature).
        autils.configure_mac_random_interval(dut, 1800)

        # DUT: attach and wait for confirmation & identity 10 times
        mac_addresses = {}
        for i in range(self.NUM_ITERATIONS):
            id = dut.droid.wifiAwareAttach(True)
            autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)
            ident_event = autils.wait_for_event(
                dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)

            # process NMI
            mac = ident_event["data"]["mac"]
            dut.log.info("NMI=%s", mac)
            if mac in mac_addresses:
                mac_addresses[mac] = mac_addresses[mac] + 1
            else:
                mac_addresses[mac] = 1

            # process NDIs
            time.sleep(5)  # wait for NDI creation to complete
            for j in range(
                    dut.aware_capabilities[aconsts.CAP_MAX_NDI_INTERFACES]):
                ndi_interface = "%s%d" % (aconsts.AWARE_NDI_PREFIX, j)
                ndi_mac = autils.get_mac_addr(dut, ndi_interface)
                dut.log.info("NDI %s=%s", ndi_interface, ndi_mac)
                if ndi_mac in mac_addresses:
                    mac_addresses[ndi_mac] = mac_addresses[ndi_mac] + 1
                else:
                    mac_addresses[ndi_mac] = 1

            dut.droid.wifiAwareDestroy(id)

        # Test for uniqueness
        for mac in mac_addresses.keys():
            if mac_addresses[mac] != 1:
                asserts.fail("MAC address %s repeated %d times (all=%s)" %
                             (mac, mac_addresses[mac], mac_addresses))

        # Verify that infra interface (e.g. wlan0) MAC address is not used for NMI
        infra_mac = autils.get_wifi_mac_address(dut)
        asserts.assert_false(
            infra_mac in mac_addresses,
            "Infrastructure MAC address (%s) is used for Aware NMI (all=%s)" %
            (infra_mac, mac_addresses))
    def run_incompat_service_then_aware(self, is_p2p):
        """Validate that if an Aware-incompatible service is already up then any
    Aware operation fails"""
        dut = self.android_devices[0]

        # start other service
        if is_p2p:
            dut.droid.wifiP2pInitialize()
        else:
            wutils.start_wifi_tethering(dut, self.TETHER_SSID, password=None)

        # expect an announcement about Aware non-availability
        autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_NOT_AVAILABLE)

        # try starting anyway (expect failure)
        dut.droid.wifiAwareAttach()
        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACH_FAILED)

        # stop other service
        if is_p2p:
            dut.droid.wifiP2pClose()
        else:
            wutils.stop_wifi_tethering(dut)

        # expect an announcement about Aware availability
        autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_AVAILABLE)

        # try starting Aware
        dut.droid.wifiAwareAttach()
        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)
Пример #11
0
  def setup_test(self):
    required_params = ("default_power_mode", )
    self.unpack_userparams(required_params)

    for ad in self.android_devices:
      wutils.wifi_toggle_state(ad, True)
      ad.droid.wifiP2pClose()
      aware_avail = ad.droid.wifiIsAwareAvailable()
      if not aware_avail:
        self.log.info('Aware not available. Waiting ...')
        autils.wait_for_event(ad, aconsts.BROADCAST_WIFI_AWARE_AVAILABLE)
      ad.ed.pop_all(aconsts.BROADCAST_WIFI_AWARE_AVAILABLE) # clear-out extras
      ad.aware_capabilities = autils.get_aware_capabilities(ad)
      self.reset_device_parameters(ad)
      self.reset_device_statistics(ad)
      self.set_power_mode_parameters(ad)
Пример #12
0
    def start_discovery_session(self, dut, session_id, is_publish, dtype):
        """Start a discovery session

    Args:
      dut: Device under test
      session_id: ID of the Aware session in which to start discovery
      is_publish: True for a publish session, False for subscribe session
      dtype: Type of the discovery session

    Returns:
      Discovery session started event.
    """
        config = {}
        config[aconsts.DISCOVERY_KEY_DISCOVERY_TYPE] = dtype
        config[aconsts.DISCOVERY_KEY_SERVICE_NAME] = "GoogleTestServiceXY"

        if is_publish:
            disc_id = dut.droid.wifiAwarePublish(session_id, config)
            event_name = aconsts.SESSION_CB_ON_PUBLISH_STARTED
        else:
            disc_id = dut.droid.wifiAwareSubscribe(session_id, config)
            event_name = aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED

        event = autils.wait_for_event(dut, event_name)
        return disc_id, event
    def start_aware(self, dut, is_publish):
        """Start Aware attach, then start Publish/Subscribe based on role

     Args:
         dut: Aware device
         is_publish: True for Publisher, False for subscriber
         @:return: dict with Aware discovery session info
    """
        aware_id = dut.droid.wifiAwareAttach(True)
        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)
        event = autils.wait_for_event(dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
        mac = self.transfer_mac_format(event["data"]["mac"])
        dut.log.info("NMI=%s", mac)

        if is_publish:
            config = autils.create_discovery_config(self.SERVICE_NAME,
                                                    aconsts.PUBLISH_TYPE_UNSOLICITED)
            disc_id = dut.droid.wifiAwarePublish(aware_id, config)
            autils.wait_for_event(dut, aconsts.SESSION_CB_ON_PUBLISH_STARTED)
        else:
            config = autils.create_discovery_config(self.SERVICE_NAME,
                                                    aconsts.SUBSCRIBE_TYPE_PASSIVE)
            disc_id = dut.droid.wifiAwareSubscribe(aware_id, config)
            autils.wait_for_event(dut, aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED)
        aware_session = {"awareId": aware_id, "discId": disc_id, "mac": mac}
        return aware_session
    def test_rtt_without_initiator_aware(self):
        """Try to perform RTT operation when there is no local Aware session (on the
        Initiator). The Responder is configured normally: Aware on and a Publisher
        with Ranging enable. Should FAIL.
        """
        init_dut = self.android_devices[0]
        resp_dut = self.android_devices[1]

        # Enable a Responder and start a Publisher
        resp_id = resp_dut.droid.wifiAwareAttach(True)
        autils.wait_for_event(resp_dut, aconsts.EVENT_CB_ON_ATTACHED)
        resp_ident_event = autils.wait_for_event(
            resp_dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
        resp_mac = resp_ident_event['data']['mac']

        resp_config = autils.add_ranging_to_pub(autils.create_discovery_config(
            self.SERVICE_NAME, aconsts.PUBLISH_TYPE_UNSOLICITED),
                                                enable_ranging=True)
        resp_dut.droid.wifiAwarePublish(resp_id, resp_config)
        autils.wait_for_event(resp_dut, aconsts.SESSION_CB_ON_PUBLISH_STARTED)

        # Initiate an RTT to Responder (no Aware started on Initiator!)
        results = []
        num_no_responses = 0
        num_successes = 0
        for i in range(self.NUM_ITER):
            result = self.run_rtt_discovery(init_dut, resp_mac=resp_mac)
            self.log.debug("result: %s", result)
            results.append(result)
            if result is None:
                num_no_responses = num_no_responses + 1
            elif (result[rconsts.EVENT_CB_RANGING_KEY_STATUS] ==
                  rconsts.EVENT_CB_RANGING_STATUS_SUCCESS):
                num_successes = num_successes + 1

        asserts.assert_equal(num_no_responses,
                             0,
                             "No RTT response?",
                             extras={"data": results})
        asserts.assert_equal(num_successes,
                             0,
                             "Aware RTT w/o Aware should FAIL!",
                             extras={"data": results})
        asserts.explicit_pass("RTT Aware test done", extras={"data": results})
Пример #15
0
    def verify_discovery_session_term(self, dut, disc_id, config, is_publish,
                                      term_ind_on):
        """Utility to verify that the specified discovery session has terminated (by
    waiting for the TTL and then attempting to reconfigure).

    Args:
      dut: device under test
      disc_id: discovery id for the existing session
      config: configuration of the existing session
      is_publish: True if the configuration was publish, False if subscribe
      term_ind_on: True if a termination indication is expected, False otherwise
    """
        # Wait for session termination
        if term_ind_on:
            autils.wait_for_event(
                dut,
                autils.decorate_event(aconsts.SESSION_CB_ON_SESSION_TERMINATED,
                                      disc_id))
        else:
            # can't defer wait to end since in any case have to wait for session to
            # expire
            autils.fail_on_event(
                dut,
                autils.decorate_event(aconsts.SESSION_CB_ON_SESSION_TERMINATED,
                                      disc_id))

        # Validate that session expired by trying to configure it (expect failure)
        config[aconsts.DISCOVERY_KEY_SSI] = "something else"
        if is_publish:
            dut.droid.wifiAwareUpdatePublish(disc_id, config)
        else:
            dut.droid.wifiAwareUpdateSubscribe(disc_id, config)

        # The response to update discovery session is:
        # term_ind_on=True: session was cleaned-up so won't get an explicit failure, but won't get a
        #                   success either. Can check for no SESSION_CB_ON_SESSION_CONFIG_UPDATED but
        #                   will defer to the end of the test (no events on queue).
        # term_ind_on=False: session was not cleaned-up (yet). So expect
        #                    SESSION_CB_ON_SESSION_CONFIG_FAILED.
        if not term_ind_on:
            autils.wait_for_event(
                dut,
                autils.decorate_event(
                    aconsts.SESSION_CB_ON_SESSION_CONFIG_FAILED, disc_id))
Пример #16
0
    def setup_test(self):
        required_params = ("aware_default_power_mode", )
        self.unpack_userparams(required_params)

        for ad in self.android_devices:
            asserts.skip_if(
                not ad.droid.doesDeviceSupportWifiAwareFeature(),
                "Device under test does not support Wi-Fi Aware - skipping test"
            )
            wutils.wifi_toggle_state(ad, True)
            ad.droid.wifiP2pClose()
            aware_avail = ad.droid.wifiIsAwareAvailable()
            if not aware_avail:
                self.log.info('Aware not available. Waiting ...')
                autils.wait_for_event(ad,
                                      aconsts.BROADCAST_WIFI_AWARE_AVAILABLE)
            ad.ed.clear_all_events()
            ad.aware_capabilities = autils.get_aware_capabilities(ad)
            self.reset_device_parameters(ad)
            self.reset_device_statistics(ad)
            self.set_power_mode_parameters(ad)
    def test_service_ids_in_beacon(self):
        """Verify that beacons include service IDs for both publish and subscribe
    sessions of all types: solicited/unsolicited/active/passive."""
        dut = self.android_devices[0]

        self.log.info("Reminder: start a sniffer before running test")

        # attach
        session_id = dut.droid.wifiAwareAttach(True)
        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)
        ident_event = autils.wait_for_event(
            dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
        mac = ident_event["data"]["mac"]
        self.log.info("Source MAC Address of 'interesting' packets = %s", mac)
        self.log.info("Wireshark filter = 'wlan.ta == %s:%s:%s:%s:%s:%s'",
                      mac[0:2], mac[2:4], mac[4:6], mac[6:8], mac[8:10],
                      mac[10:12])

        time.sleep(5)  # get some samples pre-discovery

        # start 4 discovery session (one of each type)
        self.start_discovery_session(dut, session_id, True,
                                     aconsts.PUBLISH_TYPE_UNSOLICITED,
                                     "GoogleTestService-Pub-Unsolicited")
        self.start_discovery_session(dut, session_id, True,
                                     aconsts.PUBLISH_TYPE_SOLICITED,
                                     "GoogleTestService-Pub-Solicited")
        self.start_discovery_session(dut, session_id, False,
                                     aconsts.SUBSCRIBE_TYPE_ACTIVE,
                                     "GoogleTestService-Sub-Active")
        self.start_discovery_session(dut, session_id, False,
                                     aconsts.SUBSCRIBE_TYPE_PASSIVE,
                                     "GoogleTestService-Sub-Passive")

        time.sleep(15)  # get some samples while discovery is alive

        self.log.info("Reminder: stop sniffer")
Пример #18
0
    def test_infra_assoc_discovery_stress(self):
        """Validates that Wi-Fi Aware discovery does not interfere with
    infrastructure (AP) association.

    Test assumes (and verifies) that device is already associated to an AP.
    """
        dut = self.android_devices[0]

        # check that associated and start tracking
        dut.droid.wifiStartTrackingStateChange()
        asserts.assert_true(self.is_associated(dut),
                            "DUT is not associated to an AP!")

        # attach
        session_id = dut.droid.wifiAwareAttach(True)
        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)

        # publish
        p_disc_id = dut.droid.wifiAwarePublish(
            session_id,
            autils.create_discovery_config(self.SERVICE_NAME,
                                           aconsts.PUBLISH_TYPE_UNSOLICITED))
        autils.wait_for_event(dut, aconsts.SESSION_CB_ON_PUBLISH_STARTED)

        # wait for any disassociation change events
        any_disassociations = False
        try:
            dut.ed.pop_event(wconsts.WIFI_DISCONNECTED,
                             self.TEST_DURATION_SECONDS)
            any_disassociations = True
        except queue.Empty:
            pass
        finally:
            dut.droid.wifiStopTrackingStateChange()

        asserts.assert_false(any_disassociations,
                             "Wi-Fi disassociated during test run")
Пример #19
0
    def test_attach_with_doze(self):
        """Function test case / Attach test cases / attempt to attach with doze on

    Validates that if trying to attach with device in doze mode will receive the
    expected failure callback. As a side-effect also validates that the
    broadcast for Aware unavailable is received.
    """
        dut = self.android_devices[0]
        asserts.assert_true(utils.enable_doze(dut), "Can't enable doze")
        autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_NOT_AVAILABLE)
        dut.droid.wifiAwareAttach()
        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACH_FAILED)
        asserts.assert_true(utils.disable_doze(dut), "Can't disable doze")
        autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_AVAILABLE)
    def test_attach_apm_toggle_attach_again(self):
        """Validates that enabling Airplane mode while Aware is on resets it
    correctly, and allows it to be re-enabled when Airplane mode is then
    disabled."""
        dut = self.android_devices[0]

        # enable Aware (attach)
        dut.droid.wifiAwareAttach()
        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)

        # enable airplane mode
        force_airplane_mode(dut, True)
        autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_NOT_AVAILABLE)

        # wait a few seconds and disable airplane mode
        time.sleep(10)
        force_airplane_mode(dut, False)
        autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_AVAILABLE)

        # try enabling Aware again (attach)
        dut.droid.wifiAwareAttach()
        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)
Пример #21
0
    def test_attach_with_location_off(self):
        """Function test case / Attach test cases / attempt to attach with location
    mode off.

    Validates that if trying to attach with device location mode off will
    receive the expected failure callback. As a side-effect also validates that
    the broadcast for Aware unavailable is received.
    """
        dut = self.android_devices[0]
        utils.set_location_service(dut, False)
        autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_NOT_AVAILABLE)
        dut.droid.wifiAwareAttach()
        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACH_FAILED)
        utils.set_location_service(dut, True)
        autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_AVAILABLE)
    def test_attach_multiple_sessions(self):
        """Functional test case / Attach test cases / multiple attach sessions

    Validates that when creating multiple attach sessions each can be
    configured independently as to whether or not to receive an identity
    callback.
    """
        dut = self.android_devices[0]

        # Create 3 attach sessions: 2 without identity callback, 1 with
        id1 = dut.droid.wifiAwareAttach(False, None, True)
        time.sleep(10)  # to make sure all calls and callbacks are done
        id2 = dut.droid.wifiAwareAttach(True, None, True)
        time.sleep(10)  # to make sure all calls and callbacks are done
        id3 = dut.droid.wifiAwareAttach(False, None, True)
        dut.log.info('id1=%d, id2=%d, id3=%d', id1, id2, id3)

        # Attach session 1: wait for attach, should not get identity
        autils.wait_for_event(
            dut, autils.decorate_event(aconsts.EVENT_CB_ON_ATTACHED, id1))
        autils.fail_on_event(
            dut,
            autils.decorate_event(aconsts.EVENT_CB_ON_IDENTITY_CHANGED, id1))

        # Attach session 2: wait for attach and for identity callback
        autils.wait_for_event(
            dut, autils.decorate_event(aconsts.EVENT_CB_ON_ATTACHED, id2))
        autils.wait_for_event(
            dut,
            autils.decorate_event(aconsts.EVENT_CB_ON_IDENTITY_CHANGED, id2))

        # Attach session 3: wait for attach, should not get identity
        autils.wait_for_event(
            dut, autils.decorate_event(aconsts.EVENT_CB_ON_ATTACHED, id3))
        autils.fail_on_event(
            dut,
            autils.decorate_event(aconsts.EVENT_CB_ON_IDENTITY_CHANGED, id3))
Пример #23
0
    def discovery_mismatch_test_utility(self,
                                        is_expected_to_pass,
                                        p_type,
                                        s_type,
                                        p_service_name=None,
                                        s_service_name=None,
                                        p_mf_1=None,
                                        s_mf_1=None):
        """Utility which runs the negative discovery test for mismatched service
    configs.

    Args:
      is_expected_to_pass: True if positive test, False if negative
      p_type: Publish discovery type
      s_type: Subscribe discovery type
      p_service_name: Publish service name (or None to leave unchanged)
      s_service_name: Subscribe service name (or None to leave unchanged)
      p_mf_1: Publish match filter element [1] (or None to leave unchanged)
      s_mf_1: Subscribe match filter element [1] (or None to leave unchanged)
    """
        p_dut = self.android_devices[0]
        p_dut.pretty_name = "Publisher"
        s_dut = self.android_devices[1]
        s_dut.pretty_name = "Subscriber"

        # create configurations
        p_config = self.create_publish_config(p_dut.aware_capabilities,
                                              p_type,
                                              self.PAYLOAD_SIZE_TYPICAL,
                                              ttl=0,
                                              term_ind_on=False,
                                              null_match=False)
        if p_service_name is not None:
            p_config[aconsts.DISCOVERY_KEY_SERVICE_NAME] = p_service_name
        if p_mf_1 is not None:
            p_config[
                aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST] = autils.encode_list([
                    (10).to_bytes(1, byteorder="big"), p_mf_1,
                    bytes(range(40))
                ])
        s_config = self.create_publish_config(s_dut.aware_capabilities,
                                              s_type,
                                              self.PAYLOAD_SIZE_TYPICAL,
                                              ttl=0,
                                              term_ind_on=False,
                                              null_match=False)
        if s_service_name is not None:
            s_config[aconsts.DISCOVERY_KEY_SERVICE_NAME] = s_service_name
        if s_mf_1 is not None:
            s_config[
                aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST] = autils.encode_list([
                    (10).to_bytes(1, byteorder="big"), s_mf_1,
                    bytes(range(40))
                ])

        p_id = p_dut.droid.wifiAwareAttach(False)
        autils.wait_for_event(p_dut, aconsts.EVENT_CB_ON_ATTACHED)
        time.sleep(self.device_startup_offset)
        s_id = s_dut.droid.wifiAwareAttach(False)
        autils.wait_for_event(s_dut, aconsts.EVENT_CB_ON_ATTACHED)

        # Publisher: start publish and wait for confirmation
        p_disc_id = p_dut.droid.wifiAwarePublish(p_id, p_config)
        autils.wait_for_event(p_dut, aconsts.SESSION_CB_ON_PUBLISH_STARTED)

        # Subscriber: start subscribe and wait for confirmation
        s_disc_id = s_dut.droid.wifiAwareSubscribe(s_id, s_config)
        autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED)

        # Subscriber: fail on service discovery
        if is_expected_to_pass:
            autils.wait_for_event(s_dut,
                                  aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)
        else:
            autils.fail_on_event(s_dut,
                                 aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)

        # Publisher+Subscriber: Terminate sessions
        p_dut.droid.wifiAwareDestroyDiscoverySession(p_disc_id)
        s_dut.droid.wifiAwareDestroyDiscoverySession(s_disc_id)

        # verify that there were no other events (including terminations)
        time.sleep(autils.EVENT_TIMEOUT)
        autils.verify_no_more_events(p_dut, timeout=0)
        autils.verify_no_more_events(s_dut, timeout=0)
Пример #24
0
    def positive_ttl_test_utility(self, is_publish, ptype, stype, term_ind_on):
        """Utility which runs a positive discovery session TTL configuration test

    Iteration 1: Verify session started with TTL
    Iteration 2: Verify session started without TTL and reconfigured with TTL
    Iteration 3: Verify session started with (long) TTL and reconfigured with
                 (short) TTL

    Args:
      is_publish: True if testing publish, False if testing subscribe
      ptype: Publish discovery type (used if is_publish is True)
      stype: Subscribe discovery type (used if is_publish is False)
      term_ind_on: Configuration of termination indication
    """
        SHORT_TTL = 5  # 5 seconds
        LONG_TTL = 100  # 100 seconds
        dut = self.android_devices[0]

        # Attach and wait for confirmation
        id = dut.droid.wifiAwareAttach(False)
        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)

        # Iteration 1: Start discovery session with TTL
        config = self.create_base_config(dut.aware_capabilities, is_publish,
                                         ptype, stype,
                                         self.PAYLOAD_SIZE_TYPICAL, SHORT_TTL,
                                         term_ind_on, False)
        if is_publish:
            disc_id = dut.droid.wifiAwarePublish(id, config, True)
            autils.wait_for_event(
                dut,
                autils.decorate_event(aconsts.SESSION_CB_ON_PUBLISH_STARTED,
                                      disc_id))
        else:
            disc_id = dut.droid.wifiAwareSubscribe(id, config, True)
            autils.wait_for_event(
                dut,
                autils.decorate_event(aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED,
                                      disc_id))

        # Wait for session termination & verify
        self.verify_discovery_session_term(dut, disc_id, config, is_publish,
                                           term_ind_on)

        # Iteration 2: Start a discovery session without TTL
        config = self.create_base_config(dut.aware_capabilities, is_publish,
                                         ptype, stype,
                                         self.PAYLOAD_SIZE_TYPICAL, 0,
                                         term_ind_on, False)
        if is_publish:
            disc_id = dut.droid.wifiAwarePublish(id, config, True)
            autils.wait_for_event(
                dut,
                autils.decorate_event(aconsts.SESSION_CB_ON_PUBLISH_STARTED,
                                      disc_id))
        else:
            disc_id = dut.droid.wifiAwareSubscribe(id, config, True)
            autils.wait_for_event(
                dut,
                autils.decorate_event(aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED,
                                      disc_id))

        # Update with a TTL
        config = self.create_base_config(dut.aware_capabilities, is_publish,
                                         ptype, stype,
                                         self.PAYLOAD_SIZE_TYPICAL, SHORT_TTL,
                                         term_ind_on, False)
        if is_publish:
            dut.droid.wifiAwareUpdatePublish(disc_id, config)
        else:
            dut.droid.wifiAwareUpdateSubscribe(disc_id, config)
        autils.wait_for_event(
            dut,
            autils.decorate_event(aconsts.SESSION_CB_ON_SESSION_CONFIG_UPDATED,
                                  disc_id))

        # Wait for session termination & verify
        self.verify_discovery_session_term(dut, disc_id, config, is_publish,
                                           term_ind_on)

        # Iteration 3: Start a discovery session with (long) TTL
        config = self.create_base_config(dut.aware_capabilities, is_publish,
                                         ptype, stype,
                                         self.PAYLOAD_SIZE_TYPICAL, LONG_TTL,
                                         term_ind_on, False)
        if is_publish:
            disc_id = dut.droid.wifiAwarePublish(id, config, True)
            autils.wait_for_event(
                dut,
                autils.decorate_event(aconsts.SESSION_CB_ON_PUBLISH_STARTED,
                                      disc_id))
        else:
            disc_id = dut.droid.wifiAwareSubscribe(id, config, True)
            autils.wait_for_event(
                dut,
                autils.decorate_event(aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED,
                                      disc_id))

        # Update with a TTL
        config = self.create_base_config(dut.aware_capabilities, is_publish,
                                         ptype, stype,
                                         self.PAYLOAD_SIZE_TYPICAL, SHORT_TTL,
                                         term_ind_on, False)
        if is_publish:
            dut.droid.wifiAwareUpdatePublish(disc_id, config)
        else:
            dut.droid.wifiAwareUpdateSubscribe(disc_id, config)
        autils.wait_for_event(
            dut,
            autils.decorate_event(aconsts.SESSION_CB_ON_SESSION_CONFIG_UPDATED,
                                  disc_id))

        # Wait for session termination & verify
        self.verify_discovery_session_term(dut, disc_id, config, is_publish,
                                           term_ind_on)

        # verify that there were no other events
        autils.verify_no_more_events(dut)

        # verify that forbidden callbacks aren't called
        if not term_ind_on:
            autils.validate_forbidden_callbacks(
                dut, {
                    aconsts.CB_EV_PUBLISH_TERMINATED: 0,
                    aconsts.CB_EV_SUBSCRIBE_TERMINATED: 0
                })
Пример #25
0
    def positive_discovery_test_utility(self, ptype, stype, payload_size):
        """Utility which runs a positive discovery test:
    - Discovery (publish/subscribe) with TTL=0 (non-self-terminating)
    - Exchange messages
    - Update publish/subscribe
    - Terminate

    Args:
      ptype: Publish discovery type
      stype: Subscribe discovery type
      payload_size: One of PAYLOAD_SIZE_* constants - MIN, TYPICAL, MAX
    """
        p_dut = self.android_devices[0]
        p_dut.pretty_name = "Publisher"
        s_dut = self.android_devices[1]
        s_dut.pretty_name = "Subscriber"

        # Publisher+Subscriber: attach and wait for confirmation
        p_id = p_dut.droid.wifiAwareAttach(False)
        autils.wait_for_event(p_dut, aconsts.EVENT_CB_ON_ATTACHED)
        time.sleep(self.device_startup_offset)
        s_id = s_dut.droid.wifiAwareAttach(False)
        autils.wait_for_event(s_dut, aconsts.EVENT_CB_ON_ATTACHED)

        # Publisher: start publish and wait for confirmation
        p_config = self.create_publish_config(p_dut.aware_capabilities,
                                              ptype,
                                              payload_size,
                                              ttl=0,
                                              term_ind_on=False,
                                              null_match=False)
        p_disc_id = p_dut.droid.wifiAwarePublish(p_id, p_config)
        autils.wait_for_event(p_dut, aconsts.SESSION_CB_ON_PUBLISH_STARTED)

        # Subscriber: start subscribe and wait for confirmation
        s_config = self.create_subscribe_config(s_dut.aware_capabilities,
                                                stype,
                                                payload_size,
                                                ttl=0,
                                                term_ind_on=False,
                                                null_match=True)
        s_disc_id = s_dut.droid.wifiAwareSubscribe(s_id, s_config)
        autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED)

        # Subscriber: wait for service discovery
        discovery_event = autils.wait_for_event(
            s_dut, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)
        peer_id_on_sub = discovery_event["data"][
            aconsts.SESSION_CB_KEY_PEER_ID]

        # Subscriber: validate contents of discovery:
        # - SSI: publisher's
        # - Match filter: UNSOLICITED - publisher, SOLICITED - subscriber
        autils.assert_equal_strings(
            bytes(discovery_event["data"][
                aconsts.SESSION_CB_KEY_SERVICE_SPECIFIC_INFO]).decode("utf-8"),
            p_config[aconsts.DISCOVERY_KEY_SSI],
            "Discovery mismatch: service specific info (SSI)")
        asserts.assert_equal(
            autils.decode_list(discovery_event["data"][
                aconsts.SESSION_CB_KEY_MATCH_FILTER_LIST]),
            autils.decode_list(
                p_config[aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST] if ptype ==
                aconsts.PUBLISH_TYPE_UNSOLICITED else s_config[
                    aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST]),
            "Discovery mismatch: match filter")

        # Subscriber: send message to peer (Publisher)
        s_dut.droid.wifiAwareSendMessage(s_disc_id, peer_id_on_sub,
                                         self.get_next_msg_id(),
                                         self.query_msg, self.msg_retx_count)
        autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_MESSAGE_SENT)

        # Publisher: wait for received message
        pub_rx_msg_event = autils.wait_for_event(
            p_dut, aconsts.SESSION_CB_ON_MESSAGE_RECEIVED)
        peer_id_on_pub = pub_rx_msg_event["data"][
            aconsts.SESSION_CB_KEY_PEER_ID]

        # Publisher: validate contents of message
        asserts.assert_equal(
            pub_rx_msg_event["data"][aconsts.SESSION_CB_KEY_MESSAGE_AS_STRING],
            self.query_msg, "Subscriber -> Publisher message corrupted")

        # Publisher: send message to peer (Subscriber)
        p_dut.droid.wifiAwareSendMessage(p_disc_id, peer_id_on_pub,
                                         self.get_next_msg_id(),
                                         self.response_msg,
                                         self.msg_retx_count)
        autils.wait_for_event(p_dut, aconsts.SESSION_CB_ON_MESSAGE_SENT)

        # Subscriber: wait for received message
        sub_rx_msg_event = autils.wait_for_event(
            s_dut, aconsts.SESSION_CB_ON_MESSAGE_RECEIVED)

        # Subscriber: validate contents of message
        asserts.assert_equal(
            sub_rx_msg_event["data"][aconsts.SESSION_CB_KEY_PEER_ID],
            peer_id_on_sub,
            "Subscriber received message from different peer ID then discovery!?"
        )
        autils.assert_equal_strings(
            sub_rx_msg_event["data"][aconsts.SESSION_CB_KEY_MESSAGE_AS_STRING],
            self.response_msg, "Publisher -> Subscriber message corrupted")

        # Subscriber: validate that we're not getting another Service Discovery
        autils.fail_on_event(s_dut, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)

        # Publisher: update publish and wait for confirmation
        p_config[aconsts.DISCOVERY_KEY_SSI] = "something else"
        p_dut.droid.wifiAwareUpdatePublish(p_disc_id, p_config)
        autils.wait_for_event(p_dut,
                              aconsts.SESSION_CB_ON_SESSION_CONFIG_UPDATED)

        # Subscriber: expect a new service discovery
        discovery_event = autils.wait_for_event(
            s_dut, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)

        # Subscriber: validate contents of discovery
        autils.assert_equal_strings(
            bytes(discovery_event["data"][
                aconsts.SESSION_CB_KEY_SERVICE_SPECIFIC_INFO]).decode("utf-8"),
            p_config[aconsts.DISCOVERY_KEY_SSI],
            "Discovery mismatch (after pub update): service specific info (SSI)"
        )
        asserts.assert_equal(
            autils.decode_list(discovery_event["data"][
                aconsts.SESSION_CB_KEY_MATCH_FILTER_LIST]),
            autils.decode_list(
                p_config[aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST] if ptype ==
                aconsts.PUBLISH_TYPE_UNSOLICITED else s_config[
                    aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST]),
            "Discovery mismatch: match filter")

        # Subscribe: update subscribe and wait for confirmation
        s_config = self.create_subscribe_config(s_dut.aware_capabilities,
                                                stype,
                                                payload_size,
                                                ttl=0,
                                                term_ind_on=False,
                                                null_match=False)
        s_dut.droid.wifiAwareUpdateSubscribe(s_disc_id, s_config)
        autils.wait_for_event(s_dut,
                              aconsts.SESSION_CB_ON_SESSION_CONFIG_UPDATED)

        # Publisher+Subscriber: Terminate sessions
        p_dut.droid.wifiAwareDestroyDiscoverySession(p_disc_id)
        s_dut.droid.wifiAwareDestroyDiscoverySession(s_disc_id)

        # sleep for timeout period and then verify all 'fail_on_event' together
        time.sleep(autils.EVENT_TIMEOUT)

        # verify that there were no other events
        autils.verify_no_more_events(p_dut, timeout=0)
        autils.verify_no_more_events(s_dut, timeout=0)

        # verify that forbidden callbacks aren't called
        autils.validate_forbidden_callbacks(p_dut, {aconsts.CB_EV_MATCH: 0})
Пример #26
0
    def run_multiple_concurrent_services(self, type_x, type_y):
        """Validate multiple identical discovery services running on both devices:
    - DUT1 & DUT2 running Publish for X
    - DUT1 & DUT2 running Publish for Y
    - DUT1 Subscribes for X
    - DUT2 Subscribes for Y
    Message exchanges.

    Note: test requires that devices support 2 publish sessions concurrently.
    The test will be skipped if the devices are not capable.

    Args:
      type_x, type_y: A list of [ptype, stype] of the publish and subscribe
                      types for services X and Y respectively.
    """
        dut1 = self.android_devices[0]
        dut2 = self.android_devices[1]

        X_SERVICE_NAME = "ServiceXXX"
        Y_SERVICE_NAME = "ServiceYYY"

        asserts.skip_if(
            dut1.aware_capabilities[aconsts.CAP_MAX_PUBLISHES] < 2
            or dut2.aware_capabilities[aconsts.CAP_MAX_PUBLISHES] < 2,
            "Devices do not support 2 publish sessions")

        # attach and wait for confirmation
        id1 = dut1.droid.wifiAwareAttach(False)
        autils.wait_for_event(dut1, aconsts.EVENT_CB_ON_ATTACHED)
        time.sleep(self.device_startup_offset)
        id2 = dut2.droid.wifiAwareAttach(False)
        autils.wait_for_event(dut2, aconsts.EVENT_CB_ON_ATTACHED)

        # DUT1 & DUT2: start publishing both X & Y services and wait for
        # confirmations
        dut1_x_pid = dut1.droid.wifiAwarePublish(
            id1, autils.create_discovery_config(X_SERVICE_NAME, type_x[0]))
        event = autils.wait_for_event(dut1,
                                      aconsts.SESSION_CB_ON_PUBLISH_STARTED)
        asserts.assert_equal(event["data"][aconsts.SESSION_CB_KEY_SESSION_ID],
                             dut1_x_pid,
                             "Unexpected DUT1 X publish session discovery ID")

        dut1_y_pid = dut1.droid.wifiAwarePublish(
            id1, autils.create_discovery_config(Y_SERVICE_NAME, type_y[0]))
        event = autils.wait_for_event(dut1,
                                      aconsts.SESSION_CB_ON_PUBLISH_STARTED)
        asserts.assert_equal(event["data"][aconsts.SESSION_CB_KEY_SESSION_ID],
                             dut1_y_pid,
                             "Unexpected DUT1 Y publish session discovery ID")

        dut2_x_pid = dut2.droid.wifiAwarePublish(
            id2, autils.create_discovery_config(X_SERVICE_NAME, type_x[0]))
        event = autils.wait_for_event(dut2,
                                      aconsts.SESSION_CB_ON_PUBLISH_STARTED)
        asserts.assert_equal(event["data"][aconsts.SESSION_CB_KEY_SESSION_ID],
                             dut2_x_pid,
                             "Unexpected DUT2 X publish session discovery ID")

        dut2_y_pid = dut2.droid.wifiAwarePublish(
            id2, autils.create_discovery_config(Y_SERVICE_NAME, type_y[0]))
        event = autils.wait_for_event(dut2,
                                      aconsts.SESSION_CB_ON_PUBLISH_STARTED)
        asserts.assert_equal(event["data"][aconsts.SESSION_CB_KEY_SESSION_ID],
                             dut2_y_pid,
                             "Unexpected DUT2 Y publish session discovery ID")

        # DUT1: start subscribing for X
        dut1_x_sid = dut1.droid.wifiAwareSubscribe(
            id1, autils.create_discovery_config(X_SERVICE_NAME, type_x[1]))
        autils.wait_for_event(dut1, aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED)

        # DUT2: start subscribing for Y
        dut2_y_sid = dut2.droid.wifiAwareSubscribe(
            id2, autils.create_discovery_config(Y_SERVICE_NAME, type_y[1]))
        autils.wait_for_event(dut2, aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED)

        # DUT1 & DUT2: wait for service discovery
        event = autils.wait_for_event(dut1,
                                      aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)
        asserts.assert_equal(
            event["data"][aconsts.SESSION_CB_KEY_SESSION_ID], dut1_x_sid,
            "Unexpected DUT1 X subscribe session discovery ID")
        dut1_peer_id_for_dut2_x = event["data"][aconsts.SESSION_CB_KEY_PEER_ID]

        event = autils.wait_for_event(dut2,
                                      aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)
        asserts.assert_equal(
            event["data"][aconsts.SESSION_CB_KEY_SESSION_ID], dut2_y_sid,
            "Unexpected DUT2 Y subscribe session discovery ID")
        dut2_peer_id_for_dut1_y = event["data"][aconsts.SESSION_CB_KEY_PEER_ID]

        # DUT1.X send message to DUT2
        x_msg = "Hello X on DUT2!"
        dut1.droid.wifiAwareSendMessage(dut1_x_sid, dut1_peer_id_for_dut2_x,
                                        self.get_next_msg_id(), x_msg,
                                        self.msg_retx_count)
        autils.wait_for_event(dut1, aconsts.SESSION_CB_ON_MESSAGE_SENT)
        event = autils.wait_for_event(dut2,
                                      aconsts.SESSION_CB_ON_MESSAGE_RECEIVED)
        asserts.assert_equal(
            event["data"][aconsts.SESSION_CB_KEY_SESSION_ID], dut2_x_pid,
            "Unexpected publish session ID on DUT2 for meesage "
            "received on service X")
        asserts.assert_equal(
            event["data"][aconsts.SESSION_CB_KEY_MESSAGE_AS_STRING], x_msg,
            "Message on service X from DUT1 to DUT2 not received correctly")

        # DUT2.Y send message to DUT1
        y_msg = "Hello Y on DUT1!"
        dut2.droid.wifiAwareSendMessage(dut2_y_sid, dut2_peer_id_for_dut1_y,
                                        self.get_next_msg_id(), y_msg,
                                        self.msg_retx_count)
        autils.wait_for_event(dut2, aconsts.SESSION_CB_ON_MESSAGE_SENT)
        event = autils.wait_for_event(dut1,
                                      aconsts.SESSION_CB_ON_MESSAGE_RECEIVED)
        asserts.assert_equal(
            event["data"][aconsts.SESSION_CB_KEY_SESSION_ID], dut1_y_pid,
            "Unexpected publish session ID on DUT1 for meesage "
            "received on service Y")
        asserts.assert_equal(
            event["data"][aconsts.SESSION_CB_KEY_MESSAGE_AS_STRING], y_msg,
            "Message on service Y from DUT2 to DUT1 not received correctly")
    def test_ib_multi_data_path_mac_random_test(self):
        """Verify there is no factory MAC Address leakage during the Aware discovery, NDP creation,
        socket setup and IP service connection."""

        p_dut = self.android_devices[0]
        s_dut = self.android_devices[1]
        mac_addresses = []
        factory_mac_addresses = []
        sec_types = [self.ENCR_TYPE_PMK, self.ENCR_TYPE_PASSPHRASE]

        self.log.info("Starting packet capture")
        pcap_procs = wutils.start_pcap(
            self.packet_capture, 'dual', self.test_name)

        factory_mac_1 = p_dut.droid.wifigetFactorymacAddresses()[0]
        p_dut.log.info("Factory Address: %s", factory_mac_1)
        factory_mac_2 = s_dut.droid.wifigetFactorymacAddresses()[0]
        s_dut.log.info("Factory Address: %s", factory_mac_2)
        factory_mac_addresses.append(factory_mac_1)
        factory_mac_addresses.append(factory_mac_2)

        # Start Aware and exchange messages
        publish_session = self.start_aware(p_dut, True)
        subscribe_session = self.start_aware(s_dut, False)
        mac_addresses.append(publish_session["mac"])
        mac_addresses.append(subscribe_session["mac"])
        discovery_event = autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)
        subscribe_session["peerId"] = discovery_event['data'][aconsts.SESSION_CB_KEY_PEER_ID]

        msg_id = self.get_next_msg_id()
        s_dut.droid.wifiAwareSendMessage(subscribe_session["discId"], subscribe_session["peerId"],
                                         msg_id, self.ping_msg, aconsts.MAX_TX_RETRIES)
        autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_MESSAGE_SENT)
        pub_rx_msg_event = autils.wait_for_event(p_dut, aconsts.SESSION_CB_ON_MESSAGE_RECEIVED)
        publish_session["peerId"] = pub_rx_msg_event['data'][aconsts.SESSION_CB_KEY_PEER_ID]

        msg_id = self.get_next_msg_id()
        p_dut.droid.wifiAwareSendMessage(publish_session["discId"], publish_session["peerId"],
                                         msg_id, self.ping_msg, aconsts.MAX_TX_RETRIES)
        autils.wait_for_event(p_dut, aconsts.SESSION_CB_ON_MESSAGE_SENT)
        autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_MESSAGE_RECEIVED)

        # Create Aware NDP
        p_req_keys = []
        s_req_keys = []
        for sec in sec_types:
            ndp_info = self.create_date_path(p_dut, publish_session, s_dut, subscribe_session, sec)
            p_req_keys.append(ndp_info["pubReqKey"])
            s_req_keys.append(ndp_info["subReqKey"])
            mac_addresses.append(ndp_info["pubIfMac"])
            mac_addresses.append(ndp_info["subIfMac"])

        # clean-up
        for p_req_key in p_req_keys:
            p_dut.droid.connectivityUnregisterNetworkCallback(p_req_key)
        for s_req_key in s_req_keys:
            s_dut.droid.connectivityUnregisterNetworkCallback(s_req_key)
        p_dut.droid.wifiAwareDestroyAll()
        s_dut.droid.wifiAwareDestroyAll()

        self.log.info("Stopping packet capture")
        wutils.stop_pcap(self.packet_capture, pcap_procs, False)

        self.verify_mac_no_leakage(pcap_procs, factory_mac_addresses, mac_addresses)
Пример #28
0
    def test_max_discovery_sessions(self):
        """Validate that the device can create as many discovery sessions as are
    indicated in the device capabilities
    """
        dut = self.android_devices[0]

        # attach
        session_id = dut.droid.wifiAwareAttach(True)
        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)

        service_name_template = 'GoogleTestService-%s-%d'

        # start the max number of publish sessions
        for i in range(dut.aware_capabilities[aconsts.CAP_MAX_PUBLISHES]):
            # create publish discovery session of both types
            pub_disc_id = self.start_discovery_session(
                dut, session_id, True, aconsts.PUBLISH_TYPE_UNSOLICITED if i %
                2 == 0 else aconsts.PUBLISH_TYPE_SOLICITED,
                service_name_template % ('pub', i), True)

        # start the max number of subscribe sessions
        for i in range(dut.aware_capabilities[aconsts.CAP_MAX_SUBSCRIBES]):
            # create publish discovery session of both types
            sub_disc_id = self.start_discovery_session(
                dut, session_id, False, aconsts.SUBSCRIBE_TYPE_PASSIVE if i %
                2 == 0 else aconsts.SUBSCRIBE_TYPE_ACTIVE,
                service_name_template % ('sub', i), True)

        # start another publish & subscribe and expect failure
        self.start_discovery_session(dut, session_id, True,
                                     aconsts.PUBLISH_TYPE_UNSOLICITED,
                                     service_name_template % ('pub', 900),
                                     False)
        self.start_discovery_session(dut, session_id, False,
                                     aconsts.SUBSCRIBE_TYPE_ACTIVE,
                                     service_name_template % ('pub', 901),
                                     False)

        # delete one of the publishes and try again (see if can create subscribe
        # instead - should not)
        dut.droid.wifiAwareDestroyDiscoverySession(pub_disc_id)
        self.start_discovery_session(dut, session_id, False,
                                     aconsts.SUBSCRIBE_TYPE_ACTIVE,
                                     service_name_template % ('pub', 902),
                                     False)
        self.start_discovery_session(dut, session_id, True,
                                     aconsts.PUBLISH_TYPE_UNSOLICITED,
                                     service_name_template % ('pub', 903),
                                     True)

        # delete one of the subscribes and try again (see if can create publish
        # instead - should not)
        dut.droid.wifiAwareDestroyDiscoverySession(sub_disc_id)
        self.start_discovery_session(dut, session_id, True,
                                     aconsts.PUBLISH_TYPE_UNSOLICITED,
                                     service_name_template % ('pub', 904),
                                     False)
        self.start_discovery_session(dut, session_id, False,
                                     aconsts.SUBSCRIBE_TYPE_ACTIVE,
                                     service_name_template % ('pub', 905),
                                     True)
    def test_oob_ndp_stress(self):
        """Run NDP (NAN data-path) stress test creating and destroying Aware
    attach sessions, discovery sessions, and NDPs."""
        init_dut = self.android_devices[0]
        init_dut.pretty_name = 'Initiator'
        resp_dut = self.android_devices[1]
        resp_dut.pretty_name = 'Responder'

        ndp_init_setup_success = 0
        ndp_init_setup_failures = 0
        ndp_resp_setup_success = 0
        ndp_resp_setup_failures = 0

        for attach_iter in range(self.ATTACH_ITERATIONS):
            init_id = init_dut.droid.wifiAwareAttach(True)
            autils.wait_for_event(init_dut, aconsts.EVENT_CB_ON_ATTACHED)
            init_ident_event = autils.wait_for_event(
                init_dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
            init_mac = init_ident_event['data']['mac']
            time.sleep(self.device_startup_offset)
            resp_id = resp_dut.droid.wifiAwareAttach(True)
            autils.wait_for_event(resp_dut, aconsts.EVENT_CB_ON_ATTACHED)
            resp_ident_event = autils.wait_for_event(
                resp_dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
            resp_mac = resp_ident_event['data']['mac']

            # wait for for devices to synchronize with each other - there are no other
            # mechanisms to make sure this happens for OOB discovery (except retrying
            # to execute the data-path request)
            time.sleep(autils.WAIT_FOR_CLUSTER)

            for ndp_iteration in range(self.NDP_ITERATIONS):
                # Responder: request network
                resp_req_key = autils.request_network(
                    resp_dut,
                    resp_dut.droid.wifiAwareCreateNetworkSpecifierOob(
                        resp_id, aconsts.DATA_PATH_RESPONDER, init_mac, None))

                # Initiator: request network
                init_req_key = autils.request_network(
                    init_dut,
                    init_dut.droid.wifiAwareCreateNetworkSpecifierOob(
                        init_id, aconsts.DATA_PATH_INITIATOR, resp_mac, None))

                # Initiator: wait for network formation
                got_on_available = False
                got_on_link_props = False
                while not got_on_available or not got_on_link_props:
                    try:
                        nc_event = init_dut.ed.pop_event(
                            cconsts.EVENT_NETWORK_CALLBACK,
                            autils.EVENT_NDP_TIMEOUT)
                        if nc_event['data'][
                                cconsts.
                                NETWORK_CB_KEY_EVENT] == cconsts.NETWORK_CB_AVAILABLE:
                            got_on_available = True
                        elif (nc_event['data'][cconsts.NETWORK_CB_KEY_EVENT] ==
                              cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED):
                            got_on_link_props = True
                    except queue.Empty:
                        ndp_init_setup_failures = ndp_init_setup_failures + 1
                        init_dut.log.info(
                            '[Initiator] Timed out while waiting for '
                            'EVENT_NETWORK_CALLBACK')
                        break

                if got_on_available and got_on_link_props:
                    ndp_init_setup_success = ndp_init_setup_success + 1

                # Responder: wait for network formation
                got_on_available = False
                got_on_link_props = False
                while not got_on_available or not got_on_link_props:
                    try:
                        nc_event = resp_dut.ed.pop_event(
                            cconsts.EVENT_NETWORK_CALLBACK,
                            autils.EVENT_NDP_TIMEOUT)
                        if nc_event['data'][
                                cconsts.
                                NETWORK_CB_KEY_EVENT] == cconsts.NETWORK_CB_AVAILABLE:
                            got_on_available = True
                        elif (nc_event['data'][cconsts.NETWORK_CB_KEY_EVENT] ==
                              cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED):
                            got_on_link_props = True
                    except queue.Empty:
                        ndp_resp_setup_failures = ndp_resp_setup_failures + 1
                        init_dut.log.info(
                            '[Responder] Timed out while waiting for '
                            'EVENT_NETWORK_CALLBACK')
                        break

                if got_on_available and got_on_link_props:
                    ndp_resp_setup_success = ndp_resp_setup_success + 1

                # clean-up
                init_dut.droid.connectivityUnregisterNetworkCallback(
                    init_req_key)
                resp_dut.droid.connectivityUnregisterNetworkCallback(
                    resp_req_key)

                # wait before trying another iteration (need to let CM clean-up)
                time.sleep(10)

            # clean-up at end of iteration
            init_dut.droid.wifiAwareDestroy(init_id)
            resp_dut.droid.wifiAwareDestroy(resp_id)

        results = {}
        results['ndp_init_setup_success'] = ndp_init_setup_success
        results['ndp_init_setup_failures'] = ndp_init_setup_failures
        results['ndp_resp_setup_success'] = ndp_resp_setup_success
        results['ndp_resp_setup_failures'] = ndp_resp_setup_failures
        asserts.assert_equal(ndp_init_setup_failures + ndp_resp_setup_failures,
                             0,
                             'test_oob_ndp_stress finished',
                             extras=results)
        asserts.explicit_pass("test_oob_ndp_stress done", extras=results)
Пример #30
0
    def test_max_ndp(self):
        """Validate that the device can create as many NDPs as are specified
    by its capabilities.

    Mechanics:
    - Publisher on DUT (first device)
    - Subscribers on all other devices
    - On discovery set up NDP

    Note: the test requires MAX_NDP + 2 devices to be validated. If these are
    not available the test will fail.
    """
        dut = self.android_devices[0]

        # get max NDP: using first available device (assumes all devices are the
        # same)
        max_ndp = dut.aware_capabilities[aconsts.CAP_MAX_NDP_SESSIONS]

        # get number of attached devices: needs to be max_ndp+2 to allow for max_ndp
        # NDPs + an additional one expected to fail.
        # However, will run the test with max_ndp+1 devices to verify that at least
        # that many NDPs can be created. Will still fail at the end to indicate that
        # full test was not run.
        num_peer_devices = min(len(self.android_devices) - 1, max_ndp + 1)
        asserts.assert_true(
            num_peer_devices >= max_ndp,
            'A minimum of %d devices is needed to run the test, have %d' %
            (max_ndp + 1, len(self.android_devices)))

        # attach
        session_id = dut.droid.wifiAwareAttach()
        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)

        # start publisher
        p_disc_id = self.start_discovery_session(
            dut,
            session_id,
            is_publish=True,
            dtype=aconsts.PUBLISH_TYPE_UNSOLICITED,
            service_name=self.SERVICE_NAME,
            expect_success=True)

        # loop over other DUTs
        for i in range(num_peer_devices):
            other_dut = self.android_devices[i + 1]

            # attach
            other_session_id = other_dut.droid.wifiAwareAttach()
            autils.wait_for_event(other_dut, aconsts.EVENT_CB_ON_ATTACHED)

            # start subscriber
            s_disc_id = self.start_discovery_session(
                other_dut,
                other_session_id,
                is_publish=False,
                dtype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
                service_name=self.SERVICE_NAME,
                expect_success=True)

            discovery_event = autils.wait_for_event(
                other_dut, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)
            peer_id_on_sub = discovery_event['data'][
                aconsts.SESSION_CB_KEY_PEER_ID]

            # Subscriber: send message to peer (Publisher - so it knows our address)
            other_dut.droid.wifiAwareSendMessage(s_disc_id, peer_id_on_sub,
                                                 self.get_next_msg_id(),
                                                 "ping",
                                                 aconsts.MAX_TX_RETRIES)
            autils.wait_for_event(other_dut,
                                  aconsts.SESSION_CB_ON_MESSAGE_SENT)

            # Publisher: wait for received message
            pub_rx_msg_event = autils.wait_for_event(
                dut, aconsts.SESSION_CB_ON_MESSAGE_RECEIVED)
            peer_id_on_pub = pub_rx_msg_event['data'][
                aconsts.SESSION_CB_KEY_PEER_ID]

            # publisher (responder): request network
            p_req_key = autils.request_network(
                dut,
                dut.droid.wifiAwareCreateNetworkSpecifier(
                    p_disc_id, peer_id_on_pub))

            # subscriber (initiator): request network
            s_req_key = autils.request_network(
                other_dut,
                other_dut.droid.wifiAwareCreateNetworkSpecifier(
                    s_disc_id, peer_id_on_sub))

            # wait for network (or not - on the last iteration)
            if i != max_ndp:
                p_net_event = autils.wait_for_event_with_keys(
                    dut, cconsts.EVENT_NETWORK_CALLBACK,
                    autils.EVENT_NDP_TIMEOUT,
                    (cconsts.NETWORK_CB_KEY_EVENT,
                     cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
                    (cconsts.NETWORK_CB_KEY_ID, p_req_key))
                s_net_event = autils.wait_for_event_with_keys(
                    other_dut, cconsts.EVENT_NETWORK_CALLBACK,
                    autils.EVENT_NDP_TIMEOUT,
                    (cconsts.NETWORK_CB_KEY_EVENT,
                     cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
                    (cconsts.NETWORK_CB_KEY_ID, s_req_key))

                p_aware_if = p_net_event['data'][
                    cconsts.NETWORK_CB_KEY_INTERFACE_NAME]
                s_aware_if = s_net_event['data'][
                    cconsts.NETWORK_CB_KEY_INTERFACE_NAME]
                self.log.info('Interface names: p=%s, s=%s', p_aware_if,
                              s_aware_if)

                p_ipv6 = dut.droid.connectivityGetLinkLocalIpv6Address(
                    p_aware_if).split('%')[0]
                s_ipv6 = other_dut.droid.connectivityGetLinkLocalIpv6Address(
                    s_aware_if).split('%')[0]
                self.log.info('Interface addresses (IPv6): p=%s, s=%s', p_ipv6,
                              s_ipv6)
            else:
                autils.fail_on_event_with_keys(
                    dut, cconsts.EVENT_NETWORK_CALLBACK,
                    autils.EVENT_NDP_TIMEOUT,
                    (cconsts.NETWORK_CB_KEY_EVENT,
                     cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
                    (cconsts.NETWORK_CB_KEY_ID, p_req_key))
                autils.fail_on_event_with_keys(
                    other_dut, cconsts.EVENT_NETWORK_CALLBACK,
                    autils.EVENT_NDP_TIMEOUT,
                    (cconsts.NETWORK_CB_KEY_EVENT,
                     cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
                    (cconsts.NETWORK_CB_KEY_ID, s_req_key))

        asserts.assert_true(
            num_peer_devices > max_ndp,
            'Needed %d devices to run the test, have %d' %
            (max_ndp + 2, len(self.android_devices)))