def run(self, args=sys.argv[1:]): args = self.parser.parse_args() host, port = args.address.split(':') self.marionette = Marionette(host=host, port=int(port)) self.marionette.start_session() self.apps = gaiatest.GaiaApps(self.marionette) self.data_layer = gaiatest.GaiaData(self.marionette) self.device = gaiatest.GaiaDevice(self.marionette) ret = args.func(args) if ret is None: ret = 0 self.marionette.delete_session() sys.exit(ret)
class GCli(object): def __init__(self): self.commands = { 'connectwifi': { 'function': self.connect_to_wifi, 'args': [{ 'name': 'ssid', 'help': 'SSID of the network to connect to' }, { 'name': '--security', 'choices': ['WPA-PSK', 'WEP'], 'help': 'Security model of the network' }, { 'name': '--password', 'help': 'Password to access the network' }], 'help': 'Connect to a WiFi network' }, 'disablewifi': { 'function': self.disable_wifi, 'help': 'Disable WiFi' }, 'enablewifi': { 'function': self.enable_wifi, 'help': 'Enable WiFi' }, 'forgetallwifi': { 'function': self.forget_all_wifi_networks, 'help': 'Forget all WiFi networks' }, 'getknownwifi': { 'function': self.known_wifi_networks, 'help': 'Show known WiFi networks' }, 'getsetting': { 'function': self.get_setting, 'args': [{ 'name': 'name', 'help': 'Name of the setting to retrieve' }], 'help': 'Show the current value of a setting' }, 'holdhome': { 'function': self.hold_home, 'help': 'Simulate holding the home button' }, 'holdsleep': { 'function': self.hold_sleep, 'help': 'Simulate holding the sleep button' }, 'home': { 'function': self.home, 'help': 'Simulate pressing the home button' }, 'killapps': { 'function': self.kill_all_apps, 'help': 'Kill all running apps' }, 'launchapp': { 'function': self.launch_app, 'args': [{ 'name': 'name', 'nargs': argparse.REMAINDER, 'help': 'Name of app to launch' }], 'help': 'Launch an application' }, 'listallapps': { 'function': self.list_all_apps, 'help': 'List all apps' }, 'listrunningapps': { 'function': self.list_running_apps, 'help': 'List the running apps' }, 'lock': { 'function': self.lock, 'help': 'Lock screen' }, 'screenshot': { 'function': self.screenshot, 'help': 'Take a screenshot' }, 'sendsms': { 'function': self.send_sms, 'args': [{ 'name': 'number', 'help': 'Phone number of recipient' }, { 'name': 'message', 'help': 'Message content' }], 'help': 'Send an SMS' }, 'setsetting': { 'function': self.set_setting, 'args': [{ 'name': 'name', 'help': 'Name of setting to change' }, { 'name': 'value', 'help': 'New value for setting' }], 'help': 'Change the value of a setting' }, 'sleep': { 'function': self.sleep, 'help': 'Enter sleep mode' }, 'unlock': { 'function': self.unlock, 'help': 'Unlock screen' }, 'volume': { 'function': self.volume, 'args': [{ 'name': 'direction', 'choices': ['down', 'up'], 'help': 'Direction to change the volume' }], 'help': 'Change the volume' }, 'wake': { 'function': self.wake, 'help': 'Wake from sleep mode' } } self.parser = argparse.ArgumentParser() self.add_options(self.parser) self.add_commands(self.parser) def run(self, args=sys.argv[1:]): args = self.parser.parse_args() host, port = args.address.split(':') self.marionette = Marionette(host=host, port=int(port)) self.marionette.start_session() self.apps = gaiatest.GaiaApps(self.marionette) self.data_layer = gaiatest.GaiaData(self.marionette) self.device = gaiatest.GaiaDevice(self.marionette) ret = args.func(args) if ret is None: ret = 0 self.marionette.delete_session() sys.exit(ret) def add_options(self, parser): parser.add_argument( '--address', default='localhost:2828', help='Address (host:port) of running Gecko instance to connect to ' '(default: %(default)s)') def add_commands(self, parser): subparsers = parser.add_subparsers(title='Commands', metavar='<command>') for (name, props) in sorted(self.commands.iteritems()): subparser = subparsers.add_parser(name, help=props['help']) if props.get('args'): for arg in props['args']: kwargs = {k: v for k, v in arg.items() if k is not 'name'} subparser.add_argument(arg['name'], **kwargs) subparser.set_defaults(func=props['function']) def connect_to_wifi(self, args): network = {'ssid': args.ssid, 'keyManagement': args.security or 'NONE'} if args.security == 'WEP': network['wep'] = args.password elif args.security == 'WPA-PSK': network['psk'] = args.password self.data_layer.connect_to_wifi(network) def disable_wifi(self, args): self.data_layer.disable_wifi() def enable_wifi(self, args): self.data_layer.enable_wifi() def forget_all_wifi_networks(self, args): self.data_layer.forget_all_networks() def get_setting(self, args): print '%s: %s' % (args.name, self.data_layer.get_setting(args.name)) def home(self, args): self.device.touch_home_button() def hold_home(self, args): self.device.hold_home_button() def hold_sleep(self, args): self.marionette.execute_script( "window.wrappedJSObject.dispatchEvent(new Event('holdsleep'));") def kill_all_apps(self, args): self.apps.kill_all() def known_wifi_networks(self, args): networks = [n for n in self.data_layer.known_networks if 'ssid' in n] if len(networks) > 0: for i, network in enumerate(networks): print '%s: %s' % (i + 1, network['ssid']) else: print 'No known networks.' def launch_app(self, args): for name in args.name: self.apps.launch(name) def list_all_apps(self, args): for i, app in enumerate( sorted(self.apps.installed_apps, key=lambda a: a.name.lower())): print '%d: %s' % (i + 1, app.name) def list_running_apps(self, args): for i, app in enumerate( sorted(self.apps.running_apps, key=lambda a: a.name.lower())): print '%d: %s' % (i + 1, app.name) def lock(self, args): self.device.lock() def screenshot(self, args): self.marionette.execute_script( "window.wrappedJSObject.dispatchEvent(new Event('volumedown+sleep'));" ) def send_sms(self, args): self.data_layer.send_sms(args.number, args.message) def set_setting(self, args): self.data_layer.set_setting(args.name, args.value) def sleep(self, args): self.marionette.execute_script( "window.wrappedJSObject.dispatchEvent(new Event('sleep'));") def unlock(self, args): self.device.unlock() def volume(self, args): self.marionette.execute_script( "window.wrappedJSObject.dispatchEvent(new Event('volume%s'));" % args.direction) def wake(self, args): self.marionette.execute_script( "window.wrappedJSObject.dispatchEvent(new Event('wake'));")
class GCli(object): def __init__(self): self.commands = { 'connectwifi': { 'function': self.connect_to_wifi, 'args': [ {'name': 'ssid', 'help': 'SSID of the network to connect to'}, {'name': '--security', 'choices': ['WPA-PSK', 'WEP'], 'help': 'Security model of the network'}, {'name': '--password', 'help': 'Password to access the network'}], 'help': 'Connect to a WiFi network'}, 'disablewifi': { 'function': self.disable_wifi, 'help': 'Disable WiFi'}, 'enablewifi': { 'function': self.enable_wifi, 'help': 'Enable WiFi'}, 'forgetallwifi': { 'function': self.forget_all_wifi_networks, 'help': 'Forget all WiFi networks'}, 'getknownwifi': { 'function': self.known_wifi_networks, 'help': 'Show known WiFi networks'}, 'getsetting': { 'function': self.get_setting, 'args': [{ 'name': 'name', 'help': 'Name of the setting to retrieve'}], 'help': 'Show the current value of a setting'}, 'holdhome': { 'function': self.hold_home, 'help': 'Simulate holding the home button'}, 'holdsleep': { 'function': self.hold_sleep, 'help': 'Simulate holding the sleep button'}, 'home': { 'function': self.home, 'help': 'Simulate pressing the home button'}, 'killapps': { 'function': self.kill_all_apps, 'help': 'Kill all running apps'}, 'launchapp': { 'function': self.launch_app, 'args': [ {'name': 'name', 'nargs': argparse.REMAINDER, 'help': 'Name of app to launch'}], 'help': 'Launch an application'}, 'listallapps': { 'function': self.list_all_apps, 'help': 'List all apps'}, 'listrunningapps': { 'function': self.list_running_apps, 'help': 'List the running apps'}, 'lock': { 'function': self.lock, 'help': 'Lock screen'}, 'screenshot': { 'function': self.screenshot, 'help': 'Take a screenshot'}, 'sendsms': { 'function': self.send_sms, 'args': [ {'name': 'number', 'help': 'Phone number of recipient'}, {'name': 'message', 'help': 'Message content'}], 'help': 'Send an SMS'}, 'setsetting': { 'function': self.set_setting, 'args': [ {'name': 'name', 'help': 'Name of setting to change'}, {'name': 'value', 'help': 'New value for setting'}], 'help': 'Change the value of a setting'}, 'sleep': { 'function': self.sleep, 'help': 'Enter sleep mode'}, 'unlock': { 'function': self.unlock, 'help': 'Unlock screen'}, 'volume': { 'function': self.volume, 'args': [ {'name': 'direction', 'choices': ['down', 'up'], 'help': 'Direction to change the volume'}], 'help': 'Change the volume'}, 'wake': { 'function': self.wake, 'help': 'Wake from sleep mode'}} self.parser = argparse.ArgumentParser() self.add_options(self.parser) self.add_commands(self.parser) def run(self, args=sys.argv[1:]): args = self.parser.parse_args() host, port = args.address.split(':') self.marionette = Marionette(host=host, port=int(port)) self.marionette.start_session() self.apps = gaiatest.GaiaApps(self.marionette) self.data_layer = gaiatest.GaiaData(self.marionette) self.device = gaiatest.GaiaDevice(self.marionette) ret = args.func(args) if ret is None: ret = 0 self.marionette.delete_session() sys.exit(ret) def add_options(self, parser): parser.add_argument( '--address', default='localhost:2828', help='Address (host:port) of running Gecko instance to connect to ' '(default: %(default)s)') def add_commands(self, parser): subparsers = parser.add_subparsers( title='Commands', metavar='<command>') for (name, props) in sorted(self.commands.iteritems()): subparser = subparsers.add_parser(name, help=props['help']) if props.get('args'): for arg in props['args']: kwargs = {k: v for k, v in arg.items() if k is not 'name'} subparser.add_argument(arg['name'], **kwargs) subparser.set_defaults(func=props['function']) def connect_to_wifi(self, args): network = { 'ssid': args.ssid, 'keyManagement': args.security or 'NONE'} if args.security == 'WEP': network['wep'] = args.password elif args.security == 'WPA-PSK': network['psk'] = args.password self.data_layer.connect_to_wifi(network) def disable_wifi(self, args): self.data_layer.disable_wifi() def enable_wifi(self, args): self.data_layer.enable_wifi() def forget_all_wifi_networks(self, args): self.data_layer.forget_all_networks() def get_setting(self, args): print '%s: %s' % ( args.name, self.data_layer.get_setting(args.name)) def home(self, args): self.device.touch_home_button() def hold_home(self, args): self.device.hold_home_button() def hold_sleep(self, args): self.marionette.execute_script( "window.wrappedJSObject.dispatchEvent(new Event('holdsleep'));") def kill_all_apps(self, args): self.apps.kill_all() def known_wifi_networks(self, args): networks = [n for n in self.data_layer.known_networks if 'ssid' in n] if len(networks) > 0: for i, network in enumerate(networks): print '%s: %s' % (i + 1, network['ssid']) else: print 'No known networks.' def launch_app(self, args): for name in args.name: self.apps.launch(name) def list_all_apps(self, args): for i, app in enumerate(sorted(self.apps.installed_apps, key=lambda a: a.name.lower())): print '%d: %s' % (i + 1, app.name) def list_running_apps(self, args): for i, app in enumerate(sorted(self.apps.running_apps, key=lambda a: a.name.lower())): print '%d: %s' % (i + 1, app.name) def lock(self, args): self.device.lock() def screenshot(self, args): self.marionette.execute_script( "window.wrappedJSObject.dispatchEvent(new Event('volumedown+sleep'));") def send_sms(self, args): self.data_layer.send_sms(args.number, args.message) def set_setting(self, args): self.data_layer.set_setting(args.name, args.value) def sleep(self, args): self.marionette.execute_script( "window.wrappedJSObject.dispatchEvent(new Event('sleep'));") def unlock(self, args): self.device.unlock() def volume(self, args): self.marionette.execute_script( "window.wrappedJSObject.dispatchEvent(new Event('volume%s'));" % args.direction) def wake(self, args): self.marionette.execute_script( "window.wrappedJSObject.dispatchEvent(new Event('wake'));")
def cli(): parser = dzOptionParser(usage='%prog file [options]') options, args = parser.parse_args() # Ensure have all required options if (not options.datazilla_project or not options.datazilla_branch or not options.datazilla_key or not options.datazilla_secret): parser.print_help() parser.exit() # Either a single file or option to process all in given folder if (not options.results_file) and (not options.process_dir): parser.print_help() parser.exit() if options.results_file and options.process_dir: parser.print_help() parser.exit() # Ensure results file actually exists if options.results_file: if not os.path.exists(options.results_file): raise Exception('%s file does not exist' %options.results_file) if options.process_dir: if not os.path.exists(options.process_dir): raise Exception("Process all path '%s' does not exist" %options.process_dir) # Parse config options datazilla_config = parser.datazilla_config(options) # Start marionette session marionette = Marionette(host='localhost', port=2828) # TODO command line option for address marionette.start_session() # Create datazilla post object poster = DatazillaPerfPoster(marionette, datazilla_config=datazilla_config, sources=options.sources) # If was an error getting required values then poster.submit_report will be false; # if it is true then ok to submit if user wants to if poster.submit_report: if not options.send_to_datazilla: poster.submit_report = False # Parse checkpoint results from provided summary log file checkpoint_summary = {} results = {} summary_file_list = [] if options.process_dir: # All files in the given path file_path = options.process_dir print "\nSearching for *_summary.log files in %s\n" % options.process_dir entire_file_list = os.listdir(file_path) if len(entire_file_list) == 0: raise Exception("No checkpoint *_summary.log files were found in the given path") for found_file in entire_file_list: if found_file.endswith("summary.log") and found_file != "avg_b2g_rss_suite_summary.log": summary_file_list.append("%s/%s" % (file_path, found_file)) if len(summary_file_list) == 0: raise Exception("No checkpoint *_summary.log files were found in the given path") print "Found the following checkpoint summary files to process:\n" for x in summary_file_list: print "%s" % x print "\n" + "-" * 50 else: # Just one file summary_file_list = [options.results_file] for next_file in summary_file_list: # Clear results as only want results for current file being processed results = {} print "\nProcessing results in '%s'\n" % next_file summary_file = open(next_file, 'r') read_in = summary_file.read().split("\n") summary_file.close() for x in read_in: try: if x.find(':') != -1: # Ignore empty lines ie. last line of file which is empty k, v = x.split(': ') if k in "total_iterations" or k in "checkpoint_interval": checkpoint_summary[k] = int(v) elif k in "b2g_rss": checkpoint_summary[k] = v.split(',') # list of strings checkpoint_summary[k] = map(int, checkpoint_summary[k]) # list of ints elif k in "test_name": # Prefix test name so all tests are grouped together in datazilla checkpoint_summary[k] = "endurance_" + v else: checkpoint_summary[k] = v except: raise Exception("Value missing from '%s', cannot proceed." % options.results_file) # Make sure we have app_under_test if (checkpoint_summary['app_under_test'] == "none"): raise Exception("Checkpoint summary file is missing value for 'app_under_test'. Cannot proceed.") # Results dictionary required format example # {'test_name': [180892, 180892, 181980, 181852, 180828, 182012, 183652, 182972, 183052, 183052]} results[checkpoint_summary['test_name']] = checkpoint_summary['b2g_rss'] # Display the Datazilla configuration print 'Datazilla configuration:' print "\napplication (datazilla 'suite'): %s" % checkpoint_summary['app_under_test'] for key, value in poster.required.items(): print key + ":", value # Submit or print the results if poster.submit_report: #poster.post_to_datazilla(results, checkpoint_summary['test_name']) poster.post_to_datazilla(results, checkpoint_summary['app_under_test']) else: print "\nCheckpoint summary for test '%s':\n" % checkpoint_summary['test_name'] print checkpoint_summary print '\nEndurance test results data:\n' print results print "\nTo submit results, fix any missing fields and use the '--submit' option.\n" if options.process_dir: # Sleep between submissions print "Pausing...\n" time.sleep(30) print "-" * 50 if options.process_dir: print "\nFinished processing all files.\n"