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_ping6_ib_solicited_active(self): """Validate that ping6 works correctly on an NDP created using Aware discovery with SOLICITED/ACTIVE sessions.""" p_dut = self.android_devices[0] s_dut = self.android_devices[1] # create NDP (p_req_key, s_req_key, p_aware_if, s_aware_if, p_ipv6, s_ipv6) = autils.create_ib_ndp( p_dut, s_dut, p_config=autils.create_discovery_config( self.SERVICE_NAME, aconsts.PUBLISH_TYPE_SOLICITED), s_config=autils.create_discovery_config( self.SERVICE_NAME, aconsts.SUBSCRIBE_TYPE_ACTIVE), device_startup_offset=self.device_startup_offset) self.log.info("Interface names: P=%s, S=%s", p_aware_if, s_aware_if) self.log.info("Interface addresses (IPv6): P=%s, S=%s", p_ipv6, s_ipv6) # run ping6 self.run_ping6(p_dut, s_ipv6, p_aware_if) self.run_ping6(s_dut, p_ipv6, s_aware_if) # clean-up p_dut.droid.connectivityUnregisterNetworkCallback(p_req_key) s_dut.droid.connectivityUnregisterNetworkCallback(s_req_key)
def run_iperf_single_ndp_aware_only(self, use_ib, results): """Measure iperf performance on a single NDP, with Aware enabled and no infrastructure connection - i.e. device is not associated to an AP. Args: use_ib: True to use in-band discovery, False to use out-of-band discovery. results: Dictionary into which to place test results. """ init_dut = self.android_devices[0] resp_dut = self.android_devices[1] if use_ib: # note: Publisher = Responder, Subscribe = Initiator (resp_req_key, init_req_key, resp_aware_if, init_aware_if, resp_ipv6, init_ipv6) = autils.create_ib_ndp( resp_dut, init_dut, autils.create_discovery_config( self.SERVICE_NAME, aconsts.PUBLISH_TYPE_UNSOLICITED), autils.create_discovery_config( self.SERVICE_NAME, aconsts.SUBSCRIBE_TYPE_PASSIVE), self.device_startup_offset) else: (init_req_key, resp_req_key, init_aware_if, resp_aware_if, init_ipv6, resp_ipv6) = autils.create_oob_ndp(init_dut, resp_dut) self.log.info("Interface names: I=%s, R=%s", init_aware_if, resp_aware_if) self.log.info("Interface addresses (IPv6): I=%s, R=%s", init_ipv6, resp_ipv6) # Run iperf3 result, data = init_dut.run_iperf_server("-D") asserts.assert_true(result, "Can't start iperf3 server") result, data = resp_dut.run_iperf_client( "%s%%%s" % (init_ipv6, resp_aware_if), "-6 -J") self.log.debug(data) asserts.assert_true(result, "Failure starting/running iperf3 in client mode") self.log.debug(pprint.pformat(data)) # clean-up resp_dut.droid.connectivityUnregisterNetworkCallback(resp_req_key) init_dut.droid.connectivityUnregisterNetworkCallback(init_req_key) # Collect results data_json = json.loads("".join(data)) if "error" in data_json: asserts.fail("iperf run failed: %s" % data_json["error"], extras=data_json) results["tx_rate"] = data_json["end"]["sum_sent"]["bits_per_second"] results["rx_rate"] = data_json["end"]["sum_received"][ "bits_per_second"] self.log.info("iPerf3: Sent = %d bps Received = %d bps", results["tx_rate"], results["rx_rate"])
def run_rtt_ib_discovery_set(self, do_both_directions, iter_count, time_between_iterations, time_between_roles): """Perform a set of RTT measurements, using in-band (Aware) 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). 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. """ p_dut = self.android_devices[0] s_dut = self.android_devices[1] (p_id, s_id, p_disc_id, s_disc_id, peer_id_on_sub, peer_id_on_pub) = autils.create_discovery_pair( p_dut, s_dut, p_config=autils.add_ranging_to_pub( autils.create_discovery_config( self.SERVICE_NAME, aconsts.PUBLISH_TYPE_UNSOLICITED), True), s_config=autils.add_ranging_to_pub( autils.create_discovery_config( self.SERVICE_NAME, aconsts.SUBSCRIBE_TYPE_PASSIVE), True), device_startup_offset=self.device_startup_offset, msg_id=self.get_next_msg_id()) resultsPS = [] resultsSP = [] for i in range(iter_count): if i != 0 and time_between_iterations != 0: time.sleep(time_between_iterations) # perform RTT from pub -> sub resultsPS.append( self.run_rtt_discovery(p_dut, resp_peer_id=peer_id_on_pub)) if do_both_directions: if time_between_roles != 0: time.sleep(time_between_roles) # perform RTT from sub -> pub resultsSP.append( self.run_rtt_discovery(s_dut, resp_peer_id=peer_id_on_sub)) return resultsPS if not do_both_directions else [resultsPS, resultsSP]
def test_upper_lower_service_name_equivalence(self): """Validate that Service Name is case-insensitive. Publish a service name with mixed case, subscribe to the same service name with alternative case and verify that discovery happens.""" p_dut = self.android_devices[0] s_dut = self.android_devices[1] pub_service_name = "GoogleAbCdEf" sub_service_name = "GoogleaBcDeF" autils.create_discovery_pair( p_dut, s_dut, p_config=autils.create_discovery_config( pub_service_name, aconsts.PUBLISH_TYPE_UNSOLICITED), s_config=autils.create_discovery_config( sub_service_name, aconsts.SUBSCRIBE_TYPE_PASSIVE), device_startup_offset=self.device_startup_offset)
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_rtt_without_responder_aware(self): """Try to perform RTT operation when there is no peer Aware session (on the Responder). 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) # Disable Responder resp_dut.droid.wifiAwareDestroy(resp_id) # Enable the Initiator init_id = init_dut.droid.wifiAwareAttach() autils.wait_for_event(init_dut, aconsts.EVENT_CB_ON_ATTACHED) # 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})
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")
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_stress_message(self): """Stress test for bi-directional message transmission and reception.""" p_dut = self.android_devices[0] s_dut = self.android_devices[1] # Start up a discovery session discovery_data = autils.create_discovery_pair( p_dut, s_dut, p_config=autils.create_discovery_config( self.SERVICE_NAME, aconsts.PUBLISH_TYPE_UNSOLICITED), s_config=autils.create_discovery_config( self.SERVICE_NAME, aconsts.SUBSCRIBE_TYPE_PASSIVE), device_startup_offset=self.device_startup_offset, msg_id=self.get_next_msg_id()) p_id = discovery_data[0] s_id = discovery_data[1] p_disc_id = discovery_data[2] s_disc_id = discovery_data[3] peer_id_on_sub = discovery_data[4] peer_id_on_pub = discovery_data[5] # Store information on Tx & Rx messages messages_by_msg = {} # keyed by message text # {text -> {id, tx_ok_count, tx_fail_count, rx_count}} messages_by_id = {} # keyed by message ID {id -> text} # send all messages at once (one in each direction) for i in range(self.NUM_ITERATIONS): msg_p2s = "Message Publisher -> Subscriber #%d" % i next_msg_id = self.get_next_msg_id() self.init_info(msg_p2s, next_msg_id, messages_by_msg, messages_by_id) p_dut.droid.wifiAwareSendMessage(p_disc_id, peer_id_on_pub, next_msg_id, msg_p2s, 0) msg_s2p = "Message Subscriber -> Publisher #%d" % i next_msg_id = self.get_next_msg_id() self.init_info(msg_s2p, next_msg_id, messages_by_msg, messages_by_id) s_dut.droid.wifiAwareSendMessage(s_disc_id, peer_id_on_sub, next_msg_id, msg_s2p, 0) # wait for message tx confirmation (p_tx_ok_count, p_tx_fail_count, p_tx_unknown_id) = self.wait_for_tx_events(p_dut, self.NUM_ITERATIONS, messages_by_msg, messages_by_id) (s_tx_ok_count, s_tx_fail_count, s_tx_unknown_id) = self.wait_for_tx_events(s_dut, self.NUM_ITERATIONS, messages_by_msg, messages_by_id) self.log.info( "Transmission done: pub=%d, sub=%d transmitted successfully", p_tx_ok_count, s_tx_ok_count) # wait for message rx confirmation (giving it the total number of messages # transmitted rather than just those transmitted correctly since sometimes # the Tx doesn't get that information correctly. I.e. a message the Tx # thought was not transmitted correctly is actually received - missing ACK? # bug?) self.wait_for_rx_events(p_dut, self.NUM_ITERATIONS, messages_by_msg) self.wait_for_rx_events(s_dut, self.NUM_ITERATIONS, messages_by_msg) # analyze results results = {} results["tx_count"] = 2 * self.NUM_ITERATIONS results["tx_unknown_ids"] = p_tx_unknown_id + s_tx_unknown_id self.analyze_results(results, messages_by_msg) # clear errors asserts.assert_equal(results["tx_unknown_ids"], 0, "Message ID corruption", results) asserts.assert_equal(results["tx_count_duplicate_fail"], 0, "Duplicate Tx fail messages", results) asserts.assert_equal(results["tx_count_duplicate_success"], 0, "Duplicate Tx success messages", results) asserts.assert_equal( results["rx_count_no_tx_message"], 0, "Rx message which wasn't sent - message corruption?", results) asserts.assert_equal(results["tx_count_tx_ok_but_no_rx"], 0, "Tx got ACK but Rx didn't get message", results) # possibly ok - but flag since most frequently a bug asserts.assert_equal(results["rx_count_no_ok_tx_indication"], 0, "Message received but Tx didn't get ACK", results) asserts.assert_equal(results["rx_count_fail_tx_indication"], 0, "Message received but Tx didn't get ACK", results) asserts.explicit_pass("test_stress_message done", extras=results)
def run_message_latency(self, results, dw_24ghz, dw_5ghz, num_iterations): """Run the message tx latency test with the specified DW intervals. Args: results: Result array to be populated - will add results (not erase it) dw_24ghz: DW interval in the 2.4GHz band. dw_5ghz: DW interval in the 5GHz band. """ key = "dw24_%d_dw5_%d" % (dw_24ghz, dw_5ghz) results[key] = {} results[key]["num_iterations"] = num_iterations p_dut = self.android_devices[0] s_dut = self.android_devices[1] # override the default DW configuration autils.config_power_settings(p_dut, dw_24ghz, dw_5ghz) autils.config_power_settings(s_dut, dw_24ghz, dw_5ghz) # Start up a discovery session (p_id, s_id, p_disc_id, s_disc_id, peer_id_on_sub) = autils.create_discovery_pair( p_dut, s_dut, p_config=autils.create_discovery_config( self.SERVICE_NAME, aconsts.PUBLISH_TYPE_UNSOLICITED), s_config=autils.create_discovery_config( self.SERVICE_NAME, aconsts.SUBSCRIBE_TYPE_PASSIVE), device_startup_offset=self.device_startup_offset) latencies = [] failed_tx = 0 messages_rx = 0 missing_rx = 0 corrupted_rx = 0 for i in range(num_iterations): # send message msg_s2p = "Message Subscriber -> Publisher #%d" % i next_msg_id = self.get_next_msg_id() s_dut.droid.wifiAwareSendMessage(s_disc_id, peer_id_on_sub, next_msg_id, msg_s2p, 0) # wait for Tx confirmation try: sub_tx_msg_event = s_dut.ed.pop_event( aconsts.SESSION_CB_ON_MESSAGE_SENT, 2 * autils.EVENT_TIMEOUT) latencies.append(sub_tx_msg_event["data"][ aconsts.SESSION_CB_KEY_LATENCY_MS]) except queue.Empty: s_dut.log.info("[Subscriber] Timed out while waiting for " "SESSION_CB_ON_MESSAGE_SENT") failed_tx = failed_tx + 1 continue # wait for Rx confirmation (and validate contents) try: pub_rx_msg_event = p_dut.ed.pop_event( aconsts.SESSION_CB_ON_MESSAGE_RECEIVED, 2 * autils.EVENT_TIMEOUT) messages_rx = messages_rx + 1 if (pub_rx_msg_event["data"][ aconsts.SESSION_CB_KEY_MESSAGE_AS_STRING] != msg_s2p): corrupted_rx = corrupted_rx + 1 except queue.Empty: s_dut.log.info("[Publisher] Timed out while waiting for " "SESSION_CB_ON_MESSAGE_RECEIVED") missing_rx = missing_rx + 1 continue autils.extract_stats( s_dut, data=latencies, results=results[key], key_prefix="", log_prefix="Subscribe Session Discovery (dw24=%d, dw5=%d)" % (dw_24ghz, dw_5ghz)) results[key]["failed_tx"] = failed_tx results[key]["messages_rx"] = messages_rx results[key]["missing_rx"] = missing_rx results[key]["corrupted_rx"] = corrupted_rx # clean up p_dut.droid.wifiAwareDestroyAll() s_dut.droid.wifiAwareDestroyAll()
def test_stress_rtt_ib_discovery_set(self): """Perform a set of RTT measurements, using in-band (Aware) discovery, and switching Initiator and Responder roles repeatedly. Stress test: repeat ranging operations. Verify rate of success and stability of results. """ p_dut = self.android_devices[0] s_dut = self.android_devices[1] (p_id, s_id, p_disc_id, s_disc_id, peer_id_on_sub, peer_id_on_pub) = autils.create_discovery_pair( p_dut, s_dut, p_config=autils.add_ranging_to_pub( autils.create_discovery_config( self.SERVICE_NAME, aconsts.PUBLISH_TYPE_UNSOLICITED), True), s_config=autils.add_ranging_to_pub( autils.create_discovery_config( self.SERVICE_NAME, aconsts.SUBSCRIBE_TYPE_PASSIVE), True), device_startup_offset=self.device_startup_offset, msg_id=self.get_next_msg_id()) results = [] start_clock = time.time() iterations_done = 0 run_time = 0 while iterations_done < self.stress_test_min_iteration_count or ( self.stress_test_target_run_time_sec != 0 and run_time < self.stress_test_target_run_time_sec): results.append( self.run_rtt_discovery(p_dut, resp_peer_id=peer_id_on_pub)) results.append( self.run_rtt_discovery(s_dut, resp_peer_id=peer_id_on_sub)) iterations_done = iterations_done + 1 run_time = time.time() - start_clock stats = rutils.extract_stats(results, self.rtt_reference_distance_mm, self.rtt_reference_distance_margin_mm, self.rtt_min_expected_rssi_dbm, summary_only=True) self.log.debug("Stats: %s", stats) asserts.assert_true(stats['num_no_results'] == 0, "Missing (timed-out) results", extras=stats) asserts.assert_false(stats['any_lci_mismatch'], "LCI mismatch", extras=stats) asserts.assert_false(stats['any_lcr_mismatch'], "LCR mismatch", extras=stats) asserts.assert_equal(stats['num_invalid_rssi'], 0, "Invalid RSSI", extras=stats) asserts.assert_true( stats['num_failures'] <= self.rtt_max_failure_rate_two_sided_rtt_percentage * stats['num_results'] / 100, "Failure rate is too high", extras=stats) asserts.assert_true( stats['num_range_out_of_margin'] <= self.rtt_max_margin_exceeded_rate_two_sided_rtt_percentage * stats['num_success_results'] / 100, "Results exceeding error margin rate is too high", extras=stats)
def run_discovery(self, p_dut, s_dut, p_mf, s_mf, do_unsolicited_passive, expect_discovery): """Creates a discovery session (publish and subscribe) with the specified configuration. Args: p_dut: Device to use as publisher. s_dut: Device to use as subscriber. p_mf: Publish's match filter. s_mf: Subscriber's match filter. do_unsolicited_passive: True to use an Unsolicited/Passive discovery, False for a Solicited/Active discovery session. expect_discovery: True if service should be discovered, False otherwise. Returns: True on success, False on failure (based on expect_discovery arg) """ # Encode the match filters p_mf = base64.b64encode(p_mf).decode( "utf-8") if p_mf is not None else None s_mf = base64.b64encode(s_mf).decode( "utf-8") if s_mf is not None else None # Publisher+Subscriber: attach and wait for confirmation p_id = p_dut.droid.wifiAwareAttach() autils.wait_for_event(p_dut, aconsts.EVENT_CB_ON_ATTACHED) time.sleep(self.device_startup_offset) s_id = s_dut.droid.wifiAwareAttach() autils.wait_for_event(s_dut, aconsts.EVENT_CB_ON_ATTACHED) # Publisher: start publish and wait for confirmation p_dut.droid.wifiAwarePublish( p_id, autils.create_discovery_config( self.SERVICE_NAME, d_type=aconsts.PUBLISH_TYPE_UNSOLICITED if do_unsolicited_passive else aconsts.PUBLISH_TYPE_SOLICITED, match_filter=p_mf)) autils.wait_for_event(p_dut, aconsts.SESSION_CB_ON_PUBLISH_STARTED) # Subscriber: start subscribe and wait for confirmation s_dut.droid.wifiAwareSubscribe( s_id, autils.create_discovery_config( self.SERVICE_NAME, d_type=aconsts.SUBSCRIBE_TYPE_PASSIVE if do_unsolicited_passive else aconsts.SUBSCRIBE_TYPE_ACTIVE, match_filter=s_mf)) autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED) # Subscriber: wait or fail on service discovery event = None try: event = s_dut.ed.pop_event( aconsts.SESSION_CB_ON_SERVICE_DISCOVERED, autils.EVENT_TIMEOUT) s_dut.log.info("[Subscriber] SESSION_CB_ON_SERVICE_DISCOVERED: %s", event) except queue.Empty: s_dut.log.info("[Subscriber] No SESSION_CB_ON_SERVICE_DISCOVERED") # clean-up p_dut.droid.wifiAwareDestroy(p_id) s_dut.droid.wifiAwareDestroy(s_id) if expect_discovery: return event is not None else: return event is None
def test_discovery_stress(self): """Create and destroy a random array of discovery sessions, up to the limit of capabilities.""" dut = self.android_devices[0] discovery_setup_success = 0 discovery_setup_fail = 0 for attach_iter in range(self.ATTACH_ITERATIONS): # attach session_id = dut.droid.wifiAwareAttach(True) autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED) p_discovery_ids = [] s_discovery_ids = [] for discovery_iter in range(self.DISCOVERY_ITERATIONS): service_name = 'GoogleTestService-%d-%d' % (attach_iter, discovery_iter) p_config = None s_config = None if discovery_iter % 4 == 0: # publish/unsolicited p_config = autils.create_discovery_config( service_name, aconsts.PUBLISH_TYPE_UNSOLICITED) elif discovery_iter % 4 == 1: # publish/solicited p_config = autils.create_discovery_config( service_name, aconsts.PUBLISH_TYPE_SOLICITED) elif discovery_iter % 4 == 2: # subscribe/passive s_config = autils.create_discovery_config( service_name, aconsts.SUBSCRIBE_TYPE_PASSIVE) elif discovery_iter % 4 == 3: # subscribe/active s_config = autils.create_discovery_config( service_name, aconsts.SUBSCRIBE_TYPE_ACTIVE) if p_config is not None: if len(p_discovery_ids) == dut.aware_capabilities[ aconsts.CAP_MAX_PUBLISHES]: dut.droid.wifiAwareDestroyDiscoverySession( p_discovery_ids.pop(dut.aware_capabilities[ aconsts.CAP_MAX_PUBLISHES] // 2)) disc_id = dut.droid.wifiAwarePublish(session_id, p_config) event_name = aconsts.SESSION_CB_ON_PUBLISH_STARTED p_discovery_ids.append(disc_id) else: if len(s_discovery_ids) == dut.aware_capabilities[ aconsts.CAP_MAX_SUBSCRIBES]: dut.droid.wifiAwareDestroyDiscoverySession( s_discovery_ids.pop(dut.aware_capabilities[ aconsts.CAP_MAX_SUBSCRIBES] // 2)) disc_id = dut.droid.wifiAwareSubscribe( session_id, s_config) event_name = aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED s_discovery_ids.append(disc_id) try: dut.ed.pop_event(event_name, autils.EVENT_TIMEOUT) discovery_setup_success = discovery_setup_success + 1 except queue.Empty: discovery_setup_fail = discovery_setup_fail + 1 dut.droid.wifiAwareDestroy(session_id) results = {} results['discovery_setup_success'] = discovery_setup_success results['discovery_setup_fail'] = discovery_setup_fail asserts.assert_equal(discovery_setup_fail, 0, 'test_discovery_stress finished', extras=results) asserts.explicit_pass('test_discovery_stress done', extras=results)
def run_aware_then_connect_to_new_ap(self): """Validate interaction of Wi-Fi Aware and infra (STA) association with randomized MAC address. Such an association may trigger interface down and up - possibly disrupting a Wi-Fi Aware session. Test behavior: - Start Aware - Associate STA - Check if an Aware state change Broadcast received - If necessary (Broadcast received) restart Aware - Start publish - Start Subscribe on peer - Verify discovery """ dut = self.android_devices[0] dut_ap = self.android_devices[1] wutils.reset_wifi(dut) wutils.reset_wifi(dut_ap) p_config = autils.create_discovery_config( self.SERVICE_NAME, aconsts.PUBLISH_TYPE_UNSOLICITED) s_config = autils.create_discovery_config( self.SERVICE_NAME, aconsts.SUBSCRIBE_TYPE_PASSIVE) # create random SSID and start softAp on dut_ap ap_ssid = self.TETHER_SSID + utils.rand_ascii_str(8) ap_password = utils.rand_ascii_str(8) config = { wutils.WifiEnums.SSID_KEY: ap_ssid, wutils.WifiEnums.PWD_KEY: ap_password } wutils.start_wifi_tethering(dut_ap, ap_ssid, ap_password) asserts.assert_true(dut_ap.droid.wifiIsApEnabled(), "SoftAp is not reported as running") # dut start Aware attach and connect to softAp on dut_ap p_id = dut.droid.wifiAwareAttach() autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED) wutils.wifi_connect(dut, config, check_connectivity=False) autils.wait_for_event(dut, wconsts.WIFI_STATE_CHANGED) # Check if the WifiAwareState changes then restart the Aware try: dut.ed.pop_event(aconsts.BROADCAST_WIFI_AWARE_AVAILABLE, EVENT_TIMEOUT) dut.log.info(aconsts.BROADCAST_WIFI_AWARE_AVAILABLE) p_id = dut.droid.wifiAwareAttach() autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED) except queue.Empty: dut.log.info('WifiAware state was not changed') # dut start Publish p_disc_id = dut.droid.wifiAwarePublish(p_id, p_config) autils.wait_for_event(dut, aconsts.SESSION_CB_ON_PUBLISH_STARTED) # dut_ap stop softAp and start Subscribe wutils.stop_wifi_tethering(dut_ap) autils.wait_for_event(dut_ap, aconsts.BROADCAST_WIFI_AWARE_AVAILABLE) s_id = dut_ap.droid.wifiAwareAttach() autils.wait_for_event(dut_ap, aconsts.EVENT_CB_ON_ATTACHED) s_disc_id = dut_ap.droid.wifiAwareSubscribe(s_id, s_config) autils.wait_for_event(dut_ap, aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED) # Check discovery session autils.wait_for_event(dut_ap, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)