def iConnect(techname): RETRY_LIMIT = 5 if techname == "wifi": can_connect = known_wifis elif techname == "bluetooth": can_connect = known_bluetooth else: fmbt.adapterlog("Don't know which services to connect via tech %s." % (techname,)) # Look for a suitable service (one of known_*) connect_me = None counter = 0 while 1: found_services = manager.GetServices() for service_path, properties in found_services: fmbt.adapterlog(" GetServices(): %s (%s)" % (service_path, properties["Name"])) if str(service_path).split("/")[-1].startswith(techname) and properties["Name"] in can_connect: connect_me = service_path break if connect_me != None: break counter += 1 assert counter < RETRY_LIMIT, "Maximum number of retries" fmbt.adapterlog("Known services not found, retrying after 2 second...") time.sleep(2) # Connect to the found service fmbt.adapterlog('Connecting to service "%s"' % (properties["Name"],)) service = dbus.Interface(bus.get_object("net.connman", service_path), "net.connman.Service") service.Connect(timeout=5000) connected_services[techname] = service_path
def soe(cmd, stdin="", cwd=None, env=None): """Run cmd, return (status, stdout, stderr)""" run_env = dict(os.environ) if not env is None: run_env.update(env) fmbt.adapterlog("%s: soe run %r" % (fmbt.actionName(), cmd)) try: p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True, cwd=cwd, env=run_env) out, err = p.communicate(input=stdin) except Exception, e: return (None, None, str(e))
def iPowerUp(techname): global g_last_powerup RETRY_LIMIT = 5 tech = dbus.Interface(bus.get_object("net.connman", "/net/connman/technology/" + techname), "net.connman.Technology") counter = 0 while 1: try: tech.SetProperty("Powered", True) break # if no exceptions except Exception, e: fmbt.adapterlog("Got exception: %s" % (e,)) if not ("InvalidArguments" in str(e) or "InvalidProperty" in str(e)): fmbt.adapterlog("BUG: undocumented exception") counter += 1 time.sleep(1) assert counter < RETRY_LIMIT, "Maximum number of retries"
def iExecute(): for f in glob.glob("stats-output-*"): try: os.remove(f) except: pass # Check if this combination hits a seeded error if ((seeded_logfile or seeded_format or seeded_output or seeded_plot) and (not seeded_logfile or fmbt_stats_logfile in seeded_logfile) and (not seeded_format or fmbt_stats_format in seeded_format) and (not seeded_output or fmbt_stats_output in seeded_output) and (not seeded_plot or fmbt_stats_plot in seeded_plot)): raise Exception("Seeded error") stepslogfile = file("teststeps.log","w") cmd = "fmbt-stats %s %s %s %s %s" % ( fmbt_stats_format, fmbt_stats_output, fmbt_stats_plot, fmbt_stats_logfile, fmbt_stats_redirect) fmbtlog("Running '%s'" % (cmd,)) p = subprocess.Popen(cmd, shell=True, stdin = subprocess.PIPE, stdout = stepslogfile.fileno(), stderr = stepslogfile.fileno()) p.stdin.close() exit_status = p.wait() adapterlog("'%s' exit status: %s" % (cmd, exit_status)) # Check exit status if fmbt_stats_logfile.endswith("-0.log"): if exit_status != 1: raise Exception("exit status != 1 with empty log. Try: " + cmd) return None # no further checks for an empty log elif exit_status != 0: raise Exception("exit status != 0 with non-empty log. Try: " + cmd) # Read produced statistics text file if fmbt_stats_output.startswith("-o"): stats_text = file(fmbt_stats_output[3:]).read() stats_text_format = fmbt_stats_output.split('.')[-1] elif fmbt_stats_redirect != "": stats_text = file("stats-output-text.txt").read() stats_text_format = "txt" if stats_text.strip() == "": raise Exception("empty output file. Try: " + cmd) # Check that every step seems to be reported expected_step_count = int(fmbt_stats_logfile[len("stats-input-"):-len(".log")]) if fmbt_stats_format.startswith("-f times") or fmbt_stats_format == "": # Times stats: sum up numbers in the total column if stats_text_format == "txt": step_count = sum([int(row[39:49]) for row in stats_text.split('\n')[2:] if row]) elif stats_text_format == "csv": step_count = sum([int(row.split(';')[4]) for row in stats_text.split('\n')[2:] if row]) elif stats_text_format == "html": step_count = sum([int(row.split('</td><td>')[4]) for row in stats_text.split('\n')[3:-2] if row]) else: raise Exception("unknown times output format: %s" % (stats_text_format,)) elif fmbt_stats_format.startswith("-f speed"): # Speed stats: count rows if stats_text_format == "txt": step_count = stats_text.count('\n')-2 elif stats_text_format == "csv": step_count = stats_text.count('\n')-2 elif stats_text_format == "html": step_count = stats_text.count('\n')-5 else: raise Exception("unknown speed output format: %s" % (stats_text_format,)) elif fmbt_stats_format.startswith("-f dist"): # Distribution stats: sum up numbers in the matrix. Needs # adding one because there's no previous action for the first # action, and there's no next action for the last one. This # validation is skipped if only unique actions are shown. if "uniq" in fmbt_stats_format: step_count = expected_step_count # skip the test elif stats_text_format == "txt": step_count = sum([sum([int(c) for c in row.split('"')[0].split()]) for row in stats_text.split('\n')[2:] if row]) + 1 elif stats_text_format == "csv": step_count = sum([sum([int(c) for c in row.split(';')[:-1]]) for row in stats_text.split('\n')[2:] if row]) + 1 elif stats_text_format == "html": step_count = sum([sum([int(c) for c in row[8:].split('</td><td>')[:-1]]) for row in stats_text.split('\n')[4:] if row]) + 1 else: raise Exception("unknown dist output format: %s" % (stats_text_format,)) if step_count != expected_step_count: raise Exception('text output reports %s steps (expected: %s). Try: %s' % (step_count, expected_step_count, cmd)) # Check that a non-empty plot file has been created if requested. if fmbt_stats_plot.startswith("-p"): if "," in fmbt_stats_plot: plot_filename = fmbt_stats_plot.split(",")[0][3:] else: plot_filename = fmbt_stats_plot[3:] if not os.stat(plot_filename).st_size > 0: raise Exception("zero-length plot file. Try: %s" % (cmd,))
def readlines_to_adapterlog(file_obj, prefix): while 1: line = file_obj.readline() if not line: break fmbt.adapterlog("%s%s" % (prefix, line))
def _adapterLog(msg): fmbt.adapterlog("fmbttizen: %s" % (msg, ))
except Exception, e: class fakeProcess(object): pass p = fakeProcess p.returncode = 127 out, err = ('', e) exitStatus = p.returncode if (expectedExitStatus != None and exitStatus != expectedExitStatus and exitStatus not in expectedExitStatus): msg = "Executing %s failed. Exit status: %s, expected %s" % ( command, exitStatus, expectedExitStatus) fmbt.adapterlog("%s\n stdout: %s\n stderr: %s\n" % (msg, out, err)) raise FMBTTizenError(msg) return exitStatus, out, err def _fileToQueue(f, outQueue): line = f.readline() while line != "": outQueue.put(line) line = f.readline() f.close() class Device(fmbtgti.GUITestInterface): def __init__(self,
def _adapterLog(msg): fmbt.adapterlog("fmbtwindows %s" % (msg, ))
def _adapterLog(msg): fmbt.adapterlog("fmbttizen: %s" % (msg,))
out, err = p.communicate() else: out, err = ('', None) except Exception, e: class fakeProcess(object): pass p = fakeProcess p.returncode = 127 out, err = ('', e) exitStatus = p.returncode if (expectedExitStatus != None and exitStatus != expectedExitStatus and exitStatus not in expectedExitStatus): msg = "Executing %s failed. Exit status: %s, expected %s" % (command, exitStatus, expectedExitStatus) fmbt.adapterlog("%s\n stdout: %s\n stderr: %s\n" % (msg, out, err)) raise FMBTTizenError(msg) return exitStatus, out, err def _fileToQueue(f, outQueue): line = f.readline() while line != "": outQueue.put(line) line = f.readline() f.close() class Device(fmbtgti.GUITestInterface): def __init__(self, serialNumber=None, loginCommand=None, debugAgentFile=None, keyboardDevice=None, touchDevice=None, mouseDevice=None,
#!/usr/bin/env python import fmbt import sys import urllib import types import traceback def put(s): sys.stdout.write(urllib.quote(s) + "\n") def names(iterable): try: results = ['"%s"' % (i,) for i in iterable] except TypeError: raise TypeError('Parameter of names() must be iterable, not %s as in "%s"' % (type(iterable), iterable)) put(", ".join(results)) line = sys.stdin.readline() while line: block = urllib.unquote(line) fmbt.adapterlog("executing '''%s'''" % (block,)) try: exec block except: put(traceback.format_exc()) sys.stdout.flush() line = sys.stdin.readline()
def iExecute(): for f in glob.glob("stats-output-*"): try: os.remove(f) except: pass # Check if this combination hits a seeded error if ((seeded_logfile or seeded_format or seeded_output or seeded_plot) and (not seeded_logfile or fmbt_stats_logfile in seeded_logfile) and (not seeded_format or fmbt_stats_format in seeded_format) and (not seeded_output or fmbt_stats_output in seeded_output) and (not seeded_plot or fmbt_stats_plot in seeded_plot)): raise Exception("Seeded error") stepslogfile = file("teststeps.log", "w") cmd = "fmbt-stats %s %s %s %s %s" % (fmbt_stats_format, fmbt_stats_output, fmbt_stats_plot, fmbt_stats_logfile, fmbt_stats_redirect) fmbtlog("Running '%s'" % (cmd, )) p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=stepslogfile.fileno(), stderr=stepslogfile.fileno()) p.stdin.close() exit_status = p.wait() adapterlog("'%s' exit status: %s" % (cmd, exit_status)) # Check exit status if fmbt_stats_logfile.endswith("-0.log"): if exit_status != 1: raise Exception("exit status != 1 with empty log. Try: " + cmd) return None # no further checks for an empty log elif exit_status != 0: raise Exception("exit status != 0 with non-empty log. Try: " + cmd) # Read produced statistics text file if fmbt_stats_output.startswith("-o"): stats_text = file(fmbt_stats_output[3:]).read() stats_text_format = fmbt_stats_output.split('.')[-1] elif fmbt_stats_redirect != "": stats_text = file("stats-output-text.txt").read() stats_text_format = "txt" if stats_text.strip() == "": raise Exception("empty output file. Try: " + cmd) # Check that every step seems to be reported expected_step_count = int( fmbt_stats_logfile[len("stats-input-"):-len(".log")]) if fmbt_stats_format.startswith("-f times") or fmbt_stats_format == "": # Times stats: sum up numbers in the total column if stats_text_format == "txt": step_count = sum( [int(row[39:49]) for row in stats_text.split('\n')[2:] if row]) elif stats_text_format == "csv": step_count = sum([ int(row.split(';')[4]) for row in stats_text.split('\n')[2:] if row ]) elif stats_text_format == "html": step_count = sum([ int(row.split('</td><td>')[4]) for row in stats_text.split('\n')[3:-2] if row ]) else: raise Exception("unknown times output format: %s" % (stats_text_format, )) elif fmbt_stats_format.startswith("-f speed"): # Speed stats: count rows if stats_text_format == "txt": step_count = stats_text.count('\n') - 2 elif stats_text_format == "csv": step_count = stats_text.count('\n') - 2 elif stats_text_format == "html": step_count = stats_text.count('\n') - 5 else: raise Exception("unknown speed output format: %s" % (stats_text_format, )) elif fmbt_stats_format.startswith("-f dist"): # Distribution stats: sum up numbers in the matrix. Needs # adding one because there's no previous action for the first # action, and there's no next action for the last one. This # validation is skipped if only unique actions are shown. if "uniq" in fmbt_stats_format: step_count = expected_step_count # skip the test elif stats_text_format == "txt": step_count = sum([ sum([int(c) for c in row.split('"')[0].split()]) for row in stats_text.split('\n')[2:] if row ]) + 1 elif stats_text_format == "csv": step_count = sum([ sum([int(c) for c in row.split(';')[:-1]]) for row in stats_text.split('\n')[2:] if row ]) + 1 elif stats_text_format == "html": step_count = sum([ sum([int(c) for c in row[8:].split('</td><td>')[:-1]]) for row in stats_text.split('\n')[4:] if row ]) + 1 else: raise Exception("unknown dist output format: %s" % (stats_text_format, )) if step_count != expected_step_count: raise Exception( 'text output reports %s steps (expected: %s). Try: %s' % (step_count, expected_step_count, cmd)) # Check that a non-empty plot file has been created if requested. if fmbt_stats_plot.startswith("-p"): if "," in fmbt_stats_plot: plot_filename = fmbt_stats_plot.split(",")[0][3:] else: plot_filename = fmbt_stats_plot[3:] if not os.stat(plot_filename).st_size > 0: raise Exception("zero-length plot file. Try: %s" % (cmd, ))
def _adapterLog(msg): fmbt.adapterlog("fmbtwindows %s" % (msg,))
tech = dbus.Interface(bus.get_object("net.connman", "/net/connman/technology/" + techname), "net.connman.Technology") counter = 0 while 1: try: tech.SetProperty("Powered", True) break # if no exceptions except Exception, e: fmbt.adapterlog("Got exception: %s" % (e,)) if not ("InvalidArguments" in str(e) or "InvalidProperty" in str(e)): fmbt.adapterlog("BUG: undocumented exception") counter += 1 time.sleep(1) assert counter < RETRY_LIMIT, "Maximum number of retries" time.sleep(3) fmbt.adapterlog("tech.GetProperties()['Powered'] = %s" % (tech.GetProperties()["Powered"],)) assert tech.GetProperties()["Powered"], "Powered == False according to properties" g_last_powerup = time.time() def iPowerDown(techname): tech = dbus.Interface(bus.get_object("net.connman", "/net/connman/technology/" + techname), "net.connman.Technology") tech.SetProperty("Powered", False) def iScan(techname): tech = dbus.Interface(bus.get_object("net.connman", "/net/connman/technology/" + techname), "net.connman.Technology") if g_last_powerup + 5 > time.time(): time.sleep(g_last_powerup + 5 - time.time())