aboutsummaryrefslogtreecommitdiff
path: root/crb
diff options
context:
space:
mode:
authorLuis Lozano <llozano@chromium.org>2015-12-15 13:49:30 -0800
committerLuis Lozano <llozano@chromium.org>2015-12-16 17:36:06 +0000
commitf2a3ef46f75d2196a93d3ed27f4d1fcf22b54fbe (patch)
tree185d243c7eed7c7a0db6f0e640746cadc1479ea9 /crb
parent2a66f70fef907c1cb15229cb58e5129cb620ac98 (diff)
downloadtoolchain-utils-f2a3ef46f75d2196a93d3ed27f4d1fcf22b54fbe.tar.gz
Run pyformat on all the toolchain-utils files.
This gets rid of a lot of lint issues. Ran by doing this: for f in *.py; do echo -n "$f " ; if [ -x $f ]; then pyformat -i --remove_trailing_comma --yapf --force_quote_type=double $f ; else pyformat -i --remove_shebang --remove_trailing_comma --yapf --force_quote_type=double $f ; fi ; done BUG=chromium:567921 TEST=Ran simple crosperf run. Change-Id: I59778835fdaa5f706d2e1765924389f9e97433d1 Reviewed-on: https://chrome-internal-review.googlesource.com/242031 Reviewed-by: Luis Lozano <llozano@chromium.org> Commit-Queue: Luis Lozano <llozano@chromium.org> Tested-by: Luis Lozano <llozano@chromium.org> Reviewed-by: Yunlian Jiang <yunlian@google.com>
Diffstat (limited to 'crb')
-rw-r--r--crb/autotest_gatherer.py20
-rw-r--r--crb/autotest_run.py175
-rwxr-xr-xcrb/crb_driver.py211
-rw-r--r--crb/machine_manager_singleton.py58
-rw-r--r--crb/table_formatter.py83
5 files changed, 289 insertions, 258 deletions
diff --git a/crb/autotest_gatherer.py b/crb/autotest_gatherer.py
index da39040d..f8f7b43f 100644
--- a/crb/autotest_gatherer.py
+++ b/crb/autotest_gatherer.py
@@ -1,30 +1,34 @@
from table_formatter import TableFormatter as TableFormatter
+
class AutotestGatherer(TableFormatter):
+
def __init__(self):
self.runs = []
TableFormatter.__init__(self)
def GetFormattedMainTable(self, percents_only, fit_string):
- ret = ""
+ ret = ''
table = self.GetTableValues()
ret += self.GetTableLabels(table)
- ret += self.GetFormattedTable(table, percents_only=percents_only,
+ ret += self.GetFormattedTable(table,
+ percents_only=percents_only,
fit_string=fit_string)
return ret
def GetFormattedSummaryTable(self, percents_only, fit_string):
- ret = ""
+ ret = ''
table = self.GetTableValues()
summary_table = self.GetSummaryTableValues(table)
ret += self.GetTableLabels(summary_table)
- ret += self.GetFormattedTable(summary_table, percents_only=percents_only,
+ ret += self.GetFormattedTable(summary_table,
+ percents_only=percents_only,
fit_string=fit_string)
return ret
def GetBenchmarksString(self):
- ret = "Benchmarks (in order):"
- ret = "\n".join(self.GetAllBenchmarks())
+ ret = 'Benchmarks (in order):'
+ ret = '\n'.join(self.GetAllBenchmarks())
return ret
def GetAllBenchmarks(self):
@@ -40,7 +44,7 @@ class AutotestGatherer(TableFormatter):
table = []
row = []
- row.append("Benchmark")
+ row.append('Benchmark')
for i in range(len(self.runs)):
run = self.runs[i]
label = run.GetLabel()
@@ -57,7 +61,7 @@ class AutotestGatherer(TableFormatter):
if benchmark in results:
row.append(results[benchmark])
else:
- row.append("")
+ row.append('')
table.append(row)
return table
diff --git a/crb/autotest_run.py b/crb/autotest_run.py
index 565246db..b774419b 100644
--- a/crb/autotest_run.py
+++ b/crb/autotest_run.py
@@ -12,25 +12,33 @@ import table_formatter
from utils import command_executer
from utils import logger
-
-SCRATCH_DIR = "/home/%s/cros_scratch" % getpass.getuser()
-PICKLE_FILE = "pickle.txt"
-VERSION = "1"
+SCRATCH_DIR = '/home/%s/cros_scratch' % getpass.getuser()
+PICKLE_FILE = 'pickle.txt'
+VERSION = '1'
def ConvertToFilename(text):
ret = text
- ret = re.sub("/", "__", ret)
- ret = re.sub(" ", "_", ret)
- ret = re.sub("=", "", ret)
- ret = re.sub("\"", "", ret)
+ ret = re.sub('/', '__', ret)
+ ret = re.sub(' ', '_', ret)
+ ret = re.sub('=', '', ret)
+ ret = re.sub("\"", '', ret)
return ret
class AutotestRun(threading.Thread):
- def __init__(self, autotest, chromeos_root="", chromeos_image="",
- board="", remote="", iteration=0, image_checksum="",
- exact_remote=False, rerun=False, rerun_if_failed=False):
+
+ def __init__(self,
+ autotest,
+ chromeos_root='',
+ chromeos_image='',
+ board='',
+ remote='',
+ iteration=0,
+ image_checksum='',
+ exact_remote=False,
+ rerun=False,
+ rerun_if_failed=False):
self.autotest = autotest
self.chromeos_root = chromeos_root
self.chromeos_image = chromeos_image
@@ -44,7 +52,7 @@ class AutotestRun(threading.Thread):
threading.Thread.__init__(self)
self.terminate = False
self.retval = None
- self.status = "PENDING"
+ self.status = 'PENDING'
self.run_completed = False
self.exact_remote = exact_remote
self.rerun = rerun
@@ -58,7 +66,7 @@ class AutotestRun(threading.Thread):
array2 = []
for v in array:
- if mean != 0 and abs(v - mean)/mean < 0.2:
+ if mean != 0 and abs(v - mean) / mean < 0.2:
array2.append(v)
if array2:
@@ -71,7 +79,7 @@ class AutotestRun(threading.Thread):
composite_keys = []
composite_dict = {}
for key in results_dict:
- mo = re.match("(.*){\d+}", key)
+ mo = re.match('(.*){\d+}', key)
if mo:
composite_keys.append(mo.group(1))
for key in results_dict:
@@ -85,24 +93,24 @@ class AutotestRun(threading.Thread):
for composite_key in composite_dict:
v = composite_dict[composite_key]
- results_dict["%s[c]" % composite_key] = sum(v) / len(v)
+ results_dict['%s[c]' % composite_key] = sum(v) / len(v)
mean_excluding_slowest = AutotestRun.MeanExcludingSlowest(v)
- results_dict["%s[ce]" % composite_key] = mean_excluding_slowest
+ results_dict['%s[ce]' % composite_key] = mean_excluding_slowest
return results_dict
def ParseOutput(self):
- p = re.compile("^-+.*?^-+", re.DOTALL|re.MULTILINE)
+ p = re.compile('^-+.*?^-+', re.DOTALL | re.MULTILINE)
matches = p.findall(self.out)
for i in range(len(matches)):
results = matches[i]
results_dict = {}
for line in results.splitlines()[1:-1]:
- mo = re.match("(.*\S)\s+\[\s+(PASSED|FAILED)\s+\]", line)
+ mo = re.match('(.*\S)\s+\[\s+(PASSED|FAILED)\s+\]', line)
if mo:
results_dict[mo.group(1)] = mo.group(2)
continue
- mo = re.match("(.*\S)\s+(.*)", line)
+ mo = re.match('(.*\S)\s+(.*)', line)
if mo:
results_dict[mo.group(1)] = mo.group(2)
@@ -115,21 +123,21 @@ class AutotestRun(threading.Thread):
# Autotest recently added a secondary table
# That reports errors and screws up the final pretty output.
break
- mo = re.search("Results placed in (\S+)", self.out)
+ mo = re.search('Results placed in (\S+)', self.out)
if mo:
self.results_dir = mo.group(1)
self.full_name = os.path.basename(self.results_dir)
def GetCacheHashBase(self):
- ret = ("%s %s %s" %
+ ret = ('%s %s %s' %
(self.image_checksum, self.autotest.name, self.iteration))
if self.autotest.args:
- ret += " %s" % self.autotest.args
- ret += "-%s" % VERSION
+ ret += ' %s' % self.autotest.args
+ ret += '-%s' % VERSION
return ret
def GetLabel(self):
- ret = "%s %s remote:%s" % (self.chromeos_image, self.autotest.name,
+ ret = '%s %s remote:%s' % (self.chromeos_image, self.autotest.name,
self.remote)
return ret
@@ -138,23 +146,23 @@ class AutotestRun(threading.Thread):
if self.exact_remote:
if not self.remote:
return False
- cache_dir_glob = "%s_%s" % (ConvertToFilename(base), self.remote)
+ cache_dir_glob = '%s_%s' % (ConvertToFilename(base), self.remote)
else:
- cache_dir_glob = "%s*" % ConvertToFilename(base)
+ cache_dir_glob = '%s*' % ConvertToFilename(base)
cache_path_glob = os.path.join(SCRATCH_DIR, cache_dir_glob)
matching_dirs = glob.glob(cache_path_glob)
if matching_dirs:
matching_dir = matching_dirs[0]
cache_file = os.path.join(matching_dir, PICKLE_FILE)
assert os.path.isfile(cache_file)
- self._logger.LogOutput("Trying to read from cache file: %s" % cache_file)
+ self._logger.LogOutput('Trying to read from cache file: %s' % cache_file)
return self.ReadFromCache(cache_file)
- self._logger.LogOutput("Cache miss. AM going to run: %s for: %s" %
+ self._logger.LogOutput('Cache miss. AM going to run: %s for: %s' %
(self.autotest.name, self.chromeos_image))
return False
def ReadFromCache(self, cache_file):
- with open(cache_file, "rb") as f:
+ with open(cache_file, 'rb') as f:
self.retval = pickle.load(f)
self.out = pickle.load(f)
self.err = pickle.load(f)
@@ -164,48 +172,46 @@ class AutotestRun(threading.Thread):
def StoreToCache(self):
base = self.GetCacheHashBase()
- self.cache_dir = os.path.join(SCRATCH_DIR, "%s_%s" % (
- ConvertToFilename(base),
- self.remote))
+ self.cache_dir = os.path.join(SCRATCH_DIR,
+ '%s_%s' % (ConvertToFilename(base),
+ self.remote))
cache_file = os.path.join(self.cache_dir, PICKLE_FILE)
- command = "mkdir -p %s" % os.path.dirname(cache_file)
+ command = 'mkdir -p %s' % os.path.dirname(cache_file)
ret = self._ce.RunCommand(command)
assert ret == 0, "Couldn't create cache dir"
- with open(cache_file, "wb") as f:
+ with open(cache_file, 'wb') as f:
pickle.dump(self.retval, f)
pickle.dump(self.out, f)
pickle.dump(self.err, f)
def run(self):
self._logger = logger.Logger(
- os.path.dirname(__file__),
- "%s.%s" % (os.path.basename(__file__),
- self.name), True)
+ os.path.dirname(__file__), '%s.%s' % (os.path.basename(__file__),
+ self.name), True)
self._ce = command_executer.GetCommandExecuter(self._logger)
self.RunCached()
def RunCached(self):
- self.status = "WAITING"
+ self.status = 'WAITING'
cache_hit = False
if not self.rerun:
cache_hit = self.TryToLoadFromCache()
else:
- self._logger.LogOutput("--rerun passed. Not using cached results.")
+ self._logger.LogOutput('--rerun passed. Not using cached results.')
if self.rerun_if_failed and self.retval:
- self._logger.LogOutput("--rerun_if_failed passed and existing test "
- "failed. Rerunning...")
+ self._logger.LogOutput('--rerun_if_failed passed and existing test '
+ 'failed. Rerunning...')
cache_hit = False
if not cache_hit:
# Get machine
while True:
if self.terminate:
return 1
- self.machine = (
- machine_manager_singleton.MachineManagerSingleton().AcquireMachine(self.image_checksum))
+ self.machine = (machine_manager_singleton.MachineManagerSingleton(
+ ).AcquireMachine(self.image_checksum))
if self.machine:
- self._logger.LogOutput("%s: Machine %s acquired at %s" %
- (self.name,
- self.machine.name,
+ self._logger.LogOutput('%s: Machine %s acquired at %s' %
+ (self.name, self.machine.name,
datetime.datetime.now()))
break
else:
@@ -216,56 +222,56 @@ class AutotestRun(threading.Thread):
if self.machine.checksum != self.image_checksum:
self.retval = self.ImageTo(self.machine.name)
- if self.retval: return self.retval
+ if self.retval:
+ return self.retval
self.machine.checksum = self.image_checksum
self.machine.image = self.chromeos_image
- self.status = "RUNNING: %s" % self.autotest.name
+ self.status = 'RUNNING: %s' % self.autotest.name
[self.retval, self.out, self.err] = self.RunTestOn(self.machine.name)
self.run_completed = True
finally:
- self._logger.LogOutput("Releasing machine: %s" % self.machine.name)
- machine_manager_singleton.MachineManagerSingleton().ReleaseMachine(self.machine)
- self._logger.LogOutput("Released machine: %s" % self.machine.name)
+ self._logger.LogOutput('Releasing machine: %s' % self.machine.name)
+ machine_manager_singleton.MachineManagerSingleton().ReleaseMachine(
+ self.machine)
+ self._logger.LogOutput('Released machine: %s' % self.machine.name)
self.StoreToCache()
if not self.retval:
- self.status = "SUCCEEDED"
+ self.status = 'SUCCEEDED'
else:
- self.status = "FAILED"
+ self.status = 'FAILED'
self.ParseOutput()
# Copy results directory to the scratch dir
if (not cache_hit and not self.retval and self.autotest.args and
- "--profile" in self.autotest.args):
- results_dir = os.path.join(self.chromeos_root, "chroot",
- self.results_dir.lstrip("/"))
+ '--profile' in self.autotest.args):
+ results_dir = os.path.join(self.chromeos_root, 'chroot',
+ self.results_dir.lstrip('/'))
tarball = os.path.join(
- self.cache_dir,
- os.path.basename(os.path.dirname(self.results_dir)))
- command = ("cd %s && tar cjf %s.tbz2 ." % (results_dir, tarball))
+ self.cache_dir, os.path.basename(os.path.dirname(self.results_dir)))
+ command = ('cd %s && tar cjf %s.tbz2 .' % (results_dir, tarball))
self._ce.RunCommand(command)
perf_data_file = os.path.join(self.results_dir, self.full_name,
- "profiling/iteration.1/perf.data")
+ 'profiling/iteration.1/perf.data')
# Attempt to build a perf report and keep it with the results.
- command = ("cd %s/src/scripts &&"
- " cros_sdk -- /usr/sbin/perf report --symfs=/build/%s"
- " -i %s --stdio" % (self.chromeos_root, self.board,
+ command = ('cd %s/src/scripts &&'
+ ' cros_sdk -- /usr/sbin/perf report --symfs=/build/%s'
+ ' -i %s --stdio' % (self.chromeos_root, self.board,
perf_data_file))
ret, out, err = self._ce.RunCommandWOutput(command)
- with open(os.path.join(self.cache_dir, "perf.report"), "wb") as f:
+ with open(os.path.join(self.cache_dir, 'perf.report'), 'wb') as f:
f.write(out)
return self.retval
def ImageTo(self, machine_name):
- image_args = [image_chromeos.__file__,
- "--chromeos_root=%s" % self.chromeos_root,
- "--image=%s" % self.chromeos_image,
- "--remote=%s" % machine_name]
+ image_args = [image_chromeos.__file__, '--chromeos_root=%s' %
+ self.chromeos_root, '--image=%s' % self.chromeos_image,
+ '--remote=%s' % machine_name]
if self.board:
- image_args.append("--board=%s" % self.board)
+ image_args.append('--board=%s' % self.board)
### devserver_port = 8080
### mo = re.search("\d+", self.name)
@@ -280,33 +286,32 @@ class AutotestRun(threading.Thread):
### image_args.append("--image_to_live_args=--devserver_port=%s" %
### devserver_port)
- # Currently can't image two machines at once.
- # So have to serialized on this lock.
- self.status = "WAITING ON IMAGE_LOCK"
+# Currently can't image two machines at once.
+# So have to serialized on this lock.
+ self.status = 'WAITING ON IMAGE_LOCK'
with machine_manager_singleton.MachineManagerSingleton().image_lock:
- self.status = "IMAGING"
- retval = self._ce.RunCommand(" ".join(["python"] + image_args))
+ self.status = 'IMAGING'
+ retval = self._ce.RunCommand(' '.join(['python'] + image_args))
machine_manager_singleton.MachineManagerSingleton().num_reimages += 1
if retval:
- self.status = "ABORTED DUE TO IMAGE FAILURE"
+ self.status = 'ABORTED DUE TO IMAGE FAILURE'
return retval
def DoPowerdHack(self):
- command = "sudo initctl stop powerd"
- self._ce.CrosRunCommand(command, machine=self.machine.name,
+ command = 'sudo initctl stop powerd'
+ self._ce.CrosRunCommand(command,
+ machine=self.machine.name,
chromeos_root=self.chromeos_root)
def RunTestOn(self, machine_name):
- command = "cd %s/src/scripts" % self.chromeos_root
- options = ""
+ command = 'cd %s/src/scripts' % self.chromeos_root
+ options = ''
if self.board:
- options += " --board=%s" % self.board
+ options += ' --board=%s' % self.board
if self.autotest.args:
options += " --args='%s'" % self.autotest.args
- if "tegra2" in self.board:
+ if 'tegra2' in self.board:
self.DoPowerdHack()
- command += ("&& cros_sdk -- /usr/bin/test_that %s %s %s" %
- (options,
- machine_name,
- self.autotest.name))
+ command += ('&& cros_sdk -- /usr/bin/test_that %s %s %s' %
+ (options, machine_name, self.autotest.name))
return self._ce.RunCommand(command, True)
diff --git a/crb/crb_driver.py b/crb/crb_driver.py
index 9e6301d0..14fe6bab 100755
--- a/crb/crb_driver.py
+++ b/crb/crb_driver.py
@@ -19,36 +19,38 @@ from utils.file_utils import FileUtils
def CanonicalizeChromeOSRoot(chromeos_root):
chromeos_root = os.path.expanduser(chromeos_root)
- if os.path.isfile(os.path.join(chromeos_root,
- "src/scripts/enter_chroot.sh")):
+ if os.path.isfile(os.path.join(chromeos_root, 'src/scripts/enter_chroot.sh')):
return chromeos_root
else:
return None
class Autotest(object):
+
def __init__(self, autotest_string):
self.name = None
self.iterations = None
self.args = None
- fields = autotest_string.split(",", 1)
+ fields = autotest_string.split(',', 1)
self.name = fields[0]
if len(fields) > 1:
autotest_string = fields[1]
- fields = autotest_string.split(",", 1)
- else: return
+ fields = autotest_string.split(',', 1)
+ else:
+ return
self.iterations = int(fields[0])
if len(fields) > 1:
self.args = fields[1]
- else: return
+ else:
+ return
def __str__(self):
- return "\n".join([self.name, self.iterations, self.args])
+ return '\n'.join([self.name, self.iterations, self.args])
def CreateAutotestListFromString(autotest_strings, default_iterations=None):
autotest_list = []
- for autotest_string in autotest_strings.split(":"):
+ for autotest_string in autotest_strings.split(':'):
autotest = Autotest(autotest_string)
if default_iterations and not autotest.iterations:
autotest.iterations = default_iterations
@@ -57,24 +59,30 @@ def CreateAutotestListFromString(autotest_strings, default_iterations=None):
return autotest_list
-def CreateAutotestRuns(images, autotests, remote, board, exact_remote,
- rerun, rerun_if_failed, main_chromeos_root=None):
+def CreateAutotestRuns(images,
+ autotests,
+ remote,
+ board,
+ exact_remote,
+ rerun,
+ rerun_if_failed,
+ main_chromeos_root=None):
autotest_runs = []
for image in images:
- logger.GetLogger().LogOutput("Computing md5sum of: %s" % image)
+ logger.GetLogger().LogOutput('Computing md5sum of: %s' % image)
image_checksum = FileUtils().Md5File(image)
- logger.GetLogger().LogOutput("md5sum %s: %s" % (image, image_checksum))
-### image_checksum = "abcdefghi"
+ logger.GetLogger().LogOutput('md5sum %s: %s' % (image, image_checksum))
+ ### image_checksum = "abcdefghi"
chromeos_root = main_chromeos_root
if not main_chromeos_root:
- image_chromeos_root = os.path.join(os.path.dirname(image),
- "../../../../..")
+ image_chromeos_root = os.path.join(
+ os.path.dirname(image), '../../../../..')
chromeos_root = CanonicalizeChromeOSRoot(image_chromeos_root)
- assert chromeos_root, "chromeos_root: %s invalid" % image_chromeos_root
+ assert chromeos_root, 'chromeos_root: %s invalid' % image_chromeos_root
else:
chromeos_root = CanonicalizeChromeOSRoot(main_chromeos_root)
- assert chromeos_root, "chromeos_root: %s invalid" % main_chromeos_root
+ assert chromeos_root, 'chromeos_root: %s invalid' % main_chromeos_root
# We just need a single ChromeOS root in the MachineManagerSingleton. It is
# needed because we can save re-image time by checking the image checksum at
@@ -101,9 +109,9 @@ def CreateAutotestRuns(images, autotests, remote, board, exact_remote,
def GetNamesAndIterations(autotest_runs):
strings = []
for autotest_run in autotest_runs:
- strings.append("%s:%s" % (autotest_run.autotest.name,
+ strings.append('%s:%s' % (autotest_run.autotest.name,
autotest_run.iteration))
- return " %s (%s)" % (len(strings), " ".join(strings))
+ return ' %s (%s)' % (len(strings), ' '.join(strings))
def GetStatusString(autotest_runs):
@@ -115,19 +123,19 @@ def GetStatusString(autotest_runs):
status_strings = []
for key, val in status_bins.items():
- status_strings.append("%s: %s" % (key, GetNamesAndIterations(val)))
- return "Thread Status:\n%s" % "\n".join(status_strings)
+ status_strings.append('%s: %s' % (key, GetNamesAndIterations(val)))
+ return 'Thread Status:\n%s' % '\n'.join(status_strings)
def GetProgressBar(num_done, num_total):
- ret = "Done: %s%%" % int(100.0 * num_done / num_total)
+ ret = 'Done: %s%%' % int(100.0 * num_done / num_total)
bar_length = 50
- done_char = ">"
- undone_char = " "
+ done_char = '>'
+ undone_char = ' '
num_done_chars = bar_length * num_done / num_total
num_undone_chars = bar_length - num_done_chars
- ret += " [%s%s]" % (num_done_chars * done_char, num_undone_chars *
- undone_char)
+ ret += ' [%s%s]' % (num_done_chars * done_char,
+ num_undone_chars * undone_char)
return ret
@@ -139,14 +147,13 @@ def GetProgressString(start_time, num_remain, num_total):
eta_seconds = int(eta_seconds)
eta = datetime.timedelta(seconds=eta_seconds)
except ZeroDivisionError:
- eta = "Unknown"
+ eta = 'Unknown'
strings = []
- strings.append("Current time: %s Elapsed: %s ETA: %s" %
- (datetime.datetime.now(),
- datetime.timedelta(seconds=int(elapsed_time)),
- eta))
+ strings.append('Current time: %s Elapsed: %s ETA: %s' %
+ (datetime.datetime.now(),
+ datetime.timedelta(seconds=int(elapsed_time)), eta))
strings.append(GetProgressBar(num_total - num_remain, num_total))
- return "\n".join(strings)
+ return '\n'.join(strings)
def RunAutotestRunsInParallel(autotest_runs):
@@ -162,25 +169,23 @@ def RunAutotestRunsInParallel(autotest_runs):
last_printed_time = time.time()
while active_threads:
try:
- active_threads = [t for t in active_threads if t is not None
- and t.isAlive()]
+ active_threads = [t for t in active_threads
+ if t is not None and t.isAlive()]
for t in active_threads:
t.join(1)
if time.time() - last_printed_time > print_interval:
- border = "=============================="
+ border = '=============================='
logger.GetLogger().LogOutput(border)
- logger.GetLogger().LogOutput(GetProgressString(
- start_time,
- len([t for t in autotest_runs if t.status not in ["SUCCEEDED",
- "FAILED"]]),
- len(autotest_runs)))
+ logger.GetLogger().LogOutput(GetProgressString(start_time, len(
+ [t for t in autotest_runs if t.status not in ['SUCCEEDED', 'FAILED']
+ ]), len(autotest_runs)))
logger.GetLogger().LogOutput(GetStatusString(autotest_runs))
- logger.GetLogger().LogOutput("%s\n" %
+ logger.GetLogger().LogOutput('%s\n' %
MachineManagerSingleton().AsString())
logger.GetLogger().LogOutput(border)
last_printed_time = time.time()
except KeyboardInterrupt:
- print "C-c received... cleaning up threads."
+ print 'C-c received... cleaning up threads.'
for t in active_threads:
t.terminate = True
return 1
@@ -190,7 +195,8 @@ def RunAutotestRunsInParallel(autotest_runs):
def RunAutotestRunsSerially(autotest_runs):
for autotest_run in autotest_runs:
retval = autotest_run.Run()
- if retval: return retval
+ if retval:
+ return retval
def ProduceTables(autotest_runs, full_table, fit_string):
@@ -201,31 +207,31 @@ def ProduceTables(autotest_runs, full_table, fit_string):
if name not in ags_dict:
ags_dict[name] = AutotestGatherer()
ags_dict[name].runs.append(autotest_run)
- output = ""
+ output = ''
for b, ag in ags_dict.items():
- output += "Benchmark: %s\n" % b
+ output += 'Benchmark: %s\n' % b
output += ag.GetFormattedMainTable(percents_only=not full_table,
fit_string=fit_string)
- output += "\n"
+ output += '\n'
- summary = ""
+ summary = ''
for b, ag in ags_dict.items():
- summary += "Benchmark Summary Table: %s\n" % b
+ summary += 'Benchmark Summary Table: %s\n' % b
summary += ag.GetFormattedSummaryTable(percents_only=not full_table,
fit_string=fit_string)
- summary += "\n"
+ summary += '\n'
output += summary
- output += ("Number of re-images performed: %s" %
+ output += ('Number of re-images performed: %s' %
MachineManagerSingleton().num_reimages)
l.LogOutput(output)
if autotest_runs:
board = autotest_runs[0].board
else:
- board = ""
+ board = ''
- subject = "%s: %s" % (board, ", ".join(ags_dict.keys()))
+ subject = '%s: %s' % (board, ', '.join(ags_dict.keys()))
if any(autotest_run.run_completed for autotest_run in autotest_runs):
SendEmailToUser(subject, summary)
@@ -239,13 +245,13 @@ def SendEmailToUser(subject, text_to_send):
# you == the recipient's email address
me = os.path.basename(__file__)
you = os.getlogin()
- msg["Subject"] = "[%s] %s" % (os.path.basename(__file__), subject)
- msg["From"] = me
- msg["To"] = you
+ msg['Subject'] = '[%s] %s' % (os.path.basename(__file__), subject)
+ msg['From'] = me
+ msg['To'] = you
# Send the message via our own SMTP server, but don't include the
# envelope header.
- s = smtplib.SMTP("localhost")
+ s = smtplib.SMTP('localhost')
s.sendmail(me, [you], msg.as_string())
s.quit()
@@ -253,61 +259,70 @@ def SendEmailToUser(subject, text_to_send):
def Main(argv):
"""The main function."""
# Common initializations
-### command_executer.InitCommandExecuter(True)
+ ### command_executer.InitCommandExecuter(True)
l = logger.GetLogger()
parser = optparse.OptionParser()
- parser.add_option("-t", "--tests", dest="tests",
- help=("Tests to compare."
- "Optionally specify per-test iterations by:"
- "<test>,<iter>:<args>"))
- parser.add_option("-c", "--chromeos_root", dest="chromeos_root",
- help="A *single* chromeos_root where scripts can be found.")
- parser.add_option("-n", "--iterations", dest="iterations",
- help="Iterations to run per benchmark.",
+ parser.add_option('-t',
+ '--tests',
+ dest='tests',
+ help=('Tests to compare.'
+ 'Optionally specify per-test iterations by:'
+ '<test>,<iter>:<args>'))
+ parser.add_option('-c',
+ '--chromeos_root',
+ dest='chromeos_root',
+ help='A *single* chromeos_root where scripts can be found.')
+ parser.add_option('-n',
+ '--iterations',
+ dest='iterations',
+ help='Iterations to run per benchmark.',
default=1)
- parser.add_option("-r", "--remote", dest="remote",
- help="The remote chromeos machine.")
- parser.add_option("-b", "--board", dest="board",
- help="The remote board.")
- parser.add_option("--full_table", dest="full_table",
- help="Print full tables.",
- action="store_true",
+ parser.add_option('-r',
+ '--remote',
+ dest='remote',
+ help='The remote chromeos machine.')
+ parser.add_option('-b', '--board', dest='board', help='The remote board.')
+ parser.add_option('--full_table',
+ dest='full_table',
+ help='Print full tables.',
+ action='store_true',
default=True)
- parser.add_option("--exact_remote",
- dest="exact_remote",
- help="Run tests on the exact remote.",
- action="store_true",
+ parser.add_option('--exact_remote',
+ dest='exact_remote',
+ help='Run tests on the exact remote.',
+ action='store_true',
default=False)
- parser.add_option("--fit_string", dest="fit_string",
- help="Fit strings to fixed sizes.",
- action="store_true",
+ parser.add_option('--fit_string',
+ dest='fit_string',
+ help='Fit strings to fixed sizes.',
+ action='store_true',
default=False)
- parser.add_option("--rerun",
- dest="rerun",
- help="Re-run regardless of cache hit.",
- action="store_true",
+ parser.add_option('--rerun',
+ dest='rerun',
+ help='Re-run regardless of cache hit.',
+ action='store_true',
default=False)
- parser.add_option("--rerun_if_failed",
- dest="rerun_if_failed",
- help="Re-run if previous run was a failure.",
- action="store_true",
+ parser.add_option('--rerun_if_failed',
+ dest='rerun_if_failed',
+ help='Re-run if previous run was a failure.',
+ action='store_true',
default=False)
- parser.add_option("--no_lock",
- dest="no_lock",
- help="Do not lock the machine before running the tests.",
- action="store_true",
+ parser.add_option('--no_lock',
+ dest='no_lock',
+ help='Do not lock the machine before running the tests.',
+ action='store_true',
default=False)
- l.LogOutput(" ".join(argv))
+ l.LogOutput(' '.join(argv))
[options, args] = parser.parse_args(argv)
if options.remote is None:
- l.LogError("No remote machine specified.")
+ l.LogError('No remote machine specified.')
parser.print_help()
return 1
if not options.board:
- l.LogError("No board specified.")
+ l.LogError('No board specified.')
parser.print_help()
return 1
@@ -335,11 +350,12 @@ def Main(argv):
try:
# At this point we have all the autotest runs.
- for machine in remote.split(","):
+ for machine in remote.split(','):
MachineManagerSingleton().AddMachine(machine)
retval = RunAutotestRunsInParallel(autotest_runs)
- if retval: return retval
+ if retval:
+ return retval
# Now print tables
ProduceTables(autotest_runs, full_table, fit_string)
@@ -349,5 +365,6 @@ def Main(argv):
return 0
-if __name__ == "__main__":
+
+if __name__ == '__main__':
sys.exit(Main(sys.argv))
diff --git a/crb/machine_manager_singleton.py b/crb/machine_manager_singleton.py
index 80369216..f32e9ef6 100644
--- a/crb/machine_manager_singleton.py
+++ b/crb/machine_manager_singleton.py
@@ -8,6 +8,7 @@ from utils import logger
class CrosMachine(object):
+
def __init__(self, name):
self.name = name
self.image = None
@@ -23,7 +24,7 @@ class CrosMachine(object):
l.append(str(self.checksum))
l.append(str(self.locked))
l.append(str(self.released_time))
- return ", ".join(l)
+ return ', '.join(l)
class MachineManagerSingleton(object):
@@ -39,25 +40,26 @@ class MachineManagerSingleton(object):
def __new__(cls, *args, **kwargs):
with cls._lock:
if not cls._instance:
- cls._instance = super(MachineManagerSingleton, cls).__new__(
- cls, *args, **kwargs)
+ cls._instance = super(MachineManagerSingleton, cls).__new__(cls, *args,
+ **kwargs)
return cls._instance
def TryToLockMachine(self, cros_machine):
with self._lock:
assert cros_machine, "Machine can't be None"
for m in self._machines:
- assert m.name != cros_machine.name, (
- "Tried to double-lock %s" % cros_machine.name)
+ assert m.name != cros_machine.name, ('Tried to double-lock %s' %
+ cros_machine.name)
if self.no_lock:
locked = True
else:
locked = lock_machine.Machine(cros_machine.name).Lock(True, sys.argv[0])
if locked:
ce = command_executer.GetCommandExecuter()
- command = "cat %s" % image_chromeos.checksum_file
+ command = 'cat %s' % image_chromeos.checksum_file
ret, out, err = ce.CrosRunCommandWOutput(
- command, chromeos_root=self.chromeos_root,
+ command,
+ chromeos_root=self.chromeos_root,
machine=cros_machine.name)
if ret == 0:
cros_machine.checksum = out.strip()
@@ -70,7 +72,7 @@ class MachineManagerSingleton(object):
def AddMachine(self, machine_name):
with self._lock:
for m in self._all_machines:
- assert m.name != machine_name, "Tried to double-add %s" % machine_name
+ assert m.name != machine_name, 'Tried to double-add %s' % machine_name
self._all_machines.append(CrosMachine(machine_name))
def AcquireMachine(self, image_checksum):
@@ -79,13 +81,13 @@ class MachineManagerSingleton(object):
if not self._machines:
for m in self._all_machines:
self.TryToLockMachine(m)
- assert self._machines, (
- "Could not lock any machine in %s" % self._all_machines)
+ assert self._machines, ('Could not lock any machine in %s' %
+ self._all_machines)
-### for m in self._machines:
-### if (m.locked and time.time() - m.released_time < 10 and
-### m.checksum == image_checksum):
-### return None
+ ### for m in self._machines:
+ ### if (m.locked and time.time() - m.released_time < 10 and
+ ### m.checksum == image_checksum):
+ ### return None
for m in [machine for machine in self._machines if not machine.locked]:
if m.checksum == image_checksum:
m.locked = True
@@ -107,10 +109,10 @@ class MachineManagerSingleton(object):
with self._lock:
for m in self._machines:
if machine.name == m.name:
- assert m.locked == True, "Tried to double-release %s" % m.name
+ assert m.locked == True, 'Tried to double-release %s' % m.name
m.released_time = time.time()
m.locked = False
- m.status = "Available"
+ m.status = 'Available'
break
def __del__(self):
@@ -123,31 +125,29 @@ class MachineManagerSingleton(object):
def __str__(self):
with self._lock:
- l = ["MachineManager Status:"]
+ l = ['MachineManager Status:']
for m in self._machines:
l.append(str(m))
- return "\n".join(l)
+ return '\n'.join(l)
def AsString(self):
with self._lock:
- stringify_fmt = "%-30s %-10s %-4s %-25s %-32s"
- header = stringify_fmt % ("Machine", "Thread", "Lock", "Status", "Checksum")
+ stringify_fmt = '%-30s %-10s %-4s %-25s %-32s'
+ header = stringify_fmt % ('Machine', 'Thread', 'Lock', 'Status',
+ 'Checksum')
table = [header]
for m in self._machines:
if m.autotest_run:
autotest_name = m.autotest_run.name
autotest_status = m.autotest_run.status
else:
- autotest_name = ""
- autotest_status = ""
+ autotest_name = ''
+ autotest_status = ''
try:
- machine_string = stringify_fmt % (m.name,
- autotest_name,
- m.locked,
- autotest_status,
- m.checksum)
+ machine_string = stringify_fmt % (m.name, autotest_name, m.locked,
+ autotest_status, m.checksum)
except:
- machine_string = ""
+ machine_string = ''
table.append(machine_string)
- return "Machine Status:\n%s" % "\n".join(table)
+ return 'Machine Status:\n%s' % '\n'.join(table)
diff --git a/crb/table_formatter.py b/crb/table_formatter.py
index b3b82f09..b8e25d5f 100644
--- a/crb/table_formatter.py
+++ b/crb/table_formatter.py
@@ -1,6 +1,7 @@
import numpy
import re
+
def IsFloat(text):
if text is None:
return False
@@ -13,22 +14,22 @@ def IsFloat(text):
def RemoveTrailingZeros(x):
ret = x
- ret = re.sub("\.0*$", "", ret)
- ret = re.sub("(\.[1-9]*)0+$", "\\1", ret)
+ ret = re.sub('\.0*$', '', ret)
+ ret = re.sub('(\.[1-9]*)0+$', '\\1', ret)
return ret
def HumanizeFloat(x, n=2):
if not IsFloat(x):
return x
- digits = re.findall("[0-9.]", str(x))
+ digits = re.findall('[0-9.]', str(x))
decimal_found = False
- ret = ""
+ ret = ''
sig_figs = 0
for digit in digits:
- if digit == ".":
+ if digit == '.':
decimal_found = True
- elif sig_figs != 0 or digit != "0":
+ elif sig_figs != 0 or digit != '0':
sig_figs += 1
if decimal_found and sig_figs >= n:
break
@@ -39,23 +40,23 @@ def HumanizeFloat(x, n=2):
def GetNSigFigs(x, n=2):
if not IsFloat(x):
return x
- my_fmt = "%." + str(n-1) + "e"
+ my_fmt = '%.' + str(n - 1) + 'e'
x_string = my_fmt % x
f = float(x_string)
return f
-def GetFormattedPercent(baseline, other, bad_result="--"):
- result = "%8s" % GetPercent(baseline, other, bad_result)
+def GetFormattedPercent(baseline, other, bad_result='--'):
+ result = '%8s' % GetPercent(baseline, other, bad_result)
return result
-def GetPercent(baseline, other, bad_result="--"):
+def GetPercent(baseline, other, bad_result='--'):
result = bad_result
if IsFloat(baseline) and IsFloat(other):
try:
- pct = (float(other)/float(baseline) - 1) * 100
- result = "%+1.1f" % pct
+ pct = (float(other) / float(baseline) - 1) * 100
+ result = '%+1.1f' % pct
except ZeroDivisionError:
pass
return result
@@ -67,14 +68,15 @@ def FitString(text, length):
elif len(text) > length:
return text[-length:]
else:
- fmt = "%%%ds" % length
+ fmt = '%%%ds' % length
return fmt % text
class TableFormatter(object):
+
def __init__(self):
- self.d = "\t"
- self.bad_result = "x"
+ self.d = '\t'
+ self.bad_result = 'x'
def GetTablePercents(self, table):
# Assumes table is not transposed.
@@ -84,7 +86,7 @@ class TableFormatter(object):
for i in range(1, len(table)):
row = []
row.append(table[i][0])
- for j in range (1, len(table[0])):
+ for j in range(1, len(table[0])):
c = table[i][j]
b = table[i][1]
p = GetPercent(b, c, self.bad_result)
@@ -99,7 +101,7 @@ class TableFormatter(object):
ret = HumanizeFloat(f, 4)
ret = RemoveTrailingZeros(ret)
if len(ret) > max_length:
- ret = "%1.1ef" % f
+ ret = '%1.1ef' % f
return ret
def TransposeTable(self, table):
@@ -112,17 +114,20 @@ class TableFormatter(object):
return transposed_table
def GetTableLabels(self, table):
- ret = ""
+ ret = ''
header = table[0]
for i in range(1, len(header)):
- ret += "%d: %s\n" % (i, header[i])
+ ret += '%d: %s\n' % (i, header[i])
return ret
- def GetFormattedTable(self, table, transposed=False,
- first_column_width=30, column_width=14,
+ def GetFormattedTable(self,
+ table,
+ transposed=False,
+ first_column_width=30,
+ column_width=14,
percents_only=True,
fit_string=True):
- o = ""
+ o = ''
pct_table = self.GetTablePercents(table)
if transposed == True:
table = self.TransposeTable(table)
@@ -143,14 +148,14 @@ class TableFormatter(object):
c = self.FormatFloat(c)
if IsFloat(p) and not percents_only:
- p = "%s%%" % p
+ p = '%s%%' % p
# Print percent values side by side.
if j != 0:
if percents_only:
- c = "%s" % p
+ c = '%s' % p
else:
- c = "%s (%s)" % (c, p)
+ c = '%s (%s)' % (c, p)
if i == 0 and j != 0:
c = str(j)
@@ -159,7 +164,7 @@ class TableFormatter(object):
o += FitString(c, width) + self.d
else:
o += c + self.d
- o += "\n"
+ o += '\n'
return o
def GetGroups(self, table):
@@ -183,11 +188,11 @@ class TableFormatter(object):
labels = table[0]
- summary_labels = ["Summary Table"]
+ summary_labels = ['Summary Table']
for group in groups:
label = labels[group[0]]
stripped_label = self.GetStrippedLabel(label)
- group_label = "%s (%d runs)" % (stripped_label, len(group))
+ group_label = '%s (%d runs)' % (stripped_label, len(group))
summary_labels.append(group_label)
summary_table.append(summary_labels)
@@ -210,8 +215,8 @@ class TableFormatter(object):
def AverageWithDrops(numbers, slow_percent=20, fast_percent=20):
sorted_numbers = list(numbers)
sorted_numbers.sort()
- num_slow = int(slow_percent/100.0 * len(sorted_numbers))
- num_fast = int(fast_percent/100.0 * len(sorted_numbers))
+ num_slow = int(slow_percent / 100.0 * len(sorted_numbers))
+ num_fast = int(fast_percent / 100.0 * len(sorted_numbers))
sorted_numbers = sorted_numbers[num_slow:]
if num_fast:
sorted_numbers = sorted_numbers[:-num_fast]
@@ -219,7 +224,7 @@ class TableFormatter(object):
@staticmethod
def AggregateResults(group_results):
- ret = ""
+ ret = ''
if not group_results:
return ret
all_floats = True
@@ -228,26 +233,26 @@ class TableFormatter(object):
for group_result in group_results:
if not IsFloat(group_result):
all_floats = False
- if group_result != "PASSED":
+ if group_result != 'PASSED':
all_passes = False
- if group_result != "FAILED":
+ if group_result != 'FAILED':
all_fails = False
if all_floats == True:
float_results = [float(v) for v in group_results]
- ret = "%f" % TableFormatter.AverageWithDrops(float_results)
+ ret = '%f' % TableFormatter.AverageWithDrops(float_results)
# Add this line for standard deviation.
-### ret += " %f" % numpy.std(float_results)
+ ### ret += " %f" % numpy.std(float_results)
elif all_passes == True:
- ret = "ALL_PASS"
+ ret = 'ALL_PASS'
elif all_fails == True:
- ret = "ALL_FAILS"
+ ret = 'ALL_FAILS'
return ret
@staticmethod
def GetStrippedLabel(label):
- return re.sub("\s*\S+:\S+\s*", "", label)
+ return re.sub('\s*\S+:\S+\s*', '', label)
### return re.sub("\s*remote:\S*\s*i:\d+$", "", label)
@staticmethod
def GetLabelWithIteration(label, iteration):
- return "%s i:%d" % (label, iteration)
+ return '%s i:%d' % (label, iteration)