[Android] Create a dummy app to upload to Appurify for gtests.

BUG=428729

Review URL: https://codereview.chromium.org/833403002

Cr-Original-Commit-Position: refs/heads/master@{#310159}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 335cbe5177b3d0ec5d5564b646cb1a7b814c26d2
This commit is contained in:
jbudorick 2015-01-06 14:26:52 -08:00 коммит произвёл Commit bot
Родитель 202e159d99
Коммит 17a5f2e42e
7 изменённых файлов: 87 добавлений и 28 удалений

Просмотреть файл

@ -0,0 +1,14 @@
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")
# GYP: //build/android/pylib/remote/device/dummy/dummy.gyp:remote_device_dummy_apk
android_apk("remote_device_dummy_apk") {
android_manifest = "//build/android/AndroidManifest.xml"
java_files = [ "src/org/chromium/dummy/Dummy.java" ]
apk_name = "remote_device_dummy"
testonly = true
}

Просмотреть файл

@ -0,0 +1,25 @@
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Running gtests on a remote device via am instrument requires both an "app"
# APK and a "test" APK with different package names. Our gtests only use one
# APK, so we build a dummy APK to upload as the app.
{
'targets': [
{
# GN: //build/android/pylib/remote/device/dummy:remote_device_dummy_apk
'target_name': 'remote_device_dummy_apk',
'type': 'none',
'variables': {
'apk_name': 'remote_device_dummy',
'java_in_dir': '.',
'android_manifest_path': '../../../../../../build/android/AndroidManifest.xml',
},
'includes': [
'../../../../../../build/java_apk.gypi',
]
},
]
}

Просмотреть файл

@ -0,0 +1,9 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.dummy;
/** Does nothing. */
class Dummy {}

Просмотреть файл

@ -18,7 +18,6 @@ from pylib.remote.device import remote_device_helper
class RemoteDeviceGtestRun(remote_device_test_run.RemoteDeviceTestRun):
"""Run gtests and uirobot tests on a remote device."""
DEFAULT_RUNNER_TYPE = 'robotium'
DEFAULT_RUNNER_PACKAGE = (
'org.chromium.native_test.ChromiumNativeTestInstrumentationTestRunner')
@ -30,24 +29,22 @@ class RemoteDeviceGtestRun(remote_device_test_run.RemoteDeviceTestRun):
def _TriggerSetUp(self):
"""Set up the triggering of a test run."""
logging.info('Triggering test run.')
self._app_id = self._UploadAppToDevice(self._test_instance.apk)
if not self._env.runner_type:
runner_type = self.DEFAULT_RUNNER_TYPE
logging.info('Using default runner type: %s', self.DEFAULT_RUNNER_TYPE)
else:
runner_type = self._env.runner_type
if self._env.runner_type:
logging.warning('Ignoring configured runner_type "%s"',
self._env.runner_type)
if not self._env.runner_package:
runner_package = self.DEFAULT_RUNNER_PACKAGE
logging.info('Using default runner package: %s',
self.DEFAULT_RUNNER_TYPE)
self.DEFAULT_RUNNER_PACKAGE)
else:
runner_package = self._env.runner_package
self._test_id = self._UploadTestToDevice(runner_type)
config_body = {'runner': runner_package}
self._SetTestConfig(runner_type, config_body)
dummy_app_path = os.path.join(
constants.GetOutDirectory(), 'apks', 'remote_device_dummy.apk')
self._AmInstrumentTestSetup(dummy_app_path, self._test_instance.apk,
runner_package)
_INSTRUMENTATION_STREAM_LEADER = 'INSTRUMENTATION_STATUS: stream='

Просмотреть файл

@ -138,28 +138,37 @@ class RemoteDeviceTestRun(test_run.TestRun):
logging.info('Test status: %s' % self._results['detailed_status'])
return self._results['status']
def _UploadAppToDevice(self, apk_path):
def _AmInstrumentTestSetup(self, app_path, test_path, runner_package):
config = {'runner': runner_package}
self._app_id = self._UploadAppToDevice(app_path)
self._test_id = self._UploadTestToDevice('robotium', test_path)
logging.info('Setting config: %s' % config)
self._SetTestConfig('robotium', config)
def _UploadAppToDevice(self, app_path):
"""Upload app to device."""
logging.info('Upload %s to remote service.' % apk_path)
apk_name = os.path.basename(apk_path)
with open(apk_path, 'rb') as apk_src:
upload_results = appurify_sanitized.api.apps_upload(self._env.token,
apk_src, 'raw', name=apk_name)
logging.info('Upload %s to remote service.' % app_path)
apk_name = os.path.basename(app_path)
with open(app_path, 'rb') as apk_src:
upload_results = appurify_sanitized.api.apps_upload(
self._env.token, apk_src, 'raw', name=apk_name)
remote_device_helper.TestHttpResponse(
upload_results, 'Unable to upload %s.' %(apk_path))
upload_results, 'Unable to upload %s.' % app_path)
return upload_results.json()['response']['app_id']
def _UploadTestToDevice(self, test_type):
def _UploadTestToDevice(self, test_type, test_path):
"""Upload test to device
Args:
test_type: Type of test that is being uploaded. Ex. uirobot, gtest..
"""
logging.info('Uploading %s to remote service.' % self._test_instance.apk)
with open(self._test_instance.apk, 'rb') as test_src:
logging.info('Uploading %s to remote service.' % test_path)
with open(test_path, 'rb') as test_src:
upload_results = appurify_sanitized.api.tests_upload(
self._env.token, test_src, 'raw', test_type, app_id=self._app_id)
self._env.token, test_src, 'raw', test_type)
remote_device_helper.TestHttpResponse(upload_results,
'Unable to upload %s.' %(self._test_instance.apk))
'Unable to upload %s.' % test_path)
return upload_results.json()['response']['test_id']
def _SetTestConfig(self, runner_type, body):
@ -174,7 +183,7 @@ class RemoteDeviceTestRun(test_run.TestRun):
config.write(''.join('%s\n' % l for l in config_data))
config.flush()
config.seek(0)
config_response = appurify_sanitized.api.config_upload(self._env.token,
config, self._test_id)
remote_device_helper.TestHttpResponse(config_response,
'Unable to upload test config.')
config_response = appurify_sanitized.api.config_upload(
self._env.token, config, self._test_id)
remote_device_helper.TestHttpResponse(
config_response, 'Unable to upload test config.')

Просмотреть файл

@ -21,6 +21,7 @@
'dependencies': [
'<(DEPTH)/base/base.gyp:base_java',
'<(DEPTH)/build/android/pylib/device/commands/commands.gyp:chromium_commands',
'<(DEPTH)/build/android/pylib/remote/device/dummy/dummy.gyp:remote_device_dummy_apk',
'<(DEPTH)/tools/android/android_tools.gyp:android_tools',
],
'conditions': [

Просмотреть файл

@ -1450,7 +1450,10 @@ template("unittest_apk") {
android_apk(target_name) {
_apk_name = test_suite_name
final_apk_path = "$root_build_dir/${_apk_name}_apk/${_apk_name}-debug.apk"
java_files = [ "//testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java" ]
java_files = [
"//testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java",
"//testing/android/java/src/org/chromium/native_test/ChromiumNativeTestInstrumentationTestRunner.java",
]
android_manifest = "//testing/android/java/AndroidManifest.xml"
native_libs = [ unittests_binary ]
if (defined(invoker.asset_location)) {
@ -1458,6 +1461,7 @@ template("unittest_apk") {
}
deps = [
"//base:base_java",
"//build/android/pylib/remote/device/dummy:remote_device_dummy_apk",
]
if (defined(invoker.deps)) {
deps += invoker.deps