def __init__(self, **kwargs): base_step.__init__(self, **kwargs) self.serial = None self.no_log = False if "serial" in kwargs: self.serial = kwargs["serial"] if "platform" in kwargs: self.platform = kwargs["platform"] else: self.platform = None if "dessert" in kwargs: self.dessert = kwargs["dessert"] else: self.dessert = None if "no_log" in kwargs: self.no_log = kwargs["no_log"] # if self.no_log is True: # self.device_info = None # else self.device_info = statics.Device(serial=self.serial, platform=self.platform, dessert=self.dessert) if self.serial not in self.passm: self.passm = self.passm.replace(" - [PASSED]", " [ {} ] - [PASSED]".format(self.serial)) if self.serial not in self.errorm: self.errorm = self.errorm.replace(" - [FAILED]", " [ {} ] - [FAILED]".format(self.serial))
def flash_devices(suite, FLASH_STATICS, SUITE_NAME_STATICS): global devices global device_prop print "Preparing image for flash" flash_xml_path = os.path.join(build_path, build_platform) flash_xml_path = "{0}{1}".format(flash_xml_path, FLASH_STATICS[suite]) flash_cfg_file = os.path.join(flash_xml_path, flash_xml_file) resource_subfolder = statics.Device(serial = devices[0]["serial"], platform = build_platform, dessert = build_version).resource_folder edit_flash_file = statics.Device(serial = devices[0]["serial"], platform = build_platform, dessert = build_version).edit_flash_file repackage_userdata = statics.Device(serial = devices[0]["serial"], platform = build_platform, dessert = build_version).repackage_userdata_on_flash device_prop = flash_steps.prepare_image_for_flash(path_to_image = build_path, platform = build_platform, cts_abi = FLASH_STATICS[suite], prop_file = "build.prop", user_signed = user_signed, resources_subfolder = resource_subfolder, device_prop = "ro.build.version.incremental", edit_flash_file = edit_flash_file, repackage_userdata = repackage_userdata, flash_xml_path = flash_cfg_file, fls_tool_location = fls_tool_location)() print "DONE preparing image!" print "Start flashing for CTS" cts_steps.flash_devices_for_cts(devices = devices, user_build = user_build, flash_xml_path = flash_cfg_file, build_no = device_prop, usb_debugging = True, version = build_version, platform = build_platform, timeout = 1200, update = update, user_signed = user_signed, blocking = False, critical = False)() print "DONE flashing devices!" check_devices(previous_step = "flash", send_mail = True, suite = suite, SUITE_NAME_STATICS = SUITE_NAME_STATICS)
def do(self): # hard boot from recovery to main OS relay_utils.select_ros_menu_item( self.relay, mode=statics.Device(serial=serial).ros_menu_entry[option]) self.relay.press_power() time.sleep(1) # accept the factory reset self.relay.press_volume_down() self.relay.press_power()
def flash_devices(): global devices global device_prop print "Preparing image for flash" flash_xml_path = "{0}{1}".format(os.path.join(build_path, build_platform), "gts") flash_cfg_file = os.path.join(flash_xml_path, flash_xml_file) resource_subfolder = statics.Device(serial=devices[0]["serial"], platform=build_platform, dessert=build_version).resource_folder has_multiple_flashfiles = statics.Device( serial=devices[0]["serial"], platform=build_platform, dessert=build_version).has_multiple_flashfiles edit_flash_file = statics.Device(serial=devices[0]["serial"], platform=build_platform, dessert=build_version).edit_flash_file device_prop = flash_steps.prepare_image_for_flash( path_to_image=build_path, platform=build_platform, prop_file="build.prop", cts_abi="gts", edit_flash_file=edit_flash_file, user_signed=user_signed, resources_subfolder=resource_subfolder, device_prop="ro.build.version.incremental", flash_xml_path=flash_cfg_file)() print "DONE preparing image!" print "Start flashing for GTS" cts_steps.flash_devices_for_cts(devices=devices, user_build=user_build, flash_xml_path=flash_cfg_file, build_no=device_prop, usb_debugging=True, version=build_version, platform=build_platform, timeout=1200, update=update, user_signed=user_signed, blocking=False, critical=False)() print "DONE flashing devices!" check_devices(previous_step="flash", send_mail=True)
def get_netcfg_content(serial=None, platform=None): if serial: adb_connection = connection_adb(serial=serial) else: adb_connection = connection_adb() if platform: platform = platform else: platform = statics.Device(serial=serial) # netcfg of ifconfig output net_conf = adb_connection.parse_cmd_output(platform.get_interfaces_tool) return net_conf
def get_local_mac_address(global_address, serial): """ given a global mac address as input, this function returns the locally administered value of a MAC address """ if statics.Device( serial=serial).p2p_mac_mode == "locally administered bit": global_address_as_list = global_address.split( ":") # splits the global mac address in a list of elements first_octet_hex_global = global_address_as_list[ 0] # takes the first octet first_octet_decimal_global = int( first_octet_hex_global, 16) # converts the value of the 1st octet from hex to decimal first_octet_decimal_local = first_octet_decimal_global + 2 # adds 2 to make set the locally administered bit first_octet_hex_local = hex( first_octet_decimal_local) # converts the 1st octet value to hex octet_local = first_octet_hex_local[ 2:] # removes "0x" prefix to prepare for local address construction local_address_as_list = global_address_as_list # initially, make the local address in list format identical to the global one local_address_as_list[ 0] = octet_local # replace the 1st octet of the address with the locally administered value local_address = ':'.join( local_address_as_list ) # join the list elements with ":", obtaining the local adddress elif statics.Device(serial=serial).p2p_mac_mode == "increment": hex_global_address = global_address.replace(":", "") decimal_global_address = int(hex_global_address, 16) decimal_p2p_address = decimal_global_address + 1 hex_p2p_address = hex(decimal_p2p_address)[2:] local_address = hex_p2p_address[:2] + ":" + hex_p2p_address[ 2:4] + ":" + hex_p2p_address[4:6] + ":" + hex_p2p_address[ 6:8] + ":" + hex_p2p_address[8:10] + ":" + hex_p2p_address[ 10:12] return local_address
def __init__(self, serial, option=None, menu_position=None, timeout=60, **kwargs): relay_step.__init__(self, **kwargs) self.serial = serial self.kwargs = kwargs self.timeout = timeout self.option = option if not menu_position: self.menu_position = statics.Device( serial=self.serial).fastboot_menu_entry[self.option] else: self.menu_position = menu_position
def check_battery_level(): global devices print "Ensure battery level on the devices is at least {0}...%".format( battery_ready_level) serials = [device["serial"] for device in devices] not_charged = True rate_per_minute = 0.25 while not_charged: not_charged = False time_sleep = 0 for serial in serials: try: battery_path = statics.Device( serial=devices[0]["serial"], platform=build_platform, dessert=build_version).battery_path b_level = adb_utils.get_battery_level(serial=serial, path=battery_path) except: print "[ {0} ]: ADB connection error".format(serial) b_level = battery_ready_level print "[ {0} ]: Battery level is: {1}%".format(serial, b_level) if int(b_level) < battery_ready_level: new_sleep = int( (battery_ready_level - int(b_level)) / rate_per_minute) not_charged = True time_sleep = time_sleep if time_sleep > new_sleep else new_sleep print "[ {0} ]: Device should charge for {0} minutes.".format( serial, new_sleep) else: print "[ {0} ]: Battery level is ok.".format(serial) if time_sleep > 0: for serial in serials: print "[ {0} ]: Put device into sleep mode".format(serial) try: ui_steps.put_device_into_sleep_mode(serial=serial)() print "[ {0} ]: Put device into sleep mode - Done!".format( serial) except: print "[ {0} ]: Error putting device intro sleep mode - {1}".format( serial, traceback.format_exc()) print "[ {0} ]: Sleeping for {1} minutes.....".format( serial, time_sleep) time.sleep(time_sleep * 60) print "Done - checking battery level"
def get_device_wlan0_ip(serial=None, platform=None): """ returns the IP Address of the Wlan0 interface """ if serial: adb_connection = connection_adb(serial=serial) else: adb_connection = connection_adb() if platform: platform = platform else: platform = statics.Device(serial=serial) get_interfaces_tool_ip = platform.get_interfaces_tool grep_for = "wlan0" if get_interfaces_tool_ip == "ifconfig": grep_for = "inet" wlan0_line = adb_connection.parse_cmd_output( cmd=platform.get_interfaces_tool, grep_for=grep_for).split() return wlan0_line[-3]
channel_bw = None if "channel_bw" in args.keys(): channel_bw = args["channel_bw"] if "interface5ghz" in args.keys(): interface5ghz = args["interface5ghz"] else: interface5ghz = "0" if "negativetest" in args.keys(): negativetest = args["negativetest"] else: negativetest = "None" if "addnetwork" in args.keys(): addnetwork = args["addnetwork"] ##### test start ##### platform = statics.Device(serial=serial) adb_steps.connect_device(serial=serial, port=adb_server_port)() # turn display on, if turned off ui_steps.wake_up_device(serial=serial)() # ensure the device is unlocked ui_steps.unlock_device(serial=serial, pin=wifi_defaults.wifi['pin'])() # go to home screen ui_steps.press_home(serial=serial)() # airplane mode on, if configured so if airplane_mode == "ON": wifi_generic_steps.set_airplane_mode(state="ON", serial=serial)()
relay_type = args["relay_type"] relay_port = args["relay_port"] power_port = args["power_port"] v_up_port = args["v_up_port"] v_down_port = args["v_down_port"] ##### test start ##### try: # ensure main OS is booted if local_utils.get_device_boot_state(serial=serial) != "android": relay_steps.reboot_main_os(serial=serial, relay_type=relay_type, relay_port=relay_port, power_port=power_port)() menu_position = statics.Device(serial=serial).ros_menu_entry["android"] # boot to recovery adb_steps.reboot_recovery(serial=serial)() time.sleep(3) # boot to main from ROS menu relay_steps.recovery_reboot(serial=serial, mode="android", menu_position=menu_position, timeout=60, relay_type=relay_type, relay_port=relay_port, power_port=power_port, v_up_port=v_up_port,
def ftp_download_file(serial, condition, event, mode='bg', security='none', ddwrt_ap_name='ddwrt', ddwrt_ap_pass='******', encryption=None, file_name='generated.bin', file_size=102400, protocol='ftp', port_number='20211', dut_security=None, conf_security='NONE', compare_method='md5', adb_server_port='5037', iteration=1, q=None): result = [] try: platform = statics.Device(serial=serial) adb_steps.connect_device(serial=serial, port=adb_server_port)() for _ in range(0, iteration): if iteration > 1: log.info("Ftp download: Iteration #{}".format(_ + 1)) if priority == 'wifi' and _ == 0: # print 'wifi 1st event wait' # print e.is_set() event.wait(CONDITION_EVENT_TIMEOUT) event.clear() elif not priority == 'toggle': # print 'wifi 1st event set' event.set() if _ == 0: with condition: if priority == 'bt' and _ == 0: condition.wait(CONDITION_EVENT_TIMEOUT) if not connect_to_ap(serial, condition): raise Exception("Not able to connect to AP") # generate URL (URL, IP) = wifi_generic_steps.create_download_url( file_name, file_size, local_path=".", protocol=protocol, port=port_number, serial=serial)() if priority == 'wifi' and _ == 0: # print 'Notify wifi process' condition.notify() # print 'Notified after creating url' if priority == 'wifi' and _ == 0: # print e.is_set() # print 'wifi 2nd event wait' event.wait(CONDITION_EVENT_TIMEOUT) elif not priority == 'toggle': # print 'wifi 2nd event set' event.set() wifi_instance = None with condition: if priority == 'bt' and _ == 0: condition.wait(CONDITION_EVENT_TIMEOUT) # start download wifi_instance = wifi_generic_steps.download_file(URL, file_name, file_size, protocol, serial=serial, check_file_downloaded=False) wifi_instance() if priority == 'wifi' and _ == 0: condition.notify() # this condition will notify the 'toggle_bt' to proceed to # toggle state if priority == 'toggle': event.set() # This notify bt operation to start validating receiving file as # this should not happen parallel to wifi download as both # rely on UI if initiator == "dev" and priority == "bt" and _ == 0: event.set() wifi_instance.check_file_downloaded = True if wifi_instance.check_condition(): # check download integrity if wifi_generic_steps.check_file_integrity(mode=compare_method, local_file=file_name, serial=serial, remote_file=platform.download_path + file_name)(): result.append('Pass') log.info("Download file is completed") else: raise Exception('File integrity check failed') else: raise Exception("Error during FTP Download") #q.put(['WifiDownloadFile', True]) except Exception: log.error(Exception.message) log.error(traceback.format_exc()) result.append('Fail') except: log.error('FtpDownloadFile: Unexpected Error') log.error(traceback.format_exc()) result.append('Fail') if False in result: q.put(['FtpDownloadFile', 'Fail', result]) else: q.put(['FtpDownloadFile', 'Pass']) log.info("Wifi Ftp download completed")
relay_port = args["relay_port"] power_port = args["power_port"] v_up_port = args["v_up_port"] v_down_port = args["v_down_port"] option = args["option"] ##### test start ##### try: # ensure main OS is booted relay_steps.reboot_main_os(serial=serial, relay_type=relay_type, relay_port=relay_port, power_port=power_port)() # get the option position in the menu as in crashmode cannot get the platform menu_position = statics.Device(serial=serial).crashmode_menu_entry[option] # boot to crashmode os.system("adb -s {} reboot crashmode > /dev/null 2>&1".format(serial)) time.sleep(15) local_steps.wait_for_crashmode(serial=serial, timeout=60)() time.sleep(3) # select the desired option from menu relay_steps.choose_crashmode_menu(serial=serial, option=option, menu_position=menu_position, timeout=60, relay_type=relay_type, relay_port=relay_port,
if no_flash: print "Skipping flash!!!" else: print "Flashing" if oem_unlock: print "Enable OEM unlock from Developer Options" cts_steps.prepare_devices_for_flash(intent = True, parallel = True, devices = devices, platform = build_platform)() flash_devices(suite, FLASH_STATICS, SUITE_NAME_STATICS) has_bios = statics.Device(serial = all_devices[0]["serial"], platform = build_platform, dessert = build_version).has_bios if has_bios: check_bios_version() else: bios = "N/A" if no_suite_prepare: print "Skipping the prepare for suite step!!!" else: if suite in ["aft", "gts"]: no_media_files = True print ("Starting to prepare the suite setup") prepare_for_suite(no_media_files, suite) reboot_devices()
def p2p_get_connection_info(go_serial=None, slave_serial=None, platform=None): # imitialize the values ret_val = { 'go_ip': None, 'slave_ip': None, 'group_name': None, 'go_mac': None, 'slave_mac': None, 'go_name': None, 'slave_name': None, 'state': None, 'group_state': None, 'slave_interface_name': None, 'go_interface_name': None, 'go_serial': None, 'slave_serial': None } if is_go_device(serial=go_serial): go_ser = go_serial slave_ser = slave_serial else: go_ser = slave_serial slave_ser = go_serial ret_val['go_serial'] = go_ser ret_val['slave_serial'] = slave_ser content1 = get_connection_content(serial=go_ser, service="wifip2p") content2 = get_connection_content(serial=slave_ser, service="wifip2p") # get values from GO device slave_device_found = False # first get connection state for line in content1.split("\n"): if "mNetworkInfo" in line: get_mNetworkInfo(ret_val, line) for line in content1.split("\n"): if "curState=" in line: ret_val['group_state'] = line.strip().split('=')[1] if ret_val['state'] == "CONNECTED/CONNECTED": if "mWifiP2pInfo" in line: get_mWifiP2pInfo(ret_val, line) elif "mGroup network:" in line: ret_val['group_name'] = line.split(':')[-1].strip() elif "deviceAddress:" in line: if not slave_device_found: ret_val['go_mac'] = line.split(': ')[-1].strip() else: ret_val['slave_mac'] = line.split(': ')[-1].strip() elif "Client: Device:" in line: slave_device_found = True ret_val['slave_name'] = line.split(':')[-1].strip() elif "interface:" in line: ret_val['go_interface_name'] = line.split(':')[-1].strip() # get values from slave device if ret_val['state'] == "CONNECTED/CONNECTED": for line in content2.split("\n"): if "GO: Device:" in line: ret_val['go_name'] = line.split(':')[-1].strip() elif "interface:" in line: ret_val['slave_interface_name'] = line.split(':')[-1].strip() # get slave IP if platform: platform = platform else: platform = statics.Device(serial=slave_ser) get_interfaces_tool_ip = platform.get_interfaces_tool content = get_netcfg_content(serial=slave_ser).split("\n") if get_interfaces_tool_ip == "ifconfig": for line in range(len(content)): if ret_val['slave_interface_name'] and ret_val[ 'slave_interface_name'] in content[line]: try: ret_val['slave_ip'] = content[ line + 1].split()[1].split(':')[1] except IndexError: time.sleep(10) content = get_netcfg_content( serial=slave_ser).split("\n") ret_val['slave_ip'] = content[ line + 1].split()[1].split(':')[1] else: for line in content: if ret_val['slave_interface_name'] and ret_val[ 'slave_interface_name'] in line: ret_val['slave_ip'] = line.split()[2].split('/')[0] return ret_val
# device definitions sophia_devices = ["oars7", "s3gr10m6s", "slti20mr6"] cht_devices = ["cht_ffd", "cht_cr_rvp", "r2_cht_ffd", "r2_cht_cr"] no_p2p_if_devices = sophia_devices + cht_devices for key,val in wifi_defaults.wifi.items(): attrs[key] = val if key in args.keys(): attrs[key] = args[key] for key,val in wifi_defaults.p2p.items(): attrs[key] = val if key in args.keys(): attrs[key] = args[key] dut_platform = statics.Device(serial=serial) ref_platform = statics.Device(serial=serial2) # set devices to root adb_steps.root_connect_device(serial = serial)() adb_steps.root_connect_device(serial = serial2)() # workaround the issue with "delete group" adb_steps.input_back(serial = serial)() adb_steps.input_back(serial = serial2)() # turn display on, if turned off ui_steps.wake_up_device(serial = serial)() ui_steps.wake_up_device(serial = serial2)() # ensure the device is unlocked
class dm_verity_prop_enabled(android_step): """ description: Checks if variables exists in fastboot mode usage: variable_exist(var = ["device-state",..])() tags: fastboot, vars """ def do(self): self.step_data = adb_steps.command(serial=serial, command="getprop" " partition.system.verified")() def check_condition(self): stdout = self.step_data.stdout.read().strip() if not stdout: return False return True if __name__ == "__main__": adb_steps.command(serial=serial, command="cat /fstab* | grep ^/ | grep /system", stdout_grep="verify")() if statics.Device(serial=serial).build_type == "user": dm_verity_prop_enabled(serial=serial)()
from testlib.scripts.android.ui import ui_steps from testlib.scripts.security.scripts import prerequisites import sys from testlib.base.base_utils import get_args globals().update(vars(get_args(sys.argv))) # Run Prerequisites prerequisites.run_prereq(serial=serial, pin="1234", set_screen_lock=True)() # Check if OEM Unlock requires PIN adb_steps.enable_developer_options(serial=serial)() ui_steps.click_button( serial=serial, view_to_find={"text": "OEM unlocking"}, view_to_check={ "text": statics.Device(serial=serial).confirm_view_pin_oem_unlock })() # Check if Smart Lock requires PIN ui_steps.open_security_settings(serial=serial)() ui_steps.click_button(serial=serial, view_to_find={"text": "Smart Lock"}, view_to_check={"text": "Confirm your PIN"})() # Check if Screen Lock requires PIN ui_steps.open_security_settings(serial=serial)() ui_steps.click_button(serial=serial, view_to_find={"text": "Screen lock"}, view_to_check={"text": "Confirm your PIN"})()
##### initialization ##### globals().update(vars(get_args(sys.argv))) args = {} for entry in script_args: key, val = entry.split("=") args[key] = val # optional params # the below params are not mandatory for all configurations, # i.e.: for open wifi iterations = 1 if "iterations" in args.keys(): iterations = args["iterations"] device_info = statics.Device(serial = serial) ##### test start ##### adb_steps.connect_device(serial = serial, port = adb_server_port)() # turn display on, if turned off ui_steps.wake_up_device(serial = serial)() # ensure the device is unlocked ui_steps.unlock_device(serial = serial, pin=wifi_defaults.wifi['pin'])() # go to home screen ui_steps.press_home(serial = serial)() # make sure there are no saved networks