aboutsummaryrefslogtreecommitdiff
path: root/crosperf
diff options
context:
space:
mode:
authorDenis Nikitin <denik@google.com>2019-09-23 18:43:37 -0700
committerDenis Nikitin <denik@chromium.org>2019-09-24 22:39:59 +0000
commit5aa82413d43af9a6aa18ce53d7a618bca0acb9df (patch)
treeddc85c08923a928101bfb5ebaeaa55de76029933 /crosperf
parent4d72583ef73e8c3bf7a1ae9dd016ef7aeed09fed (diff)
downloadtoolchain-utils-5aa82413d43af9a6aa18ce53d7a618bca0acb9df.tar.gz
crosperf: Fix cros lint warnings
Fixed python lint warnings in crosperf scripts. BUG=chromium:993035 TEST=`repo upload` works w/o --no-verify Change-Id: I3dd7b0ea956458e57e8bd77c19a5b8cb13e1d350 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1821449 Tested-by: Denis Nikitin <denik@chromium.org> Reviewed-by: George Burgess <gbiv@chromium.org>
Diffstat (limited to 'crosperf')
-rw-r--r--crosperf/benchmark.py6
-rw-r--r--crosperf/benchmark_run.py2
-rwxr-xr-xcrosperf/benchmark_run_unittest.py8
-rwxr-xr-xcrosperf/benchmark_unittest.py10
-rwxr-xr-xcrosperf/crosperf_unittest.py13
-rwxr-xr-xcrosperf/experiment_factory_unittest.py15
-rwxr-xr-xcrosperf/experiment_file_unittest.py21
-rwxr-xr-xcrosperf/experiment_runner_unittest.py23
-rwxr-xr-xcrosperf/results_cache_unittest.py2
-rw-r--r--crosperf/schedv2.py62
-rwxr-xr-xcrosperf/schedv2_unittest.py22
-rwxr-xr-xcrosperf/suite_runner_unittest.py53
12 files changed, 141 insertions, 96 deletions
diff --git a/crosperf/benchmark.py b/crosperf/benchmark.py
index e7c3b19a..5c11e27e 100644
--- a/crosperf/benchmark.py
+++ b/crosperf/benchmark.py
@@ -1,10 +1,16 @@
+# -*- coding: utf-8 -*-
# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+
"""Define a type that wraps a Benchmark instance."""
+
+from __future__ import division
from __future__ import print_function
import math
+#FIXME(denik): Fix the import in chroot.
+#pylint: disable=import-error
from scipy import stats
# See crbug.com/673558 for how these are estimated.
diff --git a/crosperf/benchmark_run.py b/crosperf/benchmark_run.py
index 3cd4479b..fd2f857b 100644
--- a/crosperf/benchmark_run.py
+++ b/crosperf/benchmark_run.py
@@ -204,7 +204,7 @@ class BenchmarkRun(threading.Thread):
raise SyntaxError('perf_args must start with either record or stat')
extra_test_args = [
'--profiler=custom_perf',
- ("--profiler_args='perf_options=\"%s\"'" % perf_args)
+ ('--profiler_args=\'perf_options="%s"\'' % perf_args)
]
return ' '.join(extra_test_args)
else:
diff --git a/crosperf/benchmark_run_unittest.py b/crosperf/benchmark_run_unittest.py
index 59d701b8..e5c77113 100755
--- a/crosperf/benchmark_run_unittest.py
+++ b/crosperf/benchmark_run_unittest.py
@@ -9,14 +9,14 @@
from __future__ import print_function
-import mock
import unittest
import inspect
-from cros_utils import logger
+import mock
import benchmark_run
+from cros_utils import logger
from suite_runner import MockSuiteRunner
from suite_runner import SuiteRunner
from label import MockLabel
@@ -363,8 +363,8 @@ class BenchmarkRunTest(unittest.TestCase):
result = br.GetExtraAutotestArgs()
self.assertEqual(
result,
- "--profiler=custom_perf --profiler_args='perf_options=\"record -a -e "
- "cycles\"'")
+ '--profiler=custom_perf --profiler_args=\'perf_options="record -a -e '
+ 'cycles"\'')
self.test_benchmark.suite = 'telemetry'
result = br.GetExtraAutotestArgs()
diff --git a/crosperf/benchmark_unittest.py b/crosperf/benchmark_unittest.py
index 4041e850..6c0c22f6 100755
--- a/crosperf/benchmark_unittest.py
+++ b/crosperf/benchmark_unittest.py
@@ -1,15 +1,19 @@
#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
#
-# Copyright 2014 Google Inc. All Rights Reserved
+# Copyright 2014 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
"""Unit tests for the Crosperf Benchmark class."""
from __future__ import print_function
import inspect
-from benchmark import Benchmark
-
import unittest
+from benchmark import Benchmark
+
class BenchmarkTestCase(unittest.TestCase):
"""Individual tests for the Benchmark class."""
diff --git a/crosperf/crosperf_unittest.py b/crosperf/crosperf_unittest.py
index 57e23b81..4f40d139 100755
--- a/crosperf/crosperf_unittest.py
+++ b/crosperf/crosperf_unittest.py
@@ -7,15 +7,17 @@
"""Unittest for crosperf."""
+from __future__ import division
from __future__ import print_function
import argparse
-import mock
-import tempfile
+import io
import os
-import StringIO
+import tempfile
import unittest
+import mock
+
import crosperf
import settings_factory
import experiment_file
@@ -43,7 +45,7 @@ class CrosperfTest(unittest.TestCase):
"""Crosperf test class."""
def setUp(self):
- input_file = StringIO.StringIO(EXPERIMENT_FILE_1)
+ input_file = io.BytesIO(EXPERIMENT_FILE_1)
self.exp_file = experiment_file.ExperimentFile(input_file)
def testDryRun(self):
@@ -83,8 +85,7 @@ class CrosperfTest(unittest.TestCase):
with mock.patch('crosperf.RunCrosperf', new=mock_RunCrosperf):
with self.assertRaises(ZeroDivisionError) as context:
crosperf.Main([])
- self.assertEqual('integer division or modulo by zero',
- str(context.exception))
+ self.assertEqual('division by zero', str(context.exception))
if __name__ == '__main__':
diff --git a/crosperf/experiment_factory_unittest.py b/crosperf/experiment_factory_unittest.py
index 1d6b1ea7..32813357 100755
--- a/crosperf/experiment_factory_unittest.py
+++ b/crosperf/experiment_factory_unittest.py
@@ -9,12 +9,13 @@
from __future__ import print_function
-import mock
+import io
import os
-import StringIO
import socket
import unittest
+import mock
+
from cros_utils import command_executer
from cros_utils.file_utils import FileUtils
@@ -82,7 +83,7 @@ class ExperimentFactoryTest(unittest.TestCase):
self.append_benchmark_call_args = []
def testLoadExperimentFile1(self):
- experiment_file = ExperimentFile(StringIO.StringIO(EXPERIMENT_FILE_1))
+ experiment_file = ExperimentFile(io.BytesIO(EXPERIMENT_FILE_1))
exp = ExperimentFactory().GetExperiment(
experiment_file, working_directory='', log_dir='')
self.assertEqual(exp.remote, ['chromeos-alex3'])
@@ -101,7 +102,7 @@ class ExperimentFactoryTest(unittest.TestCase):
self.assertEqual(exp.labels[0].board, 'x86-alex')
def testLoadExperimentFile2CWP(self):
- experiment_file = ExperimentFile(StringIO.StringIO(EXPERIMENT_FILE_2))
+ experiment_file = ExperimentFile(io.BytesIO(EXPERIMENT_FILE_2))
exp = ExperimentFactory().GetExperiment(
experiment_file, working_directory='', log_dir='')
self.assertEqual(exp.cwp_dso, 'kallsyms')
@@ -110,7 +111,7 @@ class ExperimentFactoryTest(unittest.TestCase):
self.assertEqual(exp.benchmarks[1].weight, 0.2)
def testDuplecateBenchmark(self):
- mock_experiment_file = ExperimentFile(StringIO.StringIO(''))
+ mock_experiment_file = ExperimentFile(io.BytesIO(''))
mock_experiment_file.all_settings = []
benchmark_settings1 = settings_factory.BenchmarkSettings('name')
mock_experiment_file.all_settings.append(benchmark_settings1)
@@ -122,7 +123,7 @@ class ExperimentFactoryTest(unittest.TestCase):
ef.GetExperiment(mock_experiment_file, '', '')
def testCWPExceptions(self):
- mock_experiment_file = ExperimentFile(StringIO.StringIO(''))
+ mock_experiment_file = ExperimentFile(io.BytesIO(''))
mock_experiment_file.all_settings = []
global_settings = settings_factory.GlobalSettings('test_name')
@@ -301,7 +302,7 @@ class ExperimentFactoryTest(unittest.TestCase):
label_settings.GetXbuddyPath = FakeGetXbuddyPath
- mock_experiment_file = ExperimentFile(StringIO.StringIO(''))
+ mock_experiment_file = ExperimentFile(io.BytesIO(''))
mock_experiment_file.all_settings = []
test_flag.SetTestMode(True)
diff --git a/crosperf/experiment_file_unittest.py b/crosperf/experiment_file_unittest.py
index 79ee48c0..12b68223 100755
--- a/crosperf/experiment_file_unittest.py
+++ b/crosperf/experiment_file_unittest.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
@@ -6,8 +7,10 @@
"""The unittest of experiment_file."""
from __future__ import print_function
-import StringIO
+
+import io
import unittest
+
from experiment_file import ExperimentFile
EXPERIMENT_FILE_1 = """
@@ -158,7 +161,7 @@ class ExperimentFileTest(unittest.TestCase):
"""The main class for Experiment File test."""
def testLoadExperimentFile1(self):
- input_file = StringIO.StringIO(EXPERIMENT_FILE_1)
+ input_file = io.BytesIO(EXPERIMENT_FILE_1)
experiment_file = ExperimentFile(input_file)
global_settings = experiment_file.GetGlobalSettings()
self.assertEqual(global_settings.GetField('remote'), ['chromeos-alex3'])
@@ -178,7 +181,7 @@ class ExperimentFileTest(unittest.TestCase):
self.assertEqual(label_settings[0].GetField('remote'), ['chromeos-alex3'])
def testOverrideSetting(self):
- input_file = StringIO.StringIO(EXPERIMENT_FILE_2)
+ input_file = io.BytesIO(EXPERIMENT_FILE_2)
experiment_file = ExperimentFile(input_file)
global_settings = experiment_file.GetGlobalSettings()
self.assertEqual(global_settings.GetField('remote'), ['chromeos-alex3'])
@@ -191,11 +194,11 @@ class ExperimentFileTest(unittest.TestCase):
self.assertEqual(benchmark_settings[1].GetField('iterations'), 2)
def testDuplicateLabel(self):
- input_file = StringIO.StringIO(EXPERIMENT_FILE_3)
+ input_file = io.BytesIO(EXPERIMENT_FILE_3)
self.assertRaises(Exception, ExperimentFile, input_file)
def testDuplicateBenchmark(self):
- input_file = StringIO.StringIO(EXPERIMENT_FILE_4)
+ input_file = io.BytesIO(EXPERIMENT_FILE_4)
experiment_file = ExperimentFile(input_file)
benchmark_settings = experiment_file.GetSettings('benchmark')
self.assertEqual(benchmark_settings[0].name, 'webrtc')
@@ -206,13 +209,13 @@ class ExperimentFileTest(unittest.TestCase):
'--story-tag-filter=smoothness')
def testCanonicalize(self):
- input_file = StringIO.StringIO(EXPERIMENT_FILE_1)
+ input_file = io.BytesIO(EXPERIMENT_FILE_1)
experiment_file = ExperimentFile(input_file)
res = experiment_file.Canonicalize()
self.assertEqual(res, OUTPUT_FILE)
def testLoadDutConfigExperimentFile_Good(self):
- input_file = StringIO.StringIO(DUT_CONFIG_EXPERIMENT_FILE_GOOD)
+ input_file = io.BytesIO(DUT_CONFIG_EXPERIMENT_FILE_GOOD)
experiment_file = ExperimentFile(input_file)
global_settings = experiment_file.GetGlobalSettings()
self.assertEqual(global_settings.GetField('turbostat'), False)
@@ -225,7 +228,7 @@ class ExperimentFileTest(unittest.TestCase):
self.assertEqual(global_settings.GetField('top_interval'), 5)
def testLoadDutConfigExperimentFile_WrongGovernor(self):
- input_file = StringIO.StringIO(DUT_CONFIG_EXPERIMENT_FILE_BAD_GOV)
+ input_file = io.BytesIO(DUT_CONFIG_EXPERIMENT_FILE_BAD_GOV)
with self.assertRaises(RuntimeError) as msg:
ExperimentFile(input_file)
self.assertRegexpMatches(
@@ -236,7 +239,7 @@ class ExperimentFileTest(unittest.TestCase):
r' conservative, schedutils, sched, interactive\)')
def testLoadDutConfigExperimentFile_WrongCpuUsage(self):
- input_file = StringIO.StringIO(DUT_CONFIG_EXPERIMENT_FILE_BAD_CPUUSE)
+ input_file = io.BytesIO(DUT_CONFIG_EXPERIMENT_FILE_BAD_CPUUSE)
with self.assertRaises(RuntimeError) as msg:
ExperimentFile(input_file)
self.assertRegexpMatches(str(msg.exception), 'cpu_usage: unknown')
diff --git a/crosperf/experiment_runner_unittest.py b/crosperf/experiment_runner_unittest.py
index e6cfbcd3..caac4265 100755
--- a/crosperf/experiment_runner_unittest.py
+++ b/crosperf/experiment_runner_unittest.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
#
# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
@@ -8,8 +9,8 @@
from __future__ import print_function
-import StringIO
import getpass
+import io
import os
import time
@@ -107,7 +108,7 @@ class ExperimentRunnerTest(unittest.TestCase):
def make_fake_experiment(self):
test_flag.SetTestMode(True)
- experiment_file = ExperimentFile(StringIO.StringIO(EXPERIMENT_FILE_1))
+ experiment_file = ExperimentFile(io.BytesIO(EXPERIMENT_FILE_1))
experiment = ExperimentFactory().GetExperiment(
experiment_file, working_directory='', log_dir='')
return experiment
@@ -316,7 +317,7 @@ class ExperimentRunnerTest(unittest.TestCase):
], ': image1 vs. image2',
"<pre style='font-size: 13px'>This is a fake text "
'report.\nResults are stored in _results.\n</pre>'))
- self.assertTrue(type(mock_emailer.call_args[1]) is dict)
+ self.assertTrue(isinstance(mock_emailer.call_args[1], dict))
self.assertEqual(len(mock_emailer.call_args[1]), 2)
self.assertTrue('attachments' in mock_emailer.call_args[1].keys())
self.assertEqual(mock_emailer.call_args[1]['msg_type'], 'html')
@@ -348,7 +349,7 @@ class ExperimentRunnerTest(unittest.TestCase):
], ': image1 vs. image2',
"<pre style='font-size: 13px'>This is a fake text "
'report.\nResults are stored in _results.\n</pre>'))
- self.assertTrue(type(mock_emailer.call_args[1]) is dict)
+ self.assertTrue(isinstance(mock_emailer.call_args[1], dict))
self.assertEqual(len(mock_emailer.call_args[1]), 2)
self.assertTrue('attachments' in mock_emailer.call_args[1].keys())
self.assertEqual(mock_emailer.call_args[1]['msg_type'], 'html')
@@ -375,7 +376,7 @@ class ExperimentRunnerTest(unittest.TestCase):
(['john.smith@google.com'], ': image1 vs. image2',
"<pre style='font-size: 13px'>This is a fake text "
'report.\nResults are stored in _results.\n</pre>'))
- self.assertTrue(type(mock_emailer.call_args[1]) is dict)
+ self.assertTrue(isinstance(mock_emailer.call_args[1], dict))
self.assertEqual(len(mock_emailer.call_args[1]), 2)
self.assertTrue('attachments' in mock_emailer.call_args[1].keys())
self.assertEqual(mock_emailer.call_args[1]['msg_type'], 'html')
@@ -412,8 +413,8 @@ class ExperimentRunnerTest(unittest.TestCase):
self.mock_logger.Reset()
self.exp.results_directory = '/usr/local/crosperf-results'
bench_run = self.exp.benchmark_runs[5]
- bench_path = '/usr/local/crosperf-results/' + filter(
- str.isalnum, bench_run.name)
+ bench_path = '/usr/local/crosperf-results/' + ''.join(
+ ch for ch in bench_run.name if ch.isalnum())
self.assertEqual(len(self.exp.benchmark_runs), 6)
er = experiment_runner.ExperimentRunner(
@@ -442,9 +443,9 @@ class ExperimentRunnerTest(unittest.TestCase):
er._terminated = False
er._StoreResults(self.exp)
self.assertEqual(mock_cleanup.call_count, 6)
- mock_cleanup.called_with(bench_run.benchmark.rm_chroot_tmp)
+ mock_cleanup.assert_called_with(bench_run.benchmark.rm_chroot_tmp)
self.assertEqual(mock_copy.call_count, 6)
- mock_copy.called_with(bench_path)
+ mock_copy.assert_called_with(bench_path)
self.assertEqual(mock_writefile.call_count, 3)
self.assertEqual(len(mock_writefile.call_args_list), 3)
first_args = mock_writefile.call_args_list[0]
@@ -454,9 +455,9 @@ class ExperimentRunnerTest(unittest.TestCase):
self.assertEqual(second_args[0][0],
'/usr/local/crosperf-results/results.html')
self.assertEqual(mock_mkdir.call_count, 1)
- mock_mkdir.called_with('/usr/local/crosperf-results')
+ mock_mkdir.assert_called_with('/usr/local/crosperf-results')
self.assertEqual(mock_rmdir.call_count, 1)
- mock_rmdir.called_with('/usr/local/crosperf-results')
+ mock_rmdir.assert_called_with('/usr/local/crosperf-results')
self.assertEqual(self.mock_logger.LogOutputCount, 4)
self.assertEqual(self.mock_logger.output_msgs, [
'Storing experiment file in /usr/local/crosperf-results.',
diff --git a/crosperf/results_cache_unittest.py b/crosperf/results_cache_unittest.py
index 461384f3..ece9f99d 100755
--- a/crosperf/results_cache_unittest.py
+++ b/crosperf/results_cache_unittest.py
@@ -15,6 +15,8 @@ import tempfile
import unittest
import mock
+import mock
+
import image_checksummer
import machine_manager
import test_flag
diff --git a/crosperf/schedv2.py b/crosperf/schedv2.py
index a7983d9f..0cc8f746 100644
--- a/crosperf/schedv2.py
+++ b/crosperf/schedv2.py
@@ -1,19 +1,24 @@
+# -*- coding: utf-8 -*-
# Copyright 2015 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+
"""Module to optimize the scheduling of benchmark_run tasks."""
+from __future__ import division
from __future__ import print_function
import sys
-import test_flag
import time
import traceback
from collections import defaultdict
-from machine_image_manager import MachineImageManager
from threading import Lock
from threading import Thread
+
+import test_flag
+
+from machine_image_manager import MachineImageManager
from cros_utils import command_executer
from cros_utils import logger
@@ -58,9 +63,10 @@ class DutWorker(Thread):
good = 0
# Check that dut platform supports hwp
- cmd = 'grep -q \'^flags.*hwp\' /proc/cpuinfo'
+ cmd = "grep -q '^flags.*hwp' /proc/cpuinfo"
ret_code = ce.CrosRunCommand(
- cmd, chromeos_root=self._sched.get_labels(0).chromeos_root,
+ cmd,
+ chromeos_root=self._sched.get_labels(0).chromeos_root,
machine=self._dut.name)
if ret_code != good:
# Intel hwp is not supported, update is not needed.
@@ -96,7 +102,8 @@ class DutWorker(Thread):
remove_verif_cmd = ' '.join([
'/usr/share/vboot/bin/make_dev_ssd.sh',
'--remove_rootfs_verification',
- '--partition %d'])
+ '--partition %d',
+ ])
# Command for partition 2.
verif_part2_failed = ce.CrosRunCommand(
remove_verif_cmd % 2,
@@ -113,8 +120,8 @@ class DutWorker(Thread):
self._logger.LogFatal(
'ERROR. Failed to update kernel cmdline on partition %d.\n'
'Remove verification failed with status %d' %
- (2 if verif_part2_failed else 4,
- verif_part2_failed or verif_part4_failed))
+ (2 if verif_part2_failed else 4, verif_part2_failed or
+ verif_part4_failed))
ce.CrosRunCommand(
'reboot && exit',
@@ -133,7 +140,7 @@ class DutWorker(Thread):
'/usr/share/vboot/bin/make_dev_ssd.sh --partition ${partnumb}'
' --save_config ${tmpfile}',
# Remove intel_pstate argument if present.
- 'sed -i -r \'s/ intel_pstate=[A-Za-z_]+//g\' ${tmpfile}.${partnumb}',
+ "sed -i -r 's/ intel_pstate=[A-Za-z_]+//g' ${tmpfile}.${partnumb}",
# Insert intel_pstate with a new value if it is set.
'[[ -n ${pstate} ]] &&'
' sed -i -e \"s/ *$/ intel_pstate=${pstate}/\" ${tmpfile}.${partnumb}',
@@ -143,8 +150,8 @@ class DutWorker(Thread):
' --set_config ${tmpfile}'
])
kern_part2_cmdline_cmd = kern_cmdline % (2, intel_pstate)
- self._logger.LogOutput('Command to change kernel command line: %s' %
- kern_part2_cmdline_cmd)
+ self._logger.LogOutput(
+ 'Command to change kernel command line: %s' % kern_part2_cmdline_cmd)
upd_part2_failed = ce.CrosRunCommand(
kern_part2_cmdline_cmd,
chromeos_root=self._sched.get_labels(0).chromeos_root,
@@ -153,8 +160,8 @@ class DutWorker(Thread):
# in addition to partition 2. Without this some machines
# in the lab might fail.
kern_part4_cmdline_cmd = kern_cmdline % (4, intel_pstate)
- self._logger.LogOutput('Command to change kernel command line: %s' %
- kern_part4_cmdline_cmd)
+ self._logger.LogOutput(
+ 'Command to change kernel command line: %s' % kern_part4_cmdline_cmd)
upd_part4_failed = ce.CrosRunCommand(
kern_part4_cmdline_cmd,
chromeos_root=self._sched.get_labels(0).chromeos_root,
@@ -241,8 +248,8 @@ class DutWorker(Thread):
total_waittime += br.suite_runner.GetCooldownWaitTime()
br.suite_runner.ResetCooldownWaitTime()
finally:
- self._logger.LogOutput('Total wait time for cooldown: %d min'
- % (total_waittime / 60))
+ self._logger.LogOutput(
+ 'Total wait time for cooldown: %d min' % (total_waittime // 60))
self._stat_annotation = 'finished'
# Thread finishes. Notify scheduler that I'm done.
self._sched.dut_worker_finished(self)
@@ -322,8 +329,8 @@ class DutWorker(Thread):
checksum = checksum.strip()
for l in self._sched.get_labels():
if l.checksum == checksum:
- self._logger.LogOutput(
- "Dut '{}' is pre-installed with '{}'".format(self._dut.name, l))
+ self._logger.LogOutput("Dut '{}' is pre-installed with '{}'".format(
+ self._dut.name, l))
self._dut.label = l
return
except RuntimeError:
@@ -342,9 +349,10 @@ class DutWorker(Thread):
return ('Worker thread "{}", label="{}", benchmark_run={}, '
'reimage={}, now {}'.format(
- self._dut.name, 'None' if self._dut.label is None else
- self._dut.label.name, self._stat_num_br_run,
- self._stat_num_reimage, self._stat_annotation))
+ self._dut.name,
+ 'None' if self._dut.label is None else self._dut.label.name,
+ self._stat_num_br_run, self._stat_num_reimage,
+ self._stat_annotation))
class BenchmarkRunCacheReader(Thread):
@@ -441,18 +449,19 @@ class Schedv2(object):
# Split benchmarkruns set into segments. Each segment will be handled by
# a thread. Note, we use (x+3)/4 to mimic math.ceil(x/4).
- n_threads = max(2, min(20, (n_benchmarkruns + 3) / 4))
+ n_threads = max(2, min(20, (n_benchmarkruns + 3) // 4))
self._logger.LogOutput(('Starting {} threads to read cache status for '
'{} benchmark runs ...').format(
n_threads, n_benchmarkruns))
- benchmarkruns_per_thread = (n_benchmarkruns + n_threads - 1) / n_threads
+ benchmarkruns_per_thread = (n_benchmarkruns + n_threads - 1) // n_threads
benchmarkrun_segments = []
for i in range(n_threads - 1):
start = i * benchmarkruns_per_thread
end = (i + 1) * benchmarkruns_per_thread
benchmarkrun_segments.append(self._experiment.benchmark_runs[start:end])
- benchmarkrun_segments.append(self._experiment.benchmark_runs[(
- n_threads - 1) * benchmarkruns_per_thread:])
+ benchmarkrun_segments.append(
+ self._experiment.benchmark_runs[(n_threads - 1) *
+ benchmarkruns_per_thread:])
# Assert: aggregation of benchmarkrun_segments equals to benchmark_runs.
assert sum(len(x) for x in benchmarkrun_segments) == n_benchmarkruns
@@ -470,8 +479,9 @@ class Schedv2(object):
x.join()
# Summarize.
- self._logger.LogOutput('Total {} cache hit out of {} benchmark_runs.'.
- format(len(self._cached_br_list), n_benchmarkruns))
+ self._logger.LogOutput(
+ 'Total {} cache hit out of {} benchmark_runs.'.format(
+ len(self._cached_br_list), n_benchmarkruns))
def get_cached_run_list(self):
return self._cached_br_list
@@ -483,7 +493,7 @@ class Schedv2(object):
return self._experiment
def get_labels(self, i=None):
- if i == None:
+ if i is None:
return self._labels
return self._labels[i]
diff --git a/crosperf/schedv2_unittest.py b/crosperf/schedv2_unittest.py
index 250968dc..4aced646 100755
--- a/crosperf/schedv2_unittest.py
+++ b/crosperf/schedv2_unittest.py
@@ -1,13 +1,19 @@
#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+# Copyright 2015 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
-# Copyright 2015 Google Inc. All Rights Reserved.
"""This contains the unit tests for the new Crosperf task scheduler."""
from __future__ import print_function
-import mock
+import functools
+import io
import unittest
-import StringIO
+
+import mock
import benchmark_run
import test_flag
@@ -73,7 +79,7 @@ class Schedv2Test(unittest.TestCase):
Note - we mock out BenchmarkRun in this step.
"""
- experiment_file = ExperimentFile(StringIO.StringIO(expstr))
+ experiment_file = ExperimentFile(io.BytesIO(expstr))
experiment = ExperimentFactory().GetExperiment(
experiment_file, working_directory='', log_dir='')
return experiment
@@ -191,8 +197,8 @@ class Schedv2Test(unittest.TestCase):
self.assertEquals(len(my_schedv2.get_cached_run_list()), 30)
# The non-cache-hit brs are put into Schedv2._label_brl_map.
self.assertEquals(
- reduce(lambda a, x: a + len(x[1]),
- my_schedv2.get_label_map().iteritems(), 0), 30)
+ functools.reduce(lambda a, x: a + len(x[1]),
+ my_schedv2.get_label_map().iteritems(), 0), 30)
def test_nocachehit(self):
"""Test no cache-hit."""
@@ -209,8 +215,8 @@ class Schedv2Test(unittest.TestCase):
self.assertEquals(len(my_schedv2.get_cached_run_list()), 0)
# The non-cache-hit brs are put into Schedv2._label_brl_map.
self.assertEquals(
- reduce(lambda a, x: a + len(x[1]),
- my_schedv2.get_label_map().iteritems(), 0), 60)
+ functools.reduce(lambda a, x: a + len(x[1]),
+ my_schedv2.get_label_map().iteritems(), 0), 60)
if __name__ == '__main__':
diff --git a/crosperf/suite_runner_unittest.py b/crosperf/suite_runner_unittest.py
index 10cd3a7a..8b5b1f13 100755
--- a/crosperf/suite_runner_unittest.py
+++ b/crosperf/suite_runner_unittest.py
@@ -509,9 +509,10 @@ class SuiteRunnerTest(unittest.TestCase):
self.runner.SetupArmCores.assert_not_called()
def test_setup_arm_cores_big_on_big_little(self):
- dut_runner = mock.Mock(
- side_effect=[(0, BIG_LITTLE_CPUINFO, ''),
- (0, '', '')])
+ dut_runner = mock.Mock(side_effect=[
+ (0, BIG_LITTLE_CPUINFO, ''),
+ (0, '', ''),
+ ])
self.runner.dut_config['cpu_usage'] = 'big_only'
self.runner.SetupArmCores(dut_runner)
dut_runner.assert_called_with(
@@ -519,9 +520,10 @@ class SuiteRunnerTest(unittest.TestCase):
'echo 0 | tee /sys/devices/system/cpu/cpu{0,1}/online')
def test_setup_arm_cores_little_on_big_little(self):
- dut_runner = mock.Mock(
- side_effect=[(0, BIG_LITTLE_CPUINFO, ''),
- (0, '', '')])
+ dut_runner = mock.Mock(side_effect=[
+ (0, BIG_LITTLE_CPUINFO, ''),
+ (0, '', ''),
+ ])
self.runner.dut_config['cpu_usage'] = 'little_only'
self.runner.SetupArmCores(dut_runner)
dut_runner.assert_called_with(
@@ -529,9 +531,10 @@ class SuiteRunnerTest(unittest.TestCase):
'echo 0 | tee /sys/devices/system/cpu/cpu{2}/online')
def test_setup_arm_cores_invalid_config(self):
- dut_runner = mock.Mock(
- side_effect=[(0, LITTLE_ONLY_CPUINFO, ''),
- (0, '', '')])
+ dut_runner = mock.Mock(side_effect=[
+ (0, LITTLE_ONLY_CPUINFO, ''),
+ (0, '', ''),
+ ])
self.runner.dut_config['cpu_usage'] = 'big_only'
self.runner.SetupArmCores(dut_runner)
# Check that setup command is not sent when trying
@@ -539,9 +542,10 @@ class SuiteRunnerTest(unittest.TestCase):
dut_runner.assert_called_once_with('cat /proc/cpuinfo')
def test_setup_arm_cores_not_big_little(self):
- dut_runner = mock.Mock(
- side_effect=[(0, NOT_BIG_LITTLE_CPUINFO, ''),
- (0, '', '')])
+ dut_runner = mock.Mock(side_effect=[
+ (0, NOT_BIG_LITTLE_CPUINFO, ''),
+ (0, '', ''),
+ ])
self.runner.dut_config['cpu_usage'] = 'big_only'
self.runner.SetupArmCores(dut_runner)
# Check that setup command is not sent when trying
@@ -549,9 +553,10 @@ class SuiteRunnerTest(unittest.TestCase):
dut_runner.assert_called_once_with('cat /proc/cpuinfo')
def test_setup_arm_cores_unsupported_cpu_usage(self):
- dut_runner = mock.Mock(
- side_effect=[(0, BIG_LITTLE_CPUINFO, ''),
- (0, '', '')])
+ dut_runner = mock.Mock(side_effect=[
+ (0, BIG_LITTLE_CPUINFO, ''),
+ (0, '', ''),
+ ])
self.runner.dut_config['cpu_usage'] = 'exclusive_cores'
self.runner.SetupArmCores(dut_runner)
# Check that setup command is not sent when trying to use
@@ -565,7 +570,8 @@ class SuiteRunnerTest(unittest.TestCase):
'/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies\n',
''),
(0, '1 2 3 4 5 6 7 8 9 10', ''),
- (0, '', '')])
+ (0, '', ''),
+ ])
self.runner.dut_config['cpu_freq_pct'] = 100
self.runner.SetupCpuFreq(dut_runner, online)
self.assertGreaterEqual(dut_runner.call_count, 3)
@@ -582,7 +588,8 @@ class SuiteRunnerTest(unittest.TestCase):
'/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies\n',
''),
(0, '1 2 3 4 5 6 7 8 9 10', ''),
- (0, '', '')])
+ (0, '', ''),
+ ])
self.runner.dut_config['cpu_freq_pct'] = 60
self.runner.SetupCpuFreq(dut_runner, online)
self.assertGreaterEqual(dut_runner.call_count, 2)
@@ -599,7 +606,8 @@ class SuiteRunnerTest(unittest.TestCase):
'/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies\n',
''),
(0, '1 2 3 4 5 6 7 8 9 10', ''),
- (0, '', '')])
+ (0, '', ''),
+ ])
self.runner.dut_config['cpu_freq_pct'] = 0
self.runner.SetupCpuFreq(dut_runner, online)
self.assertGreaterEqual(dut_runner.call_count, 2)
@@ -619,7 +627,8 @@ class SuiteRunnerTest(unittest.TestCase):
(0, '1 2 3 4 5 6 7 8 9 10', ''),
(0, '', ''),
(0, '1 4 6 8 10 12 14 16 18 20', ''),
- (0, '', '')])
+ (0, '', ''),
+ ])
self.runner.dut_config['cpu_freq_pct'] = 70
self.runner.SetupCpuFreq(dut_runner, online)
self.assertEqual(dut_runner.call_count, 5)
@@ -721,7 +730,8 @@ class SuiteRunnerTest(unittest.TestCase):
dut_runner = mock.Mock(side_effect=[
(0, '41000\n20000\n30000\n45000', ''),
(0, '39000\n20000\n30000\n41000', ''),
- (0, '39000\n20000\n30000\n31000', '')])
+ (0, '39000\n20000\n30000\n31000', ''),
+ ])
self.runner.dut_config['cooldown_time'] = 100
self.runner.dut_config['cooldown_temp'] = 40
wait_time = self.runner.WaitCooldown(dut_runner)
@@ -739,7 +749,8 @@ class SuiteRunnerTest(unittest.TestCase):
mock_sleep.return_value = 0
dut_runner = mock.Mock(side_effect=[
(1, '39000\n20000\n30000\n41000', 'Thermal error'),
- (1, '39000\n20000\n30000\n31000', 'Thermal error')])
+ (1, '39000\n20000\n30000\n31000', 'Thermal error'),
+ ])
self.runner.dut_config['cooldown_time'] = 10
self.runner.dut_config['cooldown_temp'] = 40
wait_time = self.runner.WaitCooldown(dut_runner)