diff options
author | bulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-11 15:41:56 +0000 |
---|---|---|
committer | bulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-11 15:41:56 +0000 |
commit | 117cae2668f9004d64df74a642591d41f6bfef2b (patch) | |
tree | 8bac2070ce22ef875628773d717fd858caf4aa58 /build | |
parent | 3ac8b1c27bd58b0476648678f076150ff60a8713 (diff) | |
download | chromium_src-117cae2668f9004d64df74a642591d41f6bfef2b.zip chromium_src-117cae2668f9004d64df74a642591d41f6bfef2b.tar.gz chromium_src-117cae2668f9004d64df74a642591d41f6bfef2b.tar.bz2 |
Android: upstream latest changes for build/android.
- uses $EXTERNAL_STORAGE rather than /sdcard
- split PerfTEstSetup from android_commands.py
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com/10914199
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156017 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build')
-rw-r--r-- | build/android/pylib/android_commands.py | 36 | ||||
-rw-r--r-- | build/android/pylib/base_test_runner.py | 6 | ||||
-rw-r--r-- | build/android/pylib/constants.py | 1 | ||||
-rw-r--r-- | build/android/pylib/perf_tests_helper.py | 39 | ||||
-rw-r--r-- | build/android/pylib/run_java_tests.py | 3 | ||||
-rw-r--r-- | build/android/pylib/single_test_runner.py | 14 | ||||
-rw-r--r-- | build/android/pylib/test_package.py | 13 | ||||
-rw-r--r-- | build/android/pylib/test_package_executable.py | 9 | ||||
-rwxr-xr-x | build/android/run_tests.py | 9 |
9 files changed, 82 insertions, 48 deletions
diff --git a/build/android/pylib/android_commands.py b/build/android/pylib/android_commands.py index a9d8cf9..2b412f3 100644 --- a/build/android/pylib/android_commands.py +++ b/build/android/pylib/android_commands.py @@ -41,10 +41,6 @@ PEXPECT_LINE_RE = re.compile('\n([^\r]*)\r') # appear at the start of any line of a command's output. SHELL_PROMPT = '~+~PQ\x17RS~+~' -# This only works for single core devices. -SCALING_GOVERNOR = '/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor' -DROP_CACHES = '/proc/sys/vm/drop_caches' - # Java properties file LOCAL_PROPERTIES_PATH = '/data/local.prop' @@ -206,10 +202,10 @@ class AndroidCommands(object): if device: self._adb.SetTargetSerial(device) self._logcat = None - self._original_governor = None self._pushed_files = [] self._device_utc_offset = self.RunShellCommand('date +%z')[0] self._md5sum_path = '' + self._external_storage = '' def Adb(self): """Returns our AdbInterface to avoid us wrapping all its methods.""" @@ -224,6 +220,12 @@ class AndroidCommands(object): """Returns the year information of the date on device.""" return self.RunShellCommand('date +%Y')[0] + def GetExternalStorage(self): + if not self._external_storage: + self._external_storage = self.RunShellCommand('echo $EXTERNAL_STORAGE')[0] + assert self._external_storage, 'Unable to find $EXTERNAL_STORAGE' + return self._external_storage + def WaitForDevicePm(self): """Blocks until the device's package manager is available. @@ -296,7 +298,8 @@ class AndroidCommands(object): Returns: A status string returned by adb install """ - assert os.path.isfile(package_file_path) + assert os.path.isfile(package_file_path), ('<%s> is not file' % + package_file_path) install_cmd = ['install'] @@ -405,8 +408,9 @@ class AndroidCommands(object): sdcard_ready = False attempts = 0 wait_period = 5 + external_storage = self.GetExternalStorage() while not sdcard_ready and attempts * wait_period < timeout_time: - output = self.RunShellCommand('ls /sdcard/') + output = self.RunShellCommand('ls ' + external_storage) if output: sdcard_ready = True else: @@ -613,21 +617,6 @@ class AndroidCommands(object): path, self.RunShellCommand('ls -lR %s' % path), re_file, self._device_utc_offset) - def SetupPerformanceTest(self): - """Sets up performance tests.""" - # Disable CPU scaling to reduce noise in tests - if not self._original_governor: - self._original_governor = self.GetFileContents( - SCALING_GOVERNOR, log_result=False) - self.RunShellCommand('echo performance > ' + SCALING_GOVERNOR) - self.DropRamCaches() - - def TearDownPerformanceTest(self): - """Tears down performance tests.""" - if self._original_governor: - self.RunShellCommand('echo %s > %s' % (self._original_governor[0], - SCALING_GOVERNOR)) - self._original_governor = None def SetJavaAssertsEnabled(self, enable): """Sets or removes the device java assertions property. @@ -665,9 +654,6 @@ class AndroidCommands(object): enable and 'all' or '')) return True - def DropRamCaches(self): - """Drops the filesystem ram caches for performance testing.""" - self.RunShellCommand('echo 3 > ' + DROP_CACHES) def StartMonitoringLogcat(self, clear=True, timeout=10, logfile=None, filters=None): diff --git a/build/android/pylib/base_test_runner.py b/build/android/pylib/base_test_runner.py index 8476664..a69d024 100644 --- a/build/android/pylib/base_test_runner.py +++ b/build/android/pylib/base_test_runner.py @@ -22,8 +22,7 @@ from valgrind_tools import CreateTool # A file on device to store ports of net test server. The format of the file is # test-spawner-server-port:test-server-port -NET_TEST_SERVER_PORT_INFO_FILE = \ - constants.TEST_DATA_DIR + '/net-test-server-ports' +NET_TEST_SERVER_PORT_INFO_FILE = 'net-test-server-ports' class BaseTestRunner(object): @@ -62,7 +61,8 @@ class BaseTestRunner(object): def _PushTestServerPortInfoToDevice(self): """Pushes the latest port information to device.""" - self.adb.SetFileContents(NET_TEST_SERVER_PORT_INFO_FILE, + self.adb.SetFileContents(self.adb.GetExternalStorage() + '/' + + NET_TEST_SERVER_PORT_INFO_FILE, '%d:%d' % (self.test_server_spawner_port, self.test_server_port)) diff --git a/build/android/pylib/constants.py b/build/android/pylib/constants.py index bcda0e2..0121fd6 100644 --- a/build/android/pylib/constants.py +++ b/build/android/pylib/constants.py @@ -36,5 +36,4 @@ TEST_SERVER_PORT_LAST = 30000 TEST_SERVER_PORT_FILE = '/tmp/test_server_port' TEST_SERVER_PORT_LOCKFILE = '/tmp/test_server_port.lock' -TEST_DATA_DIR = '/sdcard' TEST_EXECUTABLE_DIR = '/data/local/tmp' diff --git a/build/android/pylib/perf_tests_helper.py b/build/android/pylib/perf_tests_helper.py index 193442e..19c24f3 100644 --- a/build/android/pylib/perf_tests_helper.py +++ b/build/android/pylib/perf_tests_helper.py @@ -4,6 +4,7 @@ import re +import android_commands # Valid values of result type. RESULT_TYPES = {'unimportant': 'RESULT ', @@ -69,3 +70,41 @@ def PrintPerfResult(measurement, trace, values, units, result_type='default', if print_to_stdout: print output return output + + +class PerfTestSetup(object): + """Provides methods for setting up a device for perf testing.""" + _DROP_CACHES = '/proc/sys/vm/drop_caches' + _SCALING_GOVERNOR = '/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor' + + def __init__(self, adb): + self._adb = adb + num_cpus = self._adb.GetFileContents('/sys/devices/system/cpu/online', + log_result=False) + assert num_cpus, 'Unable to find /sys/devices/system/cpu/online' + self._num_cpus = int(num_cpus[0].split('-')[-1]) + self._original_scaling_governor = None + + def DropRamCaches(self): + """Drops the filesystem ram caches for performance testing.""" + self._adb.RunShellCommand('echo 3 > ' + PerfTestSetup._DROP_CACHES) + + def SetUp(self): + """Sets up performance tests.""" + if not self._original_scaling_governor: + self._original_scaling_governor = self._adb.GetFileContents( + PerfTestSetup._SCALING_GOVERNOR % 0, + log_result=False)[0] + self._SetScalingGovernorInternal('performance') + self.DropRamCaches() + + def TearDown(self): + """Tears down performance tests.""" + if self._original_scaling_governor: + self._SetScalingGovernorInternal(self._original_scaling_governor) + self._original_scaling_governor = None + + def _SetScalingGovernorInternal(self, value): + for cpu in range(self._num_cpus): + self._adb.RunShellCommand( + ('echo %s > ' + PerfTestSetup._SCALING_GOVERNOR) % (value, cpu)) diff --git a/build/android/pylib/run_java_tests.py b/build/android/pylib/run_java_tests.py index 725585a..448fd42 100644 --- a/build/android/pylib/run_java_tests.py +++ b/build/android/pylib/run_java_tests.py @@ -65,7 +65,7 @@ def FilterTests(test_names, pattern_list, inclusive): class TestRunner(BaseTestRunner): """Responsible for running a series of tests connected to a single device.""" - _DEVICE_DATA_DIR = constants.TEST_DATA_DIR + '/chrome/test/data' + _DEVICE_DATA_DIR = 'chrome/test/data' _EMMA_JAR = os.path.join(os.environ.get('ANDROID_BUILD_TOP', ''), 'external/emma/lib/emma.jar') _COVERAGE_MERGED_FILENAME = 'unittest_coverage.es' @@ -166,6 +166,7 @@ class TestRunner(BaseTestRunner): '/chrome/test/data/android/device_files') if os.path.exists(host_test_files_path): self.adb.PushIfNeeded(host_test_files_path, + self.adb.GetExternalStorage() + '/' + TestRunner._DEVICE_DATA_DIR) if self.install_apk: for apk in self.apks: diff --git a/build/android/pylib/single_test_runner.py b/build/android/pylib/single_test_runner.py index e43b08b..0a2b087 100644 --- a/build/android/pylib/single_test_runner.py +++ b/build/android/pylib/single_test_runner.py @@ -10,6 +10,7 @@ import sys from base_test_runner import BaseTestRunner import debug_info import constants +import perf_tests_helper import run_tests_helper from test_package_apk import TestPackageApk from test_package_executable import TestPackageExecutable @@ -59,6 +60,9 @@ class SingleTestRunner(BaseTestRunner): self.adb, device, test_suite, timeout, rebaseline, performance_test, cleanup_test_files, self.tool, self.dump_debug_info) + self._performance_test_setup = None + if performance_test: + self._performance_test_setup = perf_tests_helper.PerfTestSetup(self.adb) def _TestSuiteRequiresMockTestServer(self): """Returns True if the test suite requires mock test server.""" @@ -256,7 +260,7 @@ class SingleTestRunner(BaseTestRunner): # Make sure SD card is ready. self.adb.WaitForSdCardReady(20) for data in test_data: - self.CopyTestData([data], constants.TEST_DATA_DIR) + self.CopyTestData([data], self.adb.GetExternalStorage()) def RunTestsWithFilter(self): """Runs a tests via a small, temporary shell script.""" @@ -317,8 +321,8 @@ class SingleTestRunner(BaseTestRunner): """Sets up necessary test enviroment for the test suite.""" super(SingleTestRunner, self).SetUp() self.adb.ClearApplicationState(constants.CHROME_PACKAGE) - if self.test_package.performance_test: - self.adb.SetupPerformanceTest() + if self._performance_test_setup: + self._performance_test_setup.SetUp() if self.dump_debug_info: self.dump_debug_info.StartRecordingLog(True) self.StripAndCopyFiles() @@ -332,8 +336,8 @@ class SingleTestRunner(BaseTestRunner): self.adb.RemovePushedFiles() if self.dump_debug_info: self.dump_debug_info.StopRecordingLog() - if self.test_package.performance_test: - self.adb.TearDownPerformanceTest() + if self._performance_test_setup: + self._performance_test_setup.TearDown() if self.dump_debug_info: self.dump_debug_info.ArchiveNewCrashFiles() super(SingleTestRunner, self).TearDown() diff --git a/build/android/pylib/test_package.py b/build/android/pylib/test_package.py index 8f28e02..f7e321d 100644 --- a/build/android/pylib/test_package.py +++ b/build/android/pylib/test_package.py @@ -110,27 +110,28 @@ class TestPackage(object): return ret def PushDataAndPakFiles(self): + external_storage = self.adb.GetExternalStorage() if (self.test_suite_basename == 'ui_unittests' or self.test_suite_basename == 'unit_tests'): self.adb.PushIfNeeded( self.test_suite_dirname + '/chrome.pak', - constants.TEST_DATA_DIR + '/paks/chrome.pak') + external_storage + '/paks/chrome.pak') self.adb.PushIfNeeded( self.test_suite_dirname + '/locales/en-US.pak', - constants.TEST_DATA_DIR + '/paks/en-US.pak') + external_storage + '/paks/en-US.pak') if self.test_suite_basename == 'unit_tests': self.adb.PushIfNeeded( self.test_suite_dirname + '/resources.pak', - constants.TEST_DATA_DIR + '/paks/resources.pak') + external_storage + '/paks/resources.pak') self.adb.PushIfNeeded( self.test_suite_dirname + '/chrome_100_percent.pak', - constants.TEST_DATA_DIR + '/paks/chrome_100_percent.pak') + external_storage + '/paks/chrome_100_percent.pak') self.adb.PushIfNeeded(self.test_suite_dirname + '/test_data', - constants.TEST_DATA_DIR + '/test_data') + external_storage + '/test_data') if self.test_suite_basename == 'content_unittests': self.adb.PushIfNeeded( self.test_suite_dirname + '/content_resources.pak', - constants.TEST_DATA_DIR + '/paks/content_resources.pak') + external_storage + '/paks/content_resources.pak') def _WatchTestOutput(self, p): """Watches the test output. diff --git a/build/android/pylib/test_package_executable.py b/build/android/pylib/test_package_executable.py index 359de3a..292bac4 100644 --- a/build/android/pylib/test_package_executable.py +++ b/build/android/pylib/test_package_executable.py @@ -18,7 +18,7 @@ from test_package import TestPackage class TestPackageExecutable(TestPackage): """A helper class for running stand-alone executables.""" - _TEST_RUNNER_RET_VAL_FILE = constants.TEST_DATA_DIR + '/gtest_retval' + _TEST_RUNNER_RET_VAL_FILE = 'gtest_retval' def __init__(self, adb, device, test_suite, timeout, rebaseline, performance_test, cleanup_test_files, tool, dump_debug_info, @@ -48,7 +48,9 @@ class TestPackageExecutable(TestPackage): ret_code_file = tempfile.NamedTemporaryFile() try: if not self.adb.Adb().Pull( - TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE, ret_code_file.name): + self.adb.GetExternalStorage() + '/' + + TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE, + ret_code_file.name): logging.critical('Unable to pull gtest ret val file %s', ret_code_file.name) raise ValueError @@ -74,7 +76,8 @@ class TestPackageExecutable(TestPackage): logging.info('NATIVE_COVERAGE_DEPTH_STRIP is not defined: ' 'No native coverage.') return '' - export_string = 'export GCOV_PREFIX="%s/gcov"\n' % constants.TEST_DATA_DIR + export_string = ('export GCOV_PREFIX="%s/gcov"\n' % + self.adb.GetExternalStorage()) export_string += 'export GCOV_PREFIX_STRIP=%s\n' % depth return export_string diff --git a/build/android/run_tests.py b/build/android/run_tests.py index 95abe1d..84a1399 100755 --- a/build/android/run_tests.py +++ b/build/android/run_tests.py @@ -8,17 +8,18 @@ 1. Copy over test binary to /data/local on device. 2. Resources: chrome/unit_tests requires resources (chrome.pak and en-US.pak) - to be deployed to the device (in TEST_DATA_DIR). + to be deployed to the device. We use the device's $EXTERNAL_STORAGE as the + base dir (which maps to Context.getExternalFilesDir()). 3. Environment: 3.1. chrome/unit_tests requires (via chrome_paths.cc) a directory named: - TEST_DATA_DIR + /chrome/test/data + $EXTERNAL_STORAGE + /chrome/test/data 3.2. page_cycler_tests have following requirements, 3.2.1 the following data on host: <chrome_src_dir>/tools/page_cycler <chrome_src_dir>/data/page_cycler 3.2.2. two data directories to store above test data on device named: - TEST_DATA_DIR + /tools/ (for database perf test) - TEST_DATA_DIR + /data/ (for other perf tests) + $EXTERNAL_STORAGE + /tools/ (for database perf test) + $EXTERNAL_STORAGE + /data/ (for other perf tests) 3.2.3. a http server to serve http perf tests. The http root is host's <chrome_src_dir>/data/page_cycler/, port 8000. 3.2.4 a tool named forwarder is also required to run on device to |