diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2019-01-04 05:44:53 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-01-04 05:44:53 +0000 |
commit | 11dc512925822956e7c9f1d3e0dfbc61eb98360c (patch) | |
tree | 1d361dc9183230f6f01ac49814f28590265cec99 | |
parent | 21763a1441e0ccd21804363bc2d393487db0b500 (diff) | |
parent | 423091b999a6b3b5ecad8b351b80cf16b604d312 (diff) | |
download | platform_tools_test_connectivity-pie-b4s4-dev.tar.gz platform_tools_test_connectivity-pie-b4s4-dev.tar.bz2 platform_tools_test_connectivity-pie-b4s4-dev.zip |
Merge "DO NOT MERGE: Add http connection check for internet connection test." into pi-devpie-b4s4-dev
-rw-r--r-- | acts/framework/acts/test_utils/tel/tel_data_utils.py | 24 | ||||
-rw-r--r-- | acts/framework/acts/test_utils/tel/tel_test_utils.py | 75 | ||||
-rwxr-xr-x | acts/framework/acts/utils.py | 33 | ||||
-rw-r--r-- | acts/tests/google/tel/live/TelLiveDataTest.py | 3 |
4 files changed, 73 insertions, 62 deletions
diff --git a/acts/framework/acts/test_utils/tel/tel_data_utils.py b/acts/framework/acts/test_utils/tel/tel_data_utils.py index ddb57ca243..136a1a5eeb 100644 --- a/acts/framework/acts/test_utils/tel/tel_data_utils.py +++ b/acts/framework/acts/test_utils/tel/tel_data_utils.py @@ -341,7 +341,7 @@ def airplane_mode_test(log, ad, retries=3): if not wait_for_cell_data_connection(log, ad, False): ad.log.error("Failed to disable cell data connection") return False - if verify_internet_connection(log, ad): + if not verify_internet_connection(log, ad, expected_result=False): ad.log.error("Data available in airplane mode.") return False @@ -354,19 +354,9 @@ def airplane_mode_test(log, ad, retries=3): ad.log.error("Failed to enable cell data connection") return False - time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING) - - log.info("Step4 verify internet") - for i in range(retries): - if verify_internet_connection(log, ad): - ad.log.info("Data available on cell.") - break - elif i == retries - 1: - ad.log.error("Data not available on cell.") - return False - else: - ad.log.warning("Attempt %d Data not available on cell" % - (i + 1)) + if not verify_internet_connection(log, ad, retries=5): + ad.log.warning("Data not available on cell") + return False return True finally: toggle_airplane_mode(log, ad, False) @@ -411,7 +401,7 @@ def data_connectivity_single_bearer(log, ad, nw_gen): return False log.info("Step2 Verify internet") - if not verify_internet_connection(log, ad): + if not verify_internet_connection(log, ad, retries=3): ad.log.error("Data not available on cell.") return False @@ -421,7 +411,7 @@ def data_connectivity_single_bearer(log, ad, nw_gen): ad.log.error("Step3 Failed to disable data connection.") return False - if verify_internet_connection(log, ad): + if not verify_internet_connection(log, ad, expected_state=False): ad.log.error("Step3 Data still available when disabled.") return False @@ -430,7 +420,7 @@ def data_connectivity_single_bearer(log, ad, nw_gen): if not wait_for_cell_data_connection(log, ad, True): ad.log.error("Step4 failed to re-enable data.") return False - if not verify_internet_connection(log, ad): + if not verify_internet_connection(log, ad, retries=3): ad.log.error("Data not available on cell.") return False diff --git a/acts/framework/acts/test_utils/tel/tel_test_utils.py b/acts/framework/acts/test_utils/tel/tel_test_utils.py index 8378f173c3..111c0aed7d 100644 --- a/acts/framework/acts/test_utils/tel/tel_test_utils.py +++ b/acts/framework/acts/test_utils/tel/tel_test_utils.py @@ -1868,7 +1868,7 @@ def get_internet_connection_type(log, ad): def verify_http_connection(log, ad, - url="www.google.com", + url="https://www.google.com", retry=5, retry_interval=15, expected_state=True): @@ -1882,26 +1882,21 @@ def verify_http_connection(log, """ for i in range(0, retry + 1): - # b/18899134 httpPing will hang - #try: - # http_response = ad.droid.httpPing(url) - #except: - # http_response = None - # If httpPing failed, it may return {} (if phone just turn off APM) or - # None (regular fail) - state = ad.droid.pingHost(url) - ad.log.info("Connection to %s is %s", url, state) - if expected_state == state: - ad.log.info("Verify Internet connection state is %s succeeded", - str(expected_state)) + try: + http_response = ad.droid.httpPing(url) + except: + http_response = None + if (expected_state and http_response) or (not expected_state + and not http_response): + ad.log.info("Verify http connection to %s is %s as expected", url, + expected_state) return True if i < retry: - ad.log.info( - "Verify Internet connection state=%s failed. Try again", - str(expected_state)) + ad.log.info("Verify http connection to %s is %s failed. Try again", + url, expected_state) time.sleep(retry_interval) - ad.log.info("Verify Internet state=%s failed after %s second", - expected_state, i * retry_interval) + ad.log.info("Verify http connection to %s is %s failed after %s second", + url, expected_state, i * retry_interval) return False @@ -1999,7 +1994,8 @@ def active_file_download_test(log, ad, file_name="5MB", method="chrome"): return task[0](*task[1]) -def verify_internet_connection(log, ad, retries=1): +def verify_internet_connection_by_ping(log, ad, retries=1, + expected_state=True): """Verify internet connection by ping test. Args: @@ -2007,14 +2003,45 @@ def verify_internet_connection(log, ad, retries=1): ad: Android Device Object. """ - for i in range(retries): - ad.log.info("Verify internet connection - attempt %d", i + 1) - dest_to_ping = ["www.google.com", "www.amazon.com", "54.230.144.105"] - for dest in dest_to_ping: + ip_addr = "54.230.144.105" + for dest in ("www.google.com", "www.amazon.com", ip_addr): + for i in range(retries): + ad.log.info("Ping %s - attempt %d", dest, i + 1) result = adb_shell_ping( ad, count=5, timeout=60, loss_tolerance=40, dest_ip=dest) - if result: + if result == expected_state: + ad.log.info( + "Internet connection by ping test to %s is %s as expected", + dest, expected_state) + if dest == ip_addr: + ad.log.warning("Suspect dns failure") + ad.log.info("DNS config: %s", + ad.adb.shell("getprop | grep dns")) + return False return True + else: + ad.log.error( + "Internet connection by ping test to %s is not %s as expected", + dest, expected_state) + return False + + +def verify_internet_connection(log, ad, retries=3, expected_state=True): + """Verify internet connection by ping test and http connection. + + Args: + log: log object + ad: Android Device Object. + + """ + if verify_internet_connection_by_ping( + log, ad, retries=retries, expected_state=expected_state): + return True + for url in ("https://www.google.com", "https://www.amazon.com"): + if verify_http_connection( + log, ad, url=url, retry=retries, + expected_state=expected_state): + return True return False diff --git a/acts/framework/acts/utils.py b/acts/framework/acts/utils.py index edc38509cb..a16339fd3f 100755 --- a/acts/framework/acts/utils.py +++ b/acts/framework/acts/utils.py @@ -817,26 +817,23 @@ def parse_ping_ouput(ad, count, out, loss_tolerance=20): False: if packet loss is more than loss_tolerance% True: if all good """ - out = out.split('\n')[-3:] - stats = out[1].split(',') - # For failure case, line of interest becomes the last line - if len(stats) != 4: - stats = out[2].split(',') - packet_loss = float(stats[2].split('%')[0]) - packet_xmit = int(stats[0].split()[0]) - packet_rcvd = int(stats[1].split()[0]) - min_packet_xmit_rcvd = (100 - loss_tolerance) * 0.01 + result = re.search( + r"(\d+) packets transmitted, (\d+) received, (\d+)% packet loss", out) + if not result: + ad.log.info("Ping failed with %s", out) + return False + packet_loss = int(result.group(3)) + packet_xmit = int(result.group(1)) + packet_rcvd = int(result.group(2)) + min_packet_xmit_rcvd = (100 - loss_tolerance) * 0.01 if (packet_loss > loss_tolerance or packet_xmit < count * min_packet_xmit_rcvd or packet_rcvd < count * min_packet_xmit_rcvd): - ad.log.error( - "More than %d %% packet loss seen, Expected Packet_count %d \ - Packet loss %.2f%% Packets_xmitted %d Packets_rcvd %d", - loss_tolerance, count, packet_loss, packet_xmit, packet_rcvd) + ad.log.error("%s, ping failed with loss more than tolerance %s%%", + result.group(0), loss_tolerance) return False - ad.log.info("Pkt_count %d Pkt_loss %.2f%% Pkt_xmit %d Pkt_rcvd %d", count, - packet_loss, packet_xmit, packet_rcvd) + ad.log.info("Ping succeed with %s", result.group(0)) return True @@ -858,19 +855,17 @@ def adb_shell_ping(ad, if count: ping_cmd += " -c %d" % count if dest_ip: - ping_cmd += " %s | tee /data/ping.txt" % dest_ip + ping_cmd += " %s" % dest_ip try: ad.log.info("Starting ping test to %s using adb command %s", dest_ip, ping_cmd) - out = ad.adb.shell(ping_cmd, timeout=timeout) + out = ad.adb.shell(ping_cmd, timeout=timeout, ignore_status=True) if not parse_ping_ouput(ad, count, out, loss_tolerance): return False return True except Exception as e: ad.log.warning("Ping Test to %s failed with exception %s", dest_ip, e) return False - finally: - ad.adb.shell("rm /data/ping.txt", timeout=10, ignore_status=True) def unzip_maintain_permissions(zip_path, extract_location): diff --git a/acts/tests/google/tel/live/TelLiveDataTest.py b/acts/tests/google/tel/live/TelLiveDataTest.py index c0034c01f8..72bf2489ca 100644 --- a/acts/tests/google/tel/live/TelLiveDataTest.py +++ b/acts/tests/google/tel/live/TelLiveDataTest.py @@ -2414,8 +2414,7 @@ class TelLiveDataTest(TelephonyBaseTest): self.log.error("Failed wifi connection, aborting!") return False - if not verify_internet_connection( - self.log, ad, 'http://www.google.com', 100, .1): + if not verify_internet_connection(self.log, ad): self.log.error("Failed to get user-plane traffic, aborting!") return False |